repos

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package repos holds the repository operations that more than one entry point performs: the repositories API and the configuration descriptor (PATCH /api/system/configuration, config apply and the bootstrap descriptor). Its errors are apierror values, so every entry point answers a bad configuration with the same status and message.

Role

artifacts module, core layer: repository operations behind artifacts/api.Repositories, which NewRepositories binds over the store and access/api's Keys and Projects, the only way it reaches the access module (decision 0044, dependency rule 6). As artifacts core, it never imports the module's adapters or an ecosystem http package (dependency rule 8).

Inputs

  • Driving: the repositories API handlers and the configuration descriptor, through the package's functions or the Repositories that NewRepositories returns.
  • Driven: the metadata store (repository configurations, items and their properties, blob references, the package index, trash entries and the work queue, through Store, which embeds the trash can's store), the trash service (artifacts/core/trash), which keeps a deleted repository's content, and accessapi.Keys and accessapi.Projects, for the key pair and environment checks; and the P2 format (artifacts/ecosystem/p2), whose p2Urls rules PlanP2Virtual applies.

Outputs

  • NewRepositories: the artifacts module's Repositories.
  • A configuration prepared and checked for a write (PrepareCreate, CheckMembers, CheckKeypairs, CheckEnvironments), a patch merged into a stored configuration (Merge), whether an update owes a reindex (OwesReindex) and whether a key may be deleted (Protected).
  • PlanP2Virtual: the members a P2 virtual repository's p2Urls need and the P2 remote repositories to create for them, for the repositories API alone; a YAML apply or configuration patch stores p2Urls as given and creates nothing.
  • Remove: the whole-repository delete.
  • Errors: apierror values that answer 400 with the message every entry point shares, the store's sentinels, and artifactsapi.ErrChanged.

Invariants

  • A delete is one transaction, however large the repository, so a failure part of the way leaves it whole, its content where it was and the trash can as it was.
  • While the trash can is on, a delete keeps the blob references of the repository's own content for a restore, until a restore takes them over or a purge releases them.
  • Validation messages and artifactsapi.MsgKeyExists reach clients and stay byte-identical.
  • A remote's URL is never stored with a user name and password in it: PrepareCreate and Merge move them into its username and password, as 7.x's RemoteRepoConfig.processUrlCredentials does on every save, so no read has to take them out.

References

Status

Implemented P3 to P9c. Moved here in P9d.

Testing

  • repos_test.go: merges, protected keys, members, key pairs, environments and deletes, with their failures, and the user name and password a remote's URL gives up on create and update.
  • remove_test.go: deletes with the trash can on and off, restores, remote caches, a large repository and content changing during the delete.
  • api_test.go: one TestUnitRepositories* test per Repositories method, each checking the binding answers as the direct call does.
  • p2_test.go: the members and remote repositories PlanP2Virtual plans, its keys, and the p2Urls entries it refuses.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckEnvironments

func CheckEnvironments(ctx context.Context, projects accessapi.Projects, c *repo.Config) error

CheckEnvironments applies Artifactory's rule for a repository's environments (decision 0013). Outside a project they are ignored, so none are stored. In a project an empty list becomes DEV, and every entry must be DEV, PROD, a global environment or one of the project's own environments, which are named "<projectKey>-<name>". Names compare without regard to case and are stored in the environment's own spelling, because renaming or deleting an environment finds its repositories by that spelling.

In a project it reads the global and the project's environment names through projects, with ctx, so inside a store transaction the reads take part in it; a project that does not exist has only the built-in and global environments. An unknown name answers 400 "Environment '<name>' does not exist"; an error reading the names is wrapped as "repos: global environments: %w" or "repos: environments of project <key>: %w".

func CheckKeypairs

func CheckKeypairs(ctx context.Context, keys accessapi.Keys, c repo.Config) error

CheckKeypairs rejects signing key references (primaryKeyPairRef, secondaryKeyPairRef, and keyPair on an Alpine or Debian virtual repository) to key pairs that do not exist, or whose type the repository cannot use (repo.ValidateKeyPair): a repository would otherwise fail only when it first signs or verifies. It reads each named pair through keys, with ctx, so inside a store transaction the reads take part in it. A missing pair answers 400 "Key pair '<name>' does not exist" and an unusable one 400 with repo.ValidateKeyPair's message; an error reading a pair is wrapped as "repos: key pair <name>: %w".

func CheckMembers

func CheckMembers(c repo.Config, known []repo.Config) error

CheckMembers rejects a virtual repository whose members do not exist among known, or have a package type the virtual repository cannot aggregate (repo.AcceptsMember). The default deployment repository is a member (repo.Validate), so it is covered too.

The type check holds afterwards without a re-check: a repository's package type cannot change (Merge), and Remove takes a deleted repository out of every virtual repository, so a repository created again under its key joins none until a write names it, which this check sees.

func Merge

func Merge(stored repo.Config, patch map[string]json.RawMessage) (repo.Config, error)

Merge merges an update body into the stored configuration with Artifactory's rules: a field present replaces the stored value, a field left out keeps it, and null resets it to its default. The key, class and package type cannot change, nor can a field the package type takes only when the repository is created (repo.ValidateUpdate), nor can an AI Editor Extensions remote turn bypassHeadRequests off (repo.ValidateBypassHead). A key that differs from the stored one only in case is a change too: the store finds a repository by its exact key, so accepting the respelling would fail the write after validation (#472).

A class or package type that differs only in case names the stored one, which keeps its spelling (#492): 6.20 reads a package type without regard to case (RepoType.fromType), and taking the respelling would store a type no class allows, which validation then refuses as "not allowed".

A remote's merged URL gives up a user name and password written into it, as on create (moveURLCredentials).

func NewRepositories

func NewRepositories(
	st Store,
	keys accessapi.Keys,
	projects accessapi.Projects,
) artifactsapi.Repositories

NewRepositories returns the artifacts module's Repositories over st, which reads key pairs through keys and environments through projects for CheckKeypairs and CheckEnvironments. Each method calls st's repository store or work queue, or this package's function of the same name, once, and returns its results as they are, so a caller sees exactly what a direct call returns. Every call uses the context it is given, so it takes part in a transaction of st that the context carries; keys and projects must take part in that transaction too, as the access module's bindings over st do. Nothing is read or checked until a method is called.

func OwesReindex

func OwesReindex(stored, updated repo.Config) bool

OwesReindex reports whether an update of stored to updated owes the repository a reindex: one that gives a Terraform repository the terraformType it lacked, so the files it stored before are indexed as that type says (decision 0040), or one that changes the primary key pair of an npm local or federated repository, so every version is signed with the new pair, as 7.x reindexes a repository and signs all its packages when its ECDSA key is saved (decision 0034, "Signatures").

func PlanP2Virtual

func PlanP2Virtual(c repo.Config, known []repo.Config) (repo.Config, []repo.Config, error)

PlanP2Virtual gives a P2 virtual repository c the members its p2Urls need, as 7.x's UI does when it saves one (6.20's CreateRepoConfigHelper.validateAndCreateP2ConfigRepos), for a create or update through the repositories API. known holds every stored repository. It returns c with the members it adds appended in p2Urls order, and the P2 remote repositories to create before c, in the same transaction.

An http or https URL that a member remote already covers (p2.Covers) needs nothing; one that a stored P2 remote outside c covers adds that remote, as the UI matches every remote's url; any other creates a P2 remote whose url is the URL's root, <scheme>://<host>[:<port>]/, or for a site archive's entry (site.zip!/) the URL itself, which only it covers [I]. Its key is the host, or host-port when the URL names a port (RTFACT-30256), and the UI's next free <key>-1, <key>-2 when another repository holds that key. A local://<key> URL adds that local Generic or Maven repository. A created remote has the defaults and checks of a direct create (PrepareCreate), so a key the rules refuse answers that create's 400, and lists its remote folders, which the UI sets for the P2 remotes it creates. Unlike the UI, which replaces the members with those the URLs name, nothing is taken out of repositories [I]: a request to the API names its members itself.

func PrepareCreate

func PrepareCreate(c repo.Config, existing []repo.Config) (repo.Config, error)

PrepareCreate applies defaults and validates c for creation against the keys already taken (stored and earlier in the same batch). A remote's URL then gives up a user name and password written into it (moveURLCredentials), and the settings 7.x gives a repository only on create follow from it (repo.CreateDefaults).

func Protected

func Protected(key string) bool

Protected reports whether key names a repository that may not be deleted: a blank key, or one of the protected keys in any case (auto-trashcan, jfrog-support-bundle and the build-info repository). The first two are Artifactory's own trash can and support bundle repositories, and the repositories API could not create the build-info repository again, because no allowed list holds its package type.

func Remove

func Remove(ctx context.Context, st Store, key, by string) (int64, bool, error)

Remove deletes key with its content, in one transaction: the items of the repository and, for a remote, its cache, the root records that hold their own properties, its package index, its place in the virtual repositories that list it, and its configuration. by is who deletes it. found is false when no configuration exists.

While the trash can is on, the repository's own content moves to it under key, as a delete of its root does, and each file's entry keeps its blob reference until a restore takes it over or a purge releases it. A remote's cache is released for garbage collection, as the trash can holds only what was deleted from local repositories; so is everything while the trash can is off. The root's own properties go with the repository: 7.x fixed a restore of a deleted repository's root copying them onto what it restored (RTDEV-84660).

The whole delete is one transaction, however large the repository, so a failure part of the way leaves it whole, its content where it was and the trash can as it was.

Types

type Store

type Store interface {
	trash.Store
	Repos() port.RepoStore
	Packages() port.PackageStore
	WorkQueue() work.WorkQueue
}

Store is what the repositories read and write: the repository configurations, the work queue a reindex request goes to, and what Remove deletes with a repository, its items and package index, and the trash can its content moves to (trash.Store). Every call joins the transaction ctx carries. Each composite store in app is a Store.

Jump to

Keyboard shortcuts

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