volcengine_rust_sdk/service/iam/
api_create_login_profile.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-11-07 14:39:42
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-19 11:34:09
6 * @Description: api create login profile
7 */
8use crate::service::iam::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_user;
16
17/// Struct for creating a login profile in IAM.
18/// This struct encapsulates the logic for making API requests to create a login profile for an IAM user.
19pub struct ApiCreateLoginProfileIam;
20
21/// Implementation of methods for the ApiCreateLoginProfileIam struct.
22/// These methods handle the logic for creating a login profile, including constructing requests and processing responses.
23impl ApiCreateLoginProfileIam {
24    /// Creates a new API request to create a login profile for an IAM user.
25    /// This method is the primary entry point for initiating the login profile creation request.
26    ///
27    /// # Parameters:
28    /// - `&self`: A reference to the current instance of `ApiCreateLoginProfileIam`.
29    /// - `iam`: A reference to the `Iam` struct, which contains the necessary IAM client information.
30    /// - `request`: A `CreateLoginProfileReq` struct containing the parameters to create a login profile.
31    ///
32    /// # Returns:
33    /// A `Result` containing a `CreateLoginProfileResp` on success or an `error::Error` on failure.
34    pub async fn new_create_login_profile(
35        &self,
36        iam: &Iam,
37        request: iam_user::CreateLoginProfileReq,
38    ) -> Result<iam_user::CreateLoginProfileResp, error::Error> {
39        // Delegates the request creation and sending to the internal helper function.
40        self.new_create_login_profile_request(iam, request).await
41    }
42
43    /// Internal function to create and send the request to create a login profile for an IAM user.
44    /// This function constructs the request operation and sends it using the Volcengine request system.
45    ///
46    /// # Parameters:
47    /// - `&self`: A reference to the current instance of `ApiCreateLoginProfileIam`.
48    /// - `iam`: A reference to the `Iam` struct, which contains the necessary IAM client information.
49    /// - `request`: A `CreateLoginProfileReq` struct containing the parameters to create a login profile.
50    ///
51    /// # Returns:
52    /// A `Result` containing a `CreateLoginProfileResp` on success or an `error::Error` on failure.
53    async fn new_create_login_profile_request(
54        &self,
55        iam: &Iam,
56        request: iam_user::CreateLoginProfileReq,
57    ) -> Result<iam_user::CreateLoginProfileResp, error::Error> {
58        // Define the request operation with necessary configurations.
59        // The `operation_name` corresponds to the IAM "CreateLoginProfile" operation.
60        let request_operation = operation::Operation::builder()
61            .with_operation_name(
62                operation_config::operation_name::OperationName::IamOperation(
63                    operation_config::operation_name_iam::OperationNameIam::CreateLoginProfile,
64                ),
65            )
66            .with_operation_http_method(
67                operation_config::operation_http_method::OperationHttpMethod::GET,
68            )
69            .with_operation_http_path(
70                operation_config::operation_http_path::OperationHttpPath::Default,
71            )
72            .build()?; // Build the operation and return a Result
73
74        // Set up the request using the client information from the `iam` struct.
75        // The request is built with operation details and IAM client configuration.
76        // After that, the request is sent using the `send` method and the response is processed.
77        let response = request::Request::builder()
78            .with_client_info(&iam.client.client_info) // Attach client information (e.g., credentials)
79            .with_config(&iam.client.config) // Include configuration settings for the IAM client
80            .with_handles(&iam.client.handles) // Use the appropriate IAM client handles for this operation
81            .with_operation(&request_operation) // Attach the operation definition (CreateLoginProfile)
82            .build()? // Build the request
83            .send(request) // Send the request to IAM with the provided `CreateLoginProfileReq`
84            .await?;
85
86        // Convert the response into a structured format defined by the SDK's protobuf definitions.
87        // Initialize a default response structure for load balancer descriptions.
88        let mut resp =
89            volcengine_sdk_protobuf::protobuf::iam_user::CreateLoginProfileResp::default();
90        // Populate the response structure with data from the actual response.
91        resp.to_struct(response).await?;
92        // Return the structured response successfully.
93        return Ok(resp);
94    }
95}