asset

package
v0.97.0-sumo-1 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Overview

Package asset facilitates the retrieval of remote runtime assets.

Largely inspired and adapted from the source of `github.com/sensu/sensu-go`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Fetcher

type Fetcher interface {
	// Fetch a payload from the URL given as the argument, and save it in a
	// temporary file.
	Fetch(ctx context.Context, URL string) (*os.File, error)
}

func NewFetcher

func NewFetcher(log *zap.SugaredLogger, client *http.Client) Fetcher

NewFetcher creates a new HTTP based Fetcher.

Uses an exponential backoff to retry failed requests.

type Manager

type Manager struct {
	// Fetcher for downloading assets
	Fetcher Fetcher
	// StoragePath directory where assets will be unpacked and referenced
	StoragePath string
	Logger      *zap.SugaredLogger
}

func (*Manager) InstallAll

func (m *Manager) InstallAll(ctx context.Context, all []Spec) ([]Reference, error)

InstallAll runtime assets on the host file system under the StoragePath directory.

Loops through the provided asset Specs and ensures they are installed at the Manager's StoragePath. Returns the first error encountered in the install.

func (*Manager) Validate

func (m *Manager) Validate(assets []Spec) error

Validate the assets are valid and that the manager can access its storage path

type Reference

type Reference struct {
	Name string
	Path string
}

Reference to an installed runtime asset

func (Reference) MergeEnvironment

func (r Reference) MergeEnvironment(env []string) []string

MergeEnvironment merges the environment variables associated with a runtime asset into an existing set of environment variables.

Includes executables in the PATH, shared libraries in LD_LIBRARY_PATH and include source in CPATH. Also introduces an {{ asset name }}_PATH variable pointing at the installation directory.

type Spec

type Spec struct {
	// Name is the name of the asset
	Name string `mapstructure:"name"`
	// Url is the remote address used for fetching the asset
	URL string `mapstructure:"url"`
	// SHA512 is the hash of the asset tarball
	SHA512 string `mapstructure:"sha512"`
}

Spec for asset fetching

func (*Spec) Validate

func (a *Spec) Validate() error

Validate checks an asset ID is valid, but does not attempt to fetch the asset or verify the integrity of its hash

Jump to

Keyboard shortcuts

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