Skip to content

Commit d9b2683

Browse files
committed
pr feedback
1 parent f356f15 commit d9b2683

File tree

15 files changed

+109
-62
lines changed

15 files changed

+109
-62
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# ServiceOwner: @Pilchie
3636
# ServiceLabel: %Cosmos
3737
# PRLabel: %Cosmos
38-
/sdk/cosmosdb/ @analogrelay @Pilchie
38+
/sdk/cosmos/ @analogrelay @Pilchie
3939

4040
###########
4141
# Eng Sys

.vscode/cspell.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
"noSuggest": true
5757
},
5858
{
59-
"name": "cosmosdb",
60-
"path": "../sdk/cosmosdb/cosmosdb.dict.txt",
59+
"name": "cosmos",
60+
"path": "../sdk/cosmos/.dict.txt",
6161
"noSuggest": true
6262
}
6363
],
@@ -103,11 +103,12 @@
103103
]
104104
},
105105
{
106-
"filename": "sdk/cosmosdb/azure_data_cosmos/**",
107-
"dictionaries": [
108-
"crates",
109-
"cosmosdb",
110-
"rust-custom"
106+
"filename": "sdk/cosmos/**",
107+
"words": [
108+
"colls",
109+
"pkranges",
110+
"sprocs",
111+
"udfs",
111112
]
112113
}
113114
]

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ members = [
66
"sdk/typespec/typespec_derive",
77
"sdk/core/azure_core",
88
"sdk/core/azure_core_amqp",
9-
"sdk/cosmosdb/azure_data_cosmos",
9+
"sdk/cosmos/azure_data_cosmos",
1010
"sdk/identity/azure_identity",
1111
"sdk/eventhubs/azure_messaging_eventhubs",
1212
"eng/test/mock_transport",

sdk/cosmosdb/azure_data_cosmos/Cargo.toml renamed to sdk/cosmos/azure_data_cosmos/Cargo.toml

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository.workspace = true
1010
rust-version.workspace = true
1111
homepage = "https://github.com/azure/azure-sdk-for-rust"
1212
documentation = "https://docs.rs/azure_data_cosmos"
13-
keywords = ["sdk", "azure", "rest", "cloud", "cosmosdb", "database"]
13+
keywords = ["sdk", "azure", "rest", "cloud", "cosmos", "database"]
1414
categories = ["api-bindings"]
1515

1616
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -19,7 +19,6 @@ categories = ["api-bindings"]
1919
async-trait.workspace = true
2020
azure_core.workspace = true
2121
typespec_client_core = { workspace = true, features = ["derive"] }
22-
time.workspace = true
2322
tracing.workspace = true
2423
url.workspace = true
2524
serde.workspace = true
@@ -37,7 +36,7 @@ workspace = true
3736
default = ["hmac_rust"]
3837
hmac_rust = ["azure_core/hmac_rust"]
3938
hmac_openssl = ["azure_core/hmac_openssl"]
40-
key-auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens)
39+
key_auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens)
4140

4241
[package.metadata.docs.rs]
43-
features = ["key-auth"]
42+
features = ["key_auth"]

sdk/cosmosdb/azure_data_cosmos/examples/cosmosdb_connect.rs renamed to sdk/cosmos/azure_data_cosmos/examples/cosmos_connect.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
use azure_data_cosmos::{CosmosClient, CosmosClientMethods, DatabaseClientMethods};
1+
use azure_data_cosmos::{clients::DatabaseClientMethods, CosmosClient, CosmosClientMethods};
22
use clap::Parser;
33

44
/// A simple example to show connecting to a Cosmos Account and retrieving the properties of a database.
55
#[derive(Parser)]
66
pub struct Args {
7-
/// The CosmosDB endpoint to connect to.
7+
/// The Cosmos endpoint to connect to.
88
endpoint: String,
99

1010
/// The database to fetch information for.
1111
database: String,
1212

1313
/// An authentication key to use when connecting to the Cosmos DB account. If omitted, the connection will use Entra ID.
1414
#[clap(long)]
15-
#[cfg(feature = "key-auth")]
15+
#[cfg(feature = "key_auth")]
1616
key: Option<String>,
1717
}
1818

@@ -22,13 +22,13 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
2222

2323
let client = create_client(&args);
2424

25-
let db_client = client.database(&args.database);
25+
let db_client = client.database_client(&args.database);
2626
let response = db_client.read(None).await?.deserialize_body().await?;
2727
println!("{:?}", response);
2828
Ok(())
2929
}
3030

31-
#[cfg(feature = "key-auth")]
31+
#[cfg(feature = "key_auth")]
3232
fn create_client(args: &Args) -> CosmosClient {
3333
if let Some(key) = args.key.as_ref() {
3434
CosmosClient::with_key(&args.endpoint, key.clone(), None).unwrap()
@@ -38,7 +38,7 @@ fn create_client(args: &Args) -> CosmosClient {
3838
}
3939
}
4040

41-
#[cfg(not(feature = "key-auth"))]
41+
#[cfg(not(feature = "key_auth"))]
4242
fn create_client(args: &Args) -> CosmosClient {
4343
let cred = azure_identity::create_default_credential().unwrap();
4444
CosmosClient::new(&args.endpoint, cred, None).unwrap()

sdk/cosmosdb/azure_data_cosmos/src/authorization_policy.rs renamed to sdk/cosmos/azure_data_cosmos/src/authorization_policy.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
//! We implement that policy here, because we can't use any standard Azure SDK authentication policy.
66
77
use azure_core::auth::TokenCredential;
8+
use azure_core::date::OffsetDateTime;
89
use azure_core::{
910
date,
1011
headers::{HeaderValue, AUTHORIZATION, MS_DATE, VERSION},
1112
Context, Policy, PolicyResult, Request, Url,
1213
};
1314
use std::sync::Arc;
14-
use time::OffsetDateTime;
1515
use tracing::trace;
1616
use url::form_urlencoded;
1717

18-
#[cfg(feature = "key-auth")]
18+
#[cfg(feature = "key_auth")]
1919
use azure_core::{auth::Secret, hmac::hmac_sha256};
2020

2121
const AZURE_VERSION: &str = "2018-12-31";
@@ -42,11 +42,11 @@ enum Credential {
4242
Token(Arc<dyn TokenCredential>),
4343

4444
/// The credential is a key to be used to sign the HTTP request (a shared key)
45-
#[cfg(feature = "key-auth")]
45+
#[cfg(feature = "key_auth")]
4646
PrimaryKey(Secret),
4747
}
4848

49-
#[cfg(feature = "key-auth")]
49+
#[cfg(feature = "key_auth")]
5050
struct SignatureTarget<'a> {
5151
http_method: &'a azure_core::Method,
5252
resource_type: &'a ResourceType,
@@ -66,7 +66,7 @@ impl AuthorizationPolicy {
6666
}
6767
}
6868

69-
#[cfg(feature = "key-auth")]
69+
#[cfg(feature = "key_auth")]
7070
pub(crate) fn from_shared_key(key: Secret) -> Self {
7171
Self {
7272
credential: Credential::PrimaryKey(key),
@@ -99,7 +99,7 @@ impl Policy for AuthorizationPolicy {
9999
let auth = generate_authorization(
100100
&self.credential,
101101
request.url(),
102-
#[cfg(feature = "key-auth")]
102+
#[cfg(feature = "key_auth")]
103103
SignatureTarget {
104104
http_method: request.method(),
105105
resource_type,
@@ -186,7 +186,7 @@ fn extract_resource_link(request: &Request) -> String {
186186
async fn generate_authorization<'a>(
187187
auth_token: &Credential,
188188
url: &Url,
189-
#[cfg(feature = "key-auth")] signature_target: SignatureTarget<'a>,
189+
#[cfg(feature = "key_auth")] signature_target: SignatureTarget<'a>,
190190
) -> azure_core::Result<String> {
191191
let (authorization_type, signature) = match auth_token {
192192
Credential::Token(token_credential) => (
@@ -199,7 +199,7 @@ async fn generate_authorization<'a>(
199199
.to_string(),
200200
),
201201

202-
#[cfg(feature = "key-auth")]
202+
#[cfg(feature = "key_auth")]
203203
Credential::PrimaryKey(key) => {
204204
let string_to_sign = string_to_sign(signature_target);
205205
("master", hmac_sha256(&string_to_sign, key)?)
@@ -222,7 +222,7 @@ fn scope_from_url(url: &Url) -> String {
222222
/// This function generates a valid authorization string, according to the documentation.
223223
/// In case of authorization problems we can compare the `string_to_sign` generated by Azure against
224224
/// our own.
225-
#[cfg(feature = "key-auth")]
225+
#[cfg(feature = "key_auth")]
226226
fn string_to_sign(signature_target: SignatureTarget) -> String {
227227
// From official docs:
228228
// StringToSign =
@@ -266,16 +266,16 @@ fn string_to_sign(signature_target: SignatureTarget) -> String {
266266

267267
#[cfg(test)]
268268
mod tests {
269-
#[cfg(feature = "key-auth")]
269+
#[cfg(feature = "key_auth")]
270270
use azure_core::auth::AccessToken;
271271

272272
use super::*;
273273

274274
#[derive(Debug)]
275-
#[cfg(feature = "key-auth")]
275+
#[cfg(feature = "key_auth")]
276276
struct TestTokenCredential(String);
277277

278-
#[cfg(feature = "key-auth")]
278+
#[cfg(feature = "key_auth")]
279279
#[cfg_attr(target_arch = "wasm32", async_trait::async_trait(?Send))]
280280
#[cfg_attr(not(target_arch = "wasm32"), async_trait::async_trait)]
281281
impl TokenCredential for TestTokenCredential {
@@ -293,7 +293,7 @@ mod tests {
293293
}
294294

295295
#[test]
296-
#[cfg(feature = "key-auth")]
296+
#[cfg(feature = "key_auth")]
297297
fn string_to_sign_generates_expected_string_for_signing() {
298298
let time_nonce = date::parse_rfc3339("1900-01-01T01:00:00.000000000+00:00").unwrap();
299299

@@ -315,7 +315,7 @@ mon, 01 jan 1900 01:00:00 gmt
315315
}
316316

317317
#[tokio::test]
318-
#[cfg(feature = "key-auth")]
318+
#[cfg(feature = "key_auth")]
319319
async fn generate_authorization_for_token_credential() {
320320
let time_nonce = date::parse_rfc3339("1900-01-01T01:00:00.000000000+00:00").unwrap();
321321
let cred = Arc::new(TestTokenCredential("test_token".to_string()));
@@ -346,7 +346,7 @@ mon, 01 jan 1900 01:00:00 gmt
346346
}
347347

348348
#[tokio::test]
349-
#[cfg(feature = "key-auth")]
349+
#[cfg(feature = "key_auth")]
350350
async fn generate_authorization_for_primary_key_0() {
351351
let time_nonce = date::parse_rfc3339("1900-01-01T01:00:00.000000000+00:00").unwrap();
352352

@@ -379,7 +379,7 @@ mon, 01 jan 1900 01:00:00 gmt
379379
}
380380

381381
#[tokio::test]
382-
#[cfg(feature = "key-auth")]
382+
#[cfg(feature = "key_auth")]
383383
async fn generate_authorization_for_primary_key_1() {
384384
let time_nonce = date::parse_rfc3339("2017-04-27T00:51:12.000000000+00:00").unwrap();
385385

sdk/cosmosdb/azure_data_cosmos/src/clients/cosmos_client.rs renamed to sdk/cosmos/azure_data_cosmos/src/clients/cosmos_client.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use crate::authorization_policy::AuthorizationPolicy;
2-
use crate::{CosmosClientOptions, DatabaseClient};
2+
use crate::clients::DatabaseClient;
3+
use crate::CosmosClientOptions;
34
use azure_core::auth::TokenCredential;
45
use azure_core::{Pipeline, Url};
56
use std::sync::Arc;
67

7-
#[cfg(feature = "key-auth")]
8+
#[cfg(feature = "key_auth")]
89
use azure_core::auth::Secret;
910

1011
/// Client for Azure Cosmos DB.
@@ -23,7 +24,10 @@ pub struct CosmosClient {
2324
/// Rather than depending on `CosmosClient`, you can depend on a generic parameter constrained by this trait, or an `impl CosmosClientMethods` type.
2425
pub trait CosmosClientMethods {
2526
/// Gets a [`DatabaseClient`] that can be used to access the database with the specified ID.
26-
fn database(&self, name: impl Into<String>) -> DatabaseClient;
27+
///
28+
/// # Arguments
29+
/// * `id` - The ID of the database.
30+
fn database_client(&self, id: impl AsRef<str>) -> DatabaseClient;
2731
}
2832

2933
impl CosmosClient {
@@ -72,7 +76,7 @@ impl CosmosClient {
7276
/// ```rust,no_run
7377
/// let client = CosmosClient::with_shared_key("https://myaccount.documents.azure.com/", "my_key", None)?;
7478
/// ```
75-
#[cfg(feature = "key-auth")]
79+
#[cfg(feature = "key_auth")]
7680
pub fn with_key(
7781
endpoint: impl AsRef<str>,
7882
key: impl Into<Secret>,
@@ -97,8 +101,11 @@ impl CosmosClient {
97101

98102
impl CosmosClientMethods for CosmosClient {
99103
/// Gets a [`DatabaseClient`] that can be used to access the database with the specified ID.
100-
fn database(&self, id: impl Into<String>) -> DatabaseClient {
101-
DatabaseClient::new(self.clone(), id.into())
104+
///
105+
/// # Arguments
106+
/// * `id` - The ID of the database.
107+
fn database_client(&self, id: impl AsRef<str>) -> DatabaseClient {
108+
DatabaseClient::new(self.clone(), id.as_ref())
102109
}
103110
}
104111

sdk/cosmosdb/azure_data_cosmos/src/clients/database_client.rs renamed to sdk/cosmos/azure_data_cosmos/src/clients/database_client.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,42 @@ pub trait DatabaseClientMethods {
2222
///
2323
/// ```rust,no_run
2424
/// # async fn doc() {
25-
/// use azure_data_cosmos::{CosmosClient, CosmosClientMethods, DatabaseClientMethods};
25+
/// use azure_data_cosmos::{CosmosClient, CosmosClientMethods, clients::DatabaseClientMethods};
2626
///
2727
/// let credential = azure_identity::create_default_credential().unwrap();
2828
/// let client = CosmosClient::new("https://myaccount.documents.azure.com/", credential, None).unwrap();
29-
/// let db_client = client.database("my_database");
29+
/// let db_client = client.database_client("my_database");
3030
/// let response = db_client.read(None)
3131
/// .await.unwrap()
3232
/// .deserialize_body()
3333
/// .await.unwrap();
3434
/// # }
3535
/// ```
36-
fn read(
36+
#[allow(async_fn_in_trait)] // REASON: See https://github.com/Azure/azure-sdk-for-rust/issues/1796 for detailed justification
37+
async fn read(
3738
&self,
3839
options: Option<ReadDatabaseOptions>,
39-
) -> impl std::future::Future<Output = azure_core::Result<azure_core::Response<DatabaseProperties>>>;
40+
) -> azure_core::Result<azure_core::Response<DatabaseProperties>>;
4041
}
4142

4243
/// A client for working with a specific database in a Cosmos account.
4344
///
44-
/// You can get a `DatabaseClient` by calling [`CosmosClient::database()`](CosmosClient::database).
45+
/// You can get a `DatabaseClient` by calling [`CosmosClient::database_client()`](CosmosClient::database_client()).
4546
pub struct DatabaseClient {
4647
base_url: Url,
4748
root_client: CosmosClient,
4849
}
4950

5051
impl DatabaseClient {
51-
pub(crate) fn new(root_client: CosmosClient, database_id: String) -> Self {
52+
pub(crate) fn new(root_client: CosmosClient, database_id: &str) -> Self {
5253
let base_url = {
5354
let mut u = root_client.endpoint().clone();
5455
{
5556
let mut segments = u
5657
.path_segments_mut()
5758
.expect("The root client should have validated the format of the URL");
5859
segments.push("dbs");
59-
segments.push(&database_id);
60+
segments.push(database_id);
6061
}
6162
u
6263
};

sdk/cosmosdb/azure_data_cosmos/src/lib.rs renamed to sdk/cosmos/azure_data_cosmos/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
#![cfg_attr(docsrs, feature(doc_cfg_hide))]
99

1010
mod authorization_policy;
11-
mod clients;
11+
pub mod clients;
1212
mod options;
1313

1414
/// Model types sent to and received from the Cosmos API.
1515
pub mod models;
1616

17-
pub use clients::*;
17+
pub use clients::{CosmosClient, CosmosClientMethods};
1818
pub use options::*;

sdk/cosmosdb/azure_data_cosmos/src/models/mod.rs renamed to sdk/cosmos/azure_data_cosmos/src/models/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
use azure_core::Model;
1+
use azure_core::{
2+
date::{ComponentRange, OffsetDateTime},
3+
Model,
4+
};
25
use serde::{Deserialize, Serialize};
3-
use time::error::ComponentRange;
4-
use time::OffsetDateTime;
56

67
#[cfg(doc)]
7-
use crate::DatabaseClientMethods;
8+
use crate::{clients::DatabaseClientMethods, CosmosClientMethods};
89

910
/// Represents a timestamp in the format expected by Cosmos DB.
1011
///
1112
/// Cosmos DB timestamps are represented as the number of seconds since the Unix epoch.
12-
/// Use [`CosmosTimestamp::try_into`] implementation to convert this into a [`time::OffsetDateTime`].
13+
/// Use [`CosmosTimestamp::try_into`] implementation to convert this into an [`OffsetDateTime`].
1314
#[derive(Serialize, Deserialize, Debug)]
1415
pub struct CosmosTimestamp(i64);
1516

@@ -25,7 +26,7 @@ impl TryInto<OffsetDateTime> for CosmosTimestamp {
2526

2627
/// Properties of a Cosmos DB database.
2728
///
28-
/// Returned by [`DatabaseClient::read()`](crate::DatabaseClient::read()).
29+
/// Returned by [`DatabaseClient::read()`](crate::clients::DatabaseClient::read()).
2930
#[derive(Model, Debug, Deserialize)]
3031
pub struct DatabaseProperties {
3132
/// The ID of the database.

0 commit comments

Comments
 (0)