Documentation
¶
Index ¶
- Constants
- Variables
- type Authorizer
- type CatalogAuthorizer
- type HTTPHandler
- func (h *HTTPHandler) AddManifestPutHook(hook ManifestPutHook)
- func (h *HTTPHandler) AttachReferrer(ctx context.Context, repo *models.Repository, req ReferrerRequest) (*ReferrerResult, error)
- func (h *HTTPHandler) FindReferrer(ctx context.Context, repo *models.Repository, ...) (string, error)
- func (h *HTTPHandler) RegisterRoutes(r chi.Router)
- func (h *HTTPHandler) SetAuthorizer(a Authorizer)
- func (h *HTTPHandler) SetPublisher(p webhook.Publisher)
- func (h *HTTPHandler) SetUploadStore(u storage.UploadStore)
- type HTTPStore
- type ManifestEvent
- type ManifestPutHook
- type ReferrerRequest
- type ReferrerResult
Constants ¶
const DefaultUploadDir = "/tmp/openartifact/docker-uploads"
DefaultUploadDir is where in-progress blob uploads are kept on this host when the blob store cannot hold them (the oci backend), unless the operator configures workers.dockerUploadDir.
Variables ¶
var ErrChunkOffsetMismatch = errors.New("chunk offset does not match current upload offset")
ErrChunkOffsetMismatch indicates a chunked upload PATCH/PUT arrived with a Content-Range start that does not match the upload's current offset — either a gap (client skipped bytes) or an overlap (client resent bytes already accepted). Registries reject both with 416 Range Not Satisfiable.
var ErrInvalidContentRange = errors.New("invalid Content-Range")
ErrInvalidContentRange indicates a missing or malformed Content-Range header.
var ErrSubjectNotFound = errors.New("subject manifest not found in the image")
ErrSubjectNotFound is returned by AttachReferrer when the image holds no manifest with the subject digest.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶ added in v0.4.0
type Authorizer interface {
Evaluate(ctx context.Context, principal auth.Principal, repoName, artifactPath, action string) (bool, error)
}
Authorizer decides whether a principal may perform an action on a repository. The handler needs it for the one operation that reads a second repository: a cross-repository blob mount.
type CatalogAuthorizer ¶ added in v0.8.0
type CatalogAuthorizer interface {
Authorizer
PathReadFilter(ctx context.Context, principal auth.Principal) (func(repo *models.Repository, artifactPath string) (bool, error), error)
}
CatalogAuthorizer is the Authorizer of a registry that serves /v2/_catalog: it also loads a principal's permissions once to filter many (repository, path) pairs, which is what listing every image of every repository needs.
type HTTPHandler ¶
type HTTPHandler struct {
// contains filtered or unexported fields
}
func NewHTTPHandler ¶
func (*HTTPHandler) AddManifestPutHook ¶ added in v0.21.0
func (h *HTTPHandler) AddManifestPutHook(hook ManifestPutHook)
AddManifestPutHook registers a hook called after every committed manifest push. It must be called before the handler serves requests.
func (*HTTPHandler) AttachReferrer ¶ added in v0.8.0
func (h *HTTPHandler) AttachReferrer(ctx context.Context, repo *models.Repository, req ReferrerRequest) (*ReferrerResult, error)
AttachReferrer stores req as a referrer of a manifest the repository holds. It goes through the registry's own accounting: the layer, config and manifest are quota-metered, tracked for registry GC and visible to the Referrers API like a client push. It is idempotent per slot (subject, artifact type and the SlotKeys annotations): an identical referrer is left alone (Created false) and one with other content replaces the older (its layer blob is left to registry GC).
Locking: the layer and config blobs are committed first, each under its own blob lock. The referrer manifest is then stored and the slot decided under the manifest blob's lock and a per-slot lock taken together on one connection, so two attaches of one slot (on any replica) never both see an empty slot. No blob lock is taken inside that section (see attachLocked); the replaced referrer's content blob is reclaimed after it.
func (*HTTPHandler) FindReferrer ¶ added in v0.8.0
func (h *HTTPHandler) FindReferrer( ctx context.Context, repo *models.Repository, image, subjectDigest, artifactType string, annotations map[string]string, ) (string, error)
FindReferrer returns the digest of the referrer of subjectDigest that has the artifact type and carries every given annotation ("" when there is none), so a caller can skip rebuilding what is already attached.
func (*HTTPHandler) RegisterRoutes ¶
func (h *HTTPHandler) RegisterRoutes(r chi.Router)
RegisterRoutes mounts the registry. Distribution names contain "/", which chi's single-segment params cannot capture, so one wildcard route hands the path to ocipath — the same parser RBAC uses to pick the repository.
func (*HTTPHandler) SetAuthorizer ¶ added in v0.4.0
func (h *HTTPHandler) SetAuthorizer(a Authorizer)
SetAuthorizer sets the authorizer used to check read access to a mount source repository. Without one, cross-repository mounts are declined and the client falls back to a regular upload. It must be called before the handler serves requests.
func (*HTTPHandler) SetPublisher ¶ added in v0.2.0
func (h *HTTPHandler) SetPublisher(p webhook.Publisher)
SetPublisher sets the webhook publisher used for artifact events. It must be called before the handler serves requests.
func (*HTTPHandler) SetUploadStore ¶ added in v0.19.0
func (h *HTTPHandler) SetUploadStore(u storage.UploadStore)
SetUploadStore sets where the data of in-progress blob uploads is kept; storage.UploadsFor picks the store. It must be called before the handler serves requests. The default is blobStore when it can hold uploads, else DefaultUploadDir, which is right when blobStore is the store itself and wrong when it hides the capability behind a wrapper.
type HTTPStore ¶ added in v0.15.0
type HTTPStore interface {
quarantine.Checker
BlobReferenceCount(ctx context.Context, sha256 string) (int, error)
ChargeStorageUsage(ctx context.Context, repoID string, sizeBytes int64, artifactCount int) error
CreateDockerBlob(ctx context.Context, blob *models.DockerBlob) error
CreateDockerManifest(ctx context.Context, m *models.DockerManifest) error
AcquireDockerUploadLease(
ctx context.Context,
repositoryID string,
image string,
uploadUUID string,
token string,
ttl time.Duration,
) (*models.DockerUpload, error)
AdvanceDockerUpload(
ctx context.Context,
repositoryID string,
uploadUUID string,
token string,
oldOffset int64,
newOffset int64,
hashState []byte,
stageState string,
ttl time.Duration,
keepLease bool,
) (bool, error)
CreateDockerUpload(ctx context.Context, upload *models.DockerUpload) error
DecrementStorageUsage(ctx context.Context, repoID string, sizeBytes int64, artifactCount int) error
DeleteDockerBlobFromImage(ctx context.Context, repoID string, image string, digest string) (database.DockerBlobDeletion, error)
DeleteDockerManifest(ctx context.Context, repoID string, image string, digest string) error
DeleteDockerTag(ctx context.Context, repoID string, image string, name string) error
DeleteDockerTagsByDigest(ctx context.Context, repoID string, image string, digest string) error
DeleteDockerUpload(ctx context.Context, repositoryID string, uploadUUID string) error
DockerBlobQuarantined(ctx context.Context, repoID string, digest string) (bool, error)
DockerImageExists(ctx context.Context, repoID string, image string) (bool, error)
EnsureBlob(ctx context.Context, sha256 string, mediaType string, size int64) (string, error)
GetDockerBlob(ctx context.Context, repoID string, digest string) (*models.DockerBlob, error)
GetDockerManifest(ctx context.Context, repoID string, image string, digest string) (*models.DockerManifest, error)
GetDockerTag(ctx context.Context, repoID string, image string, name string) (*models.DockerTag, error)
GetDockerUpload(ctx context.Context, repositoryID string, image string, uploadUUID string) (*models.DockerUpload, error)
GetOrCreateStorageQuota(ctx context.Context, repoID string) (*models.StorageQuota, error)
GetRepositoryByName(ctx context.Context, name string) (*models.Repository, error)
ListDockerManifestsBySubject(ctx context.Context, repoID string, image string, subjectDigest string) ([]*models.DockerManifest, error)
ListDockerTagIDsByDigest(ctx context.Context, repoID string, image string, digest string) ([]string, error)
ListDockerTags(ctx context.Context, repoID string, image string, last string, n int) ([]*models.DockerTag, error)
ListLicensePolicies(ctx context.Context, repoID string) ([]*models.LicensePolicy, error)
ReleaseDockerUploadLease(ctx context.Context, repositoryID string, uploadUUID string, token string) error
RenewDockerUploadLease(ctx context.Context, repositoryID string, uploadUUID string, token string, ttl time.Duration) (bool, error)
ReserveStorageUsage(ctx context.Context, repoID string, sizeBytes int64, artifactCount int) (bool, error)
UpsertDockerTag(ctx context.Context, tag *models.DockerTag) error
}
HTTPStore is the part of the database HTTPHandler needs.
type ManifestEvent ¶ added in v0.21.0
type ManifestEvent struct {
// RepoID and RepoName identify the OpenArtifact repository.
RepoID string
RepoName string
// Image is the image path inside the repository ("" is the default image).
Image string
// Tag is the tag the manifest was pushed under; empty for a push by digest.
Tag string
// Digest is the manifest's digest ("sha256:<hex>") and MediaType the
// Content-Type it was pushed with.
Digest string
MediaType string
// ArtifactType is the manifest's artifactType, or the media type of its
// config when it declares none (the Referrers API convention); empty for an
// image index.
ArtifactType string
// SubjectDigest is the digest the manifest refers to (OCI subject); empty
// when it has none.
SubjectDigest string
// Annotations are the manifest's own annotations.
Annotations map[string]string
// Manifest is the raw manifest body. Hooks must not modify it.
Manifest []byte
// ConfigLabels returns the labels of the image config blob the manifest
// references (empty for an index, an artifact manifest or an unreadable
// config). The config is read once per event.
ConfigLabels func(ctx context.Context) map[string]string
}
ManifestEvent describes a manifest that was just pushed (PUT) to a hosted docker repository and committed.
type ManifestPutHook ¶ added in v0.21.0
type ManifestPutHook func(ctx context.Context, ev ManifestEvent)
ManifestPutHook is called after a manifest push committed. It runs outside the request, on its own context, so it neither delays nor fails the push; its work should be idempotent (a manifest can be pushed again) and its errors are its own to log.
type ReferrerRequest ¶ added in v0.8.0
type ReferrerRequest struct {
// Image is the image path inside the repository ("" is the default image).
Image string
// SubjectDigest is the digest ("sha256:...") of the manifest to attach to.
SubjectDigest string
// ArtifactType is the referrer's artifactType and the layer's media type.
ArtifactType string
// Content is the layer.
Content []byte
// Annotations are set on the referrer manifest.
Annotations map[string]string
// SlotKeys name the annotations that, with the subject and artifact type,
// identify the slot the referrer occupies: an earlier referrer of the same
// slot is replaced instead of kept next to it.
SlotKeys []string
}
ReferrerRequest describes one artifact to attach to a manifest of a hosted docker repository as an OCI 1.1 referrer: an image manifest with `subject`, the given artifactType, an empty config and one layer holding Content.
type ReferrerResult ¶ added in v0.8.0
type ReferrerResult struct {
// Digest is the referrer manifest's digest.
Digest string
// Created is false when an identical referrer was already attached.
Created bool
// Replaced is the digest of the earlier referrer this one replaced ("" if none).
Replaced string
}
ReferrerResult reports what AttachReferrer did.