Skip to content

Cosmos Tweaks #842

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 10 commits into from
Jun 22, 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
9 changes: 6 additions & 3 deletions sdk/core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// Endpoints for Azure Resource Manager in different Azure clouds
pub mod resource_manager_endpoint {

/// Azure Resource Manager China cloud endpoint
pub const AZURE_CHINA_CLOUD: &str = "https://management.chinacloudapi.cn";

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

/// https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type
/// Constants related to the Content-Type header
///
/// <https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type>
pub mod content_type {

// Form content types
// https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4

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

/// Constants related to the Content-Type header
///
/// <https://developer.mozilla.org/docs/Web/HTTP/Headers/Content-Type>
pub mod query_param {
pub const API_VERSION: &str = "api-version";
}
6 changes: 3 additions & 3 deletions sdk/data_cosmos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ impl<'a> azure_data_cosmos::CosmosEntity<'a> for MySampleStruct {
#[tokio::main]
async fn main() -> azure_core::Result<()> {
// Let's get Cosmos account and master key from env variables.
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

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

// Next we will create a Cosmos client.
let client = CosmosClient::new(account.clone(), authorization_token, CosmosOptions::default());
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/attachments_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ async fn main() -> azure_core::Result<()> {
.nth(2)
.expect("please specify collection name as second command line parameter");

let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());
let client = client
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/cancellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables, and
// create an authorization token.
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

// Create a new Cosmos client.
let options = CosmosOptions::default();
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use futures::stream::StreamExt;
async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables.
// We expect master keys (ie, not resource constrained)
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

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

// Once we have an authorization token you can create a client instance. You can change the
// authorization token at later time if you need, for example, to escalate the privileges for a
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/create_delete_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use futures::stream::StreamExt;
async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables.
// We expect master keys (ie, not resource constrained)
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

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

// Once we have an authorization token you can create a client instance. You can change the
// authorization token at later time if you need, for example, to escalate the privileges for a
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/database_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use serde_json::Value;
async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables.
// We expect master keys (ie, not resource constrained)
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let authorization_token = permission::AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = permission::AuthorizationToken::primary_from_base64(&primary_key)?;

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

Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/database_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use futures::stream::StreamExt;
async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables.
// We expect master keys (ie, not resource constrained)
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

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

Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/document_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const COLLECTION: &str = "azuresdktc";
async fn main() -> azure_core::Result<()> {
// Let's get Cosmos account and master key from env variables.
// This helps automated testing.
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

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

// Next we will create a Cosmos client. You need an authorization_token but you can later
// change it if needed.
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/document_entries_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ async fn main() -> azure_core::Result<()> {
.nth(2)
.expect("please specify collection name as second command line parameter");

let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let authorization_token = permission::AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = permission::AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());
let client = client.database_client(database_name);
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/document_entries_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ async fn main() -> azure_core::Result<()> {
.nth(2)
.expect("please specify collection name as second command line parameter");

let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());
let client = client.database_client(database_name);
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/get_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ use azure_data_cosmos::prelude::*;
async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables.
// We expect master keys (ie, not resource constrained)
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let database_name = std::env::args()
.nth(1)
.expect("Please provide the database name as first parameter");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/key_ranges_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ async fn main() -> azure_core::Result<()> {
.nth(2)
.expect("please specify collection name as second command line parameter");

let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/permission_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use futures::StreamExt;
async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables.
// We expect master keys (ie, not resource constrained)
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let database_name = std::env::args()
Expand All @@ -22,7 +22,7 @@ async fn main() -> azure_core::Result<()> {
.nth(4)
.expect("please specify the user name as fourth command line parameter");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/query_document_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ async fn main() -> azure_core::Result<()> {
.expect("please specify requested query");

let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl azure_data_cosmos::CosmosEntity for MySampleStruct {
async fn main() -> azure_core::Result<()> {
// Let's get Cosmos account and master key from env variables.
// This helps automated testing.
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

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

// Next we will create a Cosmos client.
let client = CosmosClient::new(
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/remove_all_documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ async fn main() -> azure_core::Result<()> {
.nth(3)
.expect("please specify the partition key as third command line parameter");

let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

// Next we will create a Cosmos client.
let client = CosmosClient::new(
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/stored_proc_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ async fn main() -> azure_core::Result<()> {
.expect("please specify collection name as second command line parameter");

let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/stored_proc_01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ async fn main() -> azure_core::Result<()> {
"#;

let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");

let database_name = std::env::args()
.nth(1)
Expand All @@ -32,7 +32,7 @@ async fn main() -> azure_core::Result<()> {
.nth(3)
.expect("please specify the stored procedure name as third command line parameter");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/trigger_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ async fn main() -> azure_core::Result<()> {
.expect("please specify trigger name as third command line parameter");

let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/user_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use futures::StreamExt;
async fn main() -> azure_core::Result<()> {
// First we retrieve the account name and master key from environment variables.
// We expect master keys (ie, not resource constrained)
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");
let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");

let database_name = std::env::args()
Expand All @@ -16,7 +16,7 @@ async fn main() -> azure_core::Result<()> {
.nth(2)
.expect("please specify the user name as first command line parameter");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
6 changes: 3 additions & 3 deletions sdk/data_cosmos/examples/user_defined_function_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ async fn main() -> azure_core::Result<()> {
.expect("please specify collection name as second command line parameter");

let account = std::env::var("COSMOS_ACCOUNT").expect("Set env variable COSMOS_ACCOUNT first!");
let master_key =
std::env::var("COSMOS_MASTER_KEY").expect("Set env variable COSMOS_MASTER_KEY first!");
let primary_key =
std::env::var("COSMOS_PRIMARY_KEY").expect("Set env variable COSMOS_PRIMARY_KEY first!");

let authorization_token = AuthorizationToken::primary_from_base64(&master_key)?;
let authorization_token = AuthorizationToken::primary_from_base64(&primary_key)?;

let client = CosmosClient::new(
account.clone(),
Expand Down
Loading