| 1 | package tinygit |
| 2 | |
| 3 | import ( |
| 4 | "github.com/FelineStateMachine/tinyrelay/protocol/nostr" |
| 5 | ) |
| 6 | |
| 7 | // Event is the signed Nostr wire event accepted by the Git engine. Clients |
| 8 | // sign events themselves; the server never needs their private keys. |
| 9 | type Event = nostr.Event |
| 10 | |
| 11 | // Policy contains the policy values used by the Git engine. Hosts may keep a |
| 12 | // richer policy internally and adapt these values at the integration boundary. |
| 13 | type Policy struct { |
| 14 | Owner string |
| 15 | Reads string |
| 16 | PrivatePeers []string |
| 17 | Features PolicyFeatures |
| 18 | } |
| 19 | |
| 20 | // PolicyFeatures selects optional Git protocol capabilities. |
| 21 | type PolicyFeatures struct { |
| 22 | Grasp bool |
| 23 | Grasp02 bool |
| 24 | Grasp03 bool |
| 25 | Grasp05 bool |
| 26 | Grasp06 bool |
| 27 | Grasp08 bool |
| 28 | } |
| 29 | |
| 30 | func (p Policy) PrivateServiceEnabled() bool { |
| 31 | return p.Features.Grasp && p.Features.Grasp08 && p.Reads == "members" |
| 32 | } |
| 33 | |
| 34 | // DefaultPolicy returns the defaults for an embedded engine. |
| 35 | func DefaultPolicy(owner string) Policy { |
| 36 | return Policy{Owner: owner, Reads: "open" } |
| 37 | } |
| 38 | |
| 39 | func (g *GitRelay) policyValue() Policy { |
| 40 | if g.policy == nil { |
| 41 | return DefaultPolicy("" ) |
| 42 | } |
| 43 | return g.policy() |
| 44 | } |