Skip to content

Commit d8bf5ed

Browse files
authored
use the StorageCredentials helpers instead of using the enum variants directly (#1420)
1 parent 5ca61da commit d8bf5ed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+88
-116
lines changed

sdk/data_tables/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn main() -> azure_core::Result<()> {
2929
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");
3030
let table_name = std::env::var("STORAGE_TABLE_NAME").expect("Set env variable STORAGE_TABLE_NAME first!");
3131

32-
let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
32+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
3333
let table_service = TableServiceClient::new(account, storage_credentials);
3434

3535
let table_client = table_service.table_client(table_name);

sdk/data_tables/examples/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async fn main() -> azure_core::Result<()> {
2727
.nth(1)
2828
.expect("please specify the table name as first command line parameter");
2929

30-
let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
30+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
3131
let table_service = TableServiceClient::new(account, storage_credentials);
3232

3333
let table_client = table_service.table_client(table_name);

sdk/data_tables/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ async fn main() -> azure_core::Result<()> {
2828
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");
2929
let table_name = std::env::var("STORAGE_TABLE_NAME").expect("Set env variable STORAGE_TABLE_NAME first!");
3030
31-
let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
31+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
3232
let table_service = TableServiceClient::new(account, storage_credentials);
3333
3434
let table_client = table_service.table_client(table_name);

sdk/storage/src/connection_string.rs

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use azure_core::error::{Error, ErrorKind, ResultExt};
2-
31
use crate::StorageCredentials;
2+
use azure_core::error::{Error, ErrorKind};
43

54
// Key names.
65
pub const ACCOUNT_KEY_KEY_NAME: &str = "AccountKey";
@@ -188,15 +187,13 @@ impl<'a> ConnectionString<'a> {
188187
if self.account_key.is_some() {
189188
log::warn!("Both account key and SAS defined in connection string. Using only the provided SAS.");
190189
}
191-
Ok(StorageCredentials::SASToken(get_sas_token_parms(
192-
sas_token,
193-
)?))
190+
StorageCredentials::sas_token(*sas_token)
194191
}
195192
ConnectionString {
196193
account_name: Some(account),
197194
account_key: Some(key),
198195
..
199-
} => Ok(StorageCredentials::Key((*account).to_string(), (*key).to_string())),
196+
} => Ok(StorageCredentials::access_key(*account, *key)),
200197
_ => {
201198
Err(Error::message(ErrorKind::Credential,
202199
"Could not create a `StorageCredentail` from the provided connection string. Please validate that you have specified a means of authentication (key, SAS, etc.)."
@@ -206,30 +203,6 @@ impl<'a> ConnectionString<'a> {
206203
}
207204
}
208205

209-
fn get_sas_token_parms(sas_token: &str) -> azure_core::Result<Vec<(String, String)>> {
210-
// Any base url will do: we just need to parse the SAS token
211-
// to get its query pairs.
212-
let base_url = url::Url::parse("https://blob.core.windows.net").unwrap();
213-
214-
let url = url::Url::options().base_url(Some(&base_url));
215-
216-
// this code handles the leading ?
217-
// we support both with or without
218-
let url = if sas_token.starts_with('?') {
219-
url.parse(sas_token)
220-
} else {
221-
url.parse(&format!("?{sas_token}"))
222-
}
223-
.with_context(ErrorKind::DataConversion, || {
224-
format!("failed to parse SAS token: {sas_token}")
225-
})?;
226-
227-
Ok(url
228-
.query_pairs()
229-
.map(|p| (String::from(p.0), String::from(p.1)))
230-
.collect())
231-
}
232-
233206
#[cfg(test)]
234207
mod tests {
235208
#[allow(unused_imports)]

sdk/storage_blobs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn main() -> azure_core::Result<()> {
2121
let container = std::env::var("STORAGE_CONTAINER").expect("missing STORAGE_CONTAINER");
2222
let blob_name = std::env::var("STORAGE_BLOB_NAME").expect("missing STORAGE_BLOB_NAME");
2323

24-
let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
24+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
2525
let blob_client = ClientBuilder::new(account, storage_credentials).blob_client(&container, blob_name);
2626

2727
blob_client.put_block_blob("hello world").content_type("text/plain").await?;

sdk/storage_blobs/examples/account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ async fn main() -> azure_core::Result<()> {
1010
let access_key =
1111
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");
1212

13-
let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
13+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
1414
let service_client = BlobServiceClient::new(account, storage_credentials);
1515

1616
let account = service_client.get_account_information().await?;

sdk/storage_blobs/examples/anonymous_access.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async fn main() -> azure_core::Result<()> {
88
let account = std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT");
99
let container = std::env::var("STORAGE_CONTAINER").expect("Set env variable STORAGE_CONTAINER");
1010

11-
let storage_credentials = StorageCredentials::Anonymous;
11+
let storage_credentials = StorageCredentials::anonymous();
1212
let container_client =
1313
BlobServiceClient::new(account, storage_credentials).container_client(container);
1414

sdk/storage_blobs/examples/blob_00.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ async fn main() -> azure_core::Result<()> {
2020
.nth(2)
2121
.expect("please specify blob name as command line parameter");
2222

23-
let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
23+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
2424
let service_client = BlobServiceClient::new(account, storage_credentials);
2525

2626
// this is how you would use the SAS token:

sdk/storage_blobs/examples/blob_01.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async fn main() -> azure_core::Result<()> {
1616
.nth(1)
1717
.expect("please specify container name as command line parameter");
1818

19-
let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
19+
let storage_credentials = StorageCredentials::access_key(account.clone(), access_key);
2020
let service_client = BlobServiceClient::new(account, storage_credentials);
2121
let container_client = service_client.container_client(container_name);
2222
let blob_client = container_client.blob_client("SorgeniaReorganizeRebuildIndexes.zip");

sdk/storage_blobs/examples/blob_02_bearer_token.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn main() -> azure_core::Result<()> {
2121
.nth(4)
2222
.expect("please specify the bearer token as fourth command line parameter");
2323

24-
let storage_credentials = StorageCredentials::BearerToken(bearer_token);
24+
let storage_credentials = StorageCredentials::bearer_token(bearer_token);
2525
let blob_client = BlobServiceClient::new(account, storage_credentials)
2626
.container_client(&container)
2727
.blob_client(&blob);

0 commit comments

Comments
 (0)