volcengine_rust_sdk/service/iam/
api_list_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:41:54
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 listing policies in the IAM (Identity and Access Management) service.
18/// This struct provides methods to perform operations related to retrieving a list of policies.
19pub struct ApiListPolicyIam;
20
21/// Implementation of methods for the `ApiListPolicyIam` struct.
22/// These methods are used to create and send requests for listing policies in the IAM service.
23impl ApiListPolicyIam {
24    /// Creates a new API call to list policies.
25    ///
26    /// # Arguments
27    /// - `&self`: A reference to the `ApiListPolicyIam` instance.
28    /// - `iam`: A reference to the `Iam` service instance.
29    /// - `request`: A `ListPoliciesReq` struct containing the request details for listing policies.
30    ///
31    /// # Returns
32    /// - On success, returns a `ListPoliciesResp` struct containing the response details.
33    /// - On error, returns an `Error` struct indicating the reason for the failure.
34    pub async fn new_list_policy(
35        &self,
36        iam: &iam::Iam,
37        request: iam_policy::ListPoliciesReq,
38    ) -> Result<iam_policy::ListPoliciesResp, error::Error> {
39        self.new_list_policy_request(iam, request).await
40    }
41
42    /// Creates and sends a new API request to list policies.
43    ///
44    /// # Arguments
45    /// - `&self`: A reference to the `ApiListPolicyIam` instance.
46    /// - `iam`: A reference to the `Iam` service instance.
47    /// - `request`: A `ListPoliciesReq` struct containing the request details for listing policies.
48    ///
49    /// # Returns
50    /// - On success, returns a `ListPoliciesResp` struct containing the response details.
51    /// - On error, returns an `Error` struct indicating the reason for the failure.
52    async fn new_list_policy_request(
53        &self,
54        iam: &iam::Iam,
55        request: iam_policy::ListPoliciesReq,
56    ) -> Result<iam_policy::ListPoliciesResp, error::Error> {
57        // Define the request operation
58        // Set the operation name, HTTP method, and HTTP path for the request
59        let request_operation = operation::Operation::builder()
60            .with_operation_name(
61                operation_config::operation_name::OperationName::IamOperation(
62                    operation_config::operation_name_iam::OperationNameIam::ListPolicies,
63                ),
64            )
65            .with_operation_http_method(
66                operation_config::operation_http_method::OperationHttpMethod::GET,
67            )
68            .with_operation_http_path(
69                operation_config::operation_http_path::OperationHttpPath::Default,
70            )
71            .build()?;
72
73        // Set up the request and send it
74        // Build the request with client information, configuration, handles, and operation details
75        // Then send the request, parse the JSON response, and handle any errors that occur during the process
76        let response = request::Request::builder()
77            .with_client_info(&iam.client.client_info)
78            .with_config(&iam.client.config)
79            .with_handles(&iam.client.handles)
80            .with_operation(&request_operation)
81            .build()?
82            .send(request)
83            .await?;
84
85        // Convert the response into a structured format defined by the SDK's protobuf definitions.
86        // Initialize a default response structure for load balancer descriptions.
87        let mut resp = volcengine_sdk_protobuf::protobuf::iam_policy::ListPoliciesResp::default();
88        // Populate the response structure with data from the actual response.
89        resp.to_struct(response).await?;
90        // Return the structured response successfully.
91        return Ok(resp);
92    }
93}