Update Azure SDK and support additional authentication schemes
Microsoft has updated the golang Azure SDK significantly. Update the azure storage driver to use the new SDK. Add support for client secret and MSI authentication schemes in addition to shared key authentication. Implement rootDirectory support for the azure storage driver to mirror the S3 driver. Signed-off-by: Kirat Singh <kirat.singh@beacon.io> Co-authored-by: Cory Snider <corhere@gmail.com>
This commit is contained in:
parent
e5d5810851
commit
ba4a6bbe02
365 changed files with 44060 additions and 21016 deletions
|
@ -12,10 +12,11 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
envAccountName = "AZURE_STORAGE_ACCOUNT_NAME"
|
||||
envAccountKey = "AZURE_STORAGE_ACCOUNT_KEY"
|
||||
envContainer = "AZURE_STORAGE_CONTAINER"
|
||||
envRealm = "AZURE_STORAGE_REALM"
|
||||
envAccountName = "AZURE_STORAGE_ACCOUNT_NAME"
|
||||
envAccountKey = "AZURE_STORAGE_ACCOUNT_KEY"
|
||||
envContainer = "AZURE_STORAGE_CONTAINER"
|
||||
envRealm = "AZURE_STORAGE_REALM"
|
||||
envRootDirectory = "AZURE_ROOT_DIRECTORY"
|
||||
)
|
||||
|
||||
// Hook up gocheck into the "go test" runner.
|
||||
|
@ -23,32 +24,42 @@ func Test(t *testing.T) { TestingT(t) }
|
|||
|
||||
func init() {
|
||||
var (
|
||||
accountName string
|
||||
accountKey string
|
||||
container string
|
||||
realm string
|
||||
accountName string
|
||||
accountKey string
|
||||
container string
|
||||
realm string
|
||||
rootDirectory string
|
||||
)
|
||||
|
||||
config := []struct {
|
||||
env string
|
||||
value *string
|
||||
env string
|
||||
value *string
|
||||
missingOk bool
|
||||
}{
|
||||
{envAccountName, &accountName},
|
||||
{envAccountKey, &accountKey},
|
||||
{envContainer, &container},
|
||||
{envRealm, &realm},
|
||||
{envAccountName, &accountName, false},
|
||||
{envAccountKey, &accountKey, false},
|
||||
{envContainer, &container, false},
|
||||
{envRealm, &realm, false},
|
||||
{envRootDirectory, &rootDirectory, true},
|
||||
}
|
||||
|
||||
missing := []string{}
|
||||
for _, v := range config {
|
||||
*v.value = os.Getenv(v.env)
|
||||
if *v.value == "" {
|
||||
if *v.value == "" && !v.missingOk {
|
||||
missing = append(missing, v.env)
|
||||
}
|
||||
}
|
||||
|
||||
azureDriverConstructor := func() (storagedriver.StorageDriver, error) {
|
||||
return New(accountName, accountKey, container, realm)
|
||||
params := Parameters{
|
||||
Container: container,
|
||||
AccountName: accountName,
|
||||
AccountKey: accountKey,
|
||||
Realm: realm,
|
||||
RootDirectory: rootDirectory,
|
||||
}
|
||||
return New(¶ms)
|
||||
}
|
||||
|
||||
// Skip Azure storage driver tests if environment variable parameters are not provided
|
||||
|
@ -61,3 +72,44 @@ func init() {
|
|||
|
||||
testsuites.RegisterSuite(azureDriverConstructor, skipCheck)
|
||||
}
|
||||
|
||||
func TestParamParsing(t *testing.T) {
|
||||
expectErrors := []map[string]interface{}{
|
||||
{},
|
||||
{"accountname": "acc1"},
|
||||
}
|
||||
for _, parameters := range expectErrors {
|
||||
if _, err := NewParameters(parameters); err == nil {
|
||||
t.Fatalf("Expected an error for parameter set: %v", parameters)
|
||||
}
|
||||
}
|
||||
input := []map[string]interface{}{
|
||||
{"accountname": "acc1", "accountkey": "k1", "container": "c1"},
|
||||
{"accountname": "acc1", "container": "c1", "credentials": map[string]interface{}{"type": "default"}},
|
||||
{"accountname": "acc1", "container": "c1", "credentials": map[string]interface{}{"type": "client_secret", "clientid": "c1", "tenantid": "t1", "secret": "s1"}},
|
||||
}
|
||||
expecteds := []Parameters{
|
||||
{
|
||||
Container: "c1", AccountName: "acc1", AccountKey: "k1",
|
||||
Realm: "core.windows.net", ServiceURL: "https://acc1.blob.core.windows.net",
|
||||
},
|
||||
{
|
||||
Container: "c1", AccountName: "acc1", Credentials: Credentials{Type: "default"},
|
||||
Realm: "core.windows.net", ServiceURL: "https://acc1.blob.core.windows.net",
|
||||
},
|
||||
{
|
||||
Container: "c1", AccountName: "acc1",
|
||||
Credentials: Credentials{Type: "client_secret", ClientID: "c1", TenantID: "t1", Secret: "s1"},
|
||||
Realm: "core.windows.net", ServiceURL: "https://acc1.blob.core.windows.net",
|
||||
},
|
||||
}
|
||||
for i, expected := range expecteds {
|
||||
actual, err := NewParameters(input[i])
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to parse: %v", input[i])
|
||||
}
|
||||
if *actual != expected {
|
||||
t.Fatalf("Expected: %v != %v", *actual, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue