Skip to content

Commit

Permalink
blob/azureblob: add storage_account query parameter (#3159)
Browse files Browse the repository at this point in the history
  • Loading branch information
ekini committed Aug 12, 2022
1 parent 58fd166 commit 2ae6e17
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion blob/azureblob/azureblob.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
10 changes: 10 additions & 0 deletions blob/azureblob/azureblob_test.go
Expand Up @@ -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{
Expand Down Expand Up @@ -624,6 +632,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.
Expand Down

0 comments on commit 2ae6e17

Please sign in to comment.