Documentation
¶
Overview ¶
Package trash is the policy layer of soft delete: format handlers route deletes through Delete (soft when the repository's retention allows it, the caller's own hard delete otherwise), guard released versions with GuardRelease, and the trash API and purge worker use the audit helpers so every delete/restore/purge leaves the same trail.
Index ¶
- Variables
- func Actor(ctx context.Context) string
- func AuditDeleted(ctx context.Context, repoID string, kind models.TrashKind, id string, ...)
- func AuditPurged(ctx context.Context, res *models.TrashPurgeResult, reason string)
- func AuditRestored(ctx context.Context, item *models.TrashItem)
- func Delete(ctx context.Context, db any, req Request, hard func() error) error
- func Describe(item *models.TrashItem) string
- func ForceRequested(r *http.Request) bool
- func GuardRelease(r *http.Request, repo *models.Repository, format, version string) error
- func GuardReleaseByName(r *http.Request, db GuardReleaseByNameStore, repoName, format, version string) error
- func IsAdmin(ctx context.Context) bool
- func IsRelease(format, version string) bool
- func SetEvaluator(e *auth.Evaluator)
- type GuardReleaseByNameStore
- type Request
Constants ¶
This section is empty.
Variables ¶
var ErrImmutableRelease = errors.New("released versions are immutable in this repository; an admin may override with force")
ErrImmutableRelease is returned by GuardRelease when the repository has immutable_releases set and the operation would delete or overwrite a released version. Handlers map it to 409 Conflict.
Functions ¶
func Actor ¶
Actor returns the username of the principal behind ctx, "" when anonymous or when no principal is attached (background jobs).
func AuditDeleted ¶ added in v0.8.0
func AuditDeleted(ctx context.Context, repoID string, kind models.TrashKind, id string, soft bool, resource, pkg, version string)
AuditDeleted records one artifact.deleted event: soft when the row went to the trash, permanent otherwise. Delete does it for its callers; a caller that deletes by other means (the generic package delete) calls it itself.
func AuditPurged ¶
func AuditPurged(ctx context.Context, res *models.TrashPurgeResult, reason string)
AuditPurged records that a trashed item was permanently removed. ctx may carry no principal (the retention purge): the event is then attributed to the system.
func AuditRestored ¶
AuditRestored records that item left the trash.
func Delete ¶
Delete deletes the rows of req: it moves them to the trash when the repository's retention allows, and otherwise runs hard, the caller's existing permanent delete (DB rows, quota release, blob cleanup). It records one artifact.deleted audit event either way. A database without trash support always takes the hard path.
database.ErrTrashNotFound means the rows are no longer live in the repository; handlers answer 404.
func ForceRequested ¶
ForceRequested reports whether the request asks to override immutability (`?force=true`). It is only honoured for admins, see GuardRelease.
func GuardRelease ¶
GuardRelease rejects a delete or overwrite of version when repo is immutable and version is a release of its format (see IsRelease). An admin who sent `?force=true` is let through. Pass the version being deleted or overwritten; formats without versions pass "".
func GuardReleaseByName ¶
func GuardReleaseByName(r *http.Request, db GuardReleaseByNameStore, repoName, format, version string) error
GuardReleaseByName is GuardRelease for handlers that only have the repository name.
func IsAdmin ¶
IsAdmin reports whether the request's principal holds the global `manage` permission.
func IsRelease ¶
IsRelease reports whether version of a repository of the given format is a release: the kind of version immutable_releases protects. Snapshots and pre-releases stay mutable so CI keeps overwriting them. The rule follows the format's repotype.Versioning:
VersionMaven (ivy, maven, sbt) not a *-SNAPSHOT version
VersionSemver (cargo, go, helm, npm, nuget, terraform) no semver
pre-release part ("-rc.1"); Go pseudo-versions
(v0.0.0-2024...-abcdef) therefore count as pre-releases
VersionPEP440 (pypi) no PEP 440 a/b/rc/dev segment
VersionGem (rubygems) no letter in the version (Gem::Version#prerelease?)
VersionOpaque (apk, conan, conda, deb, docker, pacman, raw, rpm) has no
snapshot concept: every version is a release
func SetEvaluator ¶
SetEvaluator installs the permission evaluator used to honour `force`.
Types ¶
type GuardReleaseByNameStore ¶ added in v0.15.0
type GuardReleaseByNameStore interface {
GetRepositoryByName(ctx context.Context, name string) (*models.Repository, error)
}
GuardReleaseByNameStore is the part of the database GuardReleaseByName needs.
type Request ¶
type Request struct {
RepoID string
Kind models.TrashKind
// IDs are the primary keys of the rows to delete in the kind's table.
IDs []string
// Resource is a human-readable description for the audit trail
// (e.g. "com/acme/lib/1.0/lib-1.0.jar").
Resource string
// Package and Version name the package version being deleted when the
// handler knows them; they make the delete findable in the per-package
// activity of a repository. Optional.
Package string
Version string
}
Request describes the rows of one delete.