oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package equipo
2
3import (
4 "amadan.net/oficina/equipo/internal/equipo/identity"
5 "amadan.net/oficina/equipo/internal/equipo/setup"
6 "amadan.net/oficina/equipo/internal/release"
7 "amadan.net/rastrillo/rastrillo"
8 "io"
9 "net/http"
10)
11
12type OnboardingState = setup.OnboardingState
13
14func (a *application) onboardingHandler() *setup.OnboardingHandler {
15 instance, _ := runnerInstance(a.store.db.G)
16 return &setup.OnboardingHandler{InstanceID: instance, InstallAvailable: a.installAssets.CachedAvailable, Store: a.store, Origin: a.origin, Version: rastrillo.BuildVersion, Manifest: release.BuildManifest(), Invalid: ErrInvalid, Failure: a.failure,
17 Actor: func(r *http.Request) (Actor, error) {
18 id, ok := identity.From(r)
19 if !ok {
20 return Actor{}, ErrForbidden
21 }
22 return Actor{Address: id.Address}, nil
23 },
24 Render: func(w http.ResponseWriter, r *http.Request, v setup.OnboardingView) {
25 data, e := a.page(r, "connections")
26 if e != nil {
27 a.failure(w, r, e)
28 return
29 }
30 data.Onboarding = v
31 data.Title = "onboarding.title"
32 render(w, "onboarding", data)
33 },
34 }
35}
36
37// installScript is `curl -fsSL https://<instance>/install.sh | sh` (Mac
38// runners spec §3.2): one line that runs this release's versioned,
39// verified bootstrap for this instance, on a Mac or on Linux. It holds
40// no secret: the release, the address and the team the runner enrols
41// with, which a person still approves.
42func (a *application) installScript(w http.ResponseWriter, r *http.Request) {
43 instance, err := runnerInstance(a.store.db.G)
44 body, berr := installScriptBody(a.origin, rastrillo.BuildVersion, instance)
45 if err != nil || berr != nil || !a.installAssets.CachedAvailable() {
46 w.WriteHeader(http.StatusServiceUnavailable)
47 return
48 }
49 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
50 w.Header().Set("Cache-Control", "no-store")
51 w.Header().Set("X-Content-Type-Options", "nosniff")
52 _, _ = io.WriteString(w, body)
53}
54
55func installScriptBody(origin, version, instance string) (string, error) {
56 command, err := release.InstallCommand(origin, version, instance)
57 if err != nil {
58 return "", err
59 }
60 return "#!/bin/sh\nset -eu\n" + command + "\n", nil
61}
62