Skip to content
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
6 changes: 3 additions & 3 deletions sdk/storage/azfile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ or contact [opencode@microsoft.com][coc_contact] with any
additional questions or comments.

<!-- LINKS -->
[source]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/storage
[source]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/storage/azfile
[docs]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/storage/azfile
[rest_docs]: https://docs.microsoft.com/rest/api/storageservices/file-service-rest-api
[product_docs]: https://docs.microsoft.com/azure/storage/files/storage-files-introduction
Expand All @@ -257,8 +257,8 @@ additional questions or comments.
[storage_account_create_portal]: https://docs.microsoft.com/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal
[azure_sub]: https://azure.microsoft.com/free/
[azcore_response_error]: https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azcore#ResponseError
[file_error]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/storage
[samples]: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/storage
[file_error]: https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/storage/azfile/fileerror/error_codes.go
[samples]: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/storage/azfile/file/examples_test.go
[storage_contrib]: https://github.com/Azure/azure-sdk-for-go/blob/main/CONTRIBUTING.md
[cla]: https://cla.microsoft.com
[coc]: https://opensource.microsoft.com/codeofconduct/
Expand Down
2 changes: 0 additions & 2 deletions sdk/storage/azfile/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3117,5 +3117,3 @@ func (f *FileRecordedTestsSuite) TestFileForceCloseHandlesDefault() {
}

// TODO: Add tests for retry header options

// TODO: fix links in README: source, file_error, samples
2 changes: 1 addition & 1 deletion sdk/storage/azfile/file/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ func (u *UploadStreamOptions) getUploadRangeOptions() *UploadRangeOptions {
}
}

// URLParts object represents the components that make up an Azure Storage Container/Blob URL.
// URLParts object represents the components that make up an Azure Storage Share/Directory/File URL.
// NOTE: Changing any SAS-related field requires computing a new SAS signature.
type URLParts = sas.URLParts

Expand Down
33 changes: 25 additions & 8 deletions sdk/storage/azfile/internal/shared/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,20 +100,37 @@ func ParseConnectionString(connectionString string) (ParsedConnectionString, err
connStrMap[parts[0]] = parts[1]
}

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

accountName := connStrMap["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.file.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature),
}, nil

fileEndpoint, ok := connStrMap["FileEndpoint"]
if !ok {
// We don't have a FileEndpoint, assume the default
if accountName != "" {
return ParsedConnectionString{
ServiceURL: fmt.Sprintf("%v://%v.file.%v/?%v", defaultScheme, accountName, defaultSuffix, sharedAccessSignature),
}, nil
} else {
return ParsedConnectionString{}, errors.New("connection string missing AccountName")
}
} else {
if !strings.HasSuffix(fileEndpoint, "/") {
// add a trailing slash to be consistent with the portal
fileEndpoint += "/"
}
return ParsedConnectionString{
ServiceURL: fmt.Sprintf("%v?%v", fileEndpoint, sharedAccessSignature),
}, nil
}
} else {
if accountName == "" {
return ParsedConnectionString{}, errors.New("connection string missing AccountName")
Comment thread
souravgupta-msft marked this conversation as resolved.
}
}

protocol, ok := connStrMap["DefaultEndpointsProtocol"]
Expand Down
40 changes: 40 additions & 0 deletions sdk/storage/azfile/internal/shared/shared_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package shared

import (
"fmt"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -93,3 +94,42 @@ func TestCParseConnectionStringAzurite(t *testing.T) {
require.Equal(t, "dummyaccountname", parsed.AccountName)
require.Equal(t, "secretkeykey", parsed.AccountKey)
}

func TestParseConnectionStringSASAndCustomDomain(t *testing.T) {
testData := []struct {
connectionStr string
parsedServiceURL string
parsedAccountName string
parsedAccountKey string
err error
}{
{
connectionStr: "AccountName=dummyaccountname;SharedAccessSignature=fakesharedaccesssignature;FileEndpoint=http://127.0.0.1:10000/dummyaccountname;",
parsedServiceURL: "http://127.0.0.1:10000/dummyaccountname/?fakesharedaccesssignature",
},
{
connectionStr: "BlobEndpoint=https://dummyaccountname.blob.core.windows.net/;FileEndpoint=https://dummyaccountname.file.core.windows.net/;SharedAccessSignature=fakesharedaccesssignature",
parsedServiceURL: "https://dummyaccountname.file.core.windows.net/?fakesharedaccesssignature",
},
{
connectionStr: "BlobEndpoint=https://dummyaccountname.blob.core.windows.net;FileEndpoint=https://dummyaccountname.file.core.windows.net;SharedAccessSignature=fakesharedaccesssignature",
parsedServiceURL: "https://dummyaccountname.file.core.windows.net/?fakesharedaccesssignature",
},
{
connectionStr: "SharedAccessSignature=fakesharedaccesssignature",
err: fmt.Errorf("connection string missing AccountName"),
},
{
connectionStr: "DefaultEndpointsProtocol=http;AccountKey=secretkeykey;EndpointSuffix=core.windows.net",
err: fmt.Errorf("connection string missing AccountName"),
},
}

for _, td := range testData {
parsed, err := ParseConnectionString(td.connectionStr)
require.Equal(t, td.err, err)
require.Equal(t, td.parsedServiceURL, parsed.ServiceURL)
require.Equal(t, td.parsedAccountName, parsed.AccountName)
require.Equal(t, td.parsedAccountKey, parsed.AccountKey)
}
}