google / go-cloud

The Go Cloud Development Kit (Go CDK): A library and tools for open cloud development in Go.

Home Page:https://gocloud.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

azureblob Bucket.Exists() fails to work if auth uses SAS token

clairez opened this issue · comments

commented

azureblob.go

bucket.exists(ctx, objectPath) throws error even objectPath is valid

for the same objectPath, bucket.exists works when auth uses AZURE_STORAGE_KEY, but wont work when uses AZURE_STORAGE_SAS_TOKEN

this issue was caused by azureblob.go line 351: containerURL := fmt.Sprintf("%s/%s", svcURL, containerName)
where svcURL has query params in it which comes from sas token, e.g. https://myaccount.blob.core.windows.net?{sas_token}, simply concat the containerName to this svcUrl will form an invalid path for the object to be checked, e.g https://myaccount.blob.core.windows.net?{sas_token}/mycontainer, thus this function will always fail. suggest to use url.JoinPath

To Reproduce

set AZURE_STORAGE_SAS_TOKEN when create bucket and call bucket.exists on an existing file
os.Setenv("AZURE_STORAGE_SAS_TOKEN", "sko...")
os.Setenv("AZURE_STORAGE_ACCOUNT", "myaccount")
bucket, err := blob.OpenBucket(context.Background(), "azblob://mycontainer/this_is_an_existed_file_path.txt")
bucket.Exists(context.Background(),"this_is_an_existed_file_path.txt")

Expected behavior

bucket.Exists() return true on an existing and valid file path

Version

gocloud.dev v0.32.0

Additional context

Thanks for the report! If possible can you try out #3284 and see if it fixes it for you, I don't have a good test for SAS tokens (obviously).