tinyrelayfile
tinyrelay/internal/policy/privacy.go/

internal/policy/privacy.go raw
1package policy
2
3import (
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.
13type 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.
19func (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.
25func 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.
36func PrivatePeerBase(source string, peers []string) string {
37 return peerurl.Match(source, peers)
38}

About

ownerc01503e8035f
visibilitypublic
headd730679639bf

Maintainers

  • c01503e8035f owner
  • ba1b5beed5b5 agent hermes

Clone

  • https://012.run/npub1cq2s86qrtadf36eqq3epm38wmhdynrrcwxf84eldk3f94dkv7ttsrulrz5/tinyrelay.git

Refs