Skip to content

Commit edd2434

Browse files
authored
allow creation of anonymous blob-clients from a Url (#1422)
1 parent 66008eb commit edd2434

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

sdk/storage/src/cloud_location.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@ impl TryFrom<&Url> for CloudLocation {
6868
// TODO: This only works for Public and China clouds.
6969
// ref: https://github.com/Azure/azure-sdk-for-rust/issues/502
7070
fn try_from(url: &Url) -> azure_core::Result<Self> {
71-
let token = url.query().ok_or_else(|| {
72-
azure_core::Error::with_message(azure_core::error::ErrorKind::DataConversion, || {
73-
"unable to find SAS token in URL"
74-
})
75-
})?;
76-
let credentials = StorageCredentials::sas_token(token)?;
71+
let credentials = match url.query() {
72+
Some(token) => StorageCredentials::sas_token(token)?,
73+
None => StorageCredentials::Anonymous,
74+
};
7775

7876
let host = url.host_str().ok_or_else(|| {
7977
azure_core::Error::with_message(azure_core::error::ErrorKind::DataConversion, || {

sdk/storage_blobs/src/clients/blob_client.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,9 @@ mod tests {
345345
assert!(matches!(creds, StorageCredentials::SASToken(_)));
346346

347347
let url = Url::parse("https://accountname.blob.core.windows.net/mycontainer/myblob")?;
348-
assert!(BlobClient::from_sas_url(&url).is_err(), "missing token");
348+
let blob_client = BlobClient::from_sas_url(&url)?;
349+
let creds = blob_client.container_client.credentials();
350+
assert!(matches!(creds, StorageCredentials::Anonymous));
349351

350352
let url = Url::parse("https://accountname.blob.core.windows.net/mycontainer?token=1")?;
351353
assert!(BlobClient::from_sas_url(&url).is_err(), "missing path");

0 commit comments

Comments
 (0)