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

fix: ConnectionString for Azure Blob storage now supports SAS connstr… #13348

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
51 changes: 28 additions & 23 deletions pkg/storage/chunk/client/azure/blob_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,22 +635,6 @@
connStrMap[parts[0]] = parts[1]
}

accountName, ok := connStrMap["AccountName"]
if !ok {
return ParsedConnectionString{}, errors.New("connection string missing AccountName")
}

accountKey, ok := connStrMap["AccountKey"]
if !ok {
sharedAccessSignature, ok := connStrMap["SharedAccessSignature"]
if !ok {
return ParsedConnectionString{}, errors.New("connection string missing AccountKey and SharedAccessSignature")
}
return ParsedConnectionString{
ServiceURL: fmt.Sprintf("%v://%v.blob.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature),
}, nil
}

protocol, ok := connStrMap["DefaultEndpointsProtocol"]
if !ok {
protocol = defaultScheme
Expand All @@ -661,19 +645,40 @@
suffix = defaultSuffix
}

if blobEndpoint, ok := connStrMap["BlobEndpoint"]; ok {
blobEndpoint, hasBlobendpoint := connStrMap["BlobEndpoint"]
accountName, hasAccountname := connStrMap["AccountName"]

var serviceURL string
if hasBlobendpoint {
serviceURL = blobEndpoint
} else if hasAccountname {
serviceURL = fmt.Sprintf("%v://%v.blob.%v", protocol, accountName, suffix)
} else {
return ParsedConnectionString{}, errors.New("connection string needs either AccountName or BlobEndpoint")
}

if !strings.HasSuffix(serviceURL, "/") {
// add a trailing slash to be consistent with the portal
serviceURL += "/"
}

accountKey, hasAccountkey := connStrMap["AccountKey"]
sharedAccessSignature, hasSharedaccesssignature := connStrMap["SharedAccessSignature"]

if hasAccountname && hasAccountkey {
return ParsedConnectionString{
ServiceURL: blobEndpoint,
ServiceURL: serviceURL,
AccountName: accountName,
AccountKey: accountKey,
}, nil
} else if hasSharedaccesssignature {
return ParsedConnectionString{
ServiceURL: fmt.Sprintf("%v?%v", serviceURL, sharedAccessSignature),
}, nil
} else {

Check warning on line 678 in pkg/storage/chunk/client/azure/blob_storage_client.go

View workflow job for this annotation

GitHub Actions / check / golangciLint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
return ParsedConnectionString{}, errors.New("connection string needs either AccountKey or SharedAccessSignature")
}

return ParsedConnectionString{
ServiceURL: fmt.Sprintf("%v://%v.blob.%v", protocol, accountName, suffix),
AccountName: accountName,
AccountKey: accountKey,
}, nil
}

// TODO(dannyk): implement for client
Expand Down
Loading