descriptor

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

Documentation

Overview

Package descriptor reads Artifactory's YAML configuration descriptor and applies it (decision 0009): the body of PATCH /api/system/configuration, `artifactweave config apply` and the bootstrap descriptor. Named entities that do not exist are created, existing ones are updated field by field, omitted keys are untouched, and an entry or a string field whose value is null is deleted.

Role

configuration module, core layer: the implementation of configuration/api's Descriptor and System. It reaches the artifacts and access modules only through their api packages, and the configuration documents through platform/configdoc (decision 0044), so applying a descriptor is the one transaction that spans modules.

Inputs

  • Parse: a YAML document and a lookup for its ${NAME} references.
  • Deps, which Apply and NewAPI take: the unit of work (platform/tx), the artifacts module's Repositories and Layouts, the configuration document port (platform/configdoc) and access's AnonymousAccess, all over one store.
  • DownloadRedirectMinSize: the configuration document port.

Outputs

  • Parse: a *Patch, the configapi.Plan holding the repository, configuration document and security changes and the count of the document's values. A refusal wraps ErrInvalid, which is configapi.ErrInvalid.
  • Apply: a configapi.Result naming what was created, updated, deleted and left alone.
  • DownloadRedirectMinSize: the minimum redirect size that downloadRedirectConfig.fileMinimumSize set, in bytes.
  • NewAPI: configapi.API, with Descriptor and System bound over Deps.
  • The section names (SectionLocal and the rest) and Lookup.

Invariants

  • One transaction per patch: Apply checks every entry first, then writes them all in one transaction of Deps.Tx, which every port joins through its context. A patch with one bad entry, or one whose last write fails, changes nothing; a port that opened its own transaction would leave half a descriptor applied.
  • Parse before key or store: Parse reads none of Deps, so config apply refuses a broken descriptor before it builds the keyring or opens the store, and that error is reported ahead of a key or database error.
  • Parsing is strict: an unset ${NAME}, a section artifactweave does not apply, an unknown field and a null on a field that is not a string are refused, so a pipeline never takes a 200 for settings that changed nothing. Secrets go to the documents' sealed secrets, never their JSON.
  • Applying a descriptor again changes nothing, and Merged answers the same count of values either time.
  • Error texts reach clients and logs, so they stay byte-identical.

References

  • Decision 0009: docs/research/decisions/0009-configuration-as-code.md.
  • Decision 0029: docs/research/decisions/0029-cdn-delivery-and-download-redirect.md, lines 51 to 55 and 100 to 102 (downloadRedirectConfig.fileMinimumSize, in whole MB, replaces download.redirect.min_size once applied).
  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md (modules reach each other through their api packages).
  • Research 06: docs/research/06-system-configuration-and-descriptor.md, "What artifactweave serves".
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, line 308 (core/descriptor), line 994 (calls artifacts and access through api/) and lines 1111 to 1116 (descriptor apply as the one sanctioned transaction across modules).
  • Plan: docs/implementation/plan.md#p3-repositories-generic-artifacts-cli-aql-shape, task 7, and #p9d-modular-monolith-migration.
  • https://github.com/weaveplatform/artifactweave/issues/1077

Status

Implemented P3: the repository sections, proxies, property sets and layouts, with null deletes, for PATCH /api/system/configuration and `config apply`. Later phases added the downloadRedirectConfig section (decision 0029), the security section's anonymous access switch and the bootstrap descriptor. Moved here in P9d behind configuration/api. Planned for P12: the XML descriptor and the remaining YAML sections.

Testing

  • parse_test.go: the documented keys and spellings, JFrog's example, the count of values, nulls only on strings, the legacy type flags only the repositories API takes, and the refused sections and errors.
  • apply_test.go: creates, updates, deletes and second applies that change nothing; the dry run; refusals and store errors that write nothing; the deleted repository's trash entry; virtual members, environments and the Terraform reindex; and the transaction, which a failing late write, a failing anonymous access write and a failure after it all roll back whole.
  • layout_name_test.go: the bodies of the artifactory_repository_layout Terraform resource, whose layouts repeat their own name.
  • redirect_test.go: downloadRedirectConfig and DownloadRedirectMinSize.

Index

Constants

View Source
const (
	SectionLocal        = "localRepositories"
	SectionRemote       = "remoteRepositories"
	SectionVirtual      = "virtualRepositories"
	SectionFederated    = "federatedRepositories"
	SectionProxies      = "proxies"
	SectionPropertySets = "propertySets"
	SectionLayouts      = "repoLayouts"
	SectionSecurity     = "security"
)

Sections artifactweave applies. Any other top-level section is refused, so a pipeline never takes a 200 for settings that changed nothing.

View Source
const SectionDownloadRedirect = "downloadRedirectConfig"

SectionDownloadRedirect is the system's direct cloud storage download settings: "Minimum Direct Cloud Storage Download Size" in 7.x's General settings, <downloadRedirectConfig><fileMinimumSize> in its descriptor. Unlike the named sections it is one mapping, not entries by name.

Variables

View Source
var ErrInvalid = configapi.ErrInvalid

ErrInvalid is configapi.ErrInvalid, the same value, which every refusal of a descriptor wraps: errors.Is matches it under either name, and the refusal's message names the first problem.

Functions

func Apply

func Apply(
	ctx context.Context,
	d Deps,
	p *Patch,
	now time.Time,
	dryRun bool,
) (configapi.Result, error)

Apply checks the whole patch against the current state that d reads, then, unless dryRun, writes it in one transaction of d.Tx, so a patch with one bad entry, or one whose last write fails, changes nothing. Entries that would not change are left alone, which makes applying the same descriptor twice a no-op the second time; the result names what was, or with dryRun would be, created, updated, deleted and left alone. An anonymous access setting that was never written counts as off. A patch the checks refuse answers an error matching ErrInvalid; a failed write is wrapped as "apply configuration: %w". A repository the patch deletes is removed as Repositories.Remove removes it, by ctx's principal, or by no one when ctx carries none.

func DownloadRedirectMinSize

func DownloadRedirectMinSize(
	ctx context.Context,
	configs configdoc.ConfigStore,
) (int64, bool, error)

DownloadRedirectMinSize returns, in bytes, the minimum redirect size a descriptor set with downloadRedirectConfig.fileMinimumSize; ok is false when none has. It then takes precedence over download.redirect.min_size, the installation's default: the descriptor is the instance's own setting, which the API and its clients change at run time.

func NewAPI

func NewAPI(d Deps) configapi.API

NewAPI binds the configuration module's API over d. Its Descriptor parses with Parse, which reads none of d, so NewAPI(Deps{}).Descriptor parses a descriptor before any store is open, as config apply does; its Apply takes only the plans Parse returned and applies them with Apply over d. Its System reads the minimum redirect size from d.Configs with DownloadRedirectMinSize. Nothing is read or written until a method is called.

Types

type ConfigChange

type ConfigChange struct {
	Section string
	Kind    configdoc.ConfigKind
	Key     string
	Delete  bool
	// Fields are the descriptor's own names; a nil value removes the field.
	Fields map[string]any
	// contains filtered or unexported fields
}

ConfigChange is one entry of a proxies, propertySets or repoLayouts section.

type Deps

type Deps struct {
	// Tx runs Apply's writes as one transaction.
	Tx tx.Runner
	// Repositories reads, checks and writes the repositories of the four
	// repository sections, with the key pairs and environments their
	// entries name.
	Repositories artifactsapi.Repositories
	// Layouts checks each repoLayouts entry before it is stored.
	Layouts artifactsapi.Layouts
	// Configs holds the proxies, property sets, layouts and the
	// downloadRedirectConfig section.
	Configs configdoc.ConfigStore
	// AnonymousAccess reads and writes the security section's anonymous
	// access switch.
	AnonymousAccess accessapi.AnonymousAccess
}

Deps is what Apply and the API that NewAPI binds apply a descriptor through: the other modules' api contracts and the platform's ports, all over one store. Apply runs its writes in a transaction of Tx, and every other port must take part in the store transaction its context carries, as the modules' bindings over that store do: a port that opened its own would leave half a descriptor applied when a later write fails (decision 0009). Apply needs every field; Parse reads none of them.

type Lookup

type Lookup func(name string) (string, bool)

Lookup resolves an environment variable, as os.LookupEnv does.

type Patch

type Patch struct {
	Repos   []RepoChange
	Configs []ConfigChange
	// AnonymousAccess, when present, updates the instance's anonymous access
	// switch. Permissions still determine which repositories it can read.
	AnonymousAccess *bool
	// Changes is the number Artifactory reports as "<n> changes to config
	// merged successfully": every value in the document, whether or not it
	// differs from what is stored (see values).
	Changes int
}

Patch is a parsed descriptor: the configapi.Plan that Parse returns through the Descriptor NewAPI binds, and that Apply takes.

func Parse

func Parse(doc []byte, env Lookup) (*Patch, error)

Parse reads a descriptor. String values of the form ${NAME} are resolved through env; an unset variable is an error rather than an empty value, which would silently clear a password.

func (*Patch) DescriptorPlan

func (*Patch) DescriptorPlan()

DescriptorPlan makes a *Patch the configapi.Plan that the binding's Parse returns and its Apply takes.

type RepoChange

type RepoChange struct {
	Section string
	Class   repo.Class
	Key     string
	Delete  bool
	// Fields uses the JSON API's names, so updates go through the same
	// merge as the repositories API; a JSON null, which Parse lets through
	// only on a string field, clears it.
	Fields map[string]json.RawMessage
}

RepoChange is one entry of a repository section.

Jump to

Keyboard shortcuts

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