2020-02-21 03:58:17 +00:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2023-06-01 14:19:34 +00:00
|
|
|
defaultRealm = "core.windows.net"
|
|
|
|
defaultCopyStatusPollMaxRetry = 5
|
|
|
|
defaultCopyStatusPollDelay = "100ms"
|
2020-02-21 03:58:17 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Credentials struct {
|
|
|
|
Type string `mapstructure:"type"`
|
|
|
|
ClientID string `mapstructure:"clientid"`
|
|
|
|
TenantID string `mapstructure:"tenantid"`
|
|
|
|
Secret string `mapstructure:"secret"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Parameters struct {
|
2023-06-01 14:19:34 +00:00
|
|
|
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"`
|
2020-02-21 03:58:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2023-06-01 14:19:34 +00:00
|
|
|
if params.CopyStatusPollMaxRetry == 0 {
|
|
|
|
params.CopyStatusPollMaxRetry = defaultCopyStatusPollMaxRetry
|
|
|
|
}
|
|
|
|
if params.CopyStatusPollDelay == "" {
|
|
|
|
params.CopyStatusPollDelay = defaultCopyStatusPollDelay
|
|
|
|
}
|
2020-02-21 03:58:17 +00:00
|
|
|
return ¶ms, nil
|
|
|
|
}
|