Help us shape the future of Go! Take the 2026 Go Developer Survey

gcpartifactregistry

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 57 Imported by: 0

README

Artifact Registry

Parity grade: B · SDK cloud.google.com/go/artifactregistry@v1.27.0 · last audited 2026-10-22 (364908f83)

Coverage

Metric Value
PARITY entries audited 40 (40 ok)
Feature families 6 (6 ok)
Known gaps 13
Deferred items 0
Resource leaks partial
Known gaps
  • apt, yum, KFP and Go repositories can be created but hold no artifacts: their artifact RPCs and uploads are not implemented and return FAILED_PRECONDITION.
  • Maven and Python repositories expose no Tag resources (only npm dist-tags are mapped); Maven artifact-level maven-metadata.xml is generated, so a PUT of it is accepted and ignored; Maven HTTP DELETE, the Python JSON simple API (PEP 691) and yank, and npm search/audit/login endpoints are not implemented because Google's documentation does not describe them (deletion is through the API, console and gcloud); file and package names for these formats are the emulator's choice.
  • Attachments, ExportArtifact, ImportAptArtifacts, ImportYumArtifacts and the resumable generic upload (uploadType=resumable) are not implemented.
  • Rule conditions (CEL) are stored but never evaluated, so a rule with a condition never takes effect; download rules are enforced on Docker manifest and blob reads and on file downloads only.
  • Project settings and the VPC-SC policy are stored; nothing consults them.
  • Remote and virtual repositories are stored but never proxy or merge anything; cleanup policies are stored and never run.
  • A repository id is unique per project across locations, and image data is not separated by location.
  • Operations are recorded already finished; there is no pending state, and CancelOperation changes nothing.
  • Authentication is not checked and IAM is not enforced; every credential is accepted.
  • Docker pushes to a path whose repository does not exist are refused instead of creating it (gcr.io-style auto-creation is not modelled).
  • Vulnerability scanning, signed attestations and docker image build_time are not modelled; Artifact Registry's own location catalogue is not served.
  • The embedded distribution library leaves one go-events broadcaster goroutine running until process exit.
  • No dashboard page.

More

Documentation

Overview

Package gcpartifactregistry emulates Google Artifact Registry: the v1 API (repositories, packages, versions, tags and docker images) over gRPC and REST, and a Docker Registry v2 data plane for DOCKER repositories on the same listener, so pushed images show up in the API. See PARITY.md.

Index

Constants

View Source
const DefaultPort = 8134

DefaultPort is the dedicated gRPC, REST and Docker Registry listener's default TCP port.

View Source
const DefaultRegistryHost = "localhost"

DefaultRegistryHost is the host advertised in repositories' registry_uri.

Variables

View Source
var ErrNilAppContext = errors.New("gcpartifactregistry: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

Functions

This section is empty.

Types

type ConfigProvider

type ConfigProvider interface {
	GetGCPArtifactRegistrySettings() Settings
}

ConfigProvider extracts Artifact Registry configuration from the AppContext Config.

type DataDirConfig

type DataDirConfig interface {
	GetRegistryDataDir() string
}

DataDirConfig locates the directory image blobs are kept in; empty keeps them in memory.

type DockerRepoInfo

type DockerRepoInfo struct {
	Location  string
	Immutable bool
	Docker    bool
}

DockerRepoInfo describes the repository a registry path belongs to.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves Artifact Registry on a dedicated listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) API

API exposes the Artifact Registry service for in-process callers (dashboard proxy).

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the supported gRPC methods.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler; the real API is on the dedicated port.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all in-memory state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Artifact Registry runs on its own listener.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the server, forcing a close after a short grace period.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

type InMemoryBackend struct {
	// contains filtered or unexported fields
}

InMemoryBackend holds all Artifact Registry state under one lock. Docker images live in one embedded registry whose repositories are named <project>/<repository>/<image>.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend that keeps images in memory.

func (*InMemoryBackend) BatchDeleteVersions

BatchDeleteVersions deletes several manifests of one package, force-deleting tagged ones.

func (*InMemoryBackend) Close

func (b *InMemoryBackend) Close()

Close releases the embedded registry without deleting stored images.

func (*InMemoryBackend) CreateRepository

CreateRepository stores a repository and returns the finished operation.

func (*InMemoryBackend) CreateRule

CreateRule stores a rule; a repository holds one rule for itself and one per package.

func (*InMemoryBackend) CreateTag

CreateTag points a new tag at an existing version.

func (*InMemoryBackend) DeleteFile

func (b *InMemoryBackend) DeleteFile(_ context.Context, name string) (*longrunningpb.Operation, error)

DeleteFile deletes a generic file; other formats refuse, as AR allows it on generic repositories only.

func (*InMemoryBackend) DeletePackage

func (b *InMemoryBackend) DeletePackage(ctx context.Context, name string) (*longrunningpb.Operation, error)

DeletePackage deletes every version of an image.

func (*InMemoryBackend) DeleteRepository

func (b *InMemoryBackend) DeleteRepository(
	ctx context.Context, name string,
) (*longrunningpb.Operation, error)

DeleteRepository removes a repository with every image in it.

func (*InMemoryBackend) DeleteRule

func (b *InMemoryBackend) DeleteRule(name string) (*emptypb.Empty, error)

DeleteRule removes a rule.

func (*InMemoryBackend) DeleteTag

func (b *InMemoryBackend) DeleteTag(ctx context.Context, name string) error

DeleteTag removes a tag, leaving its version in place.

func (*InMemoryBackend) DeleteVersion

DeleteVersion deletes one manifest; force is required when tags point at it.

func (*InMemoryBackend) DockerHandler

func (b *InMemoryBackend) DockerHandler() http.Handler

DockerHandler serves the Docker Registry v2 API for DOCKER repositories at /v2/<project>/<repository>/<image>. Any credential is accepted, as oauth2accesstoken:<token> Basic auth or a Bearer token; a request without one is challenged to fetch a token from /v2/token.

func (*InMemoryBackend) FileExtras

func (b *InMemoryBackend) FileExtras() gcprest.Extra

FileExtras routes the media endpoints that have no gRPC method: the generic artifact upload and file download.

func (*InMemoryBackend) GetDockerImage

func (b *InMemoryBackend) GetDockerImage(
	ctx context.Context, name string,
) (*artifactregistrypb.DockerImage, error)

GetDockerImage returns one manifest of an image, addressed by digest or tag.

func (*InMemoryBackend) GetFile

GetFile returns one file.

func (*InMemoryBackend) GetIamPolicy

func (b *InMemoryBackend) GetIamPolicy(resource string, version int32) (*iampb.Policy, error)

GetIamPolicy returns a repository's policy at the requested version, or an empty one with an etag if none was set.

func (*InMemoryBackend) GetPackage

func (b *InMemoryBackend) GetPackage(name string) (*artifactregistrypb.Package, error)

GetPackage returns one image as a package.

func (*InMemoryBackend) GetProjectSettings

func (b *InMemoryBackend) GetProjectSettings(name string) (*artifactregistrypb.ProjectSettings, error)

GetProjectSettings returns a project's settings; a project that never changed them has the defaults.

func (*InMemoryBackend) GetRepository

func (b *InMemoryBackend) GetRepository(name string) (*artifactregistrypb.Repository, error)

GetRepository returns a repository with its size and registry_uri filled in.

func (*InMemoryBackend) GetRule

func (b *InMemoryBackend) GetRule(name string) (*artifactregistrypb.Rule, error)

GetRule returns one rule.

func (*InMemoryBackend) GetTag

func (b *InMemoryBackend) GetTag(name string) (*artifactregistrypb.Tag, error)

GetTag returns one tag.

func (*InMemoryBackend) GetVPCSCConfig

func (b *InMemoryBackend) GetVPCSCConfig(name string) (*artifactregistrypb.VPCSCConfig, error)

GetVPCSCConfig returns a location's VPC-SC policy, ALLOW until it is changed.

func (*InMemoryBackend) GetVersion

GetVersion returns one manifest as a version.

func (*InMemoryBackend) ImageNames

func (b *InMemoryBackend) ImageNames(project, id string) []string

ImageNames lists the images in the repository at registry path prefix project/repository, sorted.

func (*InMemoryBackend) ListDockerImages

ListDockerImages lists every manifest of the repository's images.

func (*InMemoryBackend) ListFiles

ListFiles lists a repository's files, filtered by name, owner and annotations.

func (*InMemoryBackend) ListPackages

ListPackages lists the images of a DOCKER repository as packages.

func (*InMemoryBackend) ListRepositories

ListRepositories lists repositories under a location, or every location with "-".

func (*InMemoryBackend) ListRules

ListRules lists a repository's rules by name.

func (*InMemoryBackend) ListTags

ListTags lists an image's tags, optionally only those on one version.

func (*InMemoryBackend) ListVersions

ListVersions lists the manifests of an image as versions.

func (*InMemoryBackend) LookupDockerRepo

func (b *InMemoryBackend) LookupDockerRepo(project, id string) (DockerRepoInfo, bool)

LookupDockerRepo resolves project/repository to its location and format.

func (*InMemoryBackend) PackageExtras

func (b *InMemoryBackend) PackageExtras() gcprest.Extra

PackageExtras routes the npm, Python and Maven protocols on <location>-<format>.pkg.dev hosts, where the path is /<project>/<repository>/..., and at /<format>/<project>/<repository>/... on any other host.

func (*InMemoryBackend) RecordManifestDelete

func (b *InMemoryBackend) RecordManifestDelete(repo, ref string)

RecordManifestDelete notes a manifest or tag deleted through the Docker API.

func (*InMemoryBackend) RecordManifestPut

func (b *InMemoryBackend) RecordManifestPut(repo, ref, digest string)

RecordManifestPut notes a manifest stored through the Docker API.

func (*InMemoryBackend) Registry

func (b *InMemoryBackend) Registry() http.Handler

Registry returns the embedded Docker registry handler (no authentication).

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset removes every repository and image.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads a snapshot, replacing every repository.

func (*InMemoryBackend) SetContext

func (b *InMemoryBackend) SetContext(ctx context.Context)

SetContext bounds the lifetime of the embedded registry.

func (*InMemoryBackend) SetDataDir

func (b *InMemoryBackend) SetDataDir(dir string)

SetDataDir keeps image blobs and manifests under dir; empty keeps them in memory.

func (*InMemoryBackend) SetIamPolicy

func (b *InMemoryBackend) SetIamPolicy(resource string, policy *iampb.Policy) (*iampb.Policy, error)

SetIamPolicy replaces a repository's policy; a stale etag aborts the call.

func (*InMemoryBackend) SetRegistryAddress

func (b *InMemoryBackend) SetRegistryAddress(host, port string)

SetRegistryAddress sets the host and port advertised in registry_uri and image URIs.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises repositories, IAM policies, the ledger, generic artifacts, rules, settings and operations. Image blobs and manifests are not part of it: they live under the data directory when one is configured.

func (*InMemoryBackend) TagExists

func (b *InMemoryBackend) TagExists(repo, tag string) bool

TagExists reports whether tag already points at a manifest in repo.

func (*InMemoryBackend) TestIamPermissions

func (b *InMemoryBackend) TestIamPermissions(resource string, perms []string) ([]string, error)

TestIamPermissions reports the requested Artifact Registry permissions as granted: the emulator does not enforce IAM.

func (*InMemoryBackend) UpdateFile

UpdateFile replaces the annotations of a file.

func (*InMemoryBackend) UpdatePackage

UpdatePackage changes the display name and annotations of a package.

func (*InMemoryBackend) UpdateProjectSettings

UpdateProjectSettings applies legacy_redirection_state and pull_percent.

func (*InMemoryBackend) UpdateRepository

UpdateRepository applies the masked fields (all set fields when the mask is empty).

func (*InMemoryBackend) UpdateRule

UpdateRule applies the masked fields; an empty mask copies every field the request sets.

func (*InMemoryBackend) UpdateTag

UpdateTag moves an existing tag to another version.

func (*InMemoryBackend) UpdateVPCSCConfig

UpdateVPCSCConfig sets vpcsc_policy.

func (*InMemoryBackend) UpdateVersion

UpdateVersion changes the description and annotations of a version.

func (*InMemoryBackend) UploadGenericArtifact

func (b *InMemoryBackend) UploadGenericArtifact(
	_ context.Context, parent string, in uploadReq, data []byte,
) (*longrunningpb.Operation, error)

UploadGenericArtifact stores a file of a generic repository, creating its package and version.

type Provider

type Provider struct{}

Provider implements service.Provider for Google Artifact Registry. It serves gRPC, REST and the Docker Registry API on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Settings

type Settings struct {
	RegistryHost string `` //nolint:lll // config struct tags are intentionally verbose
	/* 197-byte string literal not displayed */
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 236-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPArtifactRegistry.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

Jump to

Keyboard shortcuts

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