resource

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2017 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSchemeUnsupported      = errors.New("unsupported source scheme")
	ErrPathNotAbsolute        = errors.New("path is not absolute")
	ErrNotFound               = errors.New("resource not found")
	ErrFailed                 = errors.New("failed to fetch resource")
	ErrCompressionUnsupported = errors.New("compression is not supported with that scheme")

	// ConfigHeaders are the HTTP headers that should be used when the Ignition
	// config is being fetched
	ConfigHeaders = http.Header{
		"Accept-Encoding": []string{"identity"},
		"Accept":          []string{"application/vnd.coreos.ignition+json; version=2.1.0, application/vnd.coreos.ignition+json; version=1; q=0.5, */*; q=0.1"},
	}
)
View Source
var (
	ErrTimeout = errors.New("unable to fetch resource in time")
)

Functions

This section is empty.

Types

type ErrHashMismatch added in v0.17.0

type ErrHashMismatch struct {
	Calculated string
	Expected   string
}

ErrHashMismatch is returned when the calculated hash for a fetched object doesn't match the expected sum of the object.

func (ErrHashMismatch) Error added in v0.17.0

func (e ErrHashMismatch) Error() string

type FetchOptions added in v0.17.0

type FetchOptions struct {
	// Headers are the http headers that will be used when fetching http(s)
	// resources. They have no effect on other fetching schemes.
	Headers http.Header

	// Hash is the hash to use when calculating a fetched resource's hash. If
	// left as nil, no hash will be calculated.
	Hash hash.Hash

	// The expected sum to be produced by the given hasher. If the Hash field is
	// nil, this field is ignored.
	ExpectedSum []byte

	// Compression specifies the type of compression to use when decompressing
	// the fetched object. If left empty, no decompression will be used.
	Compression string
}

type Fetcher added in v0.17.0

type Fetcher struct {
	// The logger object to use when logging information.
	Logger *log.Logger

	// Client is the http client that will be used when fetching http(s)
	// resources. If left nil, one will be created and used, but this means any
	// timeouts Ignition was configured to used will be ignored.
	Client *HttpClient

	// The AWS Session to use when fetching resources from S3. If left nil, the
	// first S3 object that is fetched will initialize the field. This can be
	// used to set credentials.
	AWSSession *session.Session
}

Fetcher holds settings for fetching resources from URLs

func (*Fetcher) Fetch added in v0.17.0

func (f *Fetcher) Fetch(u url.URL, dest *os.File, opts FetchOptions) error

Fetch calls the appropriate FetchFrom* function based on the scheme of the given URL. The results will be decompressed if compression is set in opts, and written into dest. If opts.Hash is set the data stream will also be hashed and compared against opts.ExpectedSum, and any match failures will result in an error being returned.

func (*Fetcher) FetchFromDataURL added in v0.17.0

func (f *Fetcher) FetchFromDataURL(u url.URL, dest *os.File, opts FetchOptions) error

FetchFromDataURL writes the data stored in the dataurl u into dest, returning an error if one is encountered.

func (*Fetcher) FetchFromHTTP added in v0.17.0

func (f *Fetcher) FetchFromHTTP(u url.URL, dest *os.File, opts FetchOptions) error

FetchFromHTTP fetches a resource from u via HTTP(S) into dest, returning an error if one is encountered.

func (*Fetcher) FetchFromOEM added in v0.17.0

func (f *Fetcher) FetchFromOEM(u url.URL, dest *os.File, opts FetchOptions) error

FetchFromOEM gets data off the oem partition as described by u and writes it into dest, returning an error if one is encountered.

func (*Fetcher) FetchFromS3 added in v0.17.0

func (f *Fetcher) FetchFromS3(u url.URL, dest *os.File, opts FetchOptions) error

FetchFromS3 gets data from an S3 bucket as described by u and writes it into dest, returning an error if one is encountered. It will attempt to acquire IAM credentials from the EC2 metadata service, and if this fails will attempt to fetch the object with anonymous credentials.

func (*Fetcher) FetchFromTFTP added in v0.17.0

func (f *Fetcher) FetchFromTFTP(u url.URL, dest *os.File, opts FetchOptions) error

FetchFromTFTP fetches a resource from u via TFTP into dest, returning an error if one is encountered.

func (*Fetcher) FetchToBuffer added in v0.17.0

func (f *Fetcher) FetchToBuffer(u url.URL, opts FetchOptions) ([]byte, error)

FetchToBuffer will fetch the given url into a temporrary file, and then read in the contents of the file and delete it. It will return the downloaded contents, or an error if one was encountered.

type HttpClient

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

HttpClient is a simple wrapper around the Go HTTP client that standardizes the process and logging of fetching payloads.

func NewHttpClient

func NewHttpClient(logger *log.Logger, timeouts types.Timeouts) HttpClient

NewHttpClient creates a new client with the given logger and timeouts.

Jump to

Keyboard shortcuts

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