fetch

package module
v0.30.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 21 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDigestMismatch = errors.New("computed digest doesn't match")

ErrDigestMismatch is an error type used to signal that the downloaded content doesn't match the expected digest, e.g. because the artifact changed between reading the source status and downloading it.

View Source
var ErrFileNotFound = errors.New("file not found")

ErrFileNotFound is an error type used to signal 404 HTTP status code responses.

Functions

This section is empty.

Types

type ArchiveFetcher

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

ArchiveFetcher is a flexible API for downloading an archive from an HTTP server, verifying its digest and extracting its contents to a given path in the Filesystem.

func New added in v0.10.0

func New(opts ...Option) *ArchiveFetcher

New creates an *ArchiveFetcher accepting options.

func NewArchiveFetcher deprecated

func NewArchiveFetcher(retries, maxDownloadSize, maxUntarSize int, hostnameOverwrite string) *ArchiveFetcher

NewArchiveFetcher configures the retryable HTTP client used for fetching archives.

Deprecated: Use New() instead.

func NewArchiveFetcherWithLogger deprecated added in v0.8.0

func NewArchiveFetcherWithLogger(retries, maxDownloadSize, maxUntarSize int, hostnameOverwrite string, logger any) *ArchiveFetcher

NewArchiveFetcherWithLogger configures the retryable HTTP client used for fetching archives and sets the logger to use.

The logger can be any type that implements the retryablehttp.Logger or retryablehttp.LeveledLogger interface. If the logger is of type logr.Logger, it will be wrapped in a retryablehttp.LeveledLogger that only logs errors.

Deprecated: Use New() instead.

func (*ArchiveFetcher) Fetch deprecated

func (r *ArchiveFetcher) Fetch(archiveURL, digest, dir string) error

Fetch is the same as FetchWithContext but uses a background context.

Deprecated: Use FetchWithContext instead.

func (*ArchiveFetcher) FetchBytes added in v0.29.0

func (r *ArchiveFetcher) FetchBytes(ctx context.Context, archiveURL, digest string) (bytes.Buffer, error)

FetchBytes is the same as FetchWithContext but returns the content of the archive as a bytes.Buffer instead of writing it to a directory. Untar options are ignored.

func (*ArchiveFetcher) FetchWithContext added in v0.10.0

func (r *ArchiveFetcher) FetchWithContext(ctx context.Context, archiveURL, digest, dir string) (err error)

FetchWithContext downloads, verifies and extracts the tarball content to the specified directory. If the file server responds with 5xx errors, the download operation is retried. If the file server responds with 404, the returned error is of type ErrFileNotFound. If the digest of the downloaded content doesn't match, the returned error wraps ErrDigestMismatch. If the file server is unavailable for more than 3 minutes, the returned error contains the original status code.

type Option added in v0.10.0

type Option func(a *ArchiveFetcher)

Option is an option for constructing the ArchiveFetcher.

func WithFileMode added in v0.10.0

func WithFileMode(fileMode fs.FileMode) Option

WithFileMode sets the file mode for the downloaded archive. Applies only if untar is not enabled and the archive is not extracted.

func WithFileName added in v0.10.0

func WithFileName(filename string) Option

WithFileName sets the file name for the downloaded archive.

func WithHostnameOverwrite added in v0.10.0

func WithHostnameOverwrite(hostnameOverwrite string) Option

WithHostnameOverwrite sets an override for the hostname in download URLs.

func WithLogger added in v0.10.0

func WithLogger(logger any) Option

WithLogger sets a logger for the HTTP client. The logger can be any type that implements the retryablehttp.Logger or retryablehttp.LeveledLogger interface. If the logger is of type logr.Logger, it will be wrapped in a retryablehttp.LeveledLogger that only logs errors.

func WithMaxDownloadSize added in v0.10.0

func WithMaxDownloadSize(maxDownloadSize int) Option

WithMaxDownloadSize specifies a limit for the size of the downloaded archive.

func WithRetries added in v0.10.0

func WithRetries(retries int) Option

WithRetries sets the maximum amount of retries the HTTP client will be allowed to make.

func WithTLSConfig added in v0.29.0

func WithTLSConfig(tlsConfig *tls.Config) Option

WithTLSConfig sets the TLS configuration for the HTTP client.

func WithUntar added in v0.10.0

func WithUntar(opts ...tar.Option) Option

WithUntar tells the ArchiveFetcher to untar the archive expecting it to be a tarball.

Jump to

Keyboard shortcuts

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