oficina / home Public

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

Plain git — no account needed to clone.

Download

Download this file

1package teammode
2
3import (
4 "encoding/json"
5 "net/http"
6)
7
8// ProbePath is the readiness probe Alta polls at provisioning step 11
9// before it activates an instance in Home's directory (team-members.md §7;
10// Alta provision/steps.go TeamProbe). Mount Probe there for GET.
11const ProbePath = "/api/team"
12
13type probeBody struct {
14 TeamMode bool `json:"team_mode"`
15 Consumer string `json:"consumer,omitempty"`
16 Roster string `json:"roster,omitempty"`
17}
18
19// Probe answers GET /api/team, unauthenticated, with only {team_mode,
20// consumer, roster}: whether this instance runs in team mode, the consumer
21// ID its verified provisioning record names, and RosterState. No account
22// data — no subject, role, member count, address, team ID or issuer — and
23// nothing that differs with who is asking. A nil Runtime (team mode off)
24// answers {"team_mode":false} and nothing else. Docs' and Sheets' probe,
25// byte for byte.
26func Probe(t *Runtime) http.Handler {
27 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
28 body := probeBody{}
29 if t != nil {
30 body = probeBody{TeamMode: true, Consumer: t.bindings.Consumer, Roster: t.RosterState(r.Context())}
31 }
32 raw, err := json.Marshal(body)
33 if err != nil {
34 http.Error(w, "Unavailable.", http.StatusInternalServerError)
35 return
36 }
37 w.Header().Set("Content-Type", "application/json; charset=utf-8")
38 // Readiness changes from one second to the next; a cached "ok"
39 // would let Alta activate an instance whose roster has gone stale.
40 w.Header().Set("Cache-Control", "no-store")
41 w.Header().Set("X-Content-Type-Options", "nosniff")
42 _, _ = w.Write(raw)
43 })
44}
45