| 1 | package policy |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "github.com/FelineStateMachine/tinyrelay/internal/event" |
| 7 | "github.com/FelineStateMachine/tinyrelay/internal/peerurl" |
| 8 | ) |
| 9 | |
| 10 | // PrivateRepositoryLookup supplies the stored repository privacy marker for |
| 11 | // replaceable repository state events. It keeps the policy package independent |
| 12 | // from the storage implementation. |
| 13 | type PrivateRepositoryLookup interface { |
| 14 | IsPrivateRepository(ctx context.Context, pubkey, identifier string) (bool, error) |
| 15 | } |
| 16 | |
| 17 | // PrivateServiceEnabled reports whether the tenant has the complete GRASP-08 |
| 18 | // private service contract enabled. |
| 19 | func (p Policy) PrivateServiceEnabled() bool { |
| 20 | return p.Features.Grasp && p.Features.Grasp08 && p.Reads == "members" |
| 21 | } |
| 22 | |
| 23 | // PrivateRepository reports whether an event is a private repository event. |
| 24 | // Repository state inherits privacy from its corresponding announcement. |
| 25 | func PrivateRepository(ctx context.Context, lookup PrivateRepositoryLookup, e event.Event) (bool, error) { |
| 26 | if IsPrivateRepository(e) { |
| 27 | return true, nil |
| 28 | } |
| 29 | if lookup == nil || e.Kind != event.KIND_REPO_STATE { |
| 30 | return false, nil |
| 31 | } |
| 32 | return lookup.IsPrivateRepository(ctx, e.PubKey, event.Tag(e, "d" )) |
| 33 | } |
| 34 | |
| 35 | // PrivatePeerBase returns the configured HTTP base for a private peer URL. |
| 36 | func PrivatePeerBase(source string, peers []string) string { |
| 37 | return peerurl.Match(source, peers) |
| 38 | } |