Skip to content

drop as_ prefix from as_X_client from storage crates #847

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

Merged
merged 1 commit into from
Jun 24, 2022
Merged
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
14 changes: 7 additions & 7 deletions sdk/data_tables/examples/table_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ async fn main() -> azure_core::Result<()> {
StorageAccountClient::new_access_key(http_client.clone(), &account, &access_key);

let table_service = storage_account_client
.as_storage_client()
.as_table_service_client()?;
.storage_client()
.table_service_client()?;

let table_client = table_service.as_table_client(table_name);
let table_client = table_service.table_client(table_name);
let response = table_client.create().execute().await?;
println!("response = {:?}\n", response);

Expand All @@ -43,7 +43,7 @@ async fn main() -> azure_core::Result<()> {
surname: "Cogno".to_owned(),
};

let partition_key_client = table_client.as_partition_key_client(&entity.city);
let partition_key_client = table_client.partition_key_client(&entity.city);

let mut transaction = Transaction::default();

Expand All @@ -56,7 +56,7 @@ async fn main() -> azure_core::Result<()> {
transaction.add(table_client.insert().to_transaction_operation(&entity)?);

entity.surname = "Potter".to_owned();
let entity_client = partition_key_client.as_entity_client(&entity.surname)?;
let entity_client = partition_key_client.entity_client(&entity.surname)?;
transaction.add(
entity_client
.insert_or_replace()
Expand Down Expand Up @@ -94,8 +94,8 @@ async fn main() -> azure_core::Result<()> {
println!("response = {:?}\n", response);

let entity_client = table_client
.as_partition_key_client(&entity.city)
.as_entity_client(&entity.surname)?;
.partition_key_client(&entity.city)
.entity_client(&entity.surname)?;
// update the name passing the Etag received from the previous call.
entity.name = "Ryan".to_owned();
let response = entity_client
Expand Down
32 changes: 16 additions & 16 deletions sdk/data_tables/src/clients/entity_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use std::sync::Arc;
use url::Url;

pub trait AsEntityClient<RK: Into<String>> {
fn as_entity_client(&self, row_key: RK) -> azure_core::Result<Arc<EntityClient>>;
fn entity_client(&self, row_key: RK) -> azure_core::Result<Arc<EntityClient>>;
}

impl<RK: Into<String>> AsEntityClient<RK> for Arc<PartitionKeyClient> {
fn as_entity_client(&self, row_key: RK) -> azure_core::Result<Arc<EntityClient>> {
fn entity_client(&self, row_key: RK) -> azure_core::Result<Arc<EntityClient>> {
EntityClient::new(self.clone(), row_key)
}
}
Expand Down Expand Up @@ -137,17 +137,17 @@ mod integration_tests {
}

fn get_emulator_client() -> Arc<TableServiceClient> {
let storage_account = StorageAccountClient::new_emulator_default().as_storage_client();
let storage_account = StorageAccountClient::new_emulator_default().storage_client();
storage_account
.as_table_service_client()
.table_service_client()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this just be table_client? What's the benefit of the service nomenclature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things that could stand clearing up is this issue. I understand the underlying intent in this implementation, but it's confusing. Currently, with a StorageAccount.table_service_client gets you a TableServiceClient.

TableServiceClient lets you:

  1. list tables
  2. get a TableClient for a specified table.

TableClient lets you interact with a given table (create it, query it, delete it, insert things into it, etc)

.expect("a table service client")
}

#[tokio::test]
async fn test_update() {
let table_client = get_emulator_client();

let table = table_client.as_table_client("EntityClientUpdate");
let table = table_client.table_client("EntityClientUpdate");

println!("Delete the table (if it exists)");
match table.delete().execute().await {
Expand All @@ -168,8 +168,8 @@ mod integration_tests {
};

let entity_client = table
.as_partition_key_client(&entity.city)
.as_entity_client(&entity.surname)
.partition_key_client(&entity.city)
.entity_client(&entity.surname)
.expect("an entity client");

entity_client
Expand Down Expand Up @@ -199,7 +199,7 @@ mod integration_tests {
async fn test_merge() {
let table_client = get_emulator_client();

let table = table_client.as_table_client("EntityClientMerge");
let table = table_client.table_client("EntityClientMerge");

println!("Delete the table (if it exists)");
match table.delete().execute().await {
Expand All @@ -226,8 +226,8 @@ mod integration_tests {
};

let entity_client = table
.as_partition_key_client(&entity.city)
.as_entity_client(&entity.surname)
.partition_key_client(&entity.city)
.entity_client(&entity.surname)
.expect("an entity client");

entity_client
Expand Down Expand Up @@ -257,7 +257,7 @@ mod integration_tests {
async fn test_insert_or_replace() {
let table_client = get_emulator_client();

let table = table_client.as_table_client("EntityClientInsertOrReplace");
let table = table_client.table_client("EntityClientInsertOrReplace");

println!("Delete the table (if it exists)");
match table.delete().execute().await {
Expand All @@ -278,8 +278,8 @@ mod integration_tests {
};

let entity_client = table
.as_partition_key_client(&entity.city)
.as_entity_client(&entity.surname)
.partition_key_client(&entity.city)
.entity_client(&entity.surname)
.expect("an entity client");
entity_client
.insert_or_replace()
Expand All @@ -303,7 +303,7 @@ mod integration_tests {
async fn test_insert_or_merge() {
let table_client = get_emulator_client();

let table = table_client.as_table_client("EntityClientInsertOrMerge");
let table = table_client.table_client("EntityClientInsertOrMerge");

println!("Delete the table (if it exists)");
match table.delete().execute().await {
Expand All @@ -324,8 +324,8 @@ mod integration_tests {
};

let entity_client = table
.as_partition_key_client(&entity.city)
.as_entity_client(&entity.surname)
.partition_key_client(&entity.city)
.entity_client(&entity.surname)
.expect("an entity client");
entity_client
.insert_or_merge()
Expand Down
12 changes: 6 additions & 6 deletions sdk/data_tables/src/clients/partition_key_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use http::method::Method;
use std::sync::Arc;

pub trait AsPartitionKeyClient<PK: Into<String>> {
fn as_partition_key_client(&self, partition_key: PK) -> Arc<PartitionKeyClient>;
fn partition_key_client(&self, partition_key: PK) -> Arc<PartitionKeyClient>;
}

impl<PK: Into<String>> AsPartitionKeyClient<PK> for Arc<TableClient> {
fn as_partition_key_client(&self, partition_key: PK) -> Arc<PartitionKeyClient> {
fn partition_key_client(&self, partition_key: PK) -> Arc<PartitionKeyClient> {
PartitionKeyClient::new(self.clone(), partition_key)
}
}
Expand Down Expand Up @@ -83,17 +83,17 @@ mod integration_tests {
}

fn get_emulator_client() -> Arc<TableServiceClient> {
let storage_account = StorageAccountClient::new_emulator_default().as_storage_client();
let storage_account = StorageAccountClient::new_emulator_default().storage_client();
storage_account
.as_table_service_client()
.table_service_client()
.expect("a table service client")
}

#[ignore = "enable test once transactions are working in Azurite #297"]
#[tokio::test]
async fn test_transaction() {
let table_service = get_emulator_client();
let table = table_service.as_table_client("PartitionKeyClientTransaction");
let table = table_service.table_client("PartitionKeyClientTransaction");

println!("Delete the table (if it exists)");
match table.delete().execute().await {
Expand All @@ -107,7 +107,7 @@ mod integration_tests {
.await
.expect("the table should be created");

let partition_client = table.as_partition_key_client("Milan");
let partition_client = table.partition_key_client("Milan");

println!("Create the transaction");
let mut transaction = Transaction::default();
Expand Down
12 changes: 6 additions & 6 deletions sdk/data_tables/src/clients/table_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use http::method::Method;
use std::sync::Arc;

pub trait AsTableClient<S: Into<String>> {
fn as_table_client(&self, s: S) -> Arc<TableClient>;
fn table_client(&self, s: S) -> Arc<TableClient>;
}

impl<S: Into<String>> AsTableClient<S> for Arc<TableServiceClient> {
fn as_table_client(&self, s: S) -> Arc<TableClient> {
fn table_client(&self, s: S) -> Arc<TableClient> {
TableClient::new(self.clone(), s)
}
}
Expand Down Expand Up @@ -95,16 +95,16 @@ mod integration_tests {
}

fn get_emulator_client() -> Arc<TableServiceClient> {
let storage_account = StorageAccountClient::new_emulator_default().as_storage_client();
let storage_account = StorageAccountClient::new_emulator_default().storage_client();
storage_account
.as_table_service_client()
.table_service_client()
.expect("a table service client")
}

#[tokio::test]
async fn test_create_delete() {
let table_client = get_emulator_client();
let table = table_client.as_table_client("TableClientCreateDelete");
let table = table_client.table_client("TableClientCreateDelete");

assert_eq!(
table.table_name(),
Expand Down Expand Up @@ -155,7 +155,7 @@ mod integration_tests {
async fn test_insert() {
let table_client = get_emulator_client();

let table = table_client.as_table_client("TableClientInsert");
let table = table_client.table_client("TableClientInsert");
assert_eq!(
table.table_name(),
"TableClientInsert",
Expand Down
10 changes: 5 additions & 5 deletions sdk/data_tables/src/clients/table_service_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use std::sync::Arc;
use url::Url;

pub trait AsTableServiceClient {
fn as_table_service_client(&self) -> azure_core::Result<Arc<TableServiceClient>>;
fn table_service_client(&self) -> azure_core::Result<Arc<TableServiceClient>>;
}

impl AsTableServiceClient for Arc<StorageClient> {
fn as_table_service_client(&self) -> azure_core::Result<Arc<TableServiceClient>> {
fn table_service_client(&self) -> azure_core::Result<Arc<TableServiceClient>> {
TableServiceClient::new(self.clone())
}
}
Expand Down Expand Up @@ -81,18 +81,18 @@ mod integration_tests {
use futures::StreamExt;

fn get_emulator_client() -> Arc<StorageClient> {
StorageAccountClient::new_emulator_default().as_storage_client()
StorageAccountClient::new_emulator_default().storage_client()
}

#[tokio::test]
async fn test_list() {
let storage_account = get_emulator_client();
let table_client = storage_account
.as_table_service_client()
.table_service_client()
.expect("a table service client");

println!("Create a table in the storage account");
let table = table_client.as_table_client("TableServiceClientList");
let table = table_client.table_client("TableServiceClientList");
match table.create().execute().await {
_ => {}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/examples/account00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn main() -> azure_core::Result<()> {

let storage_client =
StorageAccountClient::new_access_key(http_client.clone(), &account, &access_key)
.as_storage_client();
.storage_client();

let response = storage_client
.get_account_information()
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/src/core/clients/storage_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ use http::method::Method;
use std::sync::Arc;

pub trait AsStorageClient {
fn as_storage_client(&self) -> Arc<StorageClient>;
fn storage_client(&self) -> Arc<StorageClient>;
}

impl AsStorageClient for Arc<StorageAccountClient> {
fn as_storage_client(&self) -> Arc<StorageClient> {
fn storage_client(&self) -> Arc<StorageClient> {
StorageClient::new(self.clone())
}
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn get_account_information() {

let storage_client =
StorageAccountClient::new_access_key(http_client.clone(), &account, &access_key)
.as_storage_client();
.storage_client();

storage_client
.get_account_information()
Expand Down
6 changes: 3 additions & 3 deletions sdk/storage_blobs/examples/blob_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ async fn main() -> azure_core::Result<()> {
// let storage_account_client = StorageAccountClient::new_sas_token(http_client.clone(), &account,
// "sv=2018-11-09&ss=b&srt=o&se=2021-01-15T12%3A09%3A01Z&sp=r&st=2021-01-15T11%3A09%3A01Z&spr=http,https&sig=some_signature")?;

let storage_client = storage_account_client.as_storage_client();
let storage_client = storage_account_client.storage_client();
let blob_client = storage_client
.as_container_client(&container)
.as_blob_client(&blob);
.container_client(&container)
.blob_client(&blob);

trace!("Requesting blob");

Expand Down
6 changes: 3 additions & 3 deletions sdk/storage_blobs/examples/blob_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ async fn main() -> azure_core::Result<()> {
let http_client = azure_core::new_http_client();
let storage_client =
StorageAccountClient::new_access_key(http_client.clone(), &account, &access_key)
.as_storage_client();
let container_client = storage_client.as_container_client(&container_name);
let blob_client = container_client.as_blob_client("SorgeniaReorganizeRebuildIndexes.zip");
.storage_client();
let container_client = storage_client.container_client(&container_name);
let blob_client = container_client.blob_client("SorgeniaReorganizeRebuildIndexes.zip");

// only get the first 8k chunk
let result = Box::pin(blob_client.get().stream(1024 * 8))
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_blobs/examples/blob_02_bearer_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ async fn main() -> azure_core::Result<()> {
let http_client = azure_core::new_http_client();
let blob_client =
StorageAccountClient::new_bearer_token(http_client.clone(), &account, bearer_token)
.as_container_client(&container)
.as_blob_client(&blob);
.container_client(&container)
.blob_client(&blob);

trace!("Requesting blob");

Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_blobs/examples/blob_04.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async fn main() -> azure_core::Result<()> {
let http_client = azure_core::new_http_client();
let blob_client =
StorageAccountClient::new_access_key(http_client.clone(), &account, &access_key)
.as_container_client(&container_name)
.as_blob_client("test1");
.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
4 changes: 2 additions & 2 deletions sdk/storage_blobs/examples/blob_05_default_credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ async fn main() -> azure_core::Result<()> {
&account,
bearer_token.token.secret(),
)
.as_container_client(&container)
.as_blob_client(&blob);
.container_client(&container)
.blob_client(&blob);

trace!("Requesting blob");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ async fn main() -> azure_core::Result<()> {
let http_client = azure_core::new_http_client();
let blob_client =
StorageAccountClient::new_token_credential(http_client.clone(), &account, auto_creds)
.as_container_client(&container)
.as_blob_client(&blob);
.container_client(&container)
.blob_client(&blob);

trace!("Requesting blob");
let content = blob_client.get_content().await?;
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage_blobs/examples/blob_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ async fn main() -> azure_core::Result<()> {
let http_client = azure_core::new_http_client();
let blob_client =
StorageAccountClient::new_access_key(http_client.clone(), &account, &access_key)
.as_container_client(&container)
.as_blob_client(&blob);
.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
Loading