oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package runnerproto
2
3import (
4 "context"
5 "net/http"
6 "time"
7)
8
9type LoginDisplay struct {
10 VerificationURI, UserCode string
11 ExpiresAt time.Time
12}
13type AccountSetup struct {
14 ID, RunnerID, Provider, Label, State, Mode string
15 Challenge *LoginDisplay
16 ConnectionID string
17 Revision int64
18}
19
20// AccountSetupResult deliberately has no provider challenge ID, home or return code.
21type AccountSetupResult struct {
22 ID, State, AccountID, ProviderVersion string
23 Revision int64
24 Challenge *LoginDisplay
25}
26type AccountSetupRequest struct {
27 Version int `json:"version"`
28 ID string `json:"id"`
29 Result *AccountSetupResult `json:"result,omitempty"`
30}
31
32// Terminal passthrough has no instance display contract. Reject all supplied
33// display data until a separately verified projection is introduced.
34func ValidLoginDisplay(_, _ string, d *LoginDisplay, _ time.Time) bool { return d == nil }
35
36type AccountSetupAPI interface {
37 RunnerAccountSetup(context.Context, RunnerPrincipal, string) (AccountSetup, error)
38 ReportAccountSetup(context.Context, RunnerPrincipal, AccountSetupResult) (AccountSetup, error)
39}
40
41func (s *Handler) runnerAccountSetup(w http.ResponseWriter, r *http.Request) {
42 p, _, ok := s.Bearer(w, r)
43 if !ok {
44 return
45 }
46 var q AccountSetupRequest
47 if !s.Body(w, r, &q, 4096) {
48 return
49 }
50 if q.Version != 2 || q.ID == "" || len(q.ID) > 128 || q.Result != nil && q.Result.ID != q.ID {
51 s.Failure(w, s.Invalid)
52 return
53 }
54 if s.AccountSetups == nil {
55 s.Failure(w, s.Unavailable)
56 return
57 }
58 var out AccountSetup
59 var err error
60 if q.Result == nil {
61 out, err = s.AccountSetups.RunnerAccountSetup(r.Context(), p, q.ID)
62 } else {
63 out, err = s.AccountSetups.ReportAccountSetup(r.Context(), p, *q.Result)
64 }
65 if err != nil {
66 s.Failure(w, err)
67 return
68 }
69 s.JSON(w, 200, WorkResponse{Version: 2, Result: out})
70}
71