Documentation
¶
Overview ¶
Package pkgroute is the router kit for package formats with a protocol of their own: npm and Go in P7, then PyPI, NuGet, Helm and Terraform (decision 0032). Mount claims /artifactory/api/<name>/{repoKey}/... for one protocol, or /artifactory/api/<name>/... when the protocol finds the repository key elsewhere in the path (Protocol.Resolve), and any routes it has at the host root (Protocol.Host). Before the protocol's handlers run it resolves the repository, checks its package type and passes it through the class gate, so every protocol answers those the same way and in its own envelope. The kit's helpers then check permissions, download through the item routes' download path, deploy through the item service and read multipart uploads (ReadForm).
Docker's registry predates the kit and keeps its own router (decision 0031). This package never imports internal/server: the server hands it what it needs through Options.
Index ¶
- func DeclaredChecksums(h http.Header) types.Checksums
- func EscapedResourcePath(r *http.Request, prefix string) string
- func Resource(r *http.Request, path, escaped string) source.Resource
- func ServeStream(w http.ResponseWriter, r *http.Request, s *source.Stream) error
- func SetChecksums(h http.Header, c types.Checksums)
- func SourceError(err error, anonymous bool) error
- func SplitValues(v string) []string
- type Form
- type FormFile
- type Found
- type HostRoute
- type Key
- type Kit
- func (k *Kit) Annotate(r *http.Request, it types.Item, set types.Properties, remove []string) error
- func (k *Kit) Blobs() blob.Store
- func (k *Kit) Can(r *http.Request, path string, want types.Actions) bool
- func (k *Kit) CanFolder(r *http.Request, path string, want types.Actions) bool
- func (k *Kit) Created(w http.ResponseWriter, r *http.Request, it types.Item)
- func (k *Kit) DB() store.Store
- func (k *Kit) Delete(r *http.Request, path string) error
- func (k *Kit) DeleteTree(r *http.Request, path string) error
- func (k *Kit) Deploy(w http.ResponseWriter, r *http.Request, path string, props types.Properties) (types.Item, bool)
- func (k *Kit) DeployItem(w http.ResponseWriter, r *http.Request)
- func (k *Kit) Error(w http.ResponseWriter, r *http.Request, err error)
- func (k *Kit) Item(r *http.Request, path string) (Found, error)
- func (k *Kit) MemberRequest(r *http.Request, member repo.Config) (*http.Request, error)
- func (k *Kit) Read(r *http.Request, resource source.Resource) (source.Result, error)
- func (k *Kit) ReadForm(r *http.Request, file string) (Form, error)
- func (k *Kit) ReadFormLimited(r *http.Request, file string, maxFileBytes int64) (Form, error)
- func (k *Kit) ReadFormWith(r *http.Request, file string, extras ...string) (Form, error)
- func (k *Kit) Require(w http.ResponseWriter, r *http.Request, path string, want types.Actions) bool
- func (k *Kit) RequireFolder(w http.ResponseWriter, r *http.Request, path string, want types.Actions) bool
- func (k *Kit) ResolveItem(r *http.Request, path string) (Found, error)
- func (k *Kit) ServeFound(w http.ResponseWriter, r *http.Request, f Found)
- func (k *Kit) ServeItem(w http.ResponseWriter, r *http.Request, path string)
- func (k *Kit) ServeResult(w http.ResponseWriter, r *http.Request, result source.Result)
- func (k *Kit) Store(r *http.Request, path string, body io.Reader, props types.Properties, ...) (types.Item, error)
- func (k *Kit) StoreNew(r *http.Request, path string, info blob.Info, props types.Properties, ...) (types.Item, error)
- func (k *Kit) StoreOnce(r *http.Request, path string, body io.Reader, props types.Properties, ...) (types.Item, error)
- func (k *Kit) StoreResolved(r *http.Request, filename string, info blob.Info, declared types.Checksums, ...) (types.Item, error)
- func (k *Kit) Upload(r *http.Request, body io.Reader) (blob.Info, error)
- type Local
- type Options
- type Path
- type Protocol
- type ReadSource
- type Remote
- type Request
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeclaredChecksums ¶
DeclaredChecksums reads the checksums a deploy declares in its X-Checksum-Sha1, -Sha256 and -Md5 headers. X-Checksum names its algorithm by length; the JFrog CLI sends the SHA-256 in it.
func EscapedResourcePath ¶
EscapedResourcePath drops the route prefix without decoding package slashes. Matrix parameters describe local selection, not an upstream path segment.
func Resource ¶
Resource builds an artifact request with an explicit escaped upstream path. Conditions belong to the downstream representation: a policy backend must not use these as upstream validators without a matching stored representation.
func ServeStream ¶
ServeStream owns and closes the body, including HEAD/304. It writes only representation headers, never cookies or upstream authentication challenges. An error after headers requires the caller to abort the HTTP stream: a partial unknown-length body must not look like a successfully completed artifact.
func SetChecksums ¶
SetChecksums sets the X-Checksum-Sha1, -Sha256 and -Md5 headers a download and a protocol deploy answer with; jf go-publish reads the SHA-256 from a deploy's (research 26 section 3.1).
func SourceError ¶
SourceError maps only known source errors. Other errors retain the router's existing internal-fault treatment; no upstream body or challenge is relayed.
func SplitValues ¶
SplitValues splits a property value list at its commas; a backslash escapes the character after it, so "a\,b" is one value.
Types ¶
type Form ¶
type Form struct {
// File is the content of the file part, committed to the blob store
// as Upload commits it; StoreNew stores it. Content no item comes to
// reference is collected as an orphan.
File blob.Info
// FileName is the file part's file name as the client sent it, and
// Field its form name.
FileName, Field string
// Fields are the values of the fields that are not files, by name, in
// the order sent.
Fields url.Values
// ExtraFiles contains explicitly requested additional file fields. Most
// protocols discard extra files; signed LuaRocks uploads keep their .asc
// sidecar beside the rock or rockspec.
ExtraFiles map[string]FormFile
}
Form is a multipart/form-data upload that ReadForm read.
type Found ¶
Found is an item a Source found, with the repository that holds it: for a virtual repository, one of its members.
type HostRoute ¶
type HostRoute struct {
// Path is the route's escaped path from the host root, such as
// "/.well-known/terraform.json".
Path string
// Methods are the methods it serves. Any other answers 405 in the
// protocol's envelope.
Methods []string
// Unauthenticated routes are served before authentication, whatever
// credentials the request carries, which are then not read: 7.x serves
// Terraform's discovery document to anyone, and Terraform sends any
// token it holds with it, so an expired token must not end in "failed
// to request discovery document" (decision 0040). The server asks
// SkipsAuthentication before it authenticates.
Unauthenticated bool
// Serve answers the route.
Serve func(w http.ResponseWriter, r *http.Request, k *Kit)
}
HostRoute is a protocol's route at a path from the host root.
type Key ¶
type Key struct {
// Key is the repository key as the path carries it, escaped. The kit
// decodes it; a malformed escape answers 400.
Key string
// CacheOnly is set by native protocols that accept a remote -cache alias.
CacheOnly bool
// Rest is the escaped path the protocol's routes match once Key names a
// repository, without its leading slash; Request.Rest carries it.
Rest string
}
Key is a candidate for the repository key in a protocol's path, which Protocol.Resolve returns.
func FirstSegment ¶
FirstSegment is the candidate the kit takes when a protocol has no Resolve: the first segment of rel is the key and what follows it the rest. An empty first segment names no repository. A protocol's Resolve falls back on it for the paths that name the key first, as Terraform's repository-scoped forms do.
func SplitKey ¶
SplitKey splits seg, a path segment that starts with a repository key joined to the rest by sep, at each sep in turn from the left, and returns each split as a Key whose Rest is what follows that sep. A split with an empty side is left out. Terraform joins a module's key and namespace with "__" and a provider's with "-rt-ns-" (decision 0040), and both may occur in a key, so every split is a candidate and the store decides.
type Kit ¶
type Kit struct {
// contains filtered or unexported fields
}
Kit is one protocol mounted on a router. Its handlers call its helpers, which answer in the protocol's envelope.
func Mount ¶
Mount claims prefix /artifactory/api/<name>/{repoKey} on r for p, or /artifactory/api/<name>/ when p has a Resolve, and p's host routes, before the generated servers are mounted (decision 0032), and returns the kit p's routes were given.
func (*Kit) Annotate ¶
func (k *Kit) Annotate( r *http.Request, it types.Item, set types.Properties, remove []string, ) error
Annotate changes the properties of it, a file of the request's repository, through the item service, so a format whose index follows properties follows this change too: set replaces the values of its keys and remove drops keys. The caller needs Annotate on it. Inside a transaction of DB's, it joins that transaction.
func (*Kit) Blobs ¶
Blobs is the blob store Upload commits to, for a handler that reads what it uploaded before deciding where to store it.
func (*Kit) Can ¶
Can reports whether the caller holds every action in want on path in the request's repository, for a handler that filters what it lists by what the caller may read. A request without a principal holds nothing, and so does one whose permissions were never evaluated: the server's middleware evaluates them for every request.
func (*Kit) CanFolder ¶
CanFolder is Can for a folder, which a caller may act on when it may act on a path below it, for a handler that accepts more than one right before it knows which the request needs.
func (*Kit) Created ¶
Created answers a deploy that stored it: 201 with its X-Checksum-Sha1, -Sha256 and -Md5 headers, which jf go-publish reads (research 26 section 3.1), and the item routes' deploy body when the server gives one (Options.Created).
func (*Kit) DB ¶
DB is the store the kit resolves repositories in, for a handler that reads the package index (decision 0018) or lists a folder: Go's version lists and npm's packuments are built from the index.
func (*Kit) Delete ¶
Delete removes the file at path in the request's repository through the item service, to the trash can while it is on, as the item routes' delete does. The caller needs Delete on path. A missing file, or a folder, answers 404. Inside a transaction of DB's, it joins that transaction.
func (*Kit) DeleteTree ¶
DeleteTree removes a protocol revision only after checking Delete on every descendant. The item service performs the actual removal in one transaction.
func (*Kit) Deploy ¶
func (k *Kit) Deploy( w http.ResponseWriter, r *http.Request, path string, props types.Properties, ) (types.Item, bool)
Deploy answers a PUT whose body is the file to store at path, with the matrix parameters props and the checksums its X-Checksum headers declare (DeclaredChecksums), through Store: Created's answer, or the refusal. It reports whether the file was stored.
func (*Kit) DeployItem ¶
func (k *Kit) DeployItem(w http.ResponseWriter, r *http.Request)
DeployItem delegates an item-path PUT to the server's complete deploy route, retaining checksum reuse, archive expansion, sidecars and folder semantics.
func (*Kit) Error ¶
Error answers err in the protocol's envelope. An error that is not an *apierror.Error is a fault: it goes to the access log and the client gets a bare 500.
func (*Kit) MemberRequest ¶
MemberRequest keeps the authenticated caller and route while resolving a virtual repository request against one concrete member. Protocol handlers still check both the virtual path and the member path before disclosure. The class and type gate is repeated here because virtual membership can change after the virtual repository was configured.
func (*Kit) Read ¶
Read is the stream-aware extension of Item. A future virtual source can implement the same optional method while retaining each member's permission and fetch intent. Existing local sources continue using their stored items.
func (*Kit) ReadForm ¶
ReadForm reads the request's multipart/form-data body as it arrives, for twine's upload and NuGet's push (decisions 0037 and 0038): the first part with a file name whose form name is file, or with any name when file is "", streams into the blob store under the request's repository's checksum policy, as Upload does, and the fields that are not files are kept in Fields, whichever side of the file part they come. Later file parts are read and dropped, as Microsoft specifies for a NuGet push.
Its refusals, in the protocol's envelope through Error: 415 for a body that is not multipart/form-data, 400 for one that is malformed or breaks off, 400 when no part matches, and 413 for fields over 10 MiB. The file part has no limit of its own, as a deploy through the item routes has none. The caller checks that the caller may deploy before it reads the body.
func (*Kit) ReadFormLimited ¶
ReadFormLimited applies a decoded byte limit to the primary file part. A client may transfer base64 bytes; the limit counts the original content after decoding, before any item is published.
func (*Kit) ReadFormWith ¶
ReadFormWith reads the primary file and explicitly named optional file fields. It leaves all other file parts discarded, as ReadForm always did.
func (*Kit) Require ¶
func (k *Kit) Require( w http.ResponseWriter, r *http.Request, path string, want types.Actions, ) bool
Require is Can, answering the refusal when it fails: 401 to an anonymous caller or one without credentials, so it sends them, and 403 to anyone else, as the item routes refuse.
func (*Kit) RequireFolder ¶
func (k *Kit) RequireFolder( w http.ResponseWriter, r *http.Request, path string, want types.Actions, ) bool
RequireFolder is Require for a folder, which a caller may read when it may read a path below it. A protocol that answers for a whole package, such as npm's packument, asks it of the package's folder before saying whether the package exists, so a refusal says nothing about what is there.
func (*Kit) ResolveItem ¶
ResolveItem applies the format's download resolution and refreshes its derived work before looking up the item. The caller checks permission first, including formats whose metadata has repository-wide visibility.
func (*Kit) ServeFound ¶
ServeFound serves an already resolved file after checking Read. Signed downloads use the verified item so a concurrent overwrite cannot replace the bytes between checking the signed digest and opening the blob.
func (*Kit) ServeItem ¶
ServeItem answers GET or HEAD of the file at path in the request's repository through the item routes' download, so the download redirect policy and download counts apply. A caller that may not read path is refused before the item is looked up, so a refusal says nothing about whether it exists; a missing file, or a folder, answers 404.
func (*Kit) ServeResult ¶
ServeResult delivers an already resolved representation after its final authority check. Callers may rewrite metadata first, preserving Revalidate and Used while replacing every header that describes the upstream bytes.
func (*Kit) Store ¶
func (k *Kit) Store( r *http.Request, path string, body io.Reader, props types.Properties, declared types.Checksums, ) (types.Item, error)
Store writes body at path in the request's repository through the item service, as the item routes' deploy does: the caller needs Write on path, and Delete too to replace a file. props are set on the file and declared is checked against its content under the repository's checksum policy. It returns the stored file, or the refusal to answer with Error. The request's repository is the target; the class gate admits only the classes a protocol serves, which in P7 hold their own items.
func (*Kit) StoreNew ¶
func (k *Kit) StoreNew( r *http.Request, path string, info blob.Info, props types.Properties, declared types.Checksums, exists func() error, ) (types.Item, error)
StoreNew stores content Upload committed as a new file at path in the request's repository, with props and the checksums the client declared as its originals, which the caller has checked against info, and answers exists() when path already holds an item: a file published once and never replaced, such as an npm version's tarball (decision 0034). The caller needs Write on path, and never Delete. The item service checks the path inside the write's transaction and inserts through ItemStore.Create, so a concurrent publication cannot replace content after that check on any backend.
func (*Kit) StoreOnce ¶
func (k *Kit) StoreOnce( r *http.Request, path string, body io.Reader, props types.Properties, declared types.Checksums, differs func(stored types.Item) error, ) (types.Item, error)
StoreOnce is Store for a file that never changes once stored, such as a Go module version's .zip or .mod (decision 0035). The caller needs Write on path and never Delete, since nothing is replaced: the same content again only merges props into the stored file's properties, and other content is not written but refused with what differs returns for the stored file. Only the body's digest tells the two apart, so the body is committed to the blob store before the stored file is read; content left unreferenced is collected as an orphan.
func (*Kit) StoreResolved ¶
func (k *Kit) StoreResolved( r *http.Request, filename string, info blob.Info, declared types.Checksums, resolve func(any) (string, error), ) (types.Item, error)
StoreResolved commits an upload whose inspection determines its destination. The resolved path needs Deploy before the transaction, while the item service checks Delete against the content actually present inside that transaction. The caller has already verified declared against info, including any digest algorithms the item service does not support.
func (*Kit) Upload ¶
Upload streams body into the blob store under the request's repository's checksum policy and stores no item, for a protocol that learns where content goes only from the content, such as an npm publish, whose tarball may come before the fields that name its version. StoreNew then stores it; content no item comes to reference is collected as an orphan.
type Options ¶
type Options struct {
// Store resolves repositories. Nil answers every request 501, as the
// server's own handlers do without a store.
Store store.Store
// Items returns the item service a deploy goes through, with the
// server's formats and work queue.
Items func() *item.Service
// ServeItem answers GET or HEAD of a file in c with the item routes'
// download, which applies the download redirect policy (decision 0029),
// sets the checksum headers and counts the download.
ServeItem func(w http.ResponseWriter, r *http.Request, c repo.Config, it types.Item)
// DeployItem delegates a PUT with its escaped repository-relative path,
// including matrix parameters and any trailing slash.
DeployItem func(http.ResponseWriter, *http.Request, repo.Config, string)
// ItemError turns an item service error into the *apierror.Error the
// item routes answer with, so a format's RejectionError keeps its status.
ItemError func(ctx context.Context, op string, err error) error
// Created answers 201 to a deploy that stored it, with the item routes'
// deploy body. Nil answers 201 with no body.
Created func(w http.ResponseWriter, r *http.Request, it types.Item)
// Fault records an unexpected error for the access log; nil drops it.
Fault func(*http.Request, error)
}
Options is what the server gives every protocol: the store, and the item routes' download, deploy and error mapping, so a protocol's files behave as the item routes' do.
type Path ¶
type Path struct {
// Segments are the path's segments, each unescaped on its own: an
// encoded slash, as npm sends in "@scope%2fname", stays inside its
// segment, so a protocol can tell it from a literal one.
Segments []string
// Folder reports a trailing slash, or matrix parameters after one
// ("a/b/;k=v").
Folder bool
// Props are the matrix parameters (";key=value" after any segment), and
// Mandatory the keys sent as "key+=value", which a download requires the
// item to carry.
Props types.Properties
Mandatory map[string]bool
}
Path is an escaped path with its matrix parameters parsed out.
type Protocol ¶
type Protocol struct {
// Name is the segment after /artifactory/api/, such as "npm" or "go".
Name string
// Types are the package types whose repositories the protocol serves.
// A repository of another type answers 404, as a missing one does.
Types []repo.PackageType
// ErrorProfile selects the error envelope, content type, and default
// authentication challenge expected by the protocol's clients.
ErrorProfile apierror.Profile
// Reserved are the JFrog operations beside the protocol, as paths after
// the prefix whose {...} segments match any one segment: "auth",
// "{repoKey}/reindex". chi routes an operation's own methods to the
// generated servers ahead of the kit, so a request for one that reaches
// the kit used a method no route serves, and answers 405, in the
// Artifactory envelope, rather than being read as a package path.
Reserved []string
// Absent are paths below every repository key that answer 404 before
// the request is authenticated or its repository looked up, as
// prefixes of the escaped path after the key: Go's "sumdb/" (decision
// 0035). The go command takes any other answer to its checksum
// database probe, a 401 included, for an outage and fails. The server
// asks SkipsAuthentication before it authenticates; Mount answers them.
Absent []string
// Resolve finds the repository key in rel, the escaped path after
// /artifactory/api/<name>/, for a protocol whose key is not always the
// path's first segment: Terraform encodes it into a namespace,
// "v1/modules/<repo>__<ns>/..." (decision 0040). It returns the
// candidates in the order they are tried, and the first that names a
// repository wins, without regard to case: keys are unique that way
// (research 03), and Terraform sends provider namespaces in lower case,
// so a key with capitals is reachable only so. No candidate answers 404.
// FirstSegment and SplitKey build candidates. Nil takes the first
// segment and matches it exactly, as npm and Go do.
Resolve func(rel string) []Key
// Challenge reports whether an anonymous request to repository c
// answers 401, with the Basic challenge, before it is routed, whatever
// the anonymous user may read: NuGet's forceNugetAuthentication
// (decision 0038). The NuGet client sends its credentials only after a
// 401, so a route that answered an anonymous caller with what it may
// read would never receive them. Nil challenges no repository.
Challenge func(c repo.Config) bool
// Host are the protocol's routes outside /artifactory/api/<name>/, at
// the host root, such as Terraform's discovery document (decision
// 0040). Mount registers them before the generated servers.
Host []HostRoute
// Signed reports a request under the protocol's prefix that carries its
// own authorization in its URL: Terraform's time-limited download URLs,
// which Terraform fetches without credentials (decision 0040). The
// server serves it without authenticating it, whatever credentials it
// carries, and its handler checks the signature. Its repository key is
// its first segment whatever Resolve would find, since a signed URL
// names the repository first. Nil signs nothing.
Signed func(r *http.Request) bool
// Sources serves each repository class the protocol reads, the seam
// remote (P9, decision 0007) and virtual (P10, decision 0008) classes
// plug into. Nil serves local and federated repositories from their own
// items. Any other class answers 501 naming it (decision 0032).
Sources map[repo.Class]Source
// Routes registers the protocol's handlers on the router for one
// repository, with paths relative to /artifactory/api/<name>/{repoKey},
// or to the Rest of the Key that Resolve found. chi matches them
// against the escaped path, so a parameter keeps its escapes; ParsePath
// decodes them. What the router answers no route for is 404 or 405 in
// the protocol's envelope.
Routes func(r chi.Router, k *Kit)
}
Protocol is one format's protocol.
type ReadSource ¶
type ReadSource interface {
Read(*http.Request, repo.Config, source.Resource) (source.Result, error)
}
ReadSource is the optional stream-aware extension of a protocol Source. Format packages consume internal/source directly and never import this HTTP adapter interface.
type Remote ¶
Remote opts one protocol into the common source boundary. It is never installed by default; each adapter must first support remote metadata and transient results. Docker keeps its separate routing seam.
func (Remote) Item ¶
Item cannot represent transient content. A protocol using Remote must consume Read instead of assuming that every successful download has a stored item.
func (Remote) Read ¶
func (s Remote) Read( r *http.Request, c repo.Config, resource source.Resource, ) (source.Result, error)
Read resolves artifact, metadata or version content through the common policy. A native adapter supplies its normalized resource and escaped upstream path; caller credentials are never copied into that resource.
type Request ¶
type Request struct {
// Repo is the repository the request addressed.
Repo repo.Config
// CacheOnly identifies a remote -cache URL selected by the native adapter.
CacheOnly bool
// Source reads Repo's items.
Source Source
// Rest is the escaped path after the repository key, without its
// leading slash; ParsePath parses it.
Rest string
}
Request is a protocol request whose repository is resolved and served.
func RequestFrom ¶
RequestFrom returns the request Mount resolved; a handler registered through Routes always has one.
type Source ¶
type Source interface {
// Item returns the file or folder at path as c's class finds it, with
// the repository it lives in, or an error wrapping store.ErrNotFound.
Item(ctx context.Context, st store.Store, c repo.Config, path string) (Found, error)
}
Source reads a repository's items for a protocol.