Documentation ¶
Index ¶
- Constants
- Variables
- func CreateOrReplaceAppendBlob(blobURI, blobSas string) (*storage.Blob, error)
- func Download(ctx *log.Context, downloader Downloader) (int, io.ReadCloser, error)
- func GetResourceNameFromBlobUri(uri string) string
- func GetSASBlob(blobURI, blobSas, targetDir string) (string, error)
- func GetUriForLogging(uriString string) string
- func IsAzureStorageBlobUri(url string) bool
- func SaveTo(ctx *log.Context, downloaders []Downloader, dst string, mode os.FileMode) (int64, error)
- func WithRetries(ctx *log.Context, downloaders []Downloader, sf SleepFunc) (io.ReadCloser, error)
- type Downloader
- type MockMsiDownloader
- func (mockMsiDownloader MockMsiDownloader) GetMsiProvider(blobUri string) MsiProvider
- func (mockMsiDownloader MockMsiDownloader) GetMsiProviderByClientId(blobUri string, clientId string) MsiProvider
- func (mockMsiDownloader MockMsiDownloader) GetMsiProviderByObjectId(blobUri, objectId string) MsiProvider
- type MsiDownloader
- type MsiProvider
- type ProdMsiDownloader
- type SleepFunc
Constants ¶
const ( // MsiDownload404ErrorString describes Msi specific error MsiDownload404ErrorString = "please ensure that the blob exists, and the specified Managed Identity has read permissions to the storage blob" // MsiDownload403ErrorString describes Msi permission specific error MsiDownload403ErrorString = "please ensure that the specified Managed Identity has read permissions to the storage blob" )
Variables ¶
var MockReturnErrorForMockMsiDownloader = false // Used only for test
Functions ¶
func CreateOrReplaceAppendBlob ¶ added in v1.2.2
CreateOrReplaceAppendBlob creates a reference to an append blob. If blob exists - it gets deleted first.
func Download ¶
func Download(ctx *log.Context, 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 GetSASBlob ¶
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 GetUriForLogging ¶ added in v1.2.2
Scrub query. Used to remove the query parts like SAS token.
func IsAzureStorageBlobUri ¶
func SaveTo ¶
func SaveTo(ctx *log.Context, downloaders []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 ¶
func NewBlobWithMsiDownload(url string, msiProvider MsiProvider) Downloader
func NewURLDownload ¶
func NewURLDownload(url string) Downloader
NewURLDownload creates a new downloader with the provided URL
type MockMsiDownloader ¶ added in v1.2.2
type MockMsiDownloader struct{} // Used only for test
func (MockMsiDownloader) GetMsiProvider ¶ added in v1.2.2
func (mockMsiDownloader MockMsiDownloader) GetMsiProvider(blobUri string) MsiProvider
Mock implementation of GetMsiProvider
func (MockMsiDownloader) GetMsiProviderByClientId ¶ added in v1.2.2
func (mockMsiDownloader MockMsiDownloader) GetMsiProviderByClientId(blobUri string, clientId string) MsiProvider
Mock implementation of GetMsiProviderByClientId
func (MockMsiDownloader) GetMsiProviderByObjectId ¶ added in v1.2.2
func (mockMsiDownloader MockMsiDownloader) GetMsiProviderByObjectId(blobUri, objectId string) MsiProvider
Mock implementation of GetMsiProviderByObjectId
type MsiDownloader ¶ added in v1.2.2
type MsiDownloader interface { GetMsiProvider(blobUri string) MsiProvider GetMsiProviderByClientId(blobUri, clientId string) MsiProvider GetMsiProviderByObjectId(blobUri, objectId string) MsiProvider }
type MsiProvider ¶
type ProdMsiDownloader ¶ added in v1.2.2
type ProdMsiDownloader struct{}
func (ProdMsiDownloader) GetMsiProvider ¶ added in v1.2.2
func (prodMsiDownloader ProdMsiDownloader) GetMsiProvider(blobUri string) MsiProvider
Uses system identity to get Msi token
func (ProdMsiDownloader) GetMsiProviderByClientId ¶ added in v1.2.2
func (prodMsiDownloader ProdMsiDownloader) GetMsiProviderByClientId(blobUri, clientId string) MsiProvider
Get Msi token by clientId
func (ProdMsiDownloader) GetMsiProviderByObjectId ¶ added in v1.2.2
func (prodMsiDownloader ProdMsiDownloader) GetMsiProviderByObjectId(blobUri, objectId string) MsiProvider
Get Msi token by objectId