puppet

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

Documentation

Overview

Package puppet validates Puppet module archives and maintains their native index. A module version is one archive, stored at <owner>-<module>/<owner>-<module>-<version>.tar.gz, whose one root folder, <owner>-<module>-<version>, holds the metadata.json that names the module, its version and its dependencies; that manifest, read from the stored bytes, is what indexes the version. The item tree remains the source of truth.

Role

artifacts module, ecosystem layer: the Puppet module archive validation and index of the Puppet slice. Its Handler plugs into the item service through the format hooks (decision 0032), so every write in a Puppet repository reaches it whichever API carried it; the slice's http package (artifacts/ecosystem/puppet/http) serves the Forge v3 protocol over what it keeps.

Inputs

  • Driving: the format registry (artifacts/ecosystem), which hands the item service's hooks for puppet repositories to Handler, and the work queue, which runs every format's reindex through it; and the protocol, which checks names, versions and paths (ValidName, ValidVersion, Path), checks an upstream release's manifest (ValidateManifest) and a fetched archive (ReadArchive, MaxArchiveBytes) before a remote caches it, and decodes the version metadata the index holds (Metadata).
  • Driven: the format hooks' environment (format.Env): its blobs hold the archives, and its store holds the items, their properties and the package index (artifacts/core/pkgindex). The generic deploy policy (artifacts/ecosystem/generic), which Handler embeds, is the first check Admit applies.
  • Settings: none.

Outputs

  • Handler: the hooks that read an archive once before its transaction (Inspect), admit only a valid archive whose identity matches its path (Admit), index a version and set its properties once its archive is stored (Deployed) and rebuild the index from the stored archives (Reindex). Deletes need no hook: the item service prunes a version whose archive is gone.
  • The package index: a package per module name, with a version per stored archive, whose metadata is the version's Metadata as JSON and whose file is the archive.
  • The puppet.name, puppet.version and puppet.sha256 item properties (PropName, PropVersion, PropSHA256) on each archive.
  • The rules the protocol shares: Manifest, Dependency, Metadata, ValidateManifest, ReadArchive, ManifestLinks (a manifest's project_page and issues_url, which a module record answers), ValidName, ValidVersion, Path, ParsePath, ErrArchive and the archive bounds.

Invariants

  • An archive is read to its end, gzip checksum included, within fixed bounds (64 MiB compressed, 128 MiB unpacked, a 1 MiB metadata.json and 4,096 entries) before its manifest is trusted. Its entries are regular files and folders under its one root, with no link and no duplicate, absolute or traversing path, and nothing but zero padding follows the TAR terminator.
  • A manifest is one JSON object with no repeated or case-aliased key. Its name is <owner>-<module>, its version a full semantic version, and it declares at most 256 dependencies, each on another module, once, with a bounded version requirement.
  • A remote's cached release metadata (v3/releases/<module>) is admitted as the protocol stored it; any other write must be a module archive in a local or federated repository, or one a remote caches.
  • The index and the properties are derived from the stored archives, never from a client's claim. The property names are stored, so they stay byte-identical.

References

Status

Implemented P9c, which delivered the plan's P33 group (issues #782 to #788). Moved here in P9d.

Testing

  • archive_test.go: whole-archive validation, names, paths and version requirements, ambiguous manifests, and folders, padding and oversized manifests.
  • links_test.go: the project_page and issues_url a manifest gives, read only as strings under exactly those keys.
  • handler_test.go: admission against the archive's identity and the repository class, and stale or invalid content at deploy and reindex.
  • contract_test.go: the format contract suite (formattest), which keeps the index right through deploy, overwrite, delete, copy, move, restore and a remote's cache on every store.

Index

Constants

View Source
const (
	// MaxArchiveBytes bounds a module archive, uploaded or fetched, at
	// 64 MiB compressed.
	MaxArchiveBytes = 64 << 20
	// MaxUnpackedBytes bounds an archive's decompressed TAR stream at
	// 128 MiB, so a small archive cannot expand without limit.
	MaxUnpackedBytes = 128 << 20
	// MaxManifestBytes bounds an archive's metadata.json at 1 MiB.
	MaxManifestBytes = 1 << 20
	// MaxFiles bounds an archive at 4,096 TAR entries, folders included.
	MaxFiles = 4096
)
View Source
const (
	// PropName is the property that holds an archive's module name.
	PropName = "puppet.name"
	// PropVersion is the property that holds an archive's module version.
	PropVersion = "puppet.version"
	// PropSHA256 is the property that holds an archive's SHA-256.
	PropSHA256 = "puppet.sha256"
)

The item properties Deployed and Reindex keep on every stored module archive, from its verified metadata.json. The items keep these names, so they never change.

Variables

View Source
var (
	// ErrArchive is what ReadArchive and the manifest decoders return for
	// every archive or manifest they refuse; Deployed and Reindex wrap it
	// when a stored archive no longer matches its path.
	ErrArchive = errors.New("puppet: invalid module archive")
)

Functions

func ManifestLinks(manifest []byte) (string, string)

ManifestLinks returns a metadata.json's project_page and issues_url, each "" unless the manifest gives it as a JSON string under exactly that key. The Forge answers a module's homepage_url and issues_url from them; a link of another type is left out rather than refusing the archive, since the Puppet client reads neither.

func ParsePath

func ParsePath(p string) (name, version string, ok bool)

ParsePath splits an item path into the module name and version whose archive it holds, and reports ok only when p is exactly Path(name, version) with a valid name and version.

func Path

func Path(name, version string) string

Path is the item path of the archive of module name at version: <name>/<name>-<version>.tar.gz.

func Serves

func Serves(t repo.PackageType) bool

Serves reports whether t is the Puppet package type.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is a Puppet module name the registry accepts: <owner>-<module>, each a lowercase letter followed by up to 63 lowercase letters, digits and underscores.

func ValidVersion

func ValidVersion(version string) bool

ValidVersion reports whether version is a full semantic version of at most 128 bytes, major.minor.patch with an optional pre-release and build, written without a leading v.

func ValidateManifest

func ValidateManifest(m Manifest) bool

ValidateManifest rejects invalid identities and dependency constraints before metadata can enter the native index. Puppet resolves the validated constraints.

Types

type Dependency

type Dependency struct {
	Name               string `json:"name"`
	VersionRequirement string `json:"version_requirement"`
}

Dependency is one entry of a manifest's dependencies: the module it needs, named <owner>/<module> or <owner>-<module>, and the version requirement the Puppet client resolves.

func (*Dependency) UnmarshalJSON

func (d *Dependency) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a dependency, refusing a repeated or case-aliased key or invalid JSON with ErrArchive, so the registry and the Puppet client cannot read different values from one entry.

type Handler

type Handler struct{ generic.Handler }

Handler is the Puppet format's hooks: it admits a module archive only when its metadata.json matches its path, and indexes each stored archive as a version of its module. It embeds the generic hooks, so every path is classed as generic content is.

func (Handler) Admit

func (Handler) Admit(
	ctx context.Context, env format.Env, c repo.Config, w format.Write,
) (format.Write, error)

Admit applies the generic deploy policy, wrapping its refusal, then passes a checksum deploy and a remote's cached release metadata (v3/releases/<module>). Any other write must go to a local or federated repository or be a remote's cached content (400), at a module archive path (400), and the archive's metadata.json must name the module and version its path does (409). A remote's copy at any other path is kept as a plain file (format.RemoteCopy). It reuses Inspect's reading when it covers the same content, and reads the stored archive itself otherwise.

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

func (Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it model.Item) error

Deployed indexes a stored module archive: it sets the archive's puppet.* properties, creates the module's package when it is new, and links the version to the archive, with its Metadata as the version's metadata. Folders and files at other paths change nothing. An archive whose metadata.json no longer matches its path fails with ErrArchive.

func (Handler) Inspect

func (Handler) Inspect(
	ctx context.Context, env format.Env, c repo.Config, w format.Write,
) (any, error)

Inspect reads and validates the stored archive of a write to a .tar.gz path before the write's transaction, and returns its metadata for Admit and Deployed, so an archive is read once per write. A checksum deploy, a remote's copy outside the archive layout and any other file inspect nothing. An invalid archive is refused with 400; an archive that cannot be opened fails the write.

func (Handler) Reindex

func (Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error

Reindex reconstructs all package versions from their admitted archives. The item tree, including the remote cache tree, remains authoritative.

type Manifest

type Manifest struct {
	Name         string       `json:"name"`
	Version      string       `json:"version"`
	Author       string       `json:"author,omitempty"`
	Summary      string       `json:"summary,omitempty"`
	License      string       `json:"license,omitempty"`
	Source       string       `json:"source,omitempty"`
	Dependencies []Dependency `json:"dependencies"`
}

Manifest is the client-visible, validated module identity and dependencies.

func (*Manifest) UnmarshalJSON

func (m *Manifest) UnmarshalJSON(data []byte) error

UnmarshalJSON rejects duplicate identity/dependency fields, including case aliases, so the archive and a client's JSON parser cannot disagree.

type Metadata

type Metadata struct {
	Name     string   `json:"name"`
	Version  string   `json:"version"`
	Manifest Manifest `json:"manifest"`
	// Document is the archive's metadata.json, compacted, which a release
	// record answers as its metadata (#1325): 7.x answers the file's other
	// fields beside the validated ones (RTFACT-19130). It is at most
	// MaxManifestBytes, since ReadArchive reads no larger manifest, and
	// Manifest validated it, so it is one JSON object whose keys do not
	// repeat.
	Document json.RawMessage `json:"document,omitempty"`
	// ProjectPage and IssuesURL are metadata.json's project_page and
	// issues_url (ManifestLinks), which a module record answers as its
	// homepage_url and issues_url. They stay out of Manifest so that the
	// release's metadata answers as it did.
	ProjectPage string `json:"project_page,omitempty"`
	IssuesURL   string `json:"issues_url,omitempty"`
	Path        string `json:"path"`
	SHA256      string `json:"sha256"`
	Size        int64  `json:"size"`
}

Metadata is what the package index keeps for a module version, as JSON, and what the protocol answers from: the module's name and version, its validated manifest, the whole metadata.json, the manifest's links, and the stored archive's item path, SHA-256 and size. ReadArchive fills all but the path and SHA-256, which Deployed and Reindex take from the stored item.

func ReadArchive

func ReadArchive(r io.Reader, size int64) (Metadata, error)

ReadArchive validates the entire gzip and TAR stream, including metadata.json. It rejects duplicate and unsafe entries, links, trailing data, oversized decompression, and a manifest whose declared identity is invalid.

Directories

Path Synopsis
Package puppethttp serves the Forge v3 module protocol at /artifactory/api/puppet/{repoKey}: a module's releases, one release and its archive, a module record, an exact-name search, and a local or federated repository's paged lists of every release and module it hosts, in the JSON the Puppet client's and puppet_forge's Forge clients read.
Package puppethttp serves the Forge v3 module protocol at /artifactory/api/puppet/{repoKey}: a module's releases, one release and its archive, a module record, an exact-name search, and a local or federated repository's paged lists of every release and module it hosts, in the JSON the Puppet client's and puppet_forge's Forge clients read.

Jump to

Keyboard shortcuts

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