package thin import ( "encoding/json" "net/http" "time" ) // Copied from amadan/amadan 1dadddf6163bb40485b9e039f8ce9085efc81274, // internal/cli/agentaccess.go:26-48. The handlers emit this shape in // internal/hub/agent_access.go:526-576 (POST and GET both call it). type testAccessInfo struct { ID string `json:"id"` State string `json:"state"` Agent string `json:"agent"` Operator string `json:"operator"` Target string `json:"target"` NS string `json:"ns"` Repo string `json:"repo"` Role string `json:"role"` Reason string `json:"reason"` Created int64 `json:"created"` Expires int64 `json:"expires"` Decided int64 `json:"decided"` DecidedBy string `json:"decided_by,omitempty"` ApproveURL string `json:"approve_url"` Existing bool `json:"existing,omitempty"` Events []struct { Kind string `json:"kind"` Actor string `json:"actor,omitempty"` At int64 `json:"at"` } `json:"events,omitempty"` } func accessResponse(id, state string) testAccessInfo { c := accessCommand() now := time.Now().Unix() return testAccessInfo{ID: id, State: state, Agent: "equipo~owner@example.com", Operator: "owner@example.com", Target: c.Target, NS: "carlos", Repo: "platform", Role: c.Role, Reason: c.Reason, Created: now, Expires: now + 72*3600, ApproveURL: "https://amadan.net/settings/agents/requests/" + id} } func writeAccessInfo(w http.ResponseWriter, v testAccessInfo) { raw, _ := json.Marshal(v) var body map[string]any json.Unmarshal(raw, &body) if _, ok := body["events"]; !ok { body["events"] = []any{} } json.NewEncoder(w).Encode(body) } func writeAccess(w http.ResponseWriter, id, state string) { writeAccessInfo(w, accessResponse(id, state)) } // Copied from the same Amadan commit, internal/hub/agent_meta.go:35-43. type testAccessAgentMeta struct { Session string `json:"session,omitempty"` Harness string `json:"harness,omitempty"` Host string `json:"host,omitempty"` Driven *bool `json:"driven,omitempty"` Driver string `json:"-"` } // POST body copied from internal/hub/agent_access.go:161-166. type testAccessCreate struct { Target string `json:"target"` Role string `json:"role"` Reason string `json:"reason"` Agent *testAccessAgentMeta `json:"agent"` }