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/azblob: Support AZURE_STORAGEBLOB_CONNECTIONSTRING as an alternative for AZURE_STORAGE_CONNECTION_STRING #3483

Merged
merged 1 commit into from
Sep 9, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion blob/azureblob/azureblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// - 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 NewClientWithSharedKeyCredential.
// - AZURE_STORAGE_CONNECTION_STRING: To use a connection string, passed to
// - AZURE_STORAGE_CONNECTION_STRING or AZURE_STORAGEBLOB_CONNECTIONSTRING: To use a connection string, passed to
// NewClientFromConnectionString.
// - AZURE_STORAGE_SAS_TOKEN: To use a SAS token. The SAS token is added
// as a URL parameter to the service URL, and passed to
Expand Down Expand Up @@ -320,6 +320,9 @@ func newCredInfoFromEnv() *credInfoT {
accountKey := os.Getenv("AZURE_STORAGE_KEY")
sasToken := os.Getenv("AZURE_STORAGE_SAS_TOKEN")
connectionString := os.Getenv("AZURE_STORAGE_CONNECTION_STRING")
if connectionString == "" {
connectionString = os.Getenv("AZURE_STORAGEBLOB_CONNECTIONSTRING")
}
credInfo := &credInfoT{
AccountName: accountName,
}
Expand Down
31 changes: 23 additions & 8 deletions blob/azureblob/azureblob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,15 @@ func TestOpenBucket(t *testing.T) {

func TestOpenerFromEnv(t *testing.T) {
tests := []struct {
accountName string
accountKey string
sasToken string
connectionString string
domain string
protocol string
isCDN bool
isLocalEmulator bool
accountName string
accountKey string
sasToken string
connectionString string
connectionString2 string
domain string
protocol string
isCDN bool
isLocalEmulator bool

want *credInfoT
wantOpts *ServiceURLOptions
Expand Down Expand Up @@ -362,6 +363,19 @@ func TestOpenerFromEnv(t *testing.T) {
AccountName: "myaccount",
},
},
{
// Alternate connection string.
accountName: "myaccount",
connectionString2: "a-connection-string",
want: &credInfoT{
CredType: credTypeConnectionString,
AccountName: "myaccount",
ConnectionString: "a-connection-string",
},
wantOpts: &ServiceURLOptions{
AccountName: "myaccount",
},
},
{
// Default.
accountName: "anotheraccount",
Expand Down Expand Up @@ -407,6 +421,7 @@ func TestOpenerFromEnv(t *testing.T) {
t.Setenv("AZURE_STORAGE_KEY", test.accountKey)
t.Setenv("AZURE_STORAGE_SAS_TOKEN", test.sasToken)
t.Setenv("AZURE_STORAGE_CONNECTION_STRING", test.connectionString)
t.Setenv("AZURE_STORAGEBLOB_CONNECTIONSTRING", test.connectionString2)
t.Setenv("AZURE_STORAGE_DOMAIN", test.domain)
t.Setenv("AZURE_STORAGE_PROTOCOL", test.protocol)
if test.isCDN {
Expand Down
Loading