Documentation
¶
Overview ¶
Package nuget is the format of NuGet repositories (decision 0038). It reads each package's .nuspec, indexes a .nupkg or .snupkg at its canonical name as a file of its version (decision 0018) with the per-version Metadata the v3 and v2 feeds are built from, and keeps the nuget.* properties. Every write reaches it through the item service, so a package pushed by dotnet nuget push, deployed by jf rt upload, or landed by a copy, a move or a restore is indexed the same way.
Every repository behaves as one created with 7.x's Enforce Layout, with no switch (DV-111): versions are normalised, a version has one package whichever route brings it, and a .nupkg or .snupkg that is no valid package, or is not at its canonical name, is refused (Admit). Files of any other name, legacy .symbols.nupkg included, are stored as plain items.
A version is its package, the id lower-cased, and its version, normalised and lower-cased (PackageName, VersionKey). Its files are every file at one of its canonical names: its .nupkg and, when pushed, its .snupkg. Admit keeps that to one of each, but a trash restore, which no format refuses, can bring back a second; the one deployed first, a tie broken by path, is the one the Metadata describes, so the hooks and a reindex agree whatever the order of events.
There is no unlisted state (decision 0038, "Delete and relist"), so no property changes the index and the format is no format.Annotator.
Index ¶
- Constants
- Variables
- func FileName(id string, v Version) string
- func NormalizeVersion(v string) (string, bool)
- func PDBKey(b []byte) (string, bool)
- func PackageName(id string) string
- func Serves(t repo.PackageType) bool
- func SymbolPath(name, key, file string) (string, bool)
- func SymbolsFileName(id string, v Version) string
- func ValidID(id string) bool
- func ValidateRemote(ctx context.Context, r io.ReadSeeker, size int64, id, key string) error
- func VersionKey(v Version) string
- type Dependency
- type DependencyGroup
- type Handler
- func (Handler) Admit(ctx context.Context, env format.Env, c repo.Config, w format.Write) (format.Write, error)
- func (Handler) Classify(c repo.Config, p string) format.Class
- func (Handler) Deleted(ctx context.Context, env format.Env, c repo.Config, removed []types.Item) error
- func (h Handler) Deployed(ctx context.Context, env format.Env, c repo.Config, it types.Item) error
- func (Handler) GuardWrite(ctx context.Context, env format.Env, c repo.Config, w format.Write) error
- func (Handler) Inspect(ctx context.Context, env format.Env, c repo.Config, w format.Write) (any, error)
- func (Handler) Owed(c repo.Config, cached bool, p string) []format.WorkRef
- func (h Handler) Reindex(ctx context.Context, env format.Env, c repo.Config) error
- func (Handler) Work(ctx context.Context, env format.Env, it types.WorkItem) error
- func (Handler) WorkKinds() []string
- type Metadata
- type Nuspec
- type PackageType
- type SymbolFile
- type SymbolSource
- type Version
Constants ¶
const ( PackageExt = ".nupkg" SymbolsExt = ".snupkg" LegacySymbolsExt = ".symbols.nupkg" )
Extensions of the files the format indexes, and of the legacy symbol packages it leaves alone. They are matched with their case, as NuGet writes them and as AQL, which a reindex finds them with, matches names.
const ( // PropID is the nuspec's id with its case. PropID = "nuget.id" // PropVersion is the normalised version. [I] Whether 7.x writes the // normalised or the nuspec's version is unknown (#216). PropVersion = "nuget.version" PropTitle = "nuget.title" PropAuthors = "nuget.authors" PropOwners = "nuget.owners" PropSummary = "nuget.summary" PropDescription = "nuget.description" PropCopyright = "nuget.copyright" PropReleaseNotes = "nuget.releaseNotes" PropProjectURL = "nuget.projectUrl" PropLicenseURL = "nuget.licenseUrl" PropIconURL = "nuget.iconUrl" // PropTags is the nuspec's space-separated string. PropTags = "nuget.tags" // PropRequireLicenseAcceptance is "true" or "false". PropRequireLicenseAcceptance = "nuget.requireLicenseAcceptance" // PropDigest is the package's SHA-512 in base64, as the v2 feed's // PackageHash gives it. [I] 7.x's value is unknown (#216). PropDigest = "nuget.digest" // PropDependency has one value per dependency, "<id>:<range>:<target // framework>", the framework empty outside a <group>, as RTFACT-31474 // shows 7.x writing it. PropDependency = "nuget.dependency" )
The nuget.* properties the format sets on each indexed .nupkg from its nuspec, the keys Artifactory 6.20's NuGetProperties defines (decision 0038, "Properties"). The feeds read the index, never these, so editing one changes no feed, and a reindex writes it back.
const Deleter = "_system_"
Deleter is who the cleanup's deletes are recorded as, Artifactory's system user.
const KindSnapshots = "nuget.snapshots"
KindSnapshots applies a package's maxUniqueSnapshots (decision 0038), keyed by "<repository key>/<package>", the package being the id lower-cased; repository keys hold no slash. It is periodic work: a deploy of a pre-release marks the package, and the runtime runs the marked packages every nuget.snapshot_cleanup_interval (work.Queue.HandleEvery), as 7.x's cleanup runs every five minutes (KB 000005403).
const KindSymbols = "nuget.symbols"
KindSymbols reconciles the PDBs of a repository after source commits. The work queue serializes a repository's runs and preserves an enqueue made during a run. Source transactions never lock derived items: that would invert lock order during deletion and cross-repository moves.
const MaxIDLength = 100
MaxIDLength is the longest id NuGet accepts, in UTF-16 code units (PackageIdValidator.MaxPackageIdLength).
const SymbolsPackageType = "SymbolsPackage"
SymbolsPackageType is the package type of a symbols package (NuGet.Packaging's PackageType.SymbolsPackage).
Variables ¶
var ErrNotPackage = errors.New("nuget: not a valid NuGet package")
ErrNotPackage is content the format cannot index: no zip, no single readable .nuspec at its root, an id NuGet would not accept, a version NuGet cannot parse, or more than limits allow. Decision 0038 stores no such .nupkg or .snupkg in a local repository. Package validation messages are included verbatim in NuGet push and deploy responses; retain their client-visible spelling.
Functions ¶
func FileName ¶
FileName is the canonical file name of the package of id at version, "<id>.<version>.nupkg" with the id's own case and the version normalised (decision 0038). A push stores it at the repository root, or in the folder it names, where the JFrog CLI looks for it.
func NormalizeVersion ¶
NormalizeVersion is v normalised, as the flat container, the registration and the v2 feed are asked for it; ok is false when v is no NuGet version.
func PDBKey ¶
PDBKey reads only the identity of a Microsoft PDB v7 or Portable PDB v1.0. The GUID uses Windows GUID byte order; the age is unpadded hex. Portable PDBs use the GUID part of their 20-byte ID and FFFFFFFF, not the trailing four-byte stamp (Microsoft's SSQP key conventions).
func PackageName ¶
PackageName is the package index's name for id: the id lower-cased, as NuGet compares ids ignoring case and as the flat container and the registration spell them.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether t is a package type of this format.
func SymbolPath ¶
SymbolPath canonicalizes both names and the key. Microsoft's symbol key convention is case-insensitive; keeping one spelling also avoids divergent derived files when two target frameworks contain the same PDB.
func SymbolsFileName ¶
SymbolsFileName is the canonical file name of the symbols of id at version, "<id>.<version>.snupkg".
func ValidateRemote ¶
ValidateRemote preserves the original archive (including its signature) while checking identity and every ZIP CRC before the remote cache publishes bytes. Cryptographic signature trust is a NuGet client decision; this validator never re-signs an upstream package or treats a well-formed signature as trusted.
func VersionKey ¶
VersionKey is the package index's version for v: normalised and lower-cased, as the flat container and the registration spell it, so that versions NuGet takes for one, such as 1.0.0-Beta and 1.0.0-beta, are one version of the index. Metadata.Version keeps the case.
Types ¶
type Dependency ¶
type Dependency struct {
ID string `json:"id"`
// Range is the version attribute as the nuspec writes it.
Range string `json:"range,omitempty"`
}
Dependency is one <dependency>.
type DependencyGroup ¶
type DependencyGroup struct {
// TargetFramework is as the nuspec writes it.
TargetFramework string `json:"target_framework,omitempty"`
Dependencies []Dependency `json:"dependencies,omitempty"`
}
DependencyGroup is a nuspec's <group>, or its dependencies outside any group, which have no target framework.
type Handler ¶
type Handler struct {
// The generic format's hooks for what NuGet leaves alone; Admit adds
// the package checks to its deploy policy.
generic.Handler
}
Handler is the NuGet format.
func (Handler) Admit ¶
func (Handler) Admit( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (format.Write, error)
Admit applies Enforce Layout's rules (decision 0038, "Storage and the package index") to every write that lands a .nupkg or .snupkg in the repository: a REST deploy, a checksum deploy, an archive's entry, a push, a copy and a move. Then come the deploy policy of every package type, blackedOut and the include and exclude patterns. The package checks go first because decision 0038 orders a push's 409 for a duplicate before the item routes' own refusals. A checksum upload for an existing file lands no package, and a remote repository's cache stores what its upstream serves, so neither is checked.
func (Handler) Classify ¶
Classify excludes regenerated symbols from replication; the .snupkg is the source of truth and travels through normal package admission. Remote PDBs instead originate upstream and are immutable cache content.
func (Handler) Deleted ¶
func (Handler) Deleted( ctx context.Context, env format.Env, c repo.Config, removed []types.Item, ) error
Deleted brings each version a delete or a move took a file from in line with the files it has left: pruning has dropped the versions left with none, and a version left with its .snupkg alone, or with a second package a restore brought back, is described anew. The removed files' links are gone by now, so their versions are found by the names their paths give.
func (Handler) Deployed ¶
Deployed indexes a .nupkg or .snupkg stored at a canonical name of the package it holds, sets a .nupkg's nuget.* properties, and marks the package for its maxUniqueSnapshots cleanup when the version is a pre-release. A file that was another version's, such as one overwritten with other content, leaves that version first. A file stored anywhere but where the index reads (pkgindex.Stored) is not indexed.
func (Handler) GuardWrite ¶
func (Handler) GuardWrite( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) error
GuardWrite serializes all admitted writes of a version, including REST, checksum deploys, copies and moves, before rechecking its duplicate rule. PostgreSQL's READ COMMITTED transactions can otherwise both observe an absent version and insert it at different paths.
func (Handler) Inspect ¶
func (Handler) Inspect( ctx context.Context, env format.Env, c repo.Config, w format.Write, ) (any, error)
Inspect reads a .nupkg or .snupkg before the write's transaction. Other content needs no reading.
func (Handler) Owed ¶
Owed makes a debugger read wait for committed source changes before looking up the extracted item. Package metadata and snapshot cleanup need no work on read.
func (Handler) Reindex ¶
Reindex rebuilds the repository's NuGet index from its .nupkg and .snupkg files, a remote repository's from its cache, and sets each package's nuget.* properties from its nuspec again, as 7.x "re-annotate[s] the NuGet properties for each NuGet package according to its internal nuspec file" (calculatenugetrepositorymetadata). Which repositories the JFrog reindex operation accepts is the API's rule, answered in internal/server.
type Metadata ¶
type Metadata struct {
// ID is the nuspec's id with its case.
ID string `json:"id,omitempty"`
// Version is the normalised version with its label's case;
// OriginalVersion is the nuspec's as written.
Version string `json:"version,omitempty"`
OriginalVersion string `json:"original_version,omitempty"`
Title string `json:"title,omitempty"`
// Authors and Owners are the nuspec's comma-separated strings, which
// the search answers split.
Authors string `json:"authors,omitempty"`
Owners string `json:"owners,omitempty"`
Description string `json:"description,omitempty"`
Summary string `json:"summary,omitempty"`
ReleaseNotes string `json:"release_notes,omitempty"`
Copyright string `json:"copyright,omitempty"`
Language string `json:"language,omitempty"`
// Tags is the nuspec's space-separated string.
Tags string `json:"tags,omitempty"`
ProjectURL string `json:"project_url,omitempty"`
IconURL string `json:"icon_url,omitempty"`
LicenseURL string `json:"license_url,omitempty"`
LicenseExpression string `json:"license_expression,omitempty"`
RequireLicenseAcceptance bool `json:"require_license_acceptance,omitempty"`
MinClientVersion string `json:"min_client_version,omitempty"`
Readme string `json:"readme,omitempty"`
DependencyGroups []DependencyGroup `json:"dependency_groups,omitempty"`
PackageTypes []PackageType `json:"package_types,omitempty"`
// Nuspec is the .nuspec as the package holds it, which the flat
// container serves.
Nuspec string `json:"nuspec,omitempty"`
// Path is the .nupkg's path in the repository, which every download
// route serves (packageContent and the v2 Download).
Path string `json:"path,omitempty"`
// SHA512 is the .nupkg's SHA-512 in base64, the v2 feed's PackageHash.
SHA512 string `json:"sha512,omitempty"`
Size int64 `json:"size,omitempty"`
// SemVer2 is whether only SemVer 2.0.0 clients may see the version
// (Nuspec.IsSemVer2).
SemVer2 bool `json:"semver2,omitempty"`
// Published is when the .nupkg was last deployed, in UTC to the
// microsecond the stores keep.
Published time.Time `json:"published,omitzero"`
// Symbols is the path of the version's .snupkg, empty without one.
Symbols string `json:"symbols,omitempty"`
SymbolSources []SymbolSource `json:"symbol_sources,omitempty"`
}
Metadata is a version's document in the package index (PackageVersion.Metadata, decision 0038): what the v3 and v2 feeds are built from, so a read needs neither the package nor its properties. Everything in it follows from the version's files and their stored checksums, so a reindex writes the same bytes.
The package fields describe the version's .nupkg. A version whose only file is a .snupkg, pushed before its package, has none of them: Path is empty, and the feeds show no such version.
func DecodeMetadata ¶
DecodeMetadata reads a version's Metadata.
func (Metadata) HasPackage ¶
HasPackage reports whether a .nupkg backs the version.
func (Metadata) IsPrerelease ¶
IsPrerelease reports a version with a pre-release label. A normalised version's numeric parts hold no hyphen, so the first one starts it.
type Nuspec ¶
type Nuspec struct {
ID string
Version Version
Title string
// Authors and Owners are the nuspec's comma-separated strings.
Authors, Owners string
Description string
Summary string
ReleaseNotes string
Copyright string
Language string
// Tags is the nuspec's space-separated string.
Tags string
ProjectURL string
IconURL string
LicenseURL string
// LicenseExpression is a <license type="expression">'s SPDX expression.
LicenseExpression string
// RequireLicenseAcceptance is nil when the nuspec does not say.
RequireLicenseAcceptance *bool
// MinClientVersion is <metadata>'s minClientVersion attribute.
MinClientVersion string
// Readme is the path in the package of its readme.
Readme string
DependencyGroups []DependencyGroup
PackageTypes []PackageType
// Raw is the .nuspec as the package holds it.
Raw []byte
}
Nuspec is what the format reads from a package's .nuspec: the elements decision 0038 indexes, each with surrounding space trimmed, as NuGet's reader trims them. An element the nuspec lacks is empty.
func ParseNuspec ¶
ParseNuspec reads a .nuspec. ErrNotPackage when it is no XML <package> with a <metadata>, or names no id NuGet accepts or no version it can parse.
func ReadPackage ¶
ReadPackage reads the package in ra, of size bytes: the one .nuspec at the root of its zip, its extension in any case, as NuGet's PackageArchiveReader finds it. ErrNotPackage when the format cannot index it; any other error is a failure to read the content.
func ReadStored ¶
ReadStored reads the stored content sha as a package; an error wrapping ErrNotPackage when it is none the format can index.
type PackageType ¶
PackageType is one <packageType>.
type SymbolFile ¶
SymbolFile identifies extracted content at its canonical repository path.
type SymbolSource ¶
type SymbolSource struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
Files []SymbolFile `json:"files"`
}
SymbolSource is trusted package-index metadata, never an item property. It records every source, including duplicates recovered by trash restore, so deleting one owner cannot remove a surviving owner's symbols.
type Version ¶
type Version struct {
// Numbers are the numeric parts, four of them, the missing ones 0: NuGet
// reads 1, 1.0, 1.0.0 and 1.0.0.0 as one version.
Numbers [4]int
// Labels are the pre-release label's parts, with their case.
Labels []string
// Metadata is the build metadata, without its "+".
Metadata string
// Original is the version as it was written, less surrounding space.
Original string
}
Version is a NuGet version as NuGet.Versioning's NuGetVersion.TryParse reads it: one to four numeric parts, an optional pre-release label of dot-separated parts, and optional build metadata.
func ParseVersion ¶
ParseVersion reads v as NuGet does. Each numeric part is digits alone, leading zeros allowed; each pre-release part is letters, digits and hyphens, with no leading zero in an all-digit part; each metadata part is the same, leading zeros allowed (NuGet's IsValidPart). ok is false for anything else, such as an empty label or a trailing "-" or "+". [I] NuGet also lets System.Version's parser take space around a numeric part ("1. 0"); no client writes one, and it is refused here.
func (Version) IsPrerelease ¶
IsPrerelease reports a version with a pre-release label.
func (Version) IsSemVer2 ¶
IsSemVer2 reports a version only SemVer 2.0.0 clients read: one whose pre-release label has more than one part, or that has build metadata (Microsoft's "Semantic Versioning 2.0.0").
func (Version) Normalized ¶
Normalized is the version as NuGet normalises it (Microsoft's "Normalized version numbers", JFrog's migration tool): Release, then the pre-release label with its case, and no build metadata. 1.0 is 1.0.0, 01.02.03 is 1.2.3, 1.2.3.0 is 1.2.3, 1.2.3.1 stays, and 1.0.7+r3456 is 1.0.7.