Skip to content

Commit ff8f954

Browse files
authored
Cosmos Tweaks (#842)
* Add some docs to header constants * Use COSMOS_PRIMARY_KEY instead of COSMOS_MASTER_KEY * Clean up Cosmos crate docs * Make operations private * Add more docs to cosmos entity * Rename add_as_partition_key_header_serialized{2,} * Stop using headers_mut * Also use primary_key instead of master_key * More client docs * Fix up order of client methods
1 parent cd89ca1 commit ff8f954

Some content is hidden

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

50 files changed

+415
-411
lines changed

sdk/core/src/constants.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// Endpoints for Azure Resource Manager in different Azure clouds
22
pub mod resource_manager_endpoint {
3-
43
/// Azure Resource Manager China cloud endpoint
54
pub const AZURE_CHINA_CLOUD: &str = "https://management.chinacloudapi.cn";
65

@@ -14,9 +13,10 @@ pub mod resource_manager_endpoint {
1413
pub const AZURE_US_GOVERNMENT_CLOUD: &str = "https://management.usgovcloudapi.net";
1514
}
1615

17-
/// https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type
16+
/// Constants related to the Content-Type header
17+
///
18+
/// <https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type>
1819
pub mod content_type {
19-
2020
// Form content types
2121
// https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4
2222

@@ -28,6 +28,9 @@ pub mod content_type {
2828
pub const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";
2929
}
3030

31+
/// Constants related to the Content-Type header
32+
///
33+
/// <https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type>
3134
pub mod query_param {
3235
pub const API_VERSION: &str = "api-version";
3336
}

sdk/data_cosmos/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ impl<'a> azure_data_cosmos::CosmosEntity<'a> for MySampleStruct {
3838
#[tokio::main]
3939
async fn main() -> azure_core::Result<()> {
4040
// Let's get Cosmos account and master key from env variables.
41-
let master_key =
42-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
41+
let primary_key =
42+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
4343
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
4444

4545
let database_name = std::env::args()
@@ -53,7 +53,7 @@ async fn main() -> azure_core::Result<()> {
5353
// constrained. This SDK supports both.
5454
// Please check the Azure documentation for details or the examples folder
5555
// on how to create and use token-based permissions.
56-
let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
56+
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;
5757

5858
// Next we will create a Cosmos client.
5959
let client = CosmosClient::new(account.clone(), authorization_token, CosmosOptions::default());

sdk/data_cosmos/examples/attachments_00.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ async fn main() -> azure_core::Result<()> {
3030
.nth(2)
3131
.expect("please specify collection name as second command line parameter");
3232

33-
let master_key =
34-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
33+
let primary_key =
34+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
3535
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
3636

37-
let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
37+
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;
3838

3939
let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());
4040
let client = client

sdk/data_cosmos/examples/cancellation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ async fn main() -> azure_core::Result<()> {
99
// First we retrieve the account name and master key from environment variables, and
1010
// create an authorization token.
1111
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
12-
let master_key =
13-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
14-
let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
12+
let primary_key =
13+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
14+
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;
1515

1616
// Create a new Cosmos client.
1717
let options = CosmosOptions::default();

sdk/data_cosmos/examples/collection.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use futures::stream::StreamExt;
55
async fn main() -> azure_core::Result<()> {
66
// First we retrieve the account name and master key from environment variables.
77
// We expect master keys (ie, not resource constrained)
8-
let master_key =
9-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
8+
let primary_key =
9+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
1010
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
1111

1212
// This is how you construct an authorization token.
@@ -17,7 +17,7 @@ async fn main() -> azure_core::Result<()> {
1717
// errors, plus Azure specific ones. For example if a REST call returns the
1818
// unexpected result (ie NotFound instead of Ok) we return an Err telling
1919
// you that.
20-
let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
20+
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;
2121

2222
// Once we have an authorization token you can create a client instance. You can change the
2323
// authorization token at later time if you need, for example, to escalate the privileges for a

sdk/data_cosmos/examples/create_delete_database.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use futures::stream::StreamExt;
55
async fn main() -> azure_core::Result<()> {
66
// First we retrieve the account name and master key from environment variables.
77
// We expect master keys (ie, not resource constrained)
8-
let master_key =
9-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
8+
let primary_key =
9+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
1010
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
1111

1212
let database_name = std::env::args()
@@ -21,7 +21,7 @@ async fn main() -> azure_core::Result<()> {
2121
// errors, plus Azure specific ones. For example if a REST call returns the
2222
// unexpected result (ie NotFound instead of Ok) we return an Err telling
2323
// you that.
24-
let authorization_token = permission::AuthorizationToken::primary_from_base64(&master_key)?;
24+
let authorization_token = permission::AuthorizationToken::primary_from_base64(&primary_key)?;
2525

2626
// Once we have an authorization token you can create a client instance. You can change the
2727
// authorization token at later time if you need, for example, to escalate the privileges for a

sdk/data_cosmos/examples/database_00.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use serde_json::Value;
66
async fn main() -> azure_core::Result<()> {
77
// First we retrieve the account name and master key from environment variables.
88
// We expect master keys (ie, not resource constrained)
9-
let master_key =
10-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
9+
let primary_key =
10+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
1111
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
1212

13-
let authorization_token = permission::AuthorizationToken::primary_from_base64(&master_key)?;
13+
let authorization_token = permission::AuthorizationToken::primary_from_base64(&primary_key)?;
1414

1515
let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());
1616

sdk/data_cosmos/examples/database_01.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ use futures::stream::StreamExt;
55
async fn main() -> azure_core::Result<()> {
66
// First we retrieve the account name and master key from environment variables.
77
// We expect master keys (ie, not resource constrained)
8-
let master_key =
9-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
8+
let primary_key =
9+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
1010
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
1111

12-
let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
12+
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;
1313

1414
let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());
1515

sdk/data_cosmos/examples/document_00.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ const COLLECTION: &str = "azuresdktc";
3535
async fn main() -> azure_core::Result<()> {
3636
// Let's get Cosmos account and master key from env variables.
3737
// This helps automated testing.
38-
let master_key =
39-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
38+
let primary_key =
39+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
4040
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
4141

4242
// First, we create an authorization token. There are two types of tokens, master and resource
4343
// constrained. Please check the Azure documentation for details. You can change tokens
4444
// at will and it's a good practice to raise your privileges only when needed.
45-
let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
45+
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;
4646

4747
// Next we will create a Cosmos client. You need an authorization_token but you can later
4848
// change it if needed.

sdk/data_cosmos/examples/document_entries_00.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ async fn main() -> azure_core::Result<()> {
3232
.nth(2)
3333
.expect("please specify collection name as second command line parameter");
3434

35-
let master_key =
36-
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
35+
let primary_key =
36+
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
3737
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
3838

39-
let authorization_token = permission::AuthorizationToken::primary_from_base64(&master_key)?;
39+
let authorization_token = permission::AuthorizationToken::primary_from_base64(&primary_key)?;
4040

4141
let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());
4242
let client = client.database_client(database_name);

0 commit comments

Comments
 (0)