diff --git a/sdk/cosmos/examples/permission_00.rs b/sdk/cosmos/examples/permission_00.rs index 879607c412..4b26743bc9 100644 --- a/sdk/cosmos/examples/permission_00.rs +++ b/sdk/cosmos/examples/permission_00.rs @@ -54,7 +54,9 @@ async fn main() -> Result<(), Box> { get_collection2_response ); - let create_user_response = user_client.create_user().execute().await?; + let create_user_response = user_client + .create_user(Context::new(), CreateUserOptions::default()) + .await?; println!("create_user_response == {:#?}", create_user_response); // create the first permission! diff --git a/sdk/cosmos/examples/user_00.rs b/sdk/cosmos/examples/user_00.rs index 6752134997..6afedd08cc 100644 --- a/sdk/cosmos/examples/user_00.rs +++ b/sdk/cosmos/examples/user_00.rs @@ -1,3 +1,4 @@ +use azure_core::Context; use azure_cosmos::prelude::*; use std::error::Error; @@ -27,18 +28,24 @@ async fn main() -> Result<(), Box> { let database_client = client.into_database_client(database_name); let user_client = database_client.clone().into_user_client(user_name.clone()); - let create_user_response = user_client.create_user().execute().await?; + let create_user_response = user_client + .create_user(Context::new(), CreateUserOptions::new()) + .await?; println!("create_user_response == {:#?}", create_user_response); let list_users_response = database_client.list_users().execute().await?; println!("list_users_response == {:#?}", list_users_response); - let get_user_response = user_client.get_user().execute().await?; + let get_user_response = user_client + .get_user(Context::new(), GetUserOptions::new()) + .await?; println!("get_user_response == {:#?}", get_user_response); let new_user = format!("{}replaced", user_name); - let replace_user_response = user_client.replace_user().execute(&new_user).await?; + let replace_user_response = user_client + .replace_user(Context::new(), &new_user, ReplaceUserOptions::new()) + .await?; println!("replace_user_response == {:#?}", replace_user_response); let user_client = database_client.into_user_client(new_user); diff --git a/sdk/cosmos/examples/user_permission_token.rs b/sdk/cosmos/examples/user_permission_token.rs index 9a03f69cb0..d987c2c786 100644 --- a/sdk/cosmos/examples/user_permission_token.rs +++ b/sdk/cosmos/examples/user_permission_token.rs @@ -1,3 +1,4 @@ +use azure_core::Context; use azure_cosmos::prelude::*; use std::error::Error; @@ -36,7 +37,9 @@ async fn main() -> Result<(), Box> { let get_collection_response = collection_client.get_collection().execute().await?; println!("get_collection_response == {:#?}", get_collection_response); - let create_user_response = user_client.create_user().execute().await?; + let create_user_response = user_client + .create_user(Context::new(), CreateUserOptions::default()) + .await?; println!("create_user_response == {:#?}", create_user_response); // test list documents diff --git a/sdk/cosmos/src/clients/user_client.rs b/sdk/cosmos/src/clients/user_client.rs index f0cdb90adc..63d0c839da 100644 --- a/sdk/cosmos/src/clients/user_client.rs +++ b/sdk/cosmos/src/clients/user_client.rs @@ -1,7 +1,10 @@ use super::*; +use crate::authorization_policy::CosmosContext; +use crate::prelude::*; use crate::resources::ResourceType; use crate::{requests, ReadonlyString}; -use azure_core::HttpClient; +use azure_core::PipelineContext; +use azure_core::{pipeline::Pipeline, Context, HttpClient}; /// A client for Cosmos user resources. #[derive(Debug, Clone)] @@ -37,18 +40,81 @@ impl UserClient { } /// Create the user - pub fn create_user(&self) -> requests::CreateUserBuilder<'_, '_> { - requests::CreateUserBuilder::new(self) + pub async fn create_user( + &self, + ctx: Context, + options: CreateUserOptions, + ) -> Result { + let mut request = self.cosmos_client().prepare_request_pipeline( + &format!("dbs/{}/users", self.database_client.database_name()), + http::Method::POST, + ); + let mut pipeline_context = PipelineContext::new(ctx, ResourceType::Users.into()); + + options.decorate_request(&mut request, self.user_name())?; + let response = self + .pipeline() + .send(&mut pipeline_context, &mut request) + .await? + .validate(http::StatusCode::CREATED) + .await?; + + Ok(CreateUserResponse::try_from(response).await?) } /// Get the user - pub fn get_user(&self) -> requests::GetUserBuilder<'_, '_> { - requests::GetUserBuilder::new(self) + pub async fn get_user( + &self, + ctx: Context, + options: GetUserOptions, + ) -> Result { + let mut request = self.cosmos_client().prepare_request_pipeline( + &format!( + "dbs/{}/users/{}", + self.database_client.database_name(), + self.user_name + ), + http::Method::GET, + ); + let mut pipeline_context = PipelineContext::new(ctx, ResourceType::Users.into()); + + options.decorate_request(&mut request)?; + let response = self + .pipeline() + .send(&mut pipeline_context, &mut request) + .await? + .validate(http::StatusCode::OK) + .await?; + + Ok(GetUserResponse::try_from(response).await?) } /// Replace the user - pub fn replace_user(&self) -> requests::ReplaceUserBuilder<'_, '_> { - requests::ReplaceUserBuilder::new(self) + pub async fn replace_user>( + &self, + ctx: Context, + user_name: S, + options: ReplaceUserOptions, + ) -> Result { + let mut request = self.cosmos_client().prepare_request_pipeline( + &format!( + "dbs/{}/users/{}", + self.database_client.database_name(), + self.user_name + ), + http::Method::PUT, + ); + let mut pipeline_context = PipelineContext::new(ctx, ResourceType::Users.into()); + + options.decorate_request(&mut request, user_name.as_ref())?; + let response = self + .pipeline() + .send(&mut pipeline_context, &mut request) + .await? + .validate(http::StatusCode::OK) + .await?; + + Ok(ReplaceUserResponse::try_from(response).await?) } /// Delete the user @@ -69,14 +135,6 @@ impl UserClient { PermissionClient::new(self, permission_name) } - pub(crate) fn prepare_request(&self, method: http::Method) -> http::request::Builder { - self.cosmos_client().prepare_request( - &format!("dbs/{}/users", self.database_client().database_name()), - method, - ResourceType::Users, - ) - } - pub(crate) fn prepare_request_with_user_name( &self, method: http::Method, @@ -95,4 +153,8 @@ impl UserClient { pub(crate) fn http_client(&self) -> &dyn HttpClient { self.cosmos_client().http_client() } + + fn pipeline(&self) -> &Pipeline { + self.cosmos_client().pipeline() + } } diff --git a/sdk/cosmos/src/consistency_level.rs b/sdk/cosmos/src/consistency_level.rs index 20576e6723..be15965001 100644 --- a/sdk/cosmos/src/consistency_level.rs +++ b/sdk/cosmos/src/consistency_level.rs @@ -1,4 +1,5 @@ use crate::headers; +use crate::operations::CreateUserResponse; use crate::responses::*; use azure_core::AddAsHeader; use http::request; diff --git a/sdk/cosmos/src/operations/create_user.rs b/sdk/cosmos/src/operations/create_user.rs new file mode 100644 index 0000000000..2c6d038b95 --- /dev/null +++ b/sdk/cosmos/src/operations/create_user.rs @@ -0,0 +1,64 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use azure_core::{ + collect_pinned_stream, + headers::{etag_from_headers, session_token_from_headers}, + Request as HttpRequest, Response as HttpResponse, +}; + +#[derive(Debug, Clone, Default)] +pub struct CreateUserOptions { + consistency_level: Option, +} + +impl CreateUserOptions { + pub fn new() -> Self { + Self { + consistency_level: None, + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + } + + pub(crate) fn decorate_request( + &self, + request: &mut HttpRequest, + user_name: &str, + ) -> Result<(), crate::Error> { + azure_core::headers::add_optional_header2(&self.consistency_level, request)?; + let body = CreateUserBody { id: user_name }; + request.set_body(bytes::Bytes::from(serde_json::to_string(&body)?).into()); + Ok(()) + } +} + +#[derive(Serialize, Debug)] +struct CreateUserBody<'a> { + id: &'a str, +} + +#[derive(Debug, Clone)] +pub struct CreateUserResponse { + pub user: User, + pub charge: f64, + pub activity_id: uuid::Uuid, + pub etag: String, + pub session_token: String, +} + +impl CreateUserResponse { + pub async fn try_from(response: HttpResponse) -> Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + Ok(Self { + user: serde_json::from_slice(&body)?, + charge: request_charge_from_headers(&headers)?, + activity_id: activity_id_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + }) + } +} diff --git a/sdk/cosmos/src/operations/get_user.rs b/sdk/cosmos/src/operations/get_user.rs new file mode 100644 index 0000000000..5561e07e72 --- /dev/null +++ b/sdk/cosmos/src/operations/get_user.rs @@ -0,0 +1,55 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use azure_core::{ + collect_pinned_stream, + headers::{etag_from_headers, session_token_from_headers}, + Request as HttpRequest, Response as HttpResponse, +}; + +#[derive(Debug, Clone, Default)] +pub struct GetUserOptions { + consistency_level: Option, +} + +impl GetUserOptions { + pub fn new() -> Self { + Self { + consistency_level: None, + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + } + + pub(crate) fn decorate_request(&self, request: &mut HttpRequest) -> Result<(), crate::Error> { + azure_core::headers::add_optional_header2(&self.consistency_level, request)?; + request.set_body(bytes::Bytes::from_static(&[]).into()); + + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct GetUserResponse { + pub user: User, + pub charge: f64, + pub activity_id: uuid::Uuid, + pub etag: String, + pub session_token: String, +} + +impl GetUserResponse { + pub async fn try_from(response: HttpResponse) -> Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + Ok(Self { + user: serde_json::from_slice(&body)?, + charge: request_charge_from_headers(&headers)?, + activity_id: activity_id_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + }) + } +} diff --git a/sdk/cosmos/src/operations/mod.rs b/sdk/cosmos/src/operations/mod.rs index 803a0e7656..75cee1d409 100644 --- a/sdk/cosmos/src/operations/mod.rs +++ b/sdk/cosmos/src/operations/mod.rs @@ -4,8 +4,14 @@ mod create_collection; mod create_database; +mod create_user; mod get_database; +mod get_user; +mod replace_user; pub use create_collection::*; pub use create_database::*; +pub use create_user::*; pub use get_database::*; +pub use get_user::*; +pub use replace_user::*; diff --git a/sdk/cosmos/src/operations/replace_user.rs b/sdk/cosmos/src/operations/replace_user.rs new file mode 100644 index 0000000000..9ca0519b89 --- /dev/null +++ b/sdk/cosmos/src/operations/replace_user.rs @@ -0,0 +1,65 @@ +use crate::headers::from_headers::*; +use crate::prelude::*; +use azure_core::{ + collect_pinned_stream, + headers::{etag_from_headers, session_token_from_headers}, + Request as HttpRequest, Response as HttpResponse, +}; + +#[derive(Debug, Clone, Default)] +pub struct ReplaceUserOptions { + consistency_level: Option, +} + +impl ReplaceUserOptions { + pub fn new() -> Self { + Self { + consistency_level: None, + } + } + + setters! { + consistency_level: ConsistencyLevel => Some(consistency_level), + } + + pub(crate) fn decorate_request( + &self, + request: &mut HttpRequest, + user_name: &str, + ) -> Result<(), crate::Error> { + azure_core::headers::add_optional_header2(&self.consistency_level, request)?; + let body = ReplaceUserBody { id: user_name }; + request.set_body(bytes::Bytes::from(serde_json::to_string(&body)?).into()); + + Ok(()) + } +} + +#[derive(Debug, Clone)] +pub struct ReplaceUserResponse { + pub user: User, + pub charge: f64, + pub activity_id: uuid::Uuid, + pub etag: String, + pub session_token: String, +} + +impl ReplaceUserResponse { + pub async fn try_from(response: HttpResponse) -> Result { + let (_status_code, headers, pinned_stream) = response.deconstruct(); + let body = collect_pinned_stream(pinned_stream).await?; + + Ok(Self { + user: serde_json::from_slice(&body)?, + charge: request_charge_from_headers(&headers)?, + activity_id: activity_id_from_headers(&headers)?, + session_token: session_token_from_headers(&headers)?, + etag: etag_from_headers(&headers)?, + }) + } +} + +#[derive(Serialize)] +struct ReplaceUserBody<'a> { + id: &'a str, +} diff --git a/sdk/cosmos/src/requests/create_user_builder.rs b/sdk/cosmos/src/requests/create_user_builder.rs deleted file mode 100644 index 7c76c25abf..0000000000 --- a/sdk/cosmos/src/requests/create_user_builder.rs +++ /dev/null @@ -1,61 +0,0 @@ -use crate::prelude::*; -use crate::responses::CreateUserResponse; -use azure_core::prelude::*; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct CreateUserBuilder<'a, 'b> { - user_client: &'a UserClient, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> CreateUserBuilder<'a, 'b> { - pub(crate) fn new(user_client: &'a UserClient) -> Self { - Self { - user_client, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } - - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } - - pub async fn execute(&self) -> Result { - trace!("CreateUserBuilder::execute called"); - - let req = self.user_client.prepare_request(http::Method::POST); - - let req = azure_core::headers::add_optional_header(&self.user_agent, req); - let req = azure_core::headers::add_optional_header(&self.activity_id, req); - let req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - let req = req.header(http::header::CONTENT_TYPE, "application/json"); - - #[derive(Serialize, Deserialize)] - struct RequestBody<'x> { - id: &'x str, - } - let request_body = RequestBody { - id: self.user_client.user_name(), - }; - let request_body = azure_core::to_json(&request_body)?; - - let req = req.body(request_body)?; - debug!("\nreq == {:?}", req); - - Ok(self - .user_client - .http_client() - .execute_request_check_status(req, StatusCode::CREATED) - .await? - .try_into()?) - } -} diff --git a/sdk/cosmos/src/requests/get_user_builder.rs b/sdk/cosmos/src/requests/get_user_builder.rs deleted file mode 100644 index 965fd473f3..0000000000 --- a/sdk/cosmos/src/requests/get_user_builder.rs +++ /dev/null @@ -1,57 +0,0 @@ -use crate::prelude::*; -use crate::responses::CreateUserResponse; -use azure_core::prelude::*; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct GetUserBuilder<'a, 'b> { - user_client: &'a UserClient, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> GetUserBuilder<'a, 'b> { - pub(crate) fn new(user_client: &'a UserClient) -> GetUserBuilder<'a, 'b> { - Self { - user_client, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } - - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } - - pub async fn execute(&self) -> Result, crate::Error> { - trace!("GetUserBuilder::execute called"); - - let req = self - .user_client - .prepare_request_with_user_name(http::Method::GET); - - let req = azure_core::headers::add_optional_header(&self.user_agent, req); - let req = azure_core::headers::add_optional_header(&self.activity_id, req); - let req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - let req = req.body(bytes::Bytes::from_static(EMPTY_BODY))?; - debug!("\nreq == {:?}", req); - - let response = self - .user_client - .http_client() - .execute_request_check_statuses(req, &[StatusCode::NOT_FOUND, StatusCode::OK]) - .await?; - - match response.status() { - StatusCode::NOT_FOUND => Ok(None), - StatusCode::OK => Ok(Some(response.try_into()?)), - _ => unreachable!(), - } - } -} diff --git a/sdk/cosmos/src/requests/mod.rs b/sdk/cosmos/src/requests/mod.rs index 8a6645a0b3..f69ab4b164 100644 --- a/sdk/cosmos/src/requests/mod.rs +++ b/sdk/cosmos/src/requests/mod.rs @@ -13,7 +13,6 @@ mod create_permission_builder; mod create_reference_attachment_builder; mod create_slug_attachment_builder; mod create_stored_procedure_builder; -mod create_user_builder; mod delete_attachment_builder; mod delete_collection_builder; mod delete_database_builder; @@ -29,7 +28,6 @@ mod get_collection_builder; mod get_document_builder; mod get_partition_key_ranges_builder; mod get_permission_builer; -mod get_user_builder; mod list_attachments_builder; mod list_collections_builder; mod list_databases_builder; @@ -46,7 +44,6 @@ mod replace_permission_builder; mod replace_reference_attachment_builder; mod replace_slug_attachment_builder; mod replace_stored_procedure_builder; -mod replace_user_builder; pub use create_document_builder::CreateDocumentBuilder; pub use create_or_replace_trigger_builder::CreateOrReplaceTriggerBuilder; @@ -55,7 +52,6 @@ pub use create_permission_builder::CreatePermissionBuilder; pub use create_reference_attachment_builder::CreateReferenceAttachmentBuilder; pub use create_slug_attachment_builder::CreateSlugAttachmentBuilder; pub use create_stored_procedure_builder::CreateStoredProcedureBuilder; -pub use create_user_builder::CreateUserBuilder; pub use delete_attachment_builder::DeleteAttachmentBuilder; pub use delete_collection_builder::DeleteCollectionBuilder; pub use delete_database_builder::DeleteDatabaseBuilder; @@ -71,7 +67,6 @@ pub use get_collection_builder::GetCollectionBuilder; pub use get_document_builder::GetDocumentBuilder; pub use get_partition_key_ranges_builder::GetPartitionKeyRangesBuilder; pub use get_permission_builer::GetPermissionBuilder; -pub use get_user_builder::GetUserBuilder; pub use list_attachments_builder::ListAttachmentsBuilder; pub use list_collections_builder::ListCollectionsBuilder; pub use list_databases_builder::ListDatabasesBuilder; @@ -88,4 +83,3 @@ pub use replace_permission_builder::ReplacePermissionBuilder; pub use replace_reference_attachment_builder::ReplaceReferenceAttachmentBuilder; pub use replace_slug_attachment_builder::ReplaceSlugAttachmentBuilder; pub use replace_stored_procedure_builder::ReplaceStoredProcedureBuilder; -pub use replace_user_builder::ReplaceUserBuilder; diff --git a/sdk/cosmos/src/requests/replace_user_builder.rs b/sdk/cosmos/src/requests/replace_user_builder.rs deleted file mode 100644 index 53adec5e63..0000000000 --- a/sdk/cosmos/src/requests/replace_user_builder.rs +++ /dev/null @@ -1,73 +0,0 @@ -use crate::prelude::*; -use crate::responses::CreateUserResponse; -use azure_core::prelude::*; -use http::StatusCode; -use std::convert::TryInto; - -#[derive(Debug, Clone)] -pub struct ReplaceUserBuilder<'a, 'b> { - user_client: &'a UserClient, - user_agent: Option>, - activity_id: Option>, - consistency_level: Option, -} - -impl<'a, 'b> ReplaceUserBuilder<'a, 'b> { - pub(crate) fn new(user_client: &'a UserClient) -> ReplaceUserBuilder<'a, 'b> { - Self { - user_client, - user_agent: None, - activity_id: None, - consistency_level: None, - } - } -} - -impl<'a, 'b> ReplaceUserBuilder<'a, 'b> { - setters! { - user_agent: &'b str => Some(UserAgent::new(user_agent)), - activity_id: &'b str => Some(ActivityId::new(activity_id)), - consistency_level: ConsistencyLevel => Some(consistency_level), - } -} - -impl<'a, 'b> ReplaceUserBuilder<'a, 'b> { - pub async fn execute>( - &self, - user_name: U, - ) -> Result, crate::Error> { - trace!("ReplaceUserBuilder::execute called"); - - let req = self - .user_client - .prepare_request_with_user_name(http::Method::PUT); - - let req = azure_core::headers::add_optional_header(&self.user_agent, req); - let req = azure_core::headers::add_optional_header(&self.activity_id, req); - let req = azure_core::headers::add_optional_header(&self.consistency_level, req); - - #[derive(Serialize)] - struct RequestBody<'x> { - id: &'x str, - } - let request_body = RequestBody { - id: user_name.as_ref(), - }; - let request_body = azure_core::to_json(&request_body)?; - - let req = req.body(request_body)?; - debug!("\nreq == {:?}", req); - - let response = self - .user_client - .http_client() - .execute_request_check_statuses(req, &[StatusCode::OK, StatusCode::NOT_FOUND]) - .await?; - - match response.status() { - StatusCode::NOT_FOUND => Ok(None), - StatusCode::OK => Ok(Some(response.try_into()?)), - _ => unreachable!(), - } - } -} diff --git a/sdk/cosmos/src/responses/create_user_response.rs b/sdk/cosmos/src/responses/create_user_response.rs deleted file mode 100644 index 0659fa60ec..0000000000 --- a/sdk/cosmos/src/responses/create_user_response.rs +++ /dev/null @@ -1,31 +0,0 @@ -use crate::headers::from_headers::*; -use crate::resources::User; -use azure_core::headers::{etag_from_headers, session_token_from_headers}; -use http::response::Response; -use std::convert::TryInto; - -#[derive(Debug, Clone, PartialEq)] -pub struct CreateUserResponse { - pub user: User, - pub charge: f64, - pub activity_id: uuid::Uuid, - pub etag: String, - pub session_token: String, -} - -impl std::convert::TryFrom> for CreateUserResponse { - type Error = crate::Error; - - fn try_from(response: Response) -> Result { - let headers = response.headers(); - let body: &[u8] = response.body(); - - Ok(Self { - user: body.try_into()?, - charge: request_charge_from_headers(headers)?, - activity_id: activity_id_from_headers(headers)?, - etag: etag_from_headers(headers)?, - session_token: session_token_from_headers(headers)?, - }) - } -} diff --git a/sdk/cosmos/src/responses/mod.rs b/sdk/cosmos/src/responses/mod.rs index 0cc2ab37b6..b93f547df9 100644 --- a/sdk/cosmos/src/responses/mod.rs +++ b/sdk/cosmos/src/responses/mod.rs @@ -10,7 +10,6 @@ mod create_slug_attachment_response; mod create_stored_procedure_response; mod create_trigger_response; mod create_user_defined_function_response; -mod create_user_response; mod delete_attachment_response; mod delete_collection_response; mod delete_database_response; @@ -49,7 +48,6 @@ pub use create_slug_attachment_response::CreateSlugAttachmentResponse; pub use create_stored_procedure_response::CreateStoredProcedureResponse; pub use create_trigger_response::CreateTriggerResponse; pub use create_user_defined_function_response::CreateUserDefinedFunctionResponse; -pub use create_user_response::CreateUserResponse; pub use delete_attachment_response::DeleteAttachmentResponse; pub use delete_collection_response::DeleteCollectionResponse; pub use delete_database_response::DeleteDatabaseResponse; diff --git a/sdk/cosmos/tests/permission.rs b/sdk/cosmos/tests/permission.rs index 19d769a7b3..3f416f9492 100644 --- a/sdk/cosmos/tests/permission.rs +++ b/sdk/cosmos/tests/permission.rs @@ -1,5 +1,5 @@ #![cfg(all(test, feature = "test_e2e"))] -use azure_core::prelude::*; +use azure_core::Context; use azure_cosmos::prelude::*; mod setup; @@ -29,9 +29,15 @@ async fn permissions() { // create two users let user1_client = database_client.clone().into_user_client(USER_NAME1); - let _create_user_response = user1_client.create_user().execute().await.unwrap(); + let _create_user_response = user1_client + .create_user(Context::new(), CreateUserOptions::new()) + .await + .unwrap(); let user2_client = database_client.clone().into_user_client(USER_NAME2); - let _create_user_response = user2_client.create_user().execute().await.unwrap(); + let _create_user_response = user2_client + .create_user(Context::new(), CreateUserOptions::new()) + .await + .unwrap(); // create a temp collection let create_collection_response = database_client diff --git a/sdk/cosmos/tests/permission_token_usage.rs b/sdk/cosmos/tests/permission_token_usage.rs index f799c2de38..c0c239fe9d 100644 --- a/sdk/cosmos/tests/permission_token_usage.rs +++ b/sdk/cosmos/tests/permission_token_usage.rs @@ -1,5 +1,5 @@ #![cfg(all(test, feature = "test_e2e"))] -use azure_core::prelude::*; +use azure_core::Context; use azure_cosmos::prelude::*; use collection::*; use serde::{Deserialize, Serialize}; @@ -60,7 +60,10 @@ async fn permission_token_usage() { .unwrap(); let user_client = database_client.clone().into_user_client(USER_NAME); - user_client.create_user().execute().await.unwrap(); + user_client + .create_user(Context::new(), CreateUserOptions::new()) + .await + .unwrap(); // create the RO permission let permission_client = user_client.into_permission_client(PERMISSION); diff --git a/sdk/cosmos/tests/user.rs b/sdk/cosmos/tests/user.rs index 236ace5a44..5308d01451 100644 --- a/sdk/cosmos/tests/user.rs +++ b/sdk/cosmos/tests/user.rs @@ -1,5 +1,6 @@ #![cfg(all(test, feature = "test_e2e"))] +use azure_core::Context; use azure_cosmos::prelude::*; mod setup; @@ -25,19 +26,27 @@ async fn users() { let database_client = client.clone().into_database_client(DATABASE_NAME); let user_client = database_client.clone().into_user_client(USER_NAME); - let _create_user_response = user_client.create_user().execute().await.unwrap(); + let _create_user_response = user_client + .create_user(Context::new(), CreateUserOptions::new()) + .await + .unwrap(); let list_users_response = database_client.list_users().execute().await.unwrap(); assert_eq!(list_users_response.users.len(), 1); - let get_user_response = user_client.get_user().execute().await.unwrap(); - assert!(get_user_response.is_some()); + let get_user_response = user_client + .get_user(Context::new(), GetUserOptions::new()) + .await; + assert!(get_user_response.is_ok()); let retrieved_user = get_user_response.unwrap(); assert_eq!(retrieved_user.user.id, USER_NAME); let _replace_user_response = user_client - .replace_user() - .execute(USER_NAME_REPLACED) + .replace_user( + Context::new(), + USER_NAME_REPLACED, + ReplaceUserOptions::new(), + ) .await .unwrap();