Allow multiple token sources instead of a single one #36
Labels
No labels
Compat/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
heiko/gogogo#36
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Currently the config supports a single token source for API authentication. This enhancement would allow specifying multiple token sources (e.g., multiple
go.schlittermann.de/heiko/secretreferences, environment variables, files) with a fallback chain, while remaining backward compatible with configs that specify a single token source.Implementation sketch
Current state
Config.Repo.Tokenis a singlestringholding asecret-scheme URI (e.g.env:FORGEJO_TOKEN,netrc:git.example.com).loader.NewHTTPClientresolves it once viasecret.Getand mutates the field in place with the plain token value. Three callsites then pass that plain string toforgejo.NewClientandbuilder.CloneRepo.Config syntax (backward compatible)
The YAML
token:key stays as-is but gains the ability to accept either a scalar (old) or a sequence (new):Go changes
1.
internal/config/config.go— new custom typeChange
Config.Repo.TokenfromstringtoTokenSources:2.
internal/cmd/loader/loader.go— resolution helper + changed signatureNewHTTPClientstops mutatingcfand instead returns the resolved token:3. Callsites — thread
tokenthrough instead of readingcf.Repo.TokenEvery caller of
NewHTTPClientchanges from:to:
The three affected spots are:
internal/cmd/status/status.go:39internal/cmd/release/release.go:296(builder.CloneRepo)internal/cmd/release/release.go:617(forgejo.NewClient)Error-reporting note
When all sources fail, the error should list which sources were tried and why each failed, so the user can debug their config.
errors.Join(Go 1.20+) is sufficient; no need for a custom type.What does NOT need to change
secretpackage — it already handles all resolution schemes.default.yml— the#token:comment line stays as-is; the doc comment can gain a list-form example.forgejoandapiclientpackages — they receive a plain resolved string, same as today.Estimated scope
~60 lines changed across 4 files, plus tests for
UnmarshalYAMLandresolveToken.