Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

blob/azureblob: add storage_account query parameter #3159

Merged
merged 2 commits into from Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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":
vangent marked this conversation as resolved.
Show resolved Hide resolved
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},
ekini marked this conversation as resolved.
Show resolved Hide resolved
// With CDN.
{"azblob://mybucket?cdn=true", false},
// With invalid CDN.
Expand Down