registry

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package registry provides functionality to get digests from registries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AuthCredentials

type AuthCredentials struct {
	Username string
	Password string
}

AuthCredentials contains a username and password required to auth with a container registry.

func NewAuthCredentials

func NewAuthCredentials(
	username string,
	password string,
	configPath string,
	extractor AuthStringExtractor,
) (*AuthCredentials, error)

NewAuthCredentials returns AuthCredentials according to the following rules: (1) If a username and password are not empty, use them. (2) Else if a username and password are empty:

a. If the configPath is empty, return empty creds.
b. Else, attempt to extract the base64 creds from the config file.
c. If creds are empty, but the config file specifies a creds store,
   retrieve the creds from the creds store.

(3) Return empty creds.

type AuthStringExtractor

type AuthStringExtractor interface {
	// ExtractAuthStr reads the base64 encoded auth string and the creds store
	// from the configuration file's bytes.
	ExtractAuthStr(confByt []byte) (authStr string, credStore string, err error)
	// ServerURL is the URL of the login server.
	ServerURL() string
}

AuthStringExtractor allows different registry wrappers to control how the auth information is extracted from docker's config file.

type DefaultTokenExtractor

type DefaultTokenExtractor struct{}

DefaultTokenExtractor provides a concrete implementation for registries whose json response returns the token with the key "token".

func (*DefaultTokenExtractor) FromBody

func (*DefaultTokenExtractor) FromBody(body io.ReadCloser) (string, error)

FromBody decodes and returns the token from the json body.

type HTTPClient

type HTTPClient struct {
	*http.Client
	RegistryURL string
	TokenURL    string
}

HTTPClient overrides base urls to get digests and auth tokens.

type TokenExtractor

type TokenExtractor interface {
	FromBody(io.ReadCloser) (string, error)
}

TokenExtractor allows registry wrappers to implement their own logic to extract tokens from from a registry's response. For instance, Dockerhub returns json with the key "token" whereas ACR returns json with the key "access_token". Since this functionality varies per registry, it is up to the registry wrapper to define how to extract the token from the registry's response.

type V2

type V2 struct {
	Client *HTTPClient
}

V2 provides methods to get digests and tokens according to the HTTP API V2 specification: https://docs.docker.com/registry/spec/api/#docker-registry-http-api-v2

func NewV2

func NewV2(client *HTTPClient) (*V2, error)

NewV2 returns a *V2 with a client initialized or an error if the client is nil.

func (*V2) Digest

func (v *V2) Digest(repo, ref, token string) (string, error)

Digest queries the container registry for the digest given a repo, ref, and token. If a token is not required, leave it empty.

func (*V2) Token

func (v *V2) Token(
	url string,
	username string,
	password string,
	extractor TokenExtractor,
) (string, error)

Token queries the container registry for a bearer token that is later required to query the container registry for a digest.

type Wrapper

type Wrapper interface {
	// Digest returns the digest from a repo and ref. For instance,
	// the repo and ref for dockerlocktestaccount.azurecr.io/busybox:latest
	// would be busybox and latest, respectively.
	Digest(repo string, ref string) (string, error)

	// Prefix returns the registry prefix and is used by the wrapper manager
	// to select which registry to use. For instance, the prefix for
	// 'dockerlocktestaccount.azurecr.io/busybox' would be
	// 'dockerlocktestaccount.azurecr.io/'.
	Prefix() string
}

Wrapper defines an interface that registry wrappers implement.

func AllWrappers

func AllWrappers(
	client *HTTPClient,
	configPath string,
	constructors []WrapperConstructor,
) []Wrapper

AllWrappers returns all wrappers constructed from constructor functions.

type WrapperConstructor

type WrapperConstructor func(
	client *HTTPClient,
	configPath string,
) (Wrapper, error)

WrapperConstructor is a type for a function that can create a wrapper. Each Wrapper has an init function that registers a WrapperConstructor so it can be found at runtime.

type WrapperManager

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

WrapperManager selects which registry wrapper to use at runtime.

func NewWrapperManager

func NewWrapperManager(defaultWrapper Wrapper) *WrapperManager

NewWrapperManager creates a WrapperManager with a default wrapper that is selected if no prefix matches in Wrapper.

func (*WrapperManager) Add

func (m *WrapperManager) Add(wrappers ...Wrapper)

Add adds a registry wrapper to the WrapperManager's collection of wrappers to use at runtime.

func (*WrapperManager) Wrapper

func (m *WrapperManager) Wrapper(line string) Wrapper

Wrapper selects a registry wrapper if the line starts with the wrapper's prefix. If no match is found, the default wrapper is used. In this context, a line means the prefix+repo+tag, as in dockerlocktestaccount.azurecr.io/helloworld:latest.

Directories

Path Synopsis
Package contrib provides functionality for getting digests from registries supported by docker-lock's community.
Package contrib provides functionality for getting digests from registries supported by docker-lock's community.
Package firstparty provides functionality for getting digests from registries supported by docker-lock's maintainers.
Package firstparty provides functionality for getting digests from registries supported by docker-lock's maintainers.

Jump to

Keyboard shortcuts

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