registry

package
v20.10.14+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2022 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Overview

Package registry contains client primitives to interact with a remote Docker registry.

Index

Constants

View Source
const (
	// DefaultNamespace is the default namespace
	DefaultNamespace = "docker.io"
	// DefaultRegistryVersionHeader is the name of the default HTTP header
	// that carries Registry version info
	DefaultRegistryVersionHeader = "Docker-Distribution-Api-Version"

	// IndexHostname is the index hostname
	IndexHostname = "index.docker.io"
	// IndexServer is used for user auth and image search
	IndexServer = "https://" + IndexHostname + "/v1/"
	// IndexName is the name of the index
	IndexName = "docker.io"
)
View Source
const (
	// AuthClientID is used the ClientID used for the token server
	AuthClientID = "docker"
)
View Source
const (
	// DefaultSearchLimit is the default value for maximum number of returned search results.
	DefaultSearchLimit = 25
)

Variables

View Source
var (
	// DefaultV2Registry is the URI of the default v2 registry
	DefaultV2Registry = &url.URL{
		Scheme: "https",
		Host:   "registry-1.docker.io",
	}

	// ErrInvalidRepositoryName is an error returned if the repository name did
	// not have the correct form
	ErrInvalidRepositoryName = errors.New("Invalid repository name (ex: \"registry.domain.tld/myrepos\")")
)
View Source
var (
	// ErrAlreadyExists is an error returned if an image being pushed
	// already exists on the remote side
	ErrAlreadyExists = errors.New("Image already exists")
)

Functions

func AuthTransport added in v1.7.0

func AuthTransport(base http.RoundTripper, authConfig *types.AuthConfig, alwaysSetBasicAuth bool) http.RoundTripper

AuthTransport handles the auth layer when communicating with a v1 registry (private or official)

For private v1 registries, set alwaysSetBasicAuth to true.

For the official v1 registry, if there isn't already an Authorization header in the request, but there is an X-Docker-Token header set to true, then Basic Auth will be used to set the Authorization header. After sending the request with the provided base http.RoundTripper, if an X-Docker-Token header, representing a token, is present in the response, then it gets cached and sent in the Authorization header of all subsequent requests.

If the server sends a token without the client having requested it, it is ignored.

This RoundTripper also has a CancelRequest method important for correct timeout handling.

func CertsDir added in v1.8.0

func CertsDir() string

CertsDir is the directory where certificates are stored

func ConvertToHostname added in v1.13.0

func ConvertToHostname(url string) string

ConvertToHostname converts a registry url which has http|https prepended to just an hostname.

func GetAuthConfigKey added in v1.10.0

func GetAuthConfigKey(index *registrytypes.IndexInfo) string

GetAuthConfigKey special-cases using the full index address of the official index as the AuthConfig key, and uses the (host)name[:port] for private indexes.

func HTTPClient added in v1.7.0

func HTTPClient(transport http.RoundTripper) *http.Client

HTTPClient returns an HTTP client structure which uses the given transport and contains the necessary headers for redirected requests

func Headers

func Headers(userAgent string, metaHeaders http.Header) []transport.RequestModifier

Headers returns request modifiers with a User-Agent and metaHeaders

func HostCertsDir

func HostCertsDir(hostname string) (string, error)

HostCertsDir returns the config directory for a specific host

func NewStaticCredentialStore added in v1.12.0

func NewStaticCredentialStore(auth *types.AuthConfig) auth.CredentialStore

NewStaticCredentialStore returns a credential store which always returns the same credential values.

func NewTransport added in v1.7.0

func NewTransport(tlsConfig *tls.Config) *http.Transport

NewTransport returns a new HTTP transport. If tlsConfig is nil, it uses the default TLS configuration.

func ParseSearchIndexInfo added in v1.10.0

func ParseSearchIndexInfo(reposName string) (*registrytypes.IndexInfo, error)

ParseSearchIndexInfo will use repository name to get back an indexInfo.

func PingV2Registry added in v1.11.0

func PingV2Registry(endpoint *url.URL, transport http.RoundTripper) (challenge.Manager, bool, error)

PingV2Registry attempts to ping a v2 registry and on success return a challenge manager for the supported authentication types and whether v2 was confirmed by the response. If a response is received but cannot be interpreted a PingResponseError will be returned.

func ReadCertsDirectory added in v1.8.0

func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error

ReadCertsDirectory reads the directory for TLS certificates including roots and certificate pairs and updates the provided TLS configuration.

func ResolveAuthConfig added in v1.7.0

func ResolveAuthConfig(authConfigs map[string]types.AuthConfig, index *registrytypes.IndexInfo) types.AuthConfig

ResolveAuthConfig matches an auth configuration to a server address or a URL

func ValidateIndexName added in v1.5.0

func ValidateIndexName(val string) (string, error)

ValidateIndexName validates an index name.

func ValidateMirror added in v1.5.0

func ValidateMirror(val string) (string, error)

ValidateMirror validates an HTTP(S) registry mirror

Types

type APIEndpoint added in v1.8.0

type APIEndpoint struct {
	Mirror                         bool
	URL                            *url.URL
	Version                        APIVersion
	AllowNondistributableArtifacts bool
	Official                       bool
	TrimHostname                   bool
	TLSConfig                      *tls.Config
}

APIEndpoint represents a remote API endpoint

func (APIEndpoint) ToV1Endpoint added in v1.8.0

func (e APIEndpoint) ToV1Endpoint(userAgent string, metaHeaders http.Header) *V1Endpoint

ToV1Endpoint returns a V1 API endpoint based on the APIEndpoint Deprecated: this function is deprecated and will be removed in a future update

type APIVersion added in v1.3.0

type APIVersion int

APIVersion is an integral representation of an API version (presently either 1 or 2)

const (
	APIVersion1 APIVersion = iota
	APIVersion2
)

API Version identifiers.

func (APIVersion) String added in v1.3.0

func (av APIVersion) String() string

type DefaultService added in v1.12.0

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

DefaultService is a registry service. It tracks configuration data such as a list of mirrors.

func NewService added in v0.11.0

func NewService(options ServiceOptions) (*DefaultService, error)

NewService returns a new instance of DefaultService ready to be installed into an engine.

func (*DefaultService) Auth added in v1.12.0

func (s *DefaultService) Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error)

Auth contacts the public registry with the provided credentials, and returns OK if authentication was successful. It can be used to verify the validity of a client's credentials.

func (*DefaultService) LoadAllowNondistributableArtifacts

func (s *DefaultService) LoadAllowNondistributableArtifacts(registries []string) error

LoadAllowNondistributableArtifacts loads allow-nondistributable-artifacts registries for Service.

func (*DefaultService) LoadInsecureRegistries added in v1.13.0

func (s *DefaultService) LoadInsecureRegistries(registries []string) error

LoadInsecureRegistries loads insecure registries for Service

func (*DefaultService) LoadMirrors

func (s *DefaultService) LoadMirrors(mirrors []string) error

LoadMirrors loads registry mirrors for Service

func (*DefaultService) LookupPullEndpoints added in v1.12.0

func (s *DefaultService) LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error)

LookupPullEndpoints creates a list of v2 endpoints to try to pull from, in order of preference. It gives preference to mirrors over the actual registry, and HTTPS over plain HTTP.

func (*DefaultService) LookupPushEndpoints added in v1.12.0

func (s *DefaultService) LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error)

LookupPushEndpoints creates a list of v2 endpoints to try to push to, in order of preference. It gives preference to HTTPS over plain HTTP. Mirrors are not included.

func (*DefaultService) ResolveRepository added in v1.12.0

func (s *DefaultService) ResolveRepository(name reference.Named) (*RepositoryInfo, error)

ResolveRepository splits a repository name into its components and configuration of the associated registry.

func (*DefaultService) Search added in v1.12.0

func (s *DefaultService) Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error)

Search queries the public registry for images matching the specified search terms, and returns the results.

func (*DefaultService) ServiceConfig added in v1.12.0

func (s *DefaultService) ServiceConfig() *registrytypes.ServiceConfig

ServiceConfig returns the public registry service configuration.

func (*DefaultService) TLSConfig added in v1.12.0

func (s *DefaultService) TLSConfig(hostname string) (*tls.Config, error)

TLSConfig constructs a client TLS configuration based on server defaults

type ImgData

type ImgData struct {
	// ID is an opaque string that identifies the image
	ID              string `json:"id"`
	Checksum        string `json:"checksum,omitempty"`
	ChecksumPayload string `json:"-"`
	Tag             string `json:",omitempty"`
}

ImgData is used to transfer image checksums to and from the registry

type PingResponseError added in v1.11.0

type PingResponseError struct {
	Err error
}

PingResponseError is used when the response from a ping was received but invalid.

func (PingResponseError) Error added in v1.11.0

func (err PingResponseError) Error() string

type PingResult added in v1.8.0

type PingResult struct {
	// Version is the registry version supplied by the registry in an HTTP
	// header
	Version string `json:"version"`
	// Standalone is set to true if the registry indicates it is a
	// standalone registry in the X-Docker-Registry-Standalone
	// header
	Standalone bool `json:"standalone"`
}

PingResult contains the information returned when pinging a registry. It indicates the registry's version and whether the registry claims to be a standalone registry.

type RepositoryData

type RepositoryData struct {
	// ImgList is a list of images in the repository
	ImgList map[string]*ImgData
	// Endpoints is a list of endpoints returned in X-Docker-Endpoints
	Endpoints []string
}

RepositoryData tracks the image list, list of endpoints for a repository

type RepositoryInfo added in v1.5.0

type RepositoryInfo struct {
	Name reference.Named
	// Index points to registry information
	Index *registrytypes.IndexInfo
	// Official indicates whether the repository is considered official.
	// If the registry is official, and the normalized name does not
	// contain a '/' (e.g. "foo"), then it is considered an official repo.
	Official bool
	// Class represents the class of the repository, such as "plugin"
	// or "image".
	Class string
}

RepositoryInfo describes a repository

func ParseRepositoryInfo added in v1.5.0

func ParseRepositoryInfo(reposName reference.Named) (*RepositoryInfo, error)

ParseRepositoryInfo performs the breakdown of a repository name into a RepositoryInfo, but lacks registry configuration.

type Service added in v0.11.0

type Service interface {
	Auth(ctx context.Context, authConfig *types.AuthConfig, userAgent string) (status, token string, err error)
	LookupPullEndpoints(hostname string) (endpoints []APIEndpoint, err error)
	LookupPushEndpoints(hostname string) (endpoints []APIEndpoint, err error)
	ResolveRepository(name reference.Named) (*RepositoryInfo, error)
	Search(ctx context.Context, term string, limit int, authConfig *types.AuthConfig, userAgent string, headers map[string][]string) (*registrytypes.SearchResults, error)
	ServiceConfig() *registrytypes.ServiceConfig
	TLSConfig(hostname string) (*tls.Config, error)
	LoadAllowNondistributableArtifacts([]string) error
	LoadMirrors([]string) error
	LoadInsecureRegistries([]string) error
}

Service is the interface defining what a registry service should implement.

type ServiceOptions added in v1.11.0

type ServiceOptions struct {
	AllowNondistributableArtifacts []string `json:"allow-nondistributable-artifacts,omitempty"`
	Mirrors                        []string `json:"registry-mirrors,omitempty"`
	InsecureRegistries             []string `json:"insecure-registries,omitempty"`
}

ServiceOptions holds command line options.

type Session added in v1.2.0

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

A Session is used to communicate with a V1 registry

func NewSession added in v1.2.0

func NewSession(client *http.Client, authConfig *types.AuthConfig, endpoint *V1Endpoint) (*Session, error)

NewSession creates a new session TODO(tiborvass): remove authConfig param once registry client v2 is vendored

func (*Session) SearchRepositories added in v1.2.0

func (r *Session) SearchRepositories(term string, limit int) (*registrytypes.SearchResults, error)

SearchRepositories performs a search against the remote repository

type V1Endpoint added in v1.11.0

type V1Endpoint struct {
	URL      *url.URL
	IsSecure bool
	// contains filtered or unexported fields
}

V1Endpoint stores basic information about a V1 registry endpoint.

func NewV1Endpoint added in v1.11.0

func NewV1Endpoint(index *registrytypes.IndexInfo, userAgent string, metaHeaders http.Header) (*V1Endpoint, error)

NewV1Endpoint parses the given address to return a registry endpoint.

func (*V1Endpoint) Path added in v1.11.0

func (e *V1Endpoint) Path(path string) string

Path returns a formatted string for the URL of this endpoint with the given path appended.

func (*V1Endpoint) Ping added in v1.11.0

func (e *V1Endpoint) Ping() (PingResult, error)

Ping returns a PingResult which indicates whether the registry is standalone or not.

func (*V1Endpoint) String added in v1.11.0

func (e *V1Endpoint) String() string

Get the formatted URL for the root of this registry Endpoint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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