Sign in

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

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

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

Self-hosted forge that lives in your Git repo.

Let repo create choose visibility, not an owner

d74e7e231de16fa00366dc8ccc392fc9c637b52d · Keenan Nemetz · 3d ago · parent 3455902a

Let repo create choose visibility, not an owner

A repository has no owner: the argument only seeded one admin entry in the
ACL store, and instance admins can already administer every repository. The
create command therefore asked for a fact the repository does not keep.

Replace --owner with --visibility private|public on `vole admin repo create`,
the remote admin command, and the web form. The initial rule set is written
once, inside the store, so a public repository is never briefly private. An
admin who wants to hand a repository to someone grants a role with the acl
commands, exactly as for any later access change.

closes: 01M82CC7G9W46PRP89GQ5CNMDE

forge/repo/repo.go +63−7

@@ -93,12 +93,60 @@ type Meta struct {
93 93
94 94 func (s *Store) path(name string) string { return filepath.Join(s.Root, name+".git") }
95 95
96 // Create initialises a bare repo, stamps it with a stable id and seeds its ACL
97 // so the creator is admin.
98 func (s *Store) Create(name, owner, description string) (*Meta, error) {
96 // Visibility is who may read a repository. Reading is the repository default
97 // role, so these are the two states a create surface offers; anything finer is
98 // an explicit role entry in the ACL store.
99 type Visibility string
100
101 const (
102 Private Visibility = "private"
103 Public Visibility = "public"
104 )
105
106 // ParseVisibility reads the one word the create commands and the web form
107 // accept. An unknown value is refused rather than silently made private.
108 func ParseVisibility(s string) (Visibility, error) {
109 v := Visibility(strings.ToLower(strings.TrimSpace(s)))
110 switch v {
111 case Private, Public:
112 return v, nil
113 }
114 return "", fmt.Errorf("visibility must be private or public, not %q", s)
115 }
116
117 // CreateOptions are the facts a repository is born with. Access is not one of
118 // them beyond the initial visibility: the rules live in the ACL store, and a
119 // repository starts private unless Visibility says otherwise.
120 type CreateOptions struct {
121 // Description is the one line shown beside the repository.
122 Description string
123 // Visibility is the initial read rule. The zero value is private.
124 Visibility Visibility
125 // Owner, when set, is granted repository admin as part of creation. The
126 // create commands leave it empty: a repository has no owner, and access is
127 // granted through the ACL commands. Internal callers that need a repository
128 // to start with an administrator set it.
129 Owner string
130 // Actor is credited with the initial rule set in the audit log, and falls
131 // back to Owner when empty.
132 Actor string
133 }
134
135 // Create initialises a bare repo, stamps it with a stable id and writes the
136 // access rules it starts with.
137 func (s *Store) Create(name string, opt CreateOptions) (*Meta, error) {
99 138 if err := ValidateName(name); err != nil {
100 139 return nil, err
101 140 }
141 visibility := opt.Visibility
142 if visibility == "" {
143 visibility = Private
144 }
145 switch visibility {
146 case Private, Public:
147 default:
148 return nil, fmt.Errorf("unknown repository visibility %q", visibility)
149 }
102 150 dir := s.path(name)
103 151 if _, err := os.Stat(dir); err == nil {
104 152 return nil, fmt.Errorf("repo %q already exists", name)
@@ -124,14 +172,22 @@ func (s *Store) Create(name, owner, description string) (*Meta, error) {
124 172 if err := os.WriteFile(filepath.Join(dir, idFile), []byte(id+"\n"), 0o644); err != nil {
125 173 return nil, err
126 174 }
127 if description != "" {
128 if err := os.WriteFile(filepath.Join(dir, descFile), []byte(description+"\n"), 0o644); err != nil {
175 if opt.Description != "" {
176 if err := os.WriteFile(filepath.Join(dir, descFile), []byte(opt.Description+"\n"), 0o644); err != nil {
129 177 return nil, err
130 178 }
131 179 }
132 m := &Meta{ID: id, Name: name, Dir: dir, Created: time.Now().UTC(), Description: description,
180 m := &Meta{ID: id, Name: name, Dir: dir, Created: time.Now().UTC(), Description: opt.Description,
133 181 DefaultBranch: "main", ACLs: s.ACLs}
134 if err := m.SetACL(access.Empty(owner), owner); err != nil {
182 a := access.Empty(opt.Owner)
183 if visibility == Public {
184 a.Default = access.Read.String()
185 }
186 actor := opt.Actor
187 if actor == "" {
188 actor = opt.Owner
189 }
190 if err := m.SetACL(a, actor); err != nil {
135 191 return nil, err
136 192 }
137 193 if err := s.InstallHooks(m.Dir); err != nil {