registry

package
v0.0.0-...-c0f4ded Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2021 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoMorePages = errors.New("No more pages")
)

Functions

func Log

func Log(format string, args ...interface{})

Log passes log messages along to Go's "log" module.

func Quiet

func Quiet(format string, args ...interface{})

Quiet discards log messages silently.

func WrapTransport

func WrapTransport(transport http.RoundTripper, url string, opts Options) http.RoundTripper

* WrapTransport takes an existing http.RoundTripper such as http.DefaultTransport, * and builds the transport stack necessary to authenticate to the Docker registry API. * This adds in support for OAuth bearer tokens and HTTP Basic auth, and sets up * error handling this library relies on.

Types

type AuthorizationChallenge

type AuthorizationChallenge struct {
	Scheme     string
	Parameters map[string]string
}

AuthorizationChallenge carries information from a WWW-Authenticate response header.

type BasicTransport

type BasicTransport struct {
	Transport http.RoundTripper
	URL       string
	Username  string
	Password  string
}

func (*BasicTransport) RoundTrip

func (t *BasicTransport) RoundTrip(req *http.Request) (*http.Response, error)

type CannotReplayRequestBody

type CannotReplayRequestBody struct {
	Err error
}

CannotReplayRequestBody describes the HTTP error, when the server responded with a WWW-Authenticate header, but the body of the request (POST, PUT, PATCH) couldn't be replayed

func (CannotReplayRequestBody) Error

func (e CannotReplayRequestBody) Error() string

type ErrorTransport

type ErrorTransport struct {
	Transport http.RoundTripper
}

func (*ErrorTransport) RoundTrip

func (t *ErrorTransport) RoundTrip(request *http.Request) (*http.Response, error)

type HttpStatusError

type HttpStatusError struct {
	Response *http.Response
	Body     []byte // Copied from `Response.Body` to avoid problems with unclosed bodies later. Nobody calls `err.Response.Body.Close()`, ever.
}

func (*HttpStatusError) Error

func (err *HttpStatusError) Error() string

type LogfCallback

type LogfCallback func(format string, args ...interface{})

LogfCallback is the prototype of the custom logging function used by Registry

type Options

type Options struct {
	Username         string       `json:"username,omitempty"`
	Password         string       `json:"password,omitempty"`
	Insecure         bool         `json:"insecure,omitempty"`
	Logf             LogfCallback `json:"-"`
	DoInitialPing    bool         `json:"do_initial_ping,omitempty"`
	DisableBasicAuth bool         `json:"disable_basicauth,omitempty"`
}

Options stores optional parameters for constructing a new Registry See details in the docs of NewCustom()

type Registry

type Registry struct {
	URL    string
	Client *http.Client
	Logf   LogfCallback
}

Registry is the main Docker Registry API client type

func New

func New(url, username, password string) (*Registry, error)

New creates a new Registry with the given URL and credentials, then Ping()s it before returning it to verify that the registry is available. Be aware that this will print out log messages for the initial Ping() no matter what.

This constructor is left here for backward compatitibiliy, use NewCustom() if you need more control over constructor parameters.

func NewCustom

func NewCustom(url string, opts Options) (*Registry, error)

NewCustom creates a new Registry with the given URL and optional parameters. The interpretation of the optional parameters:

  Username, Password: credentials for the Docker Registry (default: anonymous access)
  Insecure: disables TLS certificate verification (default: TLS certificate verification is enabled)
  Logf: all log messages will be passed to this function (default: registry.Log)
  DoInitialPing: if true, the registry will be Ping()ed during construction (defualt: false)
					(note that some registries, e.g. quay.io, don't support anonymous Ping())
  DisableBasicAuth: disable basicauth authentication (default: basicauth is enabled)
                    (note that some registries, e.g. older versions of Artifactory, don't play well
                    with both token and basic auth enabled)

func NewInsecure

func NewInsecure(url, username, password string) (*Registry, error)

NewInsecure creates a new Registry, as with New, but using an http.Transport that disables SSL certificate verification. Be aware that this will print out log messages for the initial Ping() no matter what.

This constructor is left here for backward compatitibiliy, use NewCustom() if you need more control over constructor parameters.

func (*Registry) BlobMetadata

func (registry *Registry) BlobMetadata(repository string, digest digest.Digest) (distribution.Descriptor, error)

func (*Registry) DeleteManifest

func (registry *Registry) DeleteManifest(repository string, digest digest.Digest) error

DeleteManifest deletes the manifest given by its digest from the repository

func (*Registry) DownloadBlob

func (registry *Registry) DownloadBlob(repository string, digest digest.Digest) (io.ReadCloser, error)

func (*Registry) HasBlob

func (registry *Registry) HasBlob(repository string, digest digest.Digest) (bool, error)

func (*Registry) Manifest

func (registry *Registry) Manifest(repository, reference string) (distribution.Manifest, error)

Manifest returns a schema1 or schema2 manifest addressed by repository/reference. The schema of the result depends on the answer of the registry, it is usually the native schema of the manifest.

func (*Registry) ManifestDescriptor

func (registry *Registry) ManifestDescriptor(repository, reference string) (distribution.Descriptor, error)

ManifestDescriptor fills the returned Descriptor according to the Content-Type, Content-Length and Docker-Content-Digest headers of the HTTP Response to a Manifest query.

func (*Registry) ManifestDigest

func (registry *Registry) ManifestDigest(repository, reference string) (digest.Digest, error)

ManifestDigest returns the 'Docker-Content-Digest' field of the header when making a request to the schema1 manifest.

func (*Registry) ManifestList

func (registry *Registry) ManifestList(repository, reference string) (*manifestlist.DeserializedManifestList, error)

ManifestList returns with the ManifestList (a.k.a. fat manifest) addressed by repository/reference If the registry answers with any other manifest schema it returns an error.

func (*Registry) ManifestV1

func (registry *Registry) ManifestV1(repository, reference string) (*schema1.SignedManifest, error)

ManifestV1 returns with the schema1 manifest addressed by repository/reference. If the registry answers with any other manifest schema it returns an error.

func (*Registry) ManifestV2

func (registry *Registry) ManifestV2(repository, reference string) (*schema2.DeserializedManifest, error)

ManifestV2 returns with the schema2 manifest addressed by repository/reference If the registry answers with any other manifest schema it usually returns an error, except the following case. If reference is an image digest (sha256:...) and it is the hash of a manifestlist, then the method will return the first manifest with 'linux' OS and 'amd64' architecture, or in the absence thereof, the first manifest in the list. (Rationale: the Docker Image Digests returned by `docker images --digests` sometimes refer to manifestlists)

func (*Registry) ManifestV2Digest

func (registry *Registry) ManifestV2Digest(repository, reference string) (digest.Digest, error)

ManifestV2Digest returns the 'Docker-Content-Digest' field of the header when making a request to the schema2 manifest.

func (*Registry) Ping

func (registry *Registry) Ping() error

Ping checks if the registry is accessible and supports Docker Registry API v2

func (*Registry) PutManifest

func (registry *Registry) PutManifest(repository, reference string, manifest distribution.Manifest) error

PutManifest uploads manifest to the given repository/reference. Manifest is typically either of type schema2.DeserializedManifest or schema1.SignedManifest

func (*Registry) PutManifestV2

func (registry *Registry) PutManifestV2(repository, reference string, manifest *schema2.Manifest) (digest.Digest, error)

PutManifestV2 uploads the given schama2.Manifest to the given repository/reference and returns with its digest. If you want to upload a schema2.DeserializedManifest, please use the generic PutManifest().

func (*Registry) Repositories

func (registry *Registry) Repositories() ([]string, error)

func (*Registry) Tags

func (registry *Registry) Tags(repository string) (tags []string, err error)

func (*Registry) UploadBlob

func (registry *Registry) UploadBlob(repository string, digest digest.Digest, content io.Reader, getBody func() (io.ReadCloser, error)) error

UploadBlob can be used to upload an FS layer or an image config file into the given repository. It uploads the bytes read from content. Digest must match with the hash of those bytes. In case of token authentication the HTTP request must be retried after a 401 Unauthorized response (see https://docs.docker.com/registry/spec/auth/token/). In this case the getBody function is called in order to retrieve a fresh instance of the content reader. This behaviour matches exactly of the GetBody parameter of http.Client. This also means that if content is of type *bytes.Buffer, *bytes.Reader or *strings.Reader, then GetBody is populated automatically (as explained in the documentation of http.NewRequest()), so nil can be passed as the getBody parameter.

type TokenTransport

type TokenTransport struct {
	Transport http.RoundTripper
	Username  string
	Password  string
}

func (*TokenTransport) RoundTrip

func (t *TokenTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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