CAT-G2: the packages token is renewed on the forge's refusal, said as a finding, never on a timer
The Go bundle raises packages-token-refused in the module's findings state when the forge answers 401 to a write; the watcher mints afresh on that key's event and clears it (lead's ruling on A3n, map-onto-how-the-mesh-is-built: nothing waits on a timer). Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -27,6 +27,32 @@ type Forge struct {
|
||||
Owner string // the package registry's owner, as the seat serves it
|
||||
// Type is the registry's package type retention reads: TypeNpm when empty, or TypeGo.
|
||||
Type string
|
||||
// Refused says whether the forge refused the write side's token (401), as the finding PackagesTokenRefused in the
|
||||
// module's findings state: the TypeScript bundle mints a new token on that key's event and clears it (no timer
|
||||
// looks at the token). Nil says nothing.
|
||||
Refused func(raised bool)
|
||||
}
|
||||
|
||||
// PackagesTokenRefused is the finding this bundle raises when the forge refuses the packages account's token, and its
|
||||
// key in the module's findings state (packages-account.ts PACKAGES_TOKEN_REFUSED watches that key).
|
||||
const (
|
||||
PackagesTokenRefused = "packages-token-refused"
|
||||
PackagesTokenRefusedKey = "seat.gitea.packages-token-refused_write"
|
||||
)
|
||||
|
||||
// wrote is a write's answer, said on Refused: a 401 raises the finding, a write the forge took clears it.
|
||||
func (f *Forge) wrote(err error) error {
|
||||
if f.Refused == nil {
|
||||
return err
|
||||
}
|
||||
var status *forgehttp.StatusError
|
||||
switch {
|
||||
case errors.As(err, &status) && status.Status == http.StatusUnauthorized:
|
||||
f.Refused(true)
|
||||
case err == nil:
|
||||
f.Refused(false)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// The package types the retention reads: npm packages (the npm seat) and Go modules (the Go seat).
|
||||
@@ -59,7 +85,9 @@ func ForgeFromEnv() (*Forge, error) {
|
||||
missing = append(missing, m)
|
||||
}
|
||||
}
|
||||
f := &Forge{Client: c, Writer: &w, Owner: os.Getenv("MESH_NPM_OWNER")}
|
||||
f := &Forge{Client: c, Writer: &w, Owner: os.Getenv("MESH_NPM_OWNER"), Refused: func(raised bool) {
|
||||
finding(PackagesTokenRefused, "write", "the forge refused the package seats' write token; the module mints it afresh", raised)
|
||||
}}
|
||||
if f.Owner == "" {
|
||||
missing = append(missing, "MESH_NPM_OWNER")
|
||||
}
|
||||
@@ -152,7 +180,7 @@ func (f *Forge) Delete(ctx context.Context, name, version string) error {
|
||||
return err
|
||||
}
|
||||
_, err = w.Do(ctx, http.MethodDelete, f.versionPath(name, version), nil, maxBody)
|
||||
return err
|
||||
return f.wrote(err)
|
||||
}
|
||||
|
||||
// Repository is one repository on the forge, as far as reading its manifests needs.
|
||||
|
||||
Reference in New Issue
Block a user