oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1package wire
2
3import (
4 "net/url"
5 "regexp"
6 "strings"
7 "unicode"
8 "unicode/utf8"
9)
10
11const (
12 ToolRequestAccess = "request_access"
13 FrameRequestAccess = "request_access"
14 FrameAccess = "access"
15)
16
17// AccessRequest is a proposal until the person confirms its exact fields.
18type AccessRequest struct {
19 ApprovalOpened bool `json:"approval_opened,omitempty"`
20 Target string `json:"target"`
21 Role string `json:"role,omitempty"`
22 Reason string `json:"reason"`
23 State string `json:"state,omitempty"`
24 RequestID string `json:"request_id,omitempty"`
25 ApproveURL string `json:"approve_url,omitempty"`
26 Expires int64 `json:"expires,omitempty"`
27}
28type AccessCommand struct {
29 CardID string `json:"card_id"`
30 Person string `json:"person"`
31 Target string `json:"target"`
32 Role string `json:"role"`
33 Reason string `json:"reason"`
34 Confirmed bool `json:"confirmed"`
35}
36type AccessReport struct {
37 CardID string `json:"card_id"`
38 Person string `json:"person"`
39 RequestID string `json:"request_id"`
40 State string `json:"state"`
41 ApproveURL string `json:"approve_url,omitempty"`
42 Expires int64 `json:"expires,omitempty"`
43}
44
45var accessTarget = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]{0,99}(/[A-Za-z0-9][A-Za-z0-9_.-]{0,99})?$`)
46
47func ValidAccessTarget(s string) bool { return accessTarget.MatchString(s) }
48func AccessFinal(state string) bool {
49 switch state {
50 case "approved", "declined", "expired", "limited", "failed", "unconfirmed", "missing", "uncheckable", "authority", "not_owned", "already":
51 return true
52 }
53 return false
54}
55func AccessRole(s string) bool { return s == "agent" || s == "reader" || s == "runner" }
56
57// Amadan 1dadddf internal/hub/server.go:993 and agent_access.go:547.
58func AccessURL(s, id string) bool {
59 if !accessTarget.MatchString(id) || strings.Contains(id, "/") {
60 return false
61 }
62 u, err := url.Parse(s)
63 return err == nil && u.Scheme == "https" && u.Host == "amadan.net" && u.User == nil && u.RawQuery == "" && !u.ForceQuery && u.Fragment == "" && u.RawFragment == "" && u.RawPath == "" && !strings.ContainsAny(s, "\\#") && u.Path == "/settings/agents/requests/"+id
64}
65
66func ValidAccessReason(s string) bool {
67 if strings.TrimSpace(s) == "" || !utf8.ValidString(s) || utf8.RuneCountInString(s) > 280 {
68 return false
69 }
70 for _, r := range s {
71 if unicode.IsControl(r) || unicode.Is(unicode.Cf, r) {
72 return false
73 }
74 }
75 return true
76}
77