Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expose Storage Options when creating storage clients #922

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 2 additions & 1 deletion sdk/data_tables/examples/table_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async fn main() -> azure_core::Result<()> {
.nth(1)
.expect("please specify the table name as first command line parameter");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());

let table_service = storage_client.table_service_client()?;

Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/examples/account00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ async fn main() -> azure_core::Result<()> {
let access_key =
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());

let response = storage_client
.get_account_information()
Expand Down
53 changes: 32 additions & 21 deletions sdk/storage/src/core/clients/storage_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ pub struct StorageClient {
}

impl StorageClient {
pub fn new_access_key<A, K>(account: A, key: K) -> Self
pub fn new_access_key<A, K>(account: A, key: K, options: StorageOptions) -> Self
where
A: Into<String>,
K: Into<String>,
{
let account = account.into();
let key = key.into();
let storage_credentials = StorageCredentials::Key(account.clone(), key);
let pipeline =
new_pipeline_from_options(StorageOptions::new(), storage_credentials.clone());
let pipeline = new_pipeline_from_options(options, storage_credentials.clone());

Self {
blob_storage_url: get_endpoint_uri(None, &account, "blob").unwrap(),
Expand All @@ -114,6 +113,7 @@ impl StorageClient {
table_storage_url: &Url,
queue_storage_url: &Url,
filesystem_url: &Url,
options: StorageOptions,
) -> Self {
Self::new_emulator_with_account(
blob_storage_url,
Expand All @@ -122,6 +122,7 @@ impl StorageClient {
filesystem_url,
EMULATOR_ACCOUNT,
EMULATOR_ACCOUNT_KEY,
options,
)
}

Expand All @@ -136,6 +137,7 @@ impl StorageClient {
&table_storage_url,
&queue_storage_url,
&filesystem_url,
StorageOptions::default(),
)
}

Expand All @@ -146,6 +148,7 @@ impl StorageClient {
filesystem_url: &Url,
account: A,
key: K,
options: StorageOptions,
) -> Self
where
A: Into<String>,
Expand All @@ -154,7 +157,7 @@ impl StorageClient {
let account = account.into();
let key = key.into();
let storage_credentials = StorageCredentials::Key(account.clone(), key.clone());
let pipeline = new_pipeline_from_options(StorageOptions::new(), storage_credentials);
let pipeline = new_pipeline_from_options(options, storage_credentials);
let blob_storage_url = Url::parse(&format!("{}{}", blob_storage_url, account)).unwrap();
let table_storage_url = Url::parse(&format!("{}{}", table_storage_url, account)).unwrap();
let queue_storage_url = Url::parse(&format!("{}{}", queue_storage_url, account)).unwrap();
Expand All @@ -172,7 +175,11 @@ impl StorageClient {
}
}

pub fn new_sas_token<A, S>(account: A, sas_token: S) -> azure_core::Result<Self>
pub fn new_sas_token<A, S>(
account: A,
sas_token: S,
options: StorageOptions,
) -> azure_core::Result<Self>
where
A: Into<String>,
S: AsRef<str>,
Expand All @@ -181,8 +188,7 @@ impl StorageClient {

let storage_credentials =
StorageCredentials::SASToken(get_sas_token_parms(sas_token.as_ref())?);
let pipeline =
new_pipeline_from_options(StorageOptions::new(), storage_credentials.clone());
let pipeline = new_pipeline_from_options(options, storage_credentials.clone());

Ok(Self {
blob_storage_url: get_endpoint_uri(None, &account, "blob")?,
Expand All @@ -200,16 +206,15 @@ impl StorageClient {
})
}

pub fn new_bearer_token<A, BT>(account: A, bearer_token: BT) -> Self
pub fn new_bearer_token<A, BT>(account: A, bearer_token: BT, options: StorageOptions) -> Self
where
A: Into<String>,
BT: Into<String>,
{
let account = account.into();
let bearer_token = bearer_token.into();
let storage_credentials = StorageCredentials::BearerToken(bearer_token);
let pipeline =
new_pipeline_from_options(StorageOptions::new(), storage_credentials.clone());
let pipeline = new_pipeline_from_options(options, storage_credentials.clone());

Self {
blob_storage_url: get_endpoint_uri(None, &account, "blob").unwrap(),
Expand All @@ -228,14 +233,17 @@ impl StorageClient {
}
}

pub fn new_token_credential<A>(account: A, token_credential: Arc<dyn TokenCredential>) -> Self
pub fn new_token_credential<A>(
account: A,
token_credential: Arc<dyn TokenCredential>,
options: StorageOptions,
) -> Self
where
A: Into<String>,
{
let account = account.into();
let storage_credentials = StorageCredentials::TokenCredential(token_credential);
let pipeline =
new_pipeline_from_options(StorageOptions::new(), storage_credentials.clone());
let pipeline = new_pipeline_from_options(options, storage_credentials.clone());

Self {
blob_storage_url: get_endpoint_uri(None, &account, "blob").unwrap(),
Expand All @@ -254,7 +262,10 @@ impl StorageClient {
}
}

pub fn new_connection_string(connection_string: &str) -> azure_core::Result<Self> {
pub fn new_connection_string(
connection_string: &str,
options: StorageOptions,
) -> azure_core::Result<Self> {
match ConnectionString::new(connection_string)? {
ConnectionString {
account_name: Some(account),
Expand All @@ -271,7 +282,7 @@ impl StorageClient {
let storage_credentials = StorageCredentials::SASToken(get_sas_token_parms(
sas_token,
)?);
let pipeline = new_pipeline_from_options(StorageOptions::new(), storage_credentials.clone());
let pipeline = new_pipeline_from_options(options, storage_credentials.clone());

Ok(Self {
storage_credentials,
Expand All @@ -295,7 +306,7 @@ impl StorageClient {
} => {
let storage_credentials = StorageCredentials::SASToken(get_sas_token_parms(sas_token)?);
let pipeline =
new_pipeline_from_options(StorageOptions::new(), storage_credentials.clone());
new_pipeline_from_options(options, storage_credentials.clone());
Ok(Self {
storage_credentials,
blob_storage_url: get_endpoint_uri(blob_endpoint, account, "blob")?,
Expand All @@ -317,7 +328,7 @@ impl StorageClient {
} => {

let storage_credentials = StorageCredentials::Key(account.to_owned(), key.to_owned());
let pipeline = new_pipeline_from_options(StorageOptions::new(), storage_credentials.clone());
let pipeline = new_pipeline_from_options(options, storage_credentials.clone());
Ok(Self {
storage_credentials,
blob_storage_url: get_endpoint_uri(blob_endpoint, account, "blob")?,
Expand Down Expand Up @@ -535,21 +546,21 @@ fn new_pipeline_from_options(options: StorageOptions, credentials: StorageCreden
Pipeline::new(
option_env!("CARGO_PKG_NAME"),
option_env!("CARGO_PKG_VERSION"),
options.options,
options.client_options,
Vec::new(),
per_retry_policies,
)
}

#[derive(Debug, Clone, Default)]
pub struct StorageOptions {
options: ClientOptions,
client_options: ClientOptions,
timeout_policy: TimeoutPolicy,
}

impl StorageOptions {
fn new() -> StorageOptions {
Self::default()
setters! {
client_options: ClientOptions,
}

pub fn set_timeout(&mut self, default_timeout: Timeout) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/src/core/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use crate::core::{
clients::StorageClient,
clients::{StorageClient, StorageOptions},
shared_access_signature::{
account_sas::{AccountSasPermissions, AccountSasResource, AccountSasResourceType},
service_sas::{BlobSasPermissions, BlobSignedResource},
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ async fn get_account_information() {
let access_key =
std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());

storage_client
.get_account_information()
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_blobs/examples/blob_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ async fn main() -> azure_core::Result<()> {
.nth(2)
.expect("please specify blob name as command line parameter");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());

// this is how you would use the SAS token:
// let storage_client = StorageAccountClient::new_sas_token(http_client.clone(), &account,
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_blobs/examples/blob_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ async fn main() -> azure_core::Result<()> {
.nth(1)
.expect("please specify container name as command line parameter");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());
let container_client = storage_client.container_client(&container_name);
let blob_client = container_client.blob_client("SorgeniaReorganizeRebuildIndexes.zip");

Expand Down
7 changes: 4 additions & 3 deletions sdk/storage_blobs/examples/blob_02_bearer_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ async fn main() -> azure_core::Result<()> {
.nth(4)
.expect("please specify the bearer token as fourth command line parameter");

let blob_client = StorageClient::new_bearer_token(&account, bearer_token)
.container_client(&container)
.blob_client(&blob);
let blob_client =
StorageClient::new_bearer_token(&account, bearer_token, StorageOptions::default())
.container_client(&container)
.blob_client(&blob);

trace!("Requesting blob");

Expand Down
7 changes: 4 additions & 3 deletions sdk/storage_blobs/examples/blob_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ async fn main() -> azure_core::Result<()> {
.nth(1)
.expect("please specify container name as command line parameter");

let blob_client = StorageClient::new_access_key(&account, &access_key)
.container_client(&container_name)
.blob_client("test1");
let blob_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default())
.container_client(&container_name)
.blob_client("test1");

// this example fills a 1 KB file with ASCII text and
// sends it in chunks of 256 bytes (4 chunks).
Expand Down
10 changes: 7 additions & 3 deletions sdk/storage_blobs/examples/blob_05_default_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ async fn main() -> azure_core::Result<()> {
.get_token("https://storage.azure.com/")
.await?;

let blob_client = StorageClient::new_bearer_token(&account, bearer_token.token.secret())
.container_client(&container)
.blob_client(&blob);
let blob_client = StorageClient::new_bearer_token(
&account,
bearer_token.token.secret(),
StorageOptions::default(),
)
.container_client(&container)
.blob_client(&blob);

trace!("Requesting blob");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ async fn main() -> azure_core::Result<()> {
let creds = Arc::new(DefaultAzureCredential::default());
let auto_creds = Arc::new(AutoRefreshingTokenCredential::new(creds));

let blob_client = StorageClient::new_token_credential(&account, auto_creds)
.container_client(&container)
.blob_client(&blob);
let blob_client =
StorageClient::new_token_credential(&account, auto_creds, StorageOptions::default())
.container_client(&container)
.blob_client(&blob);

trace!("Requesting blob");
let content = blob_client.get_content().await?;
Expand Down
7 changes: 4 additions & 3 deletions sdk/storage_blobs/examples/blob_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ async fn main() -> azure_core::Result<()> {
.nth(2)
.expect("please specify blob name as command line parameter");

let blob_client = StorageClient::new_access_key(&account, &access_key)
.container_client(&container)
.blob_client(&blob);
let blob_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default())
.container_client(&container)
.blob_client(&blob);

// 1024 G, 512 H and 2048 I
let mut buf: Vec<u8> = Vec::with_capacity(1024 * 4);
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_blobs/examples/connection_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ async fn main() -> azure_core::Result<()> {
.nth(1)
.expect("please specify container name as command line parameter");

let storage_client = StorageClient::new_connection_string(&connection_string)?;
let storage_client =
StorageClient::new_connection_string(&connection_string, StorageOptions::default())?;
let container_client = storage_client.container_client(&container_name);
let blob_service = storage_client.blob_service_client();

Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_blobs/examples/container_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ async fn main() -> azure_core::Result<()> {
.nth(1)
.expect("please specify container name as command line parameter");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());
let blob_service_client = storage_client.blob_service_client();
let container_client = storage_client.container_client(container_name);

Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_blobs/examples/container_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ async fn main() -> azure_core::Result<()> {
.nth(1)
.expect("please specify container name as command line parameter");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());
let container_client = storage_client.container_client(container_name);

let mut metadata = Metadata::new();
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_blobs/examples/container_and_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ async fn main() -> azure_core::Result<()> {
.nth(1)
.expect("please specify container name as command line parameter");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());
let container_client = storage_client.container_client(&container_name);

// create container
Expand Down
17 changes: 12 additions & 5 deletions sdk/storage_blobs/examples/copy_blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@ async fn main() -> azure_core::Result<()> {
.nth(4)
.expect("please specify destination blob name as fourth command line parameter");

let source_storage_client = StorageClient::new_access_key(&source_account, &source_access_key);
let source_storage_client = StorageClient::new_access_key(
&source_account,
&source_access_key,
StorageOptions::default(),
);
let source_blob = source_storage_client
.container_client(&source_container_name)
.blob_client(&source_blob_name);

let destination_blob =
StorageClient::new_access_key(&destination_account, &destination_access_key)
.container_client(&destination_container_name)
.blob_client(&destination_blob_name);
let destination_blob = StorageClient::new_access_key(
&destination_account,
&destination_access_key,
StorageOptions::default(),
)
.container_client(&destination_container_name)
.blob_client(&destination_blob_name);

// let's get a SAS key for the source
let sas_url = {
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage_blobs/examples/copy_blob_from_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ async fn main() -> azure_core::Result<()> {
.nth(4)
.expect("please specify destination blob name as fourth command line parameter");

let storage_client = StorageClient::new_access_key(&account, &access_key);
let storage_client =
StorageClient::new_access_key(&account, &access_key, StorageOptions::default());
let blob_client = storage_client
.container_client(&destination_container)
.blob_client(&destination_blob);
Expand Down
Loading