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

Documentation

Overview

Package api is the configuration module's published surface: the configuration descriptor's parse and apply behind an opaque plan, the system value that other modules read, and the configuration settings.

Role

configuration module, api layer. Other modules and the composition reach configuration only through this package, which imports only the standard library (decision 0044, dependency rules 5 and 6), so it declares its own result and sentinel. Its contracts are today's calls into the configuration module: `config apply` and the bootstrap descriptor in the composition, the PATCH /api/system/configuration handler, and the item routes' minimum download redirect size.

Inputs

None: the package holds interfaces, a result, the settings and a sentinel. The descriptor core, configuration/core/descriptor, implements Descriptor and System, and its NewAPI binds them into an API over the other modules' api contracts and the platform's ports.

Outputs

  • Descriptor: Parse reads a YAML descriptor into a Plan and touches nothing else; Apply checks a plan against the current state and writes it in one transaction, or with dryRun only checks it.
  • Plan: a parsed descriptor, which callers hold without looking inside.
  • Result: what an apply created, updated, deleted and left alone, with Merged, the PATCH endpoint's answer, and String, the summary `config apply` prints.
  • ErrInvalid: the sentinel that every refusal of a descriptor wraps.
  • System: the minimum download redirect size the descriptor set.
  • Settings: the configuration options the module's code reads.
  • API: one implementation of Descriptor and of System.

Invariants

  • Apply writes a whole plan in one transaction and joins the one its context carries, so a plan with one bad entry, or one whose last write fails, changes nothing (decision 0009).
  • Parse reads no store and no key, so a caller checks a descriptor before it builds a keyring or opens a store, and a descriptor error is reported first.
  • Texts reach clients and logs, so they stay byte-identical: ErrInvalid's "descriptor: invalid configuration descriptor", and Merged's "<n> changes to config merged successfully", which counts the document's values, as Artifactory does.

References

  • Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Public types and published api surface" (configuration/api holds Descriptor, System and Settings) and "Names the migration introduces".
  • Decision 0009: docs/research/decisions/0009-configuration-as-code.md.
  • Decision 0029: docs/research/decisions/0029-cdn-delivery-and-download-redirect.md (the minimum redirect size).
  • Target layout: docs/research/architecture-options/5-modular-monolith.md, "Full package tree", lines 302 to 306 (configuration/api's config.go and events.go), and lines 1111 to 1116 (descriptor apply as the one sanctioned transaction across modules).
  • Research 06: docs/research/06-system-configuration-and-descriptor.md.
  • Plan: docs/implementation/plan.md#p9d-modular-monolith-migration, epic WEB (https://github.com/weaveplatform/artifactweave/issues/944).
  • https://github.com/weaveplatform/artifactweave/issues/1077

Status

Added in P9d: Descriptor with Parse and Apply, Plan, Result, ErrInvalid, System with DownloadRedirectMinSize, Settings and API. The target layout's System Get and Patch, Descriptor Export (P12) and events.go with ConfigurationChanged are not created, because no other module calls them yet.

Testing

The package has no tests of its own. configuration/core/descriptor's tests check Result through the descriptor it describes: TestUnitApplyDownloadRedirectConfig its Merged answer and TestUnitApplyDryRun its String summary, and the PATCH suites check the answer the endpoint sends.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("descriptor: invalid configuration descriptor")

ErrInvalid reports a configuration descriptor that cannot be applied: Descriptor.Parse and Descriptor.Apply return an error that wraps it and names the first problem, and every entry point answers it with 400. Its text is part of that answer, so it stays byte-identical.

Functions

This section is empty.

Types

type API

type API struct {
	Descriptor Descriptor
	System     System
}

API is the configuration module's published surface: one implementation of each contract, as the module binds them.

type Descriptor

type Descriptor interface {
	// Parse reads doc strictly and resolves its ${NAME} references through
	// env, which answers as os.LookupEnv does. It reads and writes nothing
	// else, so a caller parses before it builds a keyring or opens a store,
	// and a broken descriptor is reported ahead of a key or database error.
	// A document that cannot be applied answers an error wrapping
	// ErrInvalid.
	Parse(doc []byte, env func(name string) (string, bool)) (Plan, error)
	// Apply checks the whole of p, which this Descriptor's Parse returned,
	// against the current state and then, unless dryRun, writes it in one
	// transaction, joining the one ctx carries; a plan with one bad entry, or
	// one whose last write fails, changes nothing. Entries that would not
	// change are left alone, so applying the same plan twice is a no-op the
	// second time. now stamps the documents written and the reindexes
	// queued, and a repository the plan deletes is deleted by ctx's
	// principal, or by no one when ctx carries none. A plan the checks
	// refuse answers an error wrapping ErrInvalid, and a failed write one
	// wrapped as "apply configuration: %w".
	Apply(ctx context.Context, p Plan, now time.Time, dryRun bool) (Result, error)
}

Descriptor reads and applies Artifactory's YAML configuration descriptor (decision 0009): the body of PATCH /api/system/configuration, `config apply` and the bootstrap descriptor.

type Plan

type Plan interface {
	// DescriptorPlan marks the types Parse returns as plans. It does
	// nothing.
	DescriptorPlan()
}

Plan is a parsed configuration descriptor, ready to apply. Only Descriptor.Parse makes one, and only the Descriptor implementation whose Parse made it can apply it: callers hold it without looking inside.

type Result

type Result struct {
	Created, Updated, Deleted, Unchanged []string
	// Changes counts the values in the document, whether or not they differ
	// from what is stored: the number Merged reports.
	Changes int
	// DryRun is set when nothing was written.
	DryRun bool
}

Result names what applying a descriptor changed, each entry as "section.key".

func (Result) Merged

func (r Result) Merged() string

Merged is the PATCH endpoint's answer, in Artifactory's words. It counts the document's values rather than what changed, as Artifactory does, so applying the same patch again gives the same number.

func (Result) String

func (r Result) String() string

String is the plain-text summary `config apply` prints.

type Settings

type Settings struct {
	// DockerSubdomainMatch is docker.subdomain_match. When it is set, the
	// reverse proxy configuration names the Docker subdomain method, in which
	// <repo>.<base URL host> addresses repo, and the server name expression
	// that matches those hosts; when it is not, it names the repository path
	// method.
	DockerSubdomainMatch bool
}

Settings are the configuration options that the configuration module's code reads from the installation's configuration. The zero value is the default of each.

type System

type System interface {
	// DownloadRedirectMinSize returns, in bytes, the minimum size of a file
	// that a repository with downloadRedirect or cdnRedirect redirects, as
	// the descriptor's downloadRedirectConfig.fileMinimumSize set it. ok is
	// false when no descriptor has set it, and the caller then keeps the
	// installation's download.redirect.min_size (decision 0029).
	DownloadRedirectMinSize(ctx context.Context) (n int64, ok bool, err error)
}

System is the system configuration that other modules read.

Jump to

Keyboard shortcuts

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