oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package thin
2
3import (
4 "encoding/json"
5 "net/http"
6 "time"
7)
8
9// Copied from amadan/amadan 1dadddf6163bb40485b9e039f8ce9085efc81274,
10// internal/cli/agentaccess.go:26-48. The handlers emit this shape in
11// internal/hub/agent_access.go:526-576 (POST and GET both call it).
12type testAccessInfo struct {
13 ID string `json:"id"`
14 State string `json:"state"`
15 Agent string `json:"agent"`
16 Operator string `json:"operator"`
17 Target string `json:"target"`
18 NS string `json:"ns"`
19 Repo string `json:"repo"`
20 Role string `json:"role"`
21 Reason string `json:"reason"`
22 Created int64 `json:"created"`
23 Expires int64 `json:"expires"`
24 Decided int64 `json:"decided"`
25 DecidedBy string `json:"decided_by,omitempty"`
26 ApproveURL string `json:"approve_url"`
27 Existing bool `json:"existing,omitempty"`
28 Events []struct {
29 Kind string `json:"kind"`
30 Actor string `json:"actor,omitempty"`
31 At int64 `json:"at"`
32 } `json:"events,omitempty"`
33}
34
35func accessResponse(id, state string) testAccessInfo {
36 c := accessCommand()
37 now := time.Now().Unix()
38 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}
39}
40func writeAccessInfo(w http.ResponseWriter, v testAccessInfo) {
41 raw, _ := json.Marshal(v)
42 var body map[string]any
43 json.Unmarshal(raw, &body)
44 if _, ok := body["events"]; !ok {
45 body["events"] = []any{}
46 }
47 json.NewEncoder(w).Encode(body)
48}
49func writeAccess(w http.ResponseWriter, id, state string) {
50 writeAccessInfo(w, accessResponse(id, state))
51}
52
53// Copied from the same Amadan commit, internal/hub/agent_meta.go:35-43.
54type testAccessAgentMeta struct {
55 Session string `json:"session,omitempty"`
56 Harness string `json:"harness,omitempty"`
57 Host string `json:"host,omitempty"`
58 Driven *bool `json:"driven,omitempty"`
59
60 Driver string `json:"-"`
61}
62
63// POST body copied from internal/hub/agent_access.go:161-166.
64type testAccessCreate struct {
65 Target string `json:"target"`
66 Role string `json:"role"`
67 Reason string `json:"reason"`
68 Agent *testAccessAgentMeta `json:"agent"`
69}
70