fetch

package module
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 19 Imported by: 11

Documentation

Index

Constants

This section is empty.

Variables

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

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

Fetch 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 file server is unavailable for more than 3 minutes, the returned error contains the original status code.

func (*ArchiveFetcher) FetchWithContext added in v0.10.0

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

FetchWithContext is the same as Fetch but accepts a context.

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 WithUntar added in v0.10.0

func WithUntar(opts ...tar.TarOption) 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