volcengine_rust_sdk/service/iam/api_detach_user_policy.rs
1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-11-06 10:56:34
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-19 11:37:57
6 * @Description: create policy
7 */
8use crate::service::iam;
9use crate::volcengine::error::error;
10use crate::volcengine::request::operation;
11use crate::volcengine::request::operation_config;
12use crate::volcengine::request::request;
13use crate::volcengine::request::request::RequestVolcengine;
14use crate::volcengine::request::response::ApiResponse;
15use volcengine_sdk_protobuf::protobuf::iam_policy;
16
17/// Represents an API for detaching a user policy in the IAM (Identity and Access Management) service.
18/// This struct provides methods to perform operations related to detaching user policies.
19pub struct ApiDetachUserPolicyIam;
20
21/// Implementation of methods for the `ApiDetachUserPolicyIam` struct.
22/// These methods are used to create and send requests for detaching user policies in the IAM service.
23impl ApiDetachUserPolicyIam {
24 /// Creates a new API call to detach a user policy.
25 ///
26 /// # Arguments
27 /// - `&self`: A reference to the `ApiDetachUserPolicyIam` instance.
28 /// - `iam`: A reference to the `Iam` service instance.
29 /// - `request`: A `DetachUserPolicyReq` struct containing the request details for detaching a user policy.
30 ///
31 /// # Returns
32 /// - On success, returns a `DetachUserPolicyResp` struct containing the response details.
33 /// - On error, returns an `Error` struct indicating the reason for the failure.
34 pub async fn new_detach_user_policy(
35 &self,
36 iam: &iam::Iam,
37 request: iam_policy::DetachUserPolicyReq,
38 ) -> Result<iam_policy::DetachUserPolicyResp, error::Error> {
39 self.new_detach_user_policy_request(iam, request).await
40 }
41
42 /// Creates and sends a new API request to detach a user policy.
43 ///
44 /// # Arguments
45 /// - `&self`: A reference to the `ApiDetachUserPolicyIam` instance.
46 /// - `iam`: A reference to the `Iam` service instance.
47 /// - `request`: A `DetachUserPolicyReq` struct containing the request details for detaching a user policy.
48 ///
49 /// # Returns
50 /// - On success, returns a `DetachUserPolicyResp` struct containing the response details.
51 /// - On error, returns an `Error` struct indicating the reason for the failure.
52 async fn new_detach_user_policy_request(
53 &self,
54 iam: &iam::Iam,
55 request: iam_policy::DetachUserPolicyReq,
56 ) -> Result<iam_policy::DetachUserPolicyResp, error::Error> {
57 // define request operation
58 let request_operation = operation::Operation::builder()
59 .with_operation_name(
60 operation_config::operation_name::OperationName::IamOperation(
61 operation_config::operation_name_iam::OperationNameIam::DetachUserPolicy,
62 ),
63 )
64 .with_operation_http_method(
65 operation_config::operation_http_method::OperationHttpMethod::GET,
66 )
67 .with_operation_http_path(
68 operation_config::operation_http_path::OperationHttpPath::Default,
69 )
70 .build()?;
71
72 // set request
73 // get volcengine_request
74 let response = request::Request::builder()
75 .with_client_info(&iam.client.client_info)
76 .with_config(&iam.client.config)
77 .with_handles(&iam.client.handles)
78 .with_operation(&request_operation)
79 .build()?
80 .send(request)
81 .await?;
82
83 // Convert the response into a structured format defined by the SDK's protobuf definitions.
84 // Initialize a default response structure for load balancer descriptions.
85 let mut resp =
86 volcengine_sdk_protobuf::protobuf::iam_policy::DetachUserPolicyResp::default();
87 // Populate the response structure with data from the actual response.
88 resp.to_struct(response).await?;
89 // Return the structured response successfully.
90 return Ok(resp);
91 }
92}