1package policy23import (4 "context"56 "github.com/FelineStateMachine/tinyrelay/internal/event"7 "github.com/FelineStateMachine/tinyrelay/internal/peerurl"8)910// PrivateRepositoryLookup supplies the stored repository privacy marker for11// replaceable repository state events. It keeps the policy package independent12// from the storage implementation.13type PrivateRepositoryLookup interface {14 IsPrivateRepository(ctx context.Context, pubkey, identifier string) (bool, error)15}1617// PrivateServiceEnabled reports whether the tenant has the complete GRASP-0818// private service contract enabled.19func (p Policy) PrivateServiceEnabled() bool {20 return p.Features.Grasp && p.Features.Grasp08 && p.Reads == "members"21}2223// PrivateRepository reports whether an event is a private repository event.24// Repository state inherits privacy from its corresponding announcement.25func PrivateRepository(ctx context.Context, lookup PrivateRepositoryLookup, e event.Event) (bool, error) {26 if IsPrivateRepository(e) {27 return true, nil28 }29 if lookup == nil || e.Kind != event.KIND_REPO_STATE {30 return false, nil31 }32 return lookup.IsPrivateRepository(ctx, e.PubKey, event.Tag(e, "d"))33}3435// PrivatePeerBase returns the configured HTTP base for a private peer URL.36func PrivatePeerBase(source string, peers []string) string {37 return peerurl.Match(source, peers)38}