Skip to content
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
13 changes: 9 additions & 4 deletions sdk/core/src/policies/retry_policies/retry_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ where
error
}
Err(error) => {
log::debug!(
"error occurred when making request which will be retried: {}",
if error.kind() == &ErrorKind::Io {
log::debug!(
"io error occurred when making request which will be retried: {}",
error
);
error
);
error
} else {
log::error!("non-io error occurred which will not be retried: {}", error);
return Err(error);
}
}
};

Expand Down
11 changes: 5 additions & 6 deletions sdk/data_cosmos/src/authorization_policy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::headers::{HEADER_DATE, HEADER_VERSION};
use crate::resources::permission::AuthorizationToken;
use crate::resources::ResourceType;
use azure_core::headers::{HeaderValue, AUTHORIZATION};
use azure_core::headers::{HeaderValue, AUTHORIZATION, MS_DATE, VERSION};
use azure_core::{date, Context, Policy, PolicyResult, Request};
use hmac::{Hmac, Mac};
use sha2::Sha256;
Expand All @@ -11,7 +10,7 @@ use time::OffsetDateTime;
use url::form_urlencoded;

const AZURE_VERSION: &str = "2018-12-31";
const VERSION: &str = "1.0";
const VERSION_NUMBER: &str = "1.0";

/// The `AuthorizationPolicy` takes care to authenticate your calls to Azure CosmosDB.
///
Expand Down Expand Up @@ -75,8 +74,8 @@ impl Policy for AuthorizationPolicy {
&auth
);

request.insert_header(HEADER_DATE, HeaderValue::from(time_nonce.to_string()));
request.insert_header(HEADER_VERSION, HeaderValue::from_static(AZURE_VERSION));
request.insert_header(MS_DATE, HeaderValue::from(date::to_rfc1123(&time_nonce)));
Copy link
Member

Choose a reason for hiding this comment

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

Yes, looks like this was missed in #965.

request.insert_header(VERSION, HeaderValue::from_static(AZURE_VERSION));
request.insert_header(AUTHORIZATION, HeaderValue::from(auth));

// next[0] will not panic, because we checked at the beginning of the function
Expand Down Expand Up @@ -161,7 +160,7 @@ fn generate_authorization(

let str_unencoded = format!(
"type={}&ver={}&sig={}",
authorization_type, VERSION, signature
authorization_type, VERSION_NUMBER, signature
);
trace!(
"generate_authorization::str_unencoded == {:?}",
Expand Down
2 changes: 1 addition & 1 deletion sdk/data_cosmos/src/headers/from_headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) fn number_of_read_regions_from_headers(headers: &Headers) -> azure_co
}

pub(crate) fn activity_id_from_headers(headers: &Headers) -> azure_core::Result<uuid::Uuid> {
headers.get_as(&HEADER_ACTIVITY_ID)
headers.get_as(&headers::ACTIVITY_ID)
}

pub(crate) fn content_path_from_headers(headers: &Headers) -> azure_core::Result<String> {
Expand Down
3 changes: 0 additions & 3 deletions sdk/data_cosmos/src/headers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use azure_core::headers::HeaderName;

pub(crate) mod from_headers;

pub(crate) const HEADER_VERSION: HeaderName = HeaderName::from_static("x-ms-version");
pub(crate) const HEADER_DATE: HeaderName = HeaderName::from_static("x-ms-date");
pub(crate) const HEADER_DOCUMENTDB_IS_UPSERT: HeaderName =
HeaderName::from_static("x-ms-documentdb-is-upsert");
pub(crate) const HEADER_INDEXING_DIRECTIVE: HeaderName =
Expand All @@ -14,7 +12,6 @@ pub(crate) const HEADER_SESSION_TOKEN: HeaderName = HeaderName::from_static("x-m
pub(crate) const HEADER_ALLOW_MULTIPLE_WRITES: HeaderName =
HeaderName::from_static("x-ms-cosmos-allow-tentative-writes");
pub(crate) const HEADER_A_IM: HeaderName = HeaderName::from_static("A-IM");
pub(crate) const HEADER_ACTIVITY_ID: HeaderName = HeaderName::from_static("x-ms-activity-id");
pub(crate) const HEADER_DOCUMENTDB_PARTITIONRANGEID: HeaderName =
HeaderName::from_static("x-ms-documentdb-partitionkeyrangeid");
pub(crate) const HEADER_DOCUMENTDB_PARTITIONKEY: HeaderName =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ impl CreateOrReplaceUserDefinedFunctionBuilder {
.client
.pipeline()
.send(
self.context.clone().insert(ResourceType::Permissions),
self.context
.clone()
.insert(ResourceType::UserDefinedFunctions),
&mut request,
)
.await?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl DeleteStoredProcedureBuilder {
.client
.pipeline()
.send(
self.context.clone().insert(ResourceType::Permissions),
self.context.clone().insert(ResourceType::StoredProcedures),
&mut request,
)
.await?;
Expand Down
25 changes: 20 additions & 5 deletions sdk/data_cosmos/tests/user_defined_function_operations.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#![cfg(all(test, feature = "test_e2e"))]
use azure_data_cosmos::prelude::*;
use futures::stream::StreamExt;

mod setup;
mod setup_mock;

const FN_BODY: &str = r#"
function tax(income) {
Expand All @@ -18,47 +17,58 @@ function tax(income) {

#[tokio::test]
async fn user_defined_function_operations() -> azure_core::Result<()> {
env_logger::init();
const DATABASE_NAME: &str = "test-cosmos-db-udf";
const COLLECTION_NAME: &str = "test-udf";
const USER_DEFINED_FUNCTION_NAME: &str = "test";

let client = setup::initialize()?;
let client = setup_mock::initialize("user_defined_function_operations")?;

log::info!("creating database");
// create a temp database
let _ = client.create_database(DATABASE_NAME).into_future().await?;
log::info!("created database");

let database = client.database_client(DATABASE_NAME);

// create a temp collection
log::info!("creating collection");
let _ = database
.create_collection(COLLECTION_NAME, "/id")
.into_future()
.await?;
log::info!("created collection");

let collection = database.collection_client(COLLECTION_NAME);
let user_defined_function = collection.user_defined_function_client(USER_DEFINED_FUNCTION_NAME);

log::info!("creating user defined function");
let ret = user_defined_function
.create_user_defined_function("body")
.into_future()
.await?;
log::info!("created user defined function");

log::info!("listing user defined functions");
let stream = collection
.list_user_defined_functions()
.max_item_count(3)
.consistency_level(&ret);
let mut stream = stream.into_stream();
while let Some(ret) = stream.next().await {
let ret = ret?;
assert_eq!(ret.item_count, 1);
assert_eq!(ret?.item_count, 1);
}
log::info!("listed user defined functions");

log::info!("replacing user defined functions");
let ret = user_defined_function
.replace_user_defined_function(FN_BODY)
.consistency_level(&ret)
.into_future()
.await?;
log::info!("replaced user defined functions");

log::info!("querying documents");
let query_stmt = format!("SELECT udf.{}(100)", USER_DEFINED_FUNCTION_NAME);
let ret = collection
.query_documents(Query::new(query_stmt))
Expand All @@ -74,7 +84,9 @@ async fn user_defined_function_operations() -> azure_core::Result<()> {
let fn_return = ret.documents().next().unwrap().as_object().unwrap();
let value = fn_return.iter().take(1).next().unwrap().1.as_f64().unwrap();
assert_eq!(value, 10.0);
log::info!("queried documents");

log::info!("querying documents again");
let query_stmt = format!("SELECT udf.{}(10000)", USER_DEFINED_FUNCTION_NAME);
let ret = collection
.query_documents(Query::new(query_stmt))
Expand All @@ -97,7 +109,9 @@ async fn user_defined_function_operations() -> azure_core::Result<()> {
.as_f64()
.unwrap();
assert_eq!(value, 4000.0);
log::info!("queried documents again");

log::info!("deleting test resources");
let _ret = user_defined_function
.delete_user_defined_function()
.consistency_level(&ret)
Expand All @@ -106,6 +120,7 @@ async fn user_defined_function_operations() -> azure_core::Result<()> {

// delete the database
database.delete_database().into_future().await?;
log::info!("deleted test resources");

Ok(())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"uri": "/dbs",
"method": "POST",
"headers": {
"authorization": "<<STRIPPED>>",
"user-agent": "azsdk-rust-data_cosmos/0.4.0 (1.62.1; linux; x86_64)",
"x-ms-date": "Tue, 09 Aug 2022 09:29:22 GMT",
"x-ms-version": "2018-12-31"
},
"body": "eyJpZCI6InRlc3QtY29zbW9zLWRiLXVkZiJ9"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"status": 201,
"headers": {
"cache-control": "no-store, no-cache",
"content-length": "177",
"content-type": "application/json",
"date": "Tue, 09 Aug 2022 09:28:46 GMT",
"etag": "\"0000a044-0000-0700-0000-62f228ce0000\"",
"lsn": "127",
"pragma": "no-cache",
"server": "Microsoft-HTTPAPI/2.0",
"strict-transport-security": "max-age=31536000",
"x-ms-activity-id": "49944775-1192-46af-bebf-4223266e74cc",
"x-ms-cosmos-llsn": "127",
"x-ms-cosmos-quorum-acked-llsn": "126",
"x-ms-current-replica-set-size": "4",
"x-ms-current-write-quorum": "3",
"x-ms-gatewayversion": "version=2.14.0",
"x-ms-global-committed-lsn": "126",
"x-ms-last-state-change-utc": "Wed, 03 Aug 2022 00:09:12.948 GMT",
"x-ms-number-of-read-regions": "0",
"x-ms-quorum-acked-lsn": "126",
"x-ms-request-charge": "4.95",
"x-ms-request-duration-ms": "21.661",
"x-ms-resource-quota": "databases=1000;",
"x-ms-resource-usage": "databases=1;",
"x-ms-schemaversion": "1.14",
"x-ms-serviceversion": "version=2.14.0.0",
"x-ms-session-token": "0:-1#127",
"x-ms-transport-request-id": "1334697",
"x-ms-xp-role": "1"
},
"body": "eyJpZCI6InRlc3QtY29zbW9zLWRiLXVkZiIsIl9yaWQiOiJoYkZqQUE9PSIsIl9zZWxmIjoiZGJzXC9oYkZqQUE9PVwvIiwiX2V0YWciOiJcIjAwMDBhMDQ0LTAwMDAtMDcwMC0wMDAwLTYyZjIyOGNlMDAwMFwiIiwiX2NvbGxzIjoiY29sbHNcLyIsIl91c2VycyI6InVzZXJzXC8iLCJfdHMiOjE2NjAwMzczMjZ9"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"uri": "/dbs/test-cosmos-db-udf/colls",
"method": "POST",
"headers": {
"authorization": "<<STRIPPED>>",
"user-agent": "azsdk-rust-data_cosmos/0.4.0 (1.62.1; linux; x86_64)",
"x-ms-date": "Tue, 09 Aug 2022 09:29:24 GMT",
"x-ms-version": "2018-12-31"
},
"body": "eyJpZCI6InRlc3QtdWRmIiwicGFydGl0aW9uS2V5Ijp7InBhdGhzIjpbIi9pZCJdLCJraW5kIjoiSGFzaCJ9fQ=="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"status": 201,
"headers": {
"cache-control": "no-store, no-cache",
"collection-partition-index": "0",
"collection-service-index": "0",
"content-length": "609",
"content-type": "application/json",
"date": "Tue, 09 Aug 2022 09:28:47 GMT",
"etag": "\"0000a244-0000-0700-0000-62f228d00000\"",
"lsn": "1",
"pragma": "no-cache",
"server": "Microsoft-HTTPAPI/2.0",
"strict-transport-security": "max-age=31536000",
"x-ms-activity-id": "34148ada-bf59-47fe-b905-d69619ad79f1",
"x-ms-alt-content-path": "dbs/test-cosmos-db-udf",
"x-ms-cosmos-item-llsn": "1",
"x-ms-cosmos-llsn": "1",
"x-ms-cosmos-quorum-acked-llsn": "1",
"x-ms-current-replica-set-size": "4",
"x-ms-current-write-quorum": "3",
"x-ms-documentdb-partitionkeyrangeid": "0",
"x-ms-gatewayversion": "version=2.14.0",
"x-ms-global-committed-lsn": "1",
"x-ms-item-lsn": "1",
"x-ms-last-state-change-utc": "Tue, 09 Aug 2022 09:25:35.421 GMT",
"x-ms-number-of-read-regions": "0",
"x-ms-quorum-acked-lsn": "1",
"x-ms-request-charge": "1",
"x-ms-request-duration-ms": "0.638",
"x-ms-schemaversion": "1.14",
"x-ms-serviceversion": "version=2.14.0.0",
"x-ms-session-token": "0:-1#1",
"x-ms-transport-request-id": "2",
"x-ms-xp-role": "1"
},
"body": "eyJpZCI6InRlc3QtdWRmIiwiaW5kZXhpbmdQb2xpY3kiOnsiaW5kZXhpbmdNb2RlIjoiY29uc2lzdGVudCIsImF1dG9tYXRpYyI6dHJ1ZSwiaW5jbHVkZWRQYXRocyI6W3sicGF0aCI6IlwvKiJ9XSwiZXhjbHVkZWRQYXRocyI6W3sicGF0aCI6IlwvXCJfZXRhZ1wiXC8/In1dfSwicGFydGl0aW9uS2V5Ijp7InBhdGhzIjpbIlwvaWQiXSwia2luZCI6Ikhhc2gifSwiY29uZmxpY3RSZXNvbHV0aW9uUG9saWN5Ijp7Im1vZGUiOiJMYXN0V3JpdGVyV2lucyIsImNvbmZsaWN0UmVzb2x1dGlvblBhdGgiOiJcL190cyIsImNvbmZsaWN0UmVzb2x1dGlvblByb2NlZHVyZSI6IiJ9LCJnZW9zcGF0aWFsQ29uZmlnIjp7InR5cGUiOiJHZW9ncmFwaHkifSwiX3JpZCI6ImhiRmpBTGVDRytFPSIsIl90cyI6MTY2MDAzNzMyOCwiX3NlbGYiOiJkYnNcL2hiRmpBQT09XC9jb2xsc1wvaGJGakFMZUNHK0U9XC8iLCJfZXRhZyI6IlwiMDAwMGEyNDQtMDAwMC0wNzAwLTAwMDAtNjJmMjI4ZDAwMDAwXCIiLCJfZG9jcyI6ImRvY3NcLyIsIl9zcHJvY3MiOiJzcHJvY3NcLyIsIl90cmlnZ2VycyI6InRyaWdnZXJzXC8iLCJfdWRmcyI6InVkZnNcLyIsIl9jb25mbGljdHMiOiJjb25mbGljdHNcLyJ9"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"uri": "/dbs/test-cosmos-db-udf/colls/test-udf/udfs",
"method": "POST",
"headers": {
"authorization": "<<STRIPPED>>",
"user-agent": "azsdk-rust-data_cosmos/0.4.0 (1.62.1; linux; x86_64)",
"x-ms-date": "Tue, 09 Aug 2022 09:29:26 GMT",
"x-ms-version": "2018-12-31"
},
"body": "eyJib2R5IjoiYm9keSIsImlkIjoidGVzdCJ9"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"status": 201,
"headers": {
"cache-control": "no-store, no-cache",
"content-length": "208",
"content-type": "application/json",
"date": "Tue, 09 Aug 2022 09:28:48 GMT",
"etag": "\"c100d2e1-0000-0700-0000-62f228d10000\"",
"lsn": "2",
"pragma": "no-cache",
"server": "Microsoft-HTTPAPI/2.0",
"strict-transport-security": "max-age=31536000",
"x-ms-activity-id": "798d4f0c-55c7-4a59-886b-88da4aba1c7a",
"x-ms-alt-content-path": "dbs/test-cosmos-db-udf/colls/test-udf",
"x-ms-content-path": "hbFjALeCG+E=",
"x-ms-cosmos-llsn": "2",
"x-ms-cosmos-quorum-acked-llsn": "1",
"x-ms-current-replica-set-size": "4",
"x-ms-current-write-quorum": "3",
"x-ms-documentdb-partitionkeyrangeid": "0",
"x-ms-gatewayversion": "version=2.14.0",
"x-ms-global-committed-lsn": "1",
"x-ms-last-state-change-utc": "Tue, 09 Aug 2022 09:25:35.421 GMT",
"x-ms-number-of-read-regions": "0",
"x-ms-quorum-acked-lsn": "1",
"x-ms-request-charge": "4.95",
"x-ms-request-duration-ms": "4.854",
"x-ms-resource-quota": "functions=50;",
"x-ms-resource-usage": "functions=1;",
"x-ms-schemaversion": "1.14",
"x-ms-serviceversion": "version=2.14.0.0",
"x-ms-session-token": "0:-1#2",
"x-ms-transport-request-id": "3",
"x-ms-xp-role": "1"
},
"body": "eyJib2R5IjoiYm9keSIsImlkIjoidGVzdCIsIl9yaWQiOiJoYkZqQUxlQ0crRUJBQUFBQUFBQVlBPT0iLCJfc2VsZiI6ImRic1wvaGJGakFBPT1cL2NvbGxzXC9oYkZqQUxlQ0crRT1cL3VkZnNcL2hiRmpBTGVDRytFQkFBQUFBQUFBWUE9PVwvIiwiX2V0YWciOiJcImMxMDBkMmUxLTAwMDAtMDcwMC0wMDAwLTYyZjIyOGQxMDAwMFwiIiwiX3RzIjoxNjYwMDM3MzI5fQ=="
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"uri": "/dbs/test-cosmos-db-udf/colls/test-udf/udfs",
"method": "GET",
"headers": {
"authorization": "<<STRIPPED>>",
"user-agent": "azsdk-rust-data_cosmos/0.4.0 (1.62.1; linux; x86_64)",
"x-ms-consistency-level": "Session",
"x-ms-date": "Tue, 09 Aug 2022 09:29:26 GMT",
"x-ms-max-item-count": "3",
"x-ms-session-token": "0:-1#2",
"x-ms-version": "2018-12-31"
},
"body": ""
}
Loading