2b72c4d1ca
Something seems broken on azure/azure sdk side - it is currently not possible to copy a blob of type AppendBlob using `CopyFromURL`. Using the AppendBlob client via NewAppendBlobClient does not work either. According to Azure the correct way to do this is by using StartCopyFromURL. Because this is an async operation, we need to do polling ourselves. A simple backoff mechanism is used, where during each iteration, the configured delay is multiplied by the retry number. Also introduces two new config options for the Azure driver: copy_status_poll_max_retry, and copy_status_poll_delay. Signed-off-by: Flavian Missi <fmissi@redhat.com>
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
package azure
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
)
|
|
|
|
const (
|
|
defaultRealm = "core.windows.net"
|
|
defaultCopyStatusPollMaxRetry = 5
|
|
defaultCopyStatusPollDelay = "100ms"
|
|
)
|
|
|
|
type Credentials struct {
|
|
Type string `mapstructure:"type"`
|
|
ClientID string `mapstructure:"clientid"`
|
|
TenantID string `mapstructure:"tenantid"`
|
|
Secret string `mapstructure:"secret"`
|
|
}
|
|
|
|
type Parameters struct {
|
|
Container string `mapstructure:"container"`
|
|
AccountName string `mapstructure:"accountname"`
|
|
AccountKey string `mapstructure:"accountkey"`
|
|
Credentials Credentials `mapstructure:"credentials"`
|
|
ConnectionString string `mapstructure:"connectionstring"`
|
|
Realm string `mapstructure:"realm"`
|
|
RootDirectory string `mapstructure:"rootdirectory"`
|
|
ServiceURL string `mapstructure:"serviceurl"`
|
|
CopyStatusPollMaxRetry int `mapstructure:"copy_status_poll_max_retry"`
|
|
CopyStatusPollDelay string `mapstructure:"copy_status_poll_delay"`
|
|
}
|
|
|
|
func NewParameters(parameters map[string]interface{}) (*Parameters, error) {
|
|
params := Parameters{
|
|
Realm: defaultRealm,
|
|
}
|
|
if err := mapstructure.Decode(parameters, ¶ms); err != nil {
|
|
return nil, err
|
|
}
|
|
if params.AccountName == "" {
|
|
return nil, errors.New("no accountname parameter provided")
|
|
}
|
|
if params.Container == "" {
|
|
return nil, errors.New("no container parameter provider")
|
|
}
|
|
if params.ServiceURL == "" {
|
|
params.ServiceURL = fmt.Sprintf("https://%s.blob.%s", params.AccountName, params.Realm)
|
|
}
|
|
if params.CopyStatusPollMaxRetry == 0 {
|
|
params.CopyStatusPollMaxRetry = defaultCopyStatusPollMaxRetry
|
|
}
|
|
if params.CopyStatusPollDelay == "" {
|
|
params.CopyStatusPollDelay = defaultCopyStatusPollDelay
|
|
}
|
|
return ¶ms, nil
|
|
}
|