download

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2021 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MsiDownload404ErrorString describes Msi specific error
	MsiDownload404ErrorString = "" /* 143-byte string literal not displayed */

	// MsiDownload403ErrorString describes Msi permission specific error
	MsiDownload403ErrorString = "please ensure that the specified Managed Identity has read permissions to the storage blob"
)

Variables

This section is empty.

Functions

func CreateAppendBlob added in v1.2.0

func CreateAppendBlob(blobURI, blobSas string) (*storage.Blob, error)

CreateAppendBlob creates a reference to an append blob. If blob exists - it gets deleted first.

func Download

func Download(downloader Downloader) (int, io.ReadCloser, error)

Download retrieves a response body and checks the response status code to see if it is 200 OK and then returns the response body. It issues a new request every time called. It is caller's responsibility to close the response body.

func GetResourceNameFromBlobUri added in v1.1.0

func GetResourceNameFromBlobUri(uri string) string

func GetSASBlob added in v1.2.0

func GetSASBlob(blobURI, blobSas, targetDir string) (string, error)

GetSASBlob download a blob with specified uri and sas authorization and saves it to the target directory Returns the filePath where the blob was downloaded

func IsAzureStorageBlobUri added in v1.1.0

func IsAzureStorageBlobUri(url string) bool

func SaveTo

func SaveTo(ctx *log.Context, d []Downloader, dst string, mode os.FileMode) (int64, error)

SaveTo uses given downloader to fetch the resource with retries and saves the given file. Directory of dst is not created by this function. If a file at dst exists, it will be truncated. If a new file is created, mode is used to set the permission bits. Written number of bytes are returned on success.

func WithRetries

func WithRetries(ctx *log.Context, downloaders []Downloader, sf SleepFunc) (io.ReadCloser, error)

WithRetries retrieves a response body using the specified downloader. Any error returned from d will be retried (and retrieved response bodies will be closed on failures). If the retries do not succeed, the last error is returned.

It sleeps in exponentially increasing durations between retries.

Types

type Downloader

type Downloader interface {
	// GetRequest returns a new GET request for the resource.
	GetRequest() (*http.Request, error)
}

Downloader describes a method to download files.

func NewBlobDownload

func NewBlobDownload(accountName, accountKey string, blob blobutil.AzureBlobRef) Downloader

NewBlobDownload creates a new Downloader for a blob hosted in Azure Blob Storage.

func NewBlobWithMsiDownload added in v1.1.0

func NewBlobWithMsiDownload(url string, msiProvider MsiProvider) Downloader

func NewURLDownload

func NewURLDownload(url string) Downloader

NewURLDownload creates a new downloader with the provided URL

type MsiProvider added in v1.1.0

type MsiProvider func() (msi.Msi, error)

func GetMsiProviderForStorageAccountsImplicitly added in v1.1.0

func GetMsiProviderForStorageAccountsImplicitly(blobUri string) MsiProvider

func GetMsiProviderForStorageAccountsWithClientId added in v1.1.0

func GetMsiProviderForStorageAccountsWithClientId(blobUri, clientId string) MsiProvider

func GetMsiProviderForStorageAccountsWithObjectId added in v1.1.0

func GetMsiProviderForStorageAccountsWithObjectId(blobUri, objectId string) MsiProvider

type SleepFunc

type SleepFunc func(d time.Duration)

SleepFunc pauses the execution for at least duration d.

var (
	// ActualSleep uses actual time to pause the execution.
	ActualSleep SleepFunc = time.Sleep
)

Jump to

Keyboard shortcuts

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