allow creation of anonymous blob-clients from a Url (#1422)
This commit is contained in:
Родитель
66008eb02a
Коммит
edd24346a3
|
@ -68,12 +68,10 @@ impl TryFrom<&Url> for CloudLocation {
|
|||
// TODO: This only works for Public and China clouds.
|
||||
// ref: https://github.com/Azure/azure-sdk-for-rust/issues/502
|
||||
fn try_from(url: &Url) -> azure_core::Result<Self> {
|
||||
let token = url.query().ok_or_else(|| {
|
||||
azure_core::Error::with_message(azure_core::error::ErrorKind::DataConversion, || {
|
||||
"unable to find SAS token in URL"
|
||||
})
|
||||
})?;
|
||||
let credentials = StorageCredentials::sas_token(token)?;
|
||||
let credentials = match url.query() {
|
||||
Some(token) => StorageCredentials::sas_token(token)?,
|
||||
None => StorageCredentials::Anonymous,
|
||||
};
|
||||
|
||||
let host = url.host_str().ok_or_else(|| {
|
||||
azure_core::Error::with_message(azure_core::error::ErrorKind::DataConversion, || {
|
||||
|
|
|
@ -345,7 +345,9 @@ mod tests {
|
|||
assert!(matches!(creds, StorageCredentials::SASToken(_)));
|
||||
|
||||
let url = Url::parse("https://accountname.blob.core.windows.net/mycontainer/myblob")?;
|
||||
assert!(BlobClient::from_sas_url(&url).is_err(), "missing token");
|
||||
let blob_client = BlobClient::from_sas_url(&url)?;
|
||||
let creds = blob_client.container_client.credentials();
|
||||
assert!(matches!(creds, StorageCredentials::Anonymous));
|
||||
|
||||
let url = Url::parse("https://accountname.blob.core.windows.net/mycontainer?token=1")?;
|
||||
assert!(BlobClient::from_sas_url(&url).is_err(), "missing path");
|
||||
|
|
Загрузка…
Ссылка в новой задаче