feat(allowlist): owner allowlist enforcement
This commit is contained in:
25
internal/allowlist/allowlist.go
Normal file
25
internal/allowlist/allowlist.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package allowlist
|
||||
|
||||
import "fmt"
|
||||
|
||||
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}
|
||||
}
|
||||
|
||||
func (a *Allowlist) Check(owner string) error {
|
||||
if owner == "" {
|
||||
return fmt.Errorf("owner required")
|
||||
}
|
||||
if _, ok := a.owners[owner]; !ok {
|
||||
return fmt.Errorf("owner %q not in allowlist", owner)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user