trash

package
v0.26.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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

func Actor(ctx context.Context) string

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

func AuditRestored(ctx context.Context, item *models.TrashItem)

AuditRestored records that item left the trash.

func Delete

func Delete(ctx context.Context, db any, req Request, hard func() error) error

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 Describe

func Describe(item *models.TrashItem) string

Describe renders an item as "name version" for audit messages.

func ForceRequested

func ForceRequested(r *http.Request) bool

ForceRequested reports whether the request asks to override immutability (`?force=true`). It is only honoured for admins, see GuardRelease.

func GuardRelease

func GuardRelease(r *http.Request, repo *models.Repository, format, version string) error

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

func IsAdmin(ctx context.Context) bool

IsAdmin reports whether the request's principal holds the global `manage` permission.

func IsRelease

func IsRelease(format, version string) bool

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

func SetEvaluator(e *auth.Evaluator)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL