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.
Add named release channels and a generic channel file route
24019cb30892b9fc0118697e8b89cd61e9fab576 · Keenan Nemetz · 19d ago · parent 4f8a3da8
Add named release channels and a generic channel file route A channel is a mutable pointer, channels/<name>.md, to one immutable annotated release. The target tag object is recorded so a rewritten tag is detected rather than silently followed. - metadata: channel parse/render/validate, closed-layout and size checks, set/clear writers - CLI: vole release channel set|list|clear; a dangling target is reported - server: maintain/admin path gate and audit for channel.set/clear - index: release_channels table, incremental refresh, per-tag badge query - web: /channels list, /channels/<name> redirect, and /channels/<name>/<path...> serving the target release's tree with OID ETags, Range, revalidation, and octet-stream responses - tests: metadata round trips, index moves, hook role/audit, page/tree/dangling/ private, and the CLI end to end No apt, yum, or other package-manager code is involved: a package layout is a directory in the release tree. Refs: 01M7BPHANWMSW5HK2GT0PY74QZ
server/hook/channels.go +90
| @@ -0,0 +1,90 @@ | |||
| 1 | package hook | ||
| 2 | |||
| 3 | // Channel moves are privileged: a channel is what a client follows, so pointing | ||
| 4 | // it at a different release changes every download under that name. The pointer | ||
| 5 | // itself is a metadata file, which contributors may write for issues; this is the | ||
| 6 | // path-level rule that keeps a contributor from moving stable. | ||
| 7 | |||
| 8 | import ( | ||
| 9 | "fmt" | ||
| 10 | "sort" | ||
| 11 | "strings" | ||
| 12 | |||
| 13 | "rodent.software/vole/core/git" | ||
| 14 | "rodent.software/vole/forge/access" | ||
| 15 | "rodent.software/vole/internal/audit" | ||
| 16 | "rodent.software/vole/metadata" | ||
| 17 | ) | ||
| 18 | |||
| 19 | // changedChannels lists the channel files a metadata push adds, changes, or | ||
| 20 | // deletes. A new metadata branch is all additions, so it is read from the tree | ||
| 21 | // rather than diffed against the empty tree. | ||
| 22 | func changedChannels(g *git.Repo, c change) (map[string]string, error) { | ||
| 23 | if c.ref != metadata.Ref || c.new == "" || c.new == git.ZeroSHA { | ||
| 24 | return nil, nil | ||
| 25 | } | ||
| 26 | if c.old == "" || c.old == git.ZeroSHA { | ||
| 27 | entries, err := g.LsTreeR(c.new) | ||
| 28 | if err != nil { | ||
| 29 | return nil, err | ||
| 30 | } | ||
| 31 | out := map[string]string{} | ||
| 32 | for _, e := range entries { | ||
| 33 | if strings.HasPrefix(e.Name, metadata.ChannelsDir+"/") { | ||
| 34 | out[e.Name] = "A" | ||
| 35 | } | ||
| 36 | } | ||
| 37 | return out, nil | ||
| 38 | } | ||
| 39 | return g.DiffStatusPaths(c.old, c.new, metadata.ChannelsDir) | ||
| 40 | } | ||
| 41 | |||
| 42 | // channelFindings enforces the role and records the move. A malformed channel | ||
| 43 | // file is left to the metadata validator; this only needs enough of it to make | ||
| 44 | // the audit entry useful. | ||
| 45 | func channelFindings(g *git.Repo, c change, role access.Role, actor, repo, auditPath string) []string { | ||
| 46 | changes, err := changedChannels(g, c) | ||
| 47 | if err != nil { | ||
| 48 | return []string{fmt.Sprintf("%s: cannot check channel changes: %v", c.ref, err)} | ||
| 49 | } | ||
| 50 | if len(changes) == 0 { | ||
| 51 | return nil | ||
| 52 | } | ||
| 53 | if !role.AtLeast(access.Maintain) { | ||
| 54 | return []string{fmt.Sprintf( | ||
| 55 | "%s: moving a release channel requires maintain access (role: %s)", c.ref, role)} | ||
| 56 | } | ||
| 57 | paths := make([]string, 0, len(changes)) | ||
| 58 | for path := range changes { | ||
| 59 | paths = append(paths, path) | ||
| 60 | } | ||
| 61 | sort.Strings(paths) | ||
| 62 | var problems []string | ||
| 63 | for _, path := range paths { | ||
| 64 | name, validName := metadata.ChannelNameFromPath(path) | ||
| 65 | action := "channel.set" | ||
| 66 | detail := path | ||
| 67 | if changes[path] == "D" { | ||
| 68 | action = "channel.clear" | ||
| 69 | if validName { | ||
| 70 | detail = name | ||
| 71 | } | ||
| 72 | } else if validName { | ||
| 73 | if raw, err := g.BlobAt(c.new, path); err == nil { | ||
| 74 | if ch, err := metadata.ParseChannel(name, raw); err == nil { | ||
| 75 | detail = name + " -> " + ch.Release | ||
| 76 | } | ||
| 77 | } | ||
| 78 | } | ||
| 79 | if err := auditLine(auditPath, audit.Record{ | ||
| 80 | Action: action, | ||
| 81 | Actor: actor, | ||
| 82 | Subject: repo, | ||
| 83 | Detail: detail, | ||
| 84 | }); err != nil { | ||
| 85 | problems = append(problems, fmt.Sprintf( | ||
| 86 | "%s: cannot record the channel change, refusing it: %v", c.ref, err)) | ||
| 87 | } | ||
| 88 | } | ||
| 89 | return problems | ||
| 90 | } | ||