Documentation
¶
Overview ¶
Package layout implements Artifactory repository layouts: the path patterns that tell the server which part of an artifact path is the organisation, module, base revision, integration revision, classifier and extension. A layout drives version search, snapshot cleanup and cross-layout copy, so it has to parse and build paths exactly as Artifactory does.
Role ¶
artifacts module, core layer: the repository layout engine. The layout searches, copy and move, the Maven format and remote discovery read and build paths through it, and other modules check a layout definition through artifacts/api.Layouts, which Checker implements. It imports only the standard library and artifacts/api, so it never reaches the module's adapters or an ecosystem http package (decision 0044, dependency rules).
Inputs ¶
- Layout definitions from repository configuration: a repository names its layout in repoLayoutRef (decision 0003), and the configuration descriptor's repoLayouts hold the definitions, each of which the descriptor compiles before it stores it.
- The bundled set: the layouts Artifactory 7.x ships, in the order its descriptor lists them. Bundled returns their definitions and Lookup compiles one by name.
- Repository-relative paths to read, and token values (Values) to build paths from.
Outputs ¶
- Compiled layouts: Compile and Lookup turn a Definition into a Layout, and VersionTokens gives the Layout that also reads [RELEASE] and [INTEGRATION] in a download path.
- Coordinates: Match reads a path's token values and Read its Coordinates, the module identity that the layout searches and the format handlers work with. Build and BuildDescriptor turn values back into a path.
- Folder prefixes: Prefixes, the text that every path a layout matches with the given values starts with, which narrows a search before Match decides; and FolderPrefixes, the complete folder those values fix, which remote discovery lists.
- Translations between layouts: Translate, for a copy or move between repositories of different layouts, and RemotePath, for a remote repository whose layout differs from its upstream's. Both answer a *LossError, which wraps ErrLossy, when a path has no lossless translation, so two paths never land on one.
- Errors: ErrPattern, ErrNoMatch, ErrMissingValue and ErrUnbuildable say why a pattern does not compile, a path does not read, or values do not build a path.
- Checker, implementing artifacts/api.Layouts: the check the configuration descriptor runs on a layout definition before it stores it, which answers Compile's error unchanged.
Invariants ¶
- Token expressions, pattern parsing and the bundled definitions follow Artifactory's (RepoLayoutUtils in 6.20, 7.x's descriptors), so a path reads here as Artifactory reads it.
- A translation never lands two source paths on one target path, or one version would overwrite another.
- Compile refuses a token that is neither documented nor custom. Only Lookup's bundled layouts drop one, as Artifactory does, and a pattern with a dropped token builds no path (ErrUnbuildable).
- Error texts reach clients, so they stay byte-identical: Compile's when a configuration descriptor change brings a malformed layout, and a LossError's in copy and move results.
References ¶
- https://docs.jfrog.com/artifactory/docs/repository-layouts.md, the pattern syntax.
- Research 03: docs/research/03-repository-configuration-model.md, "Repository layouts", "Bundled definitions" and "Layout translation".
- Decision 0003: docs/research/decisions/0003-repository-model.md (a repository names its layout, and the layout a create without one gets).
- Decision 0012: docs/research/decisions/0012-search-and-aql.md, lines 333 to 335 (GAVC, versions and latest version read coordinates through each repository's layout).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Dependency rules".
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 212 (core/layout), line 1053 (published through api.Layouts, which Checker implements) and rule 2 at lines 35 to 36.
- Plan: docs/implementation/plan.md#p0-foundations (task 3), #p5-full-aql-searches-build-info, #p7-npm-go-maven-locals, #p9-remote-repositories and #p9d-modular-monolith-migration, epic ART (https://github.com/weaveplatform/artifactweave/issues/941).
- https://github.com/weaveplatform/artifactweave/issues/968
- https://github.com/weaveplatform/artifactweave/issues/1009
Status ¶
Implemented P0 to P9: the pattern engine and the bundled layouts, with Bundled and Lookup, in P0; Has and Prefixes for the layout searches in P5; Coordinates, Read and VersionTokens, the bundled layouts checked against 7.x with Lookup dropping undocumented tokens, Translate and ErrUnbuildable in P7; FolderPrefixes and RemotePath for remote discovery in P9. Moved here in P9d, where Checker was added.
Testing ¶
- TestUnitMavenMatch, TestUnitMavenBuild, TestUnitOptionalGroupNesting, TestUnitCompileErrors, TestUnitOrgPath, TestUnitHas and TestUnitPrefixes: the pattern engine.
- TestUnitBundledCompile, TestUnitBundledNames and the TestUnitBundledLayouts* pair: every bundled layout compiles, is listed in 7.x's order, and reads the real paths it describes and no others. TestUnitBuildCarriesItsValues and TestUnitBuildRefusalText: a build changes with each value, or is refused.
- TestUnitRead, TestUnitVersionTokens and TestUnitReadNeedsOrganisation: coordinates.
- The TestUnitFolderPrefixes* pair: folder prefixes.
- TestUnitTranslate, TestUnitTranslateKeeps, TestUnitLossErrorText, TestUnitTranslateWithSimpleDefault and TestUnitTranslateNeverMerges, which tries every ordered pair of bundled layouts: translations.
- The TestUnitRemotePath* pair: remote paths.
- TestUnitLayoutCheckerMatchesCompile: Checker answers as Compile does for every bundled layout and for valid and malformed definitions.
Index ¶
- Constants
- Variables
- func Org(orgPath string) string
- func OrgPath(org string) string
- func RemotePath(canonical, upstream *Layout, path string) (string, error)
- func Translate(from, to *Layout, path string) (string, error)
- type Checker
- type Coordinates
- type Definition
- type FolderPrefix
- type Layout
- func (l *Layout) Build(v Values) (string, error)
- func (l *Layout) BuildDescriptor(v Values) (string, error)
- func (l *Layout) Definition() Definition
- func (l *Layout) FolderPrefixes(v Values) []FolderPrefix
- func (l *Layout) Has(token string) bool
- func (l *Layout) IsDescriptor(path string) bool
- func (l *Layout) Match(path string) (Values, error)
- func (l *Layout) Prefixes(v Values) []string
- func (l *Layout) Read(fullPath string) (Coordinates, bool)
- func (l *Layout) VersionTokens() (*Layout, error)
- type LossError
- type Values
Constants ¶
const ( TokenOrg = "org" TokenOrgPath = "orgPath" TokenModule = "module" TokenBaseRev = "baseRev" TokenFolderItegRev = "folderItegRev" //nolint:gosec // G101: layout token name, not a credential TokenFileItegRev = "fileItegRev" TokenClassifier = "classifier" TokenExt = "ext" TokenType = "type" )
Token names with a built-in meaning.
Variables ¶
var ErrLossy = errors.New("layout translation loses part of the path")
ErrLossy reports a translation between layouts that would land two source paths on one target path.
var ErrMissingValue = errors.New("missing value for layout token")
ErrMissingValue reports a Build call without a mandatory token value.
var ErrNoMatch = errors.New("path does not match layout")
ErrNoMatch reports a path that does not fit the layout.
var ErrPattern = errors.New("invalid layout pattern")
ErrPattern reports a malformed pattern.
var ErrUnbuildable = errors.New("layout cannot build a path")
ErrUnbuildable reports a Build of a pattern with a token outside the documented set, which a bundled layout drops (Lookup). Such a pattern has no place for that token's value, so every path it built would be the same literal text whatever the values, such as ansible-default's collections////--.tar.gz.
Functions ¶
func OrgPath ¶
OrgPath converts a dotted organisation into the slash form used by [orgPath]; Artifactory derives one from the other the same way.
func RemotePath ¶
RemotePath finds the unique upstream file whose lossless canonical projection is path. A remote namespace contains only that projection: for example a Maven POM projects to Gradle's ivy descriptor, so the other Gradle artifact spelling ending in .pom cannot become an alias for the same upstream bytes. Copy/move Translate retains its stricter, symmetric source-namespace rules.
func Translate ¶
Translate converts path from layout from to layout to, as a copy or move between repositories of different layouts does (suppressLayouts=0): the values from reads build to's pattern, its descriptor pattern for a descriptor. It answers ErrNoMatch when from does not read the path, and ErrMissingValue, ErrPattern or ErrUnbuildable when to cannot build one from what from reads; the caller keeps such a path as it is.
A translation must never land two source paths on one target path, or one version would overwrite another: go-default's v1.2.3-rc.1.zip and v1.2.3.zip would both be lib-1.2.3.zip in simple-default, which has no file revision. So the target path must lead back to the source path alone, or Translate answers a *LossError. The paths that lead back are those from builds out of what to reads in the target path, through either pattern of each; the source path must be one of them, and none of the others may translate to the same target. Two source paths that both passed would each be among the other's candidates, so at most one passes.
Types ¶
type Checker ¶
type Checker struct{}
Checker implements artifacts/api.Layouts with Compile, so configuration refuses exactly the layout definitions the engine cannot compile. The zero value is ready to use; it holds no state and is safe for concurrent use.
func (Checker) Check ¶
func (Checker) Check(d artifactsapi.LayoutDefinition) error
Check compiles d with Compile and returns Compile's error as it is, nil when d compiles. The conversion to Definition relies on LayoutDefinition having Definition's fields in the same order and of the same types, so it stops compiling if either struct changes rather than dropping a field.
type Coordinates ¶
type Coordinates struct {
Org, Module, BaseRev, FolderItegRev, FileItegRev, Classifier, Ext string
}
Coordinates are what a layout reads from one file's path: the module identity the searches (decision 0012) and the format handlers (decision 0032) work with.
func (Coordinates) FileVersion ¶
func (c Coordinates) FileVersion() string
FileVersion is the file's own version: the base revision with the file's integration revision, as in 1.0-20260101.120000-1.
func (Coordinates) Integration ¶
func (c Coordinates) Integration() bool
Integration reports an integration (snapshot) version.
func (Coordinates) Version ¶
func (c Coordinates) Version() string
Version is the module version the file belongs to: the base revision with the folder's integration revision, or the file's when the folder has none, as in 1.0-SNAPSHOT.
type Definition ¶
type Definition struct {
Name string
ArtifactPathPattern string
DistinctiveDescriptorPathPattern bool
DescriptorPathPattern string
FolderIntegrationRevisionRegExp string
FileIntegrationRevisionRegExp string
}
Definition is a repository layout as stored in the configuration descriptor (repoLayouts.<name>).
func Bundled ¶
func Bundled() []Definition
Bundled returns the definitions of the layouts Artifactory ships, in the order the descriptor lists them.
type FolderPrefix ¶
FolderPrefix is the longest complete directory prefix determined by Values. Bound contains only tokens determined before its final slash. A token known only in the filename cannot authorize a version or module directory.
type Layout ¶
type Layout struct {
// contains filtered or unexported fields
}
Layout is a compiled Definition.
func Compile ¶
func Compile(def Definition) (*Layout, error)
Compile parses the definition's patterns. The integration-revision regexps are substituted into [folderItegRev] and [fileItegRev] at compile time, so a layout with an empty regexp gets Artifactory's permissive ".+" and still matches. A token that is neither documented nor custom is an error, as Artifactory's layout editor reports it, so a layout the descriptor stores always reads the paths its author meant.
func Lookup ¶
Lookup compiles a bundled layout by name. Unlike Compile, it drops a token outside the documented set, as Artifactory's parser does when it matches a path, because 7.x ships layouts that use such tokens.
func (*Layout) Build ¶
Build renders an artifact path from token values. Optional groups are emitted only when every token inside them has a value; mandatory tokens without a value are an error, and so is a pattern with a token it drops (ErrUnbuildable).
func (*Layout) BuildDescriptor ¶
BuildDescriptor renders a descriptor path, or an error when the layout has no descriptor pattern or Build would refuse its pattern.
func (*Layout) Definition ¶
func (l *Layout) Definition() Definition
Definition returns the source definition.
func (*Layout) FolderPrefixes ¶
func (l *Layout) FolderPrefixes(v Values) []FolderPrefix
FolderPrefixes renders known values through optional groups, distinguishing an explicitly absent optional token (empty value) from an unknown token. Unlike Prefixes, its output is always a complete folder, never part of a name.
func (*Layout) Has ¶
Has reports whether the artifact pattern uses token; org and orgPath stand for each other, as they do in Match and Build.
func (*Layout) IsDescriptor ¶
IsDescriptor reports whether the path matches the descriptor pattern.
func (*Layout) Match ¶
Match extracts token values from an artifact path. When the layout has a distinctive descriptor pattern that pattern is tried first, because a POM also matches the artifact pattern with ext=pom and the descriptor match is the more specific one.
func (*Layout) Prefixes ¶
Prefixes return the text every path the layout matches with the tokens in v starts with: the artifact pattern's, and the descriptor pattern's when there is one, each rendered up to its first optional group or token without a value. Values are copied as given, so one with * or ? makes a prefix a glob. A search narrows by them before Match decides.
func (*Layout) Read ¶
func (l *Layout) Read(fullPath string) (Coordinates, bool)
Read returns the coordinates the layout reads from a repository-relative file path; ok is false when the path does not fit the layout or lacks one of the three fields JFrog's repository-layouts page calls mandatory for module identification: organisation, module and base revision (ModuleInfo.isValid in 6.20). So a layout without [org] or [orgPath], such as cargo-default, reads no module.
func (*Layout) VersionTokens ¶
VersionTokens returns the layout a download path that may ask for a version token is read with: [INTEGRATION] and [RELEASE] also stand for either integration revision, as Artifactory reads a request (RepoLayoutUtils.getTokenRegExp with version tokens). A base revision already reads [RELEASE]. Without this, the lazy base revision would take in a following -[INTEGRATION], and the request would read as a release. The definition stays the layout's own.
type LossError ¶
type LossError struct {
From, To string // the layouts' names
Path string // the source path
Target string // the path the translation would give
Lost []string
Rival string
}
LossError is ErrLossy for one path: the tokens whose values the target layout has no place for, or, when every value survives but the paths still meet, another source path that translates to the same target.