client

package module
v0.0.0-...-301eb93 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

README

distribution-client

distribution-client is the Go client library for the OCI Distribution Specification.

Install

go get github.com/atlaskerr/distribution-client

Usage

package main

import "log"

func main() {
	cfg := client.Config{
		Host: "http://127.0.0.1:84832",
		Auth: client.BasicAuth{
			Username: "user",
			Password: "pass",
		},
	}
	c, err := client.New(cfg)
	if err != nil {
		log.Fatal(err)
	}

	api := client.NewDistributionAPI(c)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotOCI           = errors.New("distribution: registry isn't OCI-compliant")
	ErrManifestNotExist = errors.New("distribution: manifest does not exist")
	ErrBlobNotExist     = errors.New("distribution: blob does not exist")
	ErrParseBody        = errors.New("distribtuion: could not read response body")
	ErrParseJSON        = errors.New("distribution: could not parse JSON")
	ErrUnknownMediaType = errors.New("distribution: unknown media type")
	ErrSchemaValidation = errors.New("distribution: unable to validate schema")
	ErrInvalidIndex     = errors.New("distribution: registry returned invalid index")
	ErrInvalidManifest  = errors.New("distribution: registry returned invalid manifest")
)
View Source
var DefaultTransport = http.Transport{ResponseHeaderTimeout: time.Second}

DefaultTransport is the optional transport clients may use. Requests to the registry timeout after one second.

View Source
var ErrInvalidSchema = "distribution: invalid schema"

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	Set(*http.Request)
}

Authenticator is the interface all auth methods must satisfy.

type BasicAuth

type BasicAuth struct {
	Username string
	Password string
}

BasicAuth is an implementation of the Authenticator interface for username/password authentication.

func (*BasicAuth) Set

func (a *BasicAuth) Set(req *http.Request)

Set adds an authentication header to a request.

type Blob

type Blob interface {
	GetBlob(repo string, digest digest.Digest) (io.Reader, error)
	DeleteBlob(repo string, digest digest.Digest) error
	PutBlob(repo string, digest digest.Digest, blob io.Writer) error
}

type Client

type Client struct {
	Transport http.RoundTripper
}

Client is an implementation of http.RoundTripper.

func New

func New(cfg Config) (*Client, error)

New takes a Config and returns a fully initialized Client.

func (*Client) RoundTrip

func (c *Client) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip is the Client implementation of http.RoundTripper. Used to hook into an http.Request before being set to the server.

type Config

type Config struct {
	Transport http.RoundTripper
}

Config defines the parameters for Client configuration.

type DistributionAPI

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

DistributionAPI contains methods for interacting with a remote registry.

func NewDistributionAPI

func NewDistributionAPI(c *Client) *DistributionAPI

NewDistributionAPI returns a fully initialized API for interacting with a remote registry.

func (*DistributionAPI) NewRegistry

func (api *DistributionAPI) NewRegistry(host string, auth *Authenticator) *Registry

NewRegistry returns a fully initialized Registry.

func (*DistributionAPI) Verify

func (api *DistributionAPI) Verify() error

Verify verifies that the registry is OCI-compliant.

func (*DistributionAPI) VerifyBlob

func (api *DistributionAPI) VerifyBlob(
	repo string, digest digest.Digest) error

VerifyBlob confirms the existance of a manifest in a remote registry.

type ErrorInfo

type ErrorInfo struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Detail  string `json:"detail,omitempty"`
}

type ErrorResponse

type ErrorResponse struct {
	Errors []ErrorInfo `json:"errors"`
}

func (*ErrorResponse) Detail

func (er *ErrorResponse) Detail() []ErrorInfo

func (*ErrorResponse) Error

func (er *ErrorResponse) Error() string

Error satisfies the Error interface.

type Image

type Image struct {
	Repository string
	Reference  string
}

Image represents an image located on a remote registry.

type Registry

type Registry struct {
	Host *url.URL
	Auth Authenticator
	// contains filtered or unexported fields
}

Registry represents a remote OCI-compliant registries.

func (*Registry) GetManifests

func (r *Registry) GetManifests(img Image) (*ispec.Index, *[]ispec.Manifest, error)

GetManifests returns an image index and a slice of manifests from a remote registry. If the manifest is an Image Index, all manifests referenced in the index will be downloaded and returned. If a nil Index is returned, there will only be one manifest in the slice.

func (*Registry) ManifestExists

func (r *Registry) ManifestExists(img Image) error

ManifestExists confirms the existance of a manifest in a remote registry.

func (*Registry) RoundTrip

func (r *Registry) RoundTrip(req *http.Request) (resp *http.Response, err error)

RoundTrip is the Registry implementation of http.RoundTripper.

type TokenAuth

type TokenAuth struct {
	Token string
}

TokenAuth is an implementation of the Authenticator interface for token authentication.

func (*TokenAuth) Set

func (a *TokenAuth) Set(req *http.Request)

Set add an authentication header to a request.

type ValidationError

type ValidationError []gojsonschema.ResultError

func (*ValidationError) Error

func (ve *ValidationError) Error() string

Jump to

Keyboard shortcuts

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