// Package teamprobe answers GET /api/team, the readiness probe Alta reads // before it activates a team Equipo in Home's directory (oficina/alta // design/team-bundle, spec ยง1.2). // // Equipo has no Home roster mode: its owners are seeded from // EQUIPO_OWNERS, so it answers in the seeded mode. It names the Home // consumer it was configured as, and whether an active owner exists. It // carries no address, name or count, and needs no session. An instance // without Home has no consumer and is never ready: 404. package teamprobe import ( "encoding/json" "net/http" "amadan.net/oficina/home/connect" "gorm.io/gorm" ) // Handler is the probe over Equipo's members table. func Handler(home *connect.DecodedCredentials, db *gorm.DB) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { if home == nil || home.ConsumerID == "" { http.NotFound(w, r) return } var owners int64 if err := db.WithContext(r.Context()).Raw(`SELECT count(*) FROM members WHERE active = 1 AND role = 'owner'`).Scan(&owners).Error; err != nil { http.Error(w, http.StatusText(http.StatusServiceUnavailable), http.StatusServiceUnavailable) return } roster := "owner-pending" if owners > 0 { roster = "ok" } w.Header().Set("Content-Type", "application/json") w.Header().Set("Cache-Control", "no-store") _ = json.NewEncoder(w).Encode(struct { TeamMode bool `json:"team_mode"` Seeded bool `json:"seeded"` Consumer string `json:"consumer"` Roster string `json:"roster"` }{false, true, home.ConsumerID, roster}) } }