Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

refactor

c5902451905acdaa478f8476844ccd4a510d9ca9 · Keenan Nemetz · 17d ago · parent ec2aba4b

internal/acl/acl.go → forge/access/acl.go +2−9

@@ -1,6 +1,6 @@
1 // Package acl implements Vole's role model. One policy function is used by both
1 // The role model below is used by both
2 2 // the pre-receive hook and the web handlers so the two can never disagree.
3 package acl
3 package access
4 4
5 5 import (
6 6 "encoding/json"
@@ -31,7 +31,6 @@ func ParseRole(s string) (Role, error) {
31 31 }
32 32 return None, fmt.Errorf("unknown role %q (want none, read, write or admin)", s)
33 33 }
34
35 34 func (r Role) String() string {
36 35 switch r {
37 36 case Read:
@@ -43,7 +42,6 @@ func (r Role) String() string {
43 42 }
44 43 return "none"
45 44 }
46
47 45 func (r Role) AtLeast(need Role) bool { return r >= need }
48 46
49 47 // ACL is one repository's rules. They live in the instance database beside the roster
@@ -127,7 +125,6 @@ func (a *ACL) RequiredApprovals() int {
127 125 }
128 126 return *a.ApprovalsRequired
129 127 }
130
131 128 func Empty(owner string) *ACL {
132 129 a := &ACL{Version: 1, Default: "none", Entries: map[string]string{}}
133 130 if owner != "" {
@@ -135,7 +132,6 @@ func Empty(owner string) *ACL {
135 132 }
136 133 return a
137 134 }
138
139 135 func Parse(data []byte) (*ACL, error) {
140 136 a := &ACL{}
141 137 if err := json.Unmarshal(data, a); err != nil {
@@ -161,7 +157,6 @@ func Parse(data []byte) (*ACL, error) {
161 157 a.SetRunners(a.Runners)
162 158 return a, nil
163 159 }
164
165 160 func (a *ACL) Bytes() ([]byte, error) {
166 161 b, err := json.MarshalIndent(a, "", " ")
167 162 if err != nil {
@@ -184,7 +179,6 @@ func (a *ACL) RoleFor(user string) Role {
184 179 def, _ := ParseRole(a.Default)
185 180 return def
186 181 }
187
188 182 func (a *ACL) Can(user string, need Role) bool { return a.RoleFor(user).AtLeast(need) }
189 183
190 184 // IsProtected reports whether ref matches a protected pattern. Patterns are an
@@ -217,7 +211,6 @@ func (a *ACL) SetEntry(user, role string) error {
217 211 a.Entries[user] = r.String()
218 212 return nil
219 213 }
220
221 214 func (a *ACL) Principals() []string {
222 215 out := make([]string, 0, len(a.Entries))
223 216 for k := range a.Entries {