From 03704ec1a3026d40eb8afacb993299886f50a6d0 Mon Sep 17 00:00:00 2001 From: Eugene Dementyev Date: Thu, 11 Aug 2022 22:40:16 +1200 Subject: [PATCH 1/2] blob/azureblob: add storage_account query parameter --- blob/azureblob/azureblob.go | 6 +++++- blob/azureblob/azureblob_test.go | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/blob/azureblob/azureblob.go b/blob/azureblob/azureblob.go index 729e35620f..205f93d96d 100644 --- a/blob/azureblob/azureblob.go +++ b/blob/azureblob/azureblob.go @@ -28,7 +28,9 @@ // credentials and a service URL; see // https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob // for a more complete descriptions of each approach. -// - AZURE_STORAGE_ACCOUNT: The service account name. Required. +// - AZURE_STORAGE_ACCOUNT: The service account name. Required if used along with AZURE_STORAGE KEY, because it defines +// authentication mechanism to be azblob.NewSharedKeyCredential, which creates immutable shared key credentials. +// Otherwise, "storage_account" in the URL query string parameter can be used. // - AZURE_STORAGE_KEY: To use a shared key credential. The service account // name and key are passed to NewSharedKeyCredential and then the // resulting credential is passed to NewServiceClientWithSharedKey. @@ -216,6 +218,8 @@ func (o *ServiceURLOptions) withOverrides(urlValues url.Values) (*ServiceURLOpti return nil, err } retval.IsLocalEmulator = isLocalEmulator + case "storage_account": + retval.AccountName = value default: return nil, fmt.Errorf("unknown query parameter %q", param) } diff --git a/blob/azureblob/azureblob_test.go b/blob/azureblob/azureblob_test.go index dd02b09964..85d251f607 100644 --- a/blob/azureblob/azureblob_test.go +++ b/blob/azureblob/azureblob_test.go @@ -624,6 +624,8 @@ func TestOpenBucketFromURL(t *testing.T) { {"azblob://mybucket?protocol=http", false}, // With invalid protocol. {"azblob://mybucket?protocol=ftp", true}, + // With Account. + {"azblob://mybucket?storage_account=test", false}, // With CDN. {"azblob://mybucket?cdn=true", false}, // With invalid CDN. From 49a17155deaf91a446894936d803c2c128e2b61e Mon Sep 17 00:00:00 2001 From: Eugene Dementyev Date: Fri, 12 Aug 2022 22:21:56 +1200 Subject: [PATCH 2/2] blob/azureblob: add an additional test of storage_account param --- blob/azureblob/azureblob_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/blob/azureblob/azureblob_test.go b/blob/azureblob/azureblob_test.go index 85d251f607..2183977516 100644 --- a/blob/azureblob/azureblob_test.go +++ b/blob/azureblob/azureblob_test.go @@ -469,6 +469,14 @@ func TestNewServiceURL(t *testing.T) { opts: ServiceURLOptions{}, wantErrURL: true, }, + { + // Account name set in the query + opts: ServiceURLOptions{}, + query: url.Values{ + "storage_account": {"testaccount"}, + }, + want: "https://testaccount.blob.core.windows.net", + }, { // Basic working case. opts: ServiceURLOptions{