api

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: 6 Imported by: 0

Documentation

Overview

Package api is the artifacts module's published surface for other modules: the repository operations they call (Repositories, with RepoFilter and the shared names ErrChanged, MsgKeyExists and IsNull) and the layout check (Layouts, with LayoutDefinition), which API holds as the module binds them. The repository configuration model is its subpackage repo.

Role

artifacts module, api layer: what other modules may call. Other modules reach artifacts only through this package and its subpackages, and it imports only the standard library and its own repo subpackage (decision 0044, dependency rules 5 and 6), so it declares its own types rather than naming the module's core or store types: LayoutDefinition mirrors the layout engine's Definition and RepoFilter the store's repository filter. The repo subpackage imports kernel/antpath, which the api rule allows, so a dependency listing of this package shows that kernel package too.

Inputs

None: the package holds interfaces, a struct of them, two values and a pure function. The artifacts module implements the interfaces: internal/artifacts/core/repos's NewRepositories binds Repositories over the store and access's Keys and Projects, and artifacts/core/layout's Checker implements Layouts; the module's API method returns both as an API.

Outputs

  • Repositories: reading, listing, creating, updating and deleting repository configurations, requesting a reindex, and the checks and merge rules that every entry point applies before it writes one (Protected, PrepareCreate, CheckMembers, CheckKeypairs, CheckEnvironments, Merge and OwesReindex). RepoFilter narrows a listing.
  • ErrChanged, MsgKeyExists and IsNull: the sentinel a delete returns when the content changed under it, the message of a create whose key is taken, and the test for a null value in an update body or descriptor, which callers of Repositories use with its results.
  • Layouts, with LayoutDefinition: the check that configuration runs on a layout definition before it stores it.
  • API, the two contracts as the module binds them, which app hands to the configuration module.

Invariants

  • No method wraps the error behind it, so callers keep their own wrapping and errors.Is finds the store's sentinels and ErrChanged. Every text (ErrChanged, MsgKeyExists, the validation and layout messages) stays byte-identical, because clients and logs show it.
  • Every Repositories method that takes a context takes part in the store transaction the context carries, so the configuration descriptor's deletes, writes and reindex requests commit or roll back together (decision 0009).
  • LayoutDefinition and RepoFilter have the fields of the types they mirror, in the same order and of the same types, so the module converts them with plain conversions that stop compiling if either side changes.

References

  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Public types and published api surface" (artifacts/api publishes repo, Repositories and Layouts, and no Settings), "Dependency rules" and "Names the migration introduces".
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 174 to 185 (artifacts/api), line 1015 (internal/artifacts/core/repos published as api.Repositories) and line 1053 (the layout engine published through api.Layouts).
  • Decision 0003: docs/research/decisions/0003-repository-model.md (validation, defaults and protected keys stay in the module; the api only exposes them).
  • Decision 0009: docs/research/decisions/0009-configuration-as-code.md (the descriptor and the REST APIs call the same operations; a null deletes an element).
  • Decision 0013: docs/research/decisions/0013-projects-and-environments.md (a repository's environments).
  • Decision 0040: docs/research/decisions/0040-terraform.md (the reindex an update that sets terraformType owes).
  • Plan: docs/implementation/plan.md#p9d-modular-monolith-migration, epic ART (https://github.com/weaveplatform/artifactweave/issues/941).
  • https://github.com/weaveplatform/artifactweave/issues/1009 and https://github.com/weaveplatform/artifactweave/issues/1094 (API)

Status

Repositories, Layouts and API implemented in P9d. Not created, because no other module calls them today (decision 0044): the target layout's Items, Packages, Builds and Search; Gate (hooks.go), with the download and deploy gates of P17; the artifacts events (events.go, P11); and Repositories.SetProject, which a project attach will call (P11). The artifacts settings are not published here (decision 0044).

Testing

  • TestUnitIsNull: null with and without surrounding white space, and values that are not null.
  • The implementations are tested where they live: internal/artifacts/core/repos's TestUnitRepositories* tests, one per Repositories method, and artifacts/core/layout's TestUnitLayoutCheckerMatchesCompile.

Index

Constants

View Source
const MsgKeyExists = "Case insensitive repository key already exists"

MsgKeyExists is the message of the 400 answer to a create whose key is already taken, compared without regard to case. It is JFrog's text, which clients match, so it stays byte-identical; the repositories API also reports it per entry of a batch create.

Variables

View Source
var ErrChanged = errors.New("repos: the repository's content changed during the delete")

ErrChanged is a repository delete that found the repository's content changing under it: an item it moved to the trash can was gone by the time it deleted the content. Nothing is deleted, and a retry sees the content as it now is. Repositories.Remove returns it wrapped, so callers match it with errors.Is. The text is logged, so it stays byte-identical.

Functions

func IsNull

func IsNull(raw json.RawMessage) bool

IsNull reports whether raw, a JSON value from an update body or a configuration descriptor, is null, ignoring surrounding white space. A null resets a field to its default on an update (Repositories.Merge) and deletes an entry in the descriptor (decision 0009), so callers that build a patch test each value with it.

Types

type API

type API struct {
	Repositories Repositories
	Layouts      Layouts
}

API is the artifacts module's published surface for other modules: one implementation of each contract, as the module binds them.

type LayoutDefinition

type LayoutDefinition struct {
	Name                             string
	ArtifactPathPattern              string
	DistinctiveDescriptorPathPattern bool
	DescriptorPathPattern            string
	FolderIntegrationRevisionRegExp  string
	FileIntegrationRevisionRegExp    string
}

LayoutDefinition is a repository layout as the configuration descriptor stores it (repoLayouts.<name>): its name, the artifact and descriptor path patterns, and the integration-revision expressions. It has the fields of the layout engine's Definition (artifacts/core/layout), in the same order and of the same types, so the engine converts it with a plain conversion, which stops compiling if either struct changes.

type Layouts

type Layouts interface {
	// Check compiles d as the layout engine compiles a stored definition and
	// returns the compile error, nil when d compiles. The error is the
	// engine's, unwrapped: it wraps the engine's ErrPattern and names the
	// layout and which of its patterns failed, and its text reaches clients,
	// so the caller adds its own wrapping and never rewrites it. Check reads
	// and writes nothing, and is safe for concurrent use.
	Check(d LayoutDefinition) error
}

Layouts checks layout definitions for the configuration module, which stores them.

type RepoFilter

type RepoFilter struct {
	Class       repo.Class
	PackageType repo.PackageType
	ProjectKey  string
}

RepoFilter narrows a repository listing; empty fields match everything. Its fields are the store's repository filter's, in the same order and of the same types, so the artifacts module converts one into the other with a plain conversion, which stops compiling if either changes.

type Repositories

type Repositories interface {
	// Get returns the configuration stored under key, which must match
	// exactly, including remote passwords and sensitive header values: a
	// caller that shows it masks them first (repo.Masked).
	// kernel.ErrNotFound when no repository has the key.
	Get(ctx context.Context, key string) (repo.Config, error)
	// List returns every repository that f matches, ordered by key. It is
	// unpaged, as Artifactory lists repositories.
	List(ctx context.Context, f RepoFilter) ([]repo.Config, error)
	// UsingKeypair returns the keys of the repositories whose primary or
	// secondary key pair reference is name, ordered.
	UsingKeypair(ctx context.Context, name string) ([]string, error)
	// Create stores c as it is: the caller applies PrepareCreate and the
	// checks first. kernel.ErrConflict when the key exists.
	Create(ctx context.Context, c repo.Config) error
	// Update replaces the configuration stored under c.Key with c as it is:
	// the caller merges and checks it first (Merge). kernel.ErrNotFound when
	// no repository has the key.
	Update(ctx context.Context, c repo.Config) error
	// Remove deletes the repository key with its content: its items and, for
	// a remote repository, 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. It returns
	// the number of files deleted and whether a configuration existed; with
	// none, found is false and the error nil.
	//
	// While the trash can is on, the repository's own content moves to it
	// under key, as a delete of its root does, and a remote repository's
	// cache is released for garbage collection; while it is off, all of it
	// is released.
	//
	// The delete is one store transaction, however large the repository, so
	// a failure part of the way leaves the repository, its content and the
	// trash can as they were. Inside a transaction that ctx carries, Remove
	// joins it and the caller's commit or rollback decides for both. The SQL
	// store fails the caller's transaction when Remove fails even if the
	// caller drops the error, and the in-memory store does not, so callers
	// return it. Errors name the step that failed, wrapped as "delete
	// repository <key>: %w", or "get repository: %w" when reading the
	// configuration fails; ErrChanged, wrapped, refuses a delete whose
	// content changed under it.
	Remove(ctx context.Context, key, by string) (int64, bool, error)
	// RequestReindex queues a reindex of the repository key on the
	// persistent work queue (format.KindReindex in artifacts/core/format),
	// due at at, with by recorded as who asked for it: the payload is
	// {"by":"<by>"}, or {} when by is empty, byte for byte what the
	// configuration descriptor has always queued. Inside a transaction that
	// ctx carries, the request commits or rolls back with it. Requests made
	// for one key before its run begins coalesce into that run, and the
	// queue's workers poll the store, so the reindex runs whichever process
	// asked for it. Errors are the queue's: kernel.ErrInvalid for an empty or
	// overlong key.
	RequestReindex(ctx context.Context, key, by string, at time.Time) error
	// Protected reports whether key names a repository that cannot be
	// deleted, compared without regard to case: a blank key, Artifactory's
	// trash can (auto-trashcan) and support bundle (jfrog-support-bundle)
	// repositories, and the built-in build-info repository
	// (artifactory-build-info), which the repositories API cannot create
	// again.
	Protected(key string) bool
	// PrepareCreate applies the defaults Artifactory applies on create
	// (repo.Defaults) to c, validates it (repo.Validate), and refuses a key
	// that existing, the stored repositories and those created earlier in
	// the same batch, already holds in any case. It returns c with its
	// defaults, and a 400 apierror with the validation message or
	// MsgKeyExists.
	PrepareCreate(c repo.Config, existing []repo.Config) (repo.Config, error)
	// CheckMembers refuses a virtual repository whose members, its default
	// deployment repository among them, do not exist among known, or have a
	// package type the virtual repository cannot aggregate
	// (repo.AcceptsMember); a P2 virtual repository's members of another
	// package type must be local. Other classes pass. The refusal is a 400
	// apierror naming the member.
	CheckMembers(c repo.Config, known []repo.Config) error
	// CheckKeypairs refuses 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), because the repository
	// would otherwise fail only when it first signs or verifies. It reads
	// each named pair through access with ctx. A missing pair answers a 400
	// apierror "Key pair '<name>' does not exist" and an unusable one a 400
	// apierror with repo.ValidateKeyPair's message; an error reading a pair
	// is wrapped as "repos: key pair <name>: %w".
	CheckKeypairs(ctx context.Context, c repo.Config) error
	// CheckEnvironments applies Artifactory's rule for a repository's
	// environments (decision 0013) to c in place. Outside a project they are
	// cleared, 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, named "<projectKey>-<name>"; names compare without
	// regard to case and are rewritten in the environment's own spelling,
	// once each. It reads the environment names through access with ctx, and
	// a project that does not exist has only the built-in and global
	// environments. An unknown name answers a 400 apierror "Environment
	// '<name>' does not exist"; an error reading the names is wrapped as
	// "repos: global environments: %w" or "repos: environments of project
	// <key>: %w".
	CheckEnvironments(ctx context.Context, c *repo.Config) error
	// Merge merges an update body, patch, into stored with Artifactory's
	// rules and returns the result, validated (repo.ValidateStored and
	// repo.ValidateUpdate) with its defaults applied, and with a sensitive
	// header's stored value kept where the body sent that header back
	// empty, as repo.Masked shows it (repo.RestoreSecrets). A field present
	// replaces the stored value, a field left out keeps it, and null
	// (IsNull) resets it to its default. The key, class and package type
	// cannot change, nor can a field the package type takes only on create;
	// a key respelt in another case is a change, while a class or package
	// type respelt names the stored one, which keeps its spelling. Merge
	// consumes patch, so a caller that needs it afterwards passes a copy. A
	// refusal is a 400 apierror with Artifactory's message.
	Merge(stored repo.Config, patch map[string]json.RawMessage) (repo.Config, error)
	// OwesReindex reports whether an update of stored to updated owes the
	// repository a reindex (RequestReindex): one that gives a Terraform
	// repository the terraformType it lacked, so the files stored before
	// are indexed as that type says (decision 0040).
	OwesReindex(stored, updated repo.Config) bool
}

Repositories reads, validates and writes repository configurations for the modules that change repositories without owning them: the configuration descriptor, and access's key pair, role and permission services. The artifacts module implements it over its store and the access contracts it is built with, so a caller needs neither.

Every method that takes a ctx reads and writes with it: called inside a store transaction, it takes part in that transaction and commits or rolls back with it (decision 0009: the descriptor applies its deletes, writes and reindex requests in one transaction). The methods without a ctx read and write nothing. No method wraps the error of the store call or repository operation behind it, so a caller's own wrapping stays as it was and errors.Is finds the store's sentinels (kernel.ErrNotFound, kernel.ErrConflict) and ErrChanged. The validation methods answer a 400 apierror (platform/httpkit/apierror) whose message the repositories API, the descriptor and config apply all show unchanged, so every entry point refuses a bad configuration with the same text.

Directories

Path Synopsis
Package repo is the repository configuration model: the JSON document that PUT, POST and GET /artifactory/api/repositories/{key} exchange, with JFrog's field names, together with its validation, the defaults Artifactory applies on create, the views each reader gets, the package-type names and a repository's include and exclude patterns.
Package repo is the repository configuration model: the JSON document that PUT, POST and GET /artifactory/api/repositories/{key} exchange, with JFrog's field names, together with its validation, the defaults Artifactory applies on create, the views each reader gets, the package-type names and a repository's include and exclude patterns.

Jump to

Keyboard shortcuts

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