distribution/registry/storage/driver/azure/parser.go
Milos Gajdos 2ffa1171c2
Azure driver fix
* Make copy poll max retry, a global driver max retry
* Get support for etags in Azure
* Fix storage driver tests
* Fix auth mess and update docs
* Refactor Azure client and enable Azure storage tests

We use Azurite for integration testing which requires TLS,
so we had to figure out how to skip TLS verification when running tests locally:
this required updating testsuites Driver and constructor due to TestRedirectURL
sending GET and HEAD requests to remote storage which in this case is Azurite.

Signed-off-by: Milos Gajdos <milosthegajdos@gmail.com>
2025-03-14 10:03:09 -07:00

69 lines
1.9 KiB
Go

package azure
import (
"errors"
"fmt"
"github.com/mitchellh/mapstructure"
)
const (
defaultRealm = "core.windows.net"
defaultMaxRetries = 5
defaultRetryDelay = "100ms"
)
type CredentialsType string
const (
CredentialsTypeClientSecret = "client_secret"
CredentialsTypeSharedKey = "shared_key"
CredentialsTypeDefault = "default_credentials"
)
type Credentials struct {
Type CredentialsType `mapstructure:"type"`
ClientID string `mapstructure:"clientid"`
TenantID string `mapstructure:"tenantid"`
Secret string `mapstructure:"secret"`
}
type DriverParameters struct {
Credentials Credentials `mapstructure:"credentials"`
Container string `mapstructure:"container"`
AccountName string `mapstructure:"accountname"`
AccountKey string `mapstructure:"accountkey"`
ConnectionString string `mapstructure:"connectionstring"`
Realm string `mapstructure:"realm"`
RootDirectory string `mapstructure:"rootdirectory"`
ServiceURL string `mapstructure:"serviceurl"`
MaxRetries int `mapstructure:"max_retries"`
RetryDelay string `mapstructure:"retry_delay"`
SkipVerify bool `mapstructure:"skipverify"`
}
func NewParameters(parameters map[string]interface{}) (*DriverParameters, error) {
params := DriverParameters{
Realm: defaultRealm,
}
if err := mapstructure.Decode(parameters, &params); 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.MaxRetries == 0 {
params.MaxRetries = defaultMaxRetries
}
if params.RetryDelay == "" {
params.RetryDelay = defaultRetryDelay
}
return &params, nil
}