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/access/access.go → forge/access/store.go +4−9
| @@ -14,12 +14,9 @@ package access | |||
| 14 | 14 | import ( | |
| 15 | 15 | "database/sql" | |
| 16 | 16 | "fmt" | |
| 17 | _ "modernc.org/sqlite" | ||
| 17 | 18 | "os" | |
| 18 | 19 | "time" | |
| 19 | |||
| 20 | "github.com/rodent-software/vole/internal/acl" | ||
| 21 | |||
| 22 | _ "modernc.org/sqlite" | ||
| 23 | 20 | ) | |
| 24 | 21 | ||
| 25 | 22 | type Store struct { | |
| @@ -52,12 +49,11 @@ CREATE TABLE IF NOT EXISTS repo_acl ( | |||
| 52 | 49 | } | |
| 53 | 50 | return &Store{db: db}, nil | |
| 54 | 51 | } | |
| 55 | |||
| 56 | 52 | func (s *Store) Close() error { return s.db.Close() } | |
| 57 | 53 | ||
| 58 | 54 | // Get returns a repository's rules, or nil when it has none — which callers must treat | |
| 59 | 55 | // as deny-everything, the same as a repository that never had an ACL. | |
| 60 | func (s *Store) Get(repoID string) (*acl.ACL, error) { | ||
| 56 | func (s *Store) Get(repoID string) (*ACL, error) { | ||
| 61 | 57 | var raw string | |
| 62 | 58 | err := s.db.QueryRow(`SELECT acl FROM repo_acl WHERE repo_id = ?`, repoID).Scan(&raw) | |
| 63 | 59 | if err == sql.ErrNoRows { | |
| @@ -66,7 +62,7 @@ func (s *Store) Get(repoID string) (*acl.ACL, error) { | |||
| 66 | 62 | if err != nil { | |
| 67 | 63 | return nil, err | |
| 68 | 64 | } | |
| 69 | a, err := acl.Parse([]byte(raw)) | ||
| 65 | a, err := Parse([]byte(raw)) | ||
| 70 | 66 | if err != nil { | |
| 71 | 67 | return nil, fmt.Errorf("access: %s: %w", repoID, err) | |
| 72 | 68 | } | |
| @@ -76,7 +72,7 @@ func (s *Store) Get(repoID string) (*acl.ACL, error) { | |||
| 76 | 72 | // Set replaces a repository's rules. The row keeps who changed them and when, because | |
| 77 | 73 | // the git copy used to keep that in the commit and losing it would make an access | |
| 78 | 74 | // change the one thing nobody can look up afterwards. | |
| 79 | func (s *Store) Set(repoID string, a *acl.ACL, actor string, now time.Time) error { | ||
| 75 | func (s *Store) Set(repoID string, a *ACL, actor string, now time.Time) error { | ||
| 80 | 76 | raw, err := a.Bytes() | |
| 81 | 77 | if err != nil { | |
| 82 | 78 | return err | |
| @@ -114,7 +110,6 @@ func (s *Store) audit(line string) { | |||
| 114 | 110 | defer f.Close() | |
| 115 | 111 | fmt.Fprintf(f, "%s\t%s\n", time.Now().UTC().Format(time.RFC3339), line) | |
| 116 | 112 | } | |
| 117 | |||
| 118 | 113 | func actorOr(actor string) string { | |
| 119 | 114 | if actor == "" { | |
| 120 | 115 | return "unknown" | |