package allowlist import ( "context" "fmt" "git.d-ma.be/mathias/gitea-mcp/internal/gitea" ) type Allowlist struct { owners map[string]struct{} } func New(owners []string) *Allowlist { m := make(map[string]struct{}, len(owners)) for _, o := range owners { m[o] = struct{}{} } return &Allowlist{owners: m} } // Check gates owner access to the static list — except for a caller // authenticated with their own Gitea PAT (pass-through, gitea-mcp#59), whose // access Gitea's own permission model already gates more precisely than a // coarse owner name list ever could. func (a *Allowlist) Check(ctx context.Context, owner string) error { if owner == "" { return fmt.Errorf("owner required") } if _, ok := gitea.TokenFromContext(ctx); ok { return nil } if _, ok := a.owners[owner]; !ok { return fmt.Errorf("owner %q not in allowlist", owner) } return nil }