client

package
v0.41.6 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultOptions

func DefaultOptions() []crane.Option

DefaultOptions returns an empty list of client options.

func GetAuthFromCredentials

func GetAuthFromCredentials(credentials string) (authn.Authenticator, error)

GetAuthFromCredentials returns an authn.Authenticator for the static credentials, accepts a single token or a user:password format.

func IsCosignArtifact

func IsCosignArtifact(tag string) bool

IsCosignArtifact will return true if the tag has one of the following suffices: ".att", ".sbom", or ".sig". These are the suffices used by cosign to store the attestations, SBOMs, and signatures respectively.

func ParseArtifactURL

func ParseArtifactURL(ociURL string) (string, error)

ParseArtifactURL validates the OCI URL and returns the address of the artifact.

func ParseRepositoryURL

func ParseRepositoryURL(ociURL string) (string, error)

ParseRepositoryURL validates the OCI URL and returns the address of the artifact repository.

func WithRetryBackOff

func WithRetryBackOff(backoff remote.Backoff) crane.Option

WithRetryBackOff returns a function for setting the given backoff on crane.Option.

func WithRetryTransport

func WithRetryTransport(ctx context.Context, ref name.Reference, auth authn.Authenticator, backoff remote.Backoff, scopes []string) (crane.Option, error)

WithRetryTransport returns a crane.Option for setting transport that uses the backoff for retries

Most parts(including the functions below) are copied from https://github.com/google/go-containerregistry/blob/v0.14.0/pkg/v1/remote/options.go#L152 so we have the same transport used in the library but with a different retry backoff.

Types

type Client

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

Client holds the options for accessing remote OCI registries.

func NewClient

func NewClient(opts []crane.Option) *Client

NewClient returns an OCI client configured with the given crane options.

func (*Client) Build

func (c *Client) Build(artifactPath, sourceDir string, ignorePaths []string) (err error)

Build archives the given directory as a tarball to the given local path. While archiving, any environment specific data (for example, the user and group name) is stripped from file headers.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, url string) error

Delete deletes a particular image from an OCI repository If the url has no tag, the latest image is deleted

func (*Client) Diff

func (c *Client) Diff(ctx context.Context, url, dir string, ignorePaths []string) error

Diff compares the files included in an OCI image with the local files in the given path and returns an error if the contents is different

func (*Client) GetOptions

func (c *Client) GetOptions() []crane.Option

GetOptions returns the list of crane.Option used by this Client.

func (*Client) List

func (c *Client) List(ctx context.Context, url string, opts ListOptions) ([]Metadata, error)

List fetches the tags and their manifests for a given OCI repository.

func (*Client) LoginWithCredentials

func (c *Client) LoginWithCredentials(credentials string) error

LoginWithCredentials configures the client with static credentials, accepts a single token or a user:password format.

func (*Client) LoginWithProvider

func (c *Client) LoginWithProvider(ctx context.Context, url string, provider oci.Provider) error

LoginWithProvider configures the client to log in to the specified provider

func (*Client) Pull

func (c *Client) Pull(ctx context.Context, url, outPath string, opts ...PullOption) (*Metadata, error)

Pull downloads an artifact from an OCI repository and extracts the content. It untar or copies the content to the given outPath depending on the layerType. If no layer type is given, it tries to determine the right type by checking compressed content of the layer.

func (*Client) Push

func (c *Client) Push(ctx context.Context, url, sourcePath string, opts ...PushOption) (string, error)

Push creates an artifact from the given path, uploads the artifact to the given OCI repository and returns the digest.

func (*Client) Tag

func (c *Client) Tag(ctx context.Context, url, tag string) (string, error)

Tag creates a new tag for the given artifact using the same OCI repository as the origin.

type LayerType

type LayerType string

LayerType is an enumeration of the supported layer types when pushing an image.

const (
	// LayerTypeTarball produces a layer that contains a gzipped archive
	LayerTypeTarball LayerType = "tarball"
	// LayerTypeStatic produces a layer that contains the contents of a
	// file without any compression.
	LayerTypeStatic LayerType = "static"
)

type ListOptions

type ListOptions struct {
	// SemverFilter contains semver for filtering tags.
	SemverFilter string
	// RegexFilter contains a regex that tags will be filtered by.
	RegexFilter string
	// IncludeCosignArtifacts can be used to include cosign attestation,
	// signature and SBOM tags in the list, as these are excluded by default.
	IncludeCosignArtifacts bool
}

ListOptions contains options for listing tags from an OCI repository.

type Metadata

type Metadata struct {
	Created     string            `json:"created,omitempty"`
	Source      string            `json:"source_url,omitempty"`
	Revision    string            `json:"source_revision,omitempty"`
	Digest      string            `json:"digest"`
	URL         string            `json:"url"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

Metadata holds the upstream information about on artifact's source. https://github.com/opencontainers/image-spec/blob/main/annotations.md

func MetadataFromAnnotations

func MetadataFromAnnotations(annotations map[string]string) *Metadata

MetadataFromAnnotations parses the OpenContainers annotations and returns a Metadata object.

func (*Metadata) ToAnnotations

func (m *Metadata) ToAnnotations() map[string]string

ToAnnotations returns the OpenContainers annotations map.

type PullOption

type PullOption func(o *PullOptions)

PullOption is a function for configuring PullOptions.

func WithPullLayerIndex

func WithPullLayerIndex(i int) PullOption

WithPullLayerIndex set the index of the layer to be pulled.

func WithPullLayerType

func WithPullLayerType(l LayerType) PullOption

WithPullLayerType sets the layer type of the layer that is being pulled.

type PullOptions

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

PullOptions contains options for pulling a layer.

type PushOption

type PushOption func(o *PushOptions)

PushOption is a function for configuring PushOptions.

func WithPushIgnorePaths

func WithPushIgnorePaths(paths ...string) PushOption

WithPushIgnorePaths configures ignore paths for PushOptions

func WithPushLayerType

func WithPushLayerType(l LayerType) PushOption

WithPushLayerType set the layer type that will be used when creating the image layer.

func WithPushMediaTypeExt

func WithPushMediaTypeExt(extension string) PushOption

WithPushMediaTypeExt configures the media type extension for the image layer. This is only used when the layer type is `LayerTypeStatic`. The final media type will be prefixed with `application/vnd.cncf.flux.content.v1`

func WithPushMetadata

func WithPushMetadata(meta Metadata) PushOption

WithPushMetadata configures Metadata that will be used for image annotations.

type PushOptions

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

PushOptions are options for configuring the Push operation.

Directories

Path Synopsis
internal
fs

Jump to

Keyboard shortcuts

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