Documentation
¶
Overview ¶
Package swift implements the Swift package registry's stored archive format. A release is one immutable source archive, a ZIP stored at <scope>/<name>/<name>-<version>.zip, the layout JFrog documents for local Swift repositories, with exactly one package root holding Package.swift. The package index links each package (<scope>.<name>) to the releases whose archives are stored, and is rebuilt from them.
Role ¶
artifacts module, ecosystem layer: the Swift package registry archive layout of the Swift slice. Its Handler plugs into the item service through the format hooks (decision 0032), so every write, an item PUT, copy or restore included, meets the same checks; the slice's http package (artifacts/ecosystem/swift/http) serves the Swift Package Registry API over what it keeps.
Inputs ¶
- Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for swift repositories to Handler, and the work queue, which runs every format's reindex through it (JFrog's /api/swift/{repoKey}/reindex schedules one); and the protocol, which checks identities (Package, ValidScope, ValidName, ValidVersion), builds archive paths (Package.ArchivePath) and inspects published, stored and upstream archives (InspectArchive).
- Driven: the format hooks' environment (format.Env): its blobs hold the archives, and its store holds the items and the package index (artifacts/core/pkgindex), which Reindex rebuilds from an AQL search of the stored files. The generic blackout and include and exclude checks (artifacts/ecosystem/generic) run before the format's own. InspectArchive spools an archive to a temporary file, since a ZIP is read from its central directory at the end.
- Settings: none.
Outputs ¶
- Handler: the hooks that inspect an archive once before its transaction (Inspect), admit only a valid archive at a canonical path that does not replace a release with other content (Admit), link a stored release to its package (Deployed), class every path as unique content (Classify) and rebuild the index from the stored archives (Reindex). Deletes need no hook.
- The package index: a package per <scope>.<name>, with a version per stored release archive.
- The identity and archive rules: Package with ID, ArchivePath and IsValid, ValidScope, ValidName, ValidVersion, ParseArchivePath, InspectArchive, Archive and MaxArchiveBytes.
Invariants ¶
- An archive is read whole within fixed bounds (512 MiB compressed, 1 GiB expanded, 100,000 entries and 1 MiB for each manifest): one package root, at the top or in one folder; unique members under it that are regular files or folders, neither encrypted nor at an absolute, backslashed or traversing path; every member read to its end; and manifests that import PackageDescription and declare a swift-tools-version.
- A release is immutable: a write of other content to a stored release's path is refused (409), while the same content passes.
- Reindex omits an archive that no longer validates rather than advertising it.
References ¶
- Decision 0032: docs/research/decisions/0032-package-format-handlers.md (the format hooks); decision 0007: docs/research/decisions/0007-remote-repositories.md (remote repositories, whose upstream archives InspectArchive checks).
- docs/testing/swift.md (connecting SwiftPM, the native operations, the archive validator and the evidence).
- JFrog Swift repositories: https://docs.jfrog.com/artifactory/docs/swift-repositories, and the Swift Package Registry specification: https://github.com/swiftlang/swift-package-manager/blob/main/Documentation/PackageRegistry/Registry.md.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 234 (ecosystem/swift), line 379 (the slice row) and line 997 (the mapping row).
- Plan: docs/implementation/plan.md#p30-language-package-repositories and #p9d-modular-monolith-migration, epic ECO (https://github.com/weaveplatform/artifactweave/issues/943).
- https://github.com/weaveplatform/artifactweave/issues/766 and https://github.com/weaveplatform/artifactweave/issues/1048
Status ¶
Implemented P9c, which delivered the plan's P30 group (issues #762 to #768). Moved here in P9d.
Testing ¶
- path_test.go: the identity grammar and the archive path.
- archive_test.go: archive inspection and a failing read.
- coverage_test.go: unsafe members and cancelled inspection, the bounds and every member's checks, admission of corrupt and changed archives, and a reindex that restores only valid stored archives.
Index ¶
- Constants
- func Serves(t repo.PackageType) bool
- func ValidName(s string) bool
- func ValidScope(s string) bool
- func ValidVersion(v string) bool
- type Archive
- type Handler
- func (h Handler) Admit(ctx context.Context, env format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) Classify(_ repo.Config, _ string) format.Class
- func (Handler) Deleted(context.Context, format.Env, repo.Config, []model.Item) error
- func (Handler) Deleting(context.Context, format.Env, repo.Config, model.Item) error
- func (Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error
- func (Handler) Inspect(ctx context.Context, env format.Env, _ repo.Config, w format.Write) (any, error)
- func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- type Package
Constants ¶
const ( // MaxArchiveBytes bounds a source archive at 512 MiB compressed, however // it arrives: a publish, an item write or a remote's fetch. MaxArchiveBytes = 512 << 20 )
Variables ¶
This section is empty.
Functions ¶
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is the Swift package type.
func ValidName ¶
ValidName reports whether s is a package name the registry specification's grammar allows: 1 to 100 ASCII letters, digits, hyphens and underscores, with no separator first, last or next to another.
func ValidScope ¶
ValidScope reports whether s is a scope the registry specification's grammar allows: 1 to 39 ASCII letters, digits and hyphens, with no hyphen first, last or next to another.
func ValidVersion ¶
ValidVersion reports whether v is a full semantic version of at most 128 bytes: major.minor.patch with an optional pre-release and build.
Types ¶
type Archive ¶
Archive describes a completely validated source ZIP. Manifests are kept bounded in memory; all other members are read to EOF so CRC, size and truncated-stream errors are checked before a release can be published.
func InspectArchive ¶
InspectArchive reads a whole source ZIP of size bytes from body, or of any size up to MaxArchiveBytes when size is 0, and returns its manifests. It spools the archive to a temporary file and requires 1 to 100,000 entries, at most 1 GiB expanded, exactly one package root holding Package.swift, at the top or in one folder, and unique members under that root that are regular files or folders, unencrypted and at safe paths. Every member is read to its end, and every manifest, Package.swift or Package@swift-<version>.swift, of at most 1 MiB, must import PackageDescription and declare its swift-tools-version. A refusal names its fault; when ctx ends, the error wraps ctx's.
type Handler ¶
Handler keeps the package index derived from immutable source archives. Every write path, including ordinary item PUT, copy and restore, passes through these hooks so no malformed source is advertised to SwiftPM.
func (Handler) Admit ¶
func (h Handler) Admit( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (format.Write, error)
Admit applies the generic deploy policy, returning its refusal as it is, then passes a checksum deploy. Any other write must be at a canonical release path, <scope>/<name>/<name>-<version>.zip (400), with a valid archive (422), which it inspects itself unless Inspect covered the same path and content. A write of other content over a stored release is refused (409); the same content, or a folder at the path, passes. A remote's copy at any other path is kept as a plain file (format.RemoteCopy).
func (Handler) Classify ¶
Classify classes every path as unique content, as the generic hooks do: a release archive is content only its publisher can supply again.
func (Handler) Deleted ¶
Deleted does nothing: a version is one archive, so the item service's pruning of versions left without files is all a delete needs.
func (Handler) Deleting ¶
Deleting does nothing: the item service drops a removed archive's version link with it.
func (Handler) Deployed ¶
Deployed links a stored release archive to its version in the package index, creating the package and version when they are new. Folders, files at other paths and items outside the tree the index reads (a remote repository's cache, or a local one's own items) change nothing.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, _ repo.Config, w format.Write, ) (any, error)
Inspect validates the stored archive of a write to a release archive path (ParseArchivePath) before the write's transaction, so Admit need not read it again. A checksum deploy and any other path inspect nothing. An invalid archive is refused with 422; one that cannot be opened fails the write.
type Package ¶
type Package struct {
Scope, Name, Version string
}
Package is a Swift registry identity. A release has one immutable source archive at the Artifactory layout documented for local Swift repositories.
func ParseArchivePath ¶
ParseArchivePath accepts only the documented local archive layout. It never interprets another generic item as a Swift release.
func (Package) ArchivePath ¶
ArchivePath is the item path of the release's source archive: <scope>/<name>/<name>-<version>.zip.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package swifthttp serves the Swift Package Registry API on Artifactory's /artifactory/api/swift/{repo} prefix, on Swift local, federated, remote and virtual repositories: a package's release list, a release's metadata, its manifests and source archive, the identifier lookup, and publishing a release.
|
Package swifthttp serves the Swift Package Registry API on Artifactory's /artifactory/api/swift/{repo} prefix, on Swift local, federated, remote and virtual repositories: a package's release list, a release's metadata, its manifests and source archive, the identifier lookup, and publishing a release. |