volcengine_rust_sdk/service/redis/
api_modify_allow_list.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-11-07 15:59:33
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-19 14:31:42
6 * @Description: API for modifying the allow list of a Redis database instance.
7 */
8use crate::service::redis;
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::redis_allow;
16
17/// A struct representing the API for modifying the allow list of a Redis database instance.
18/// This struct encapsulates the functionality required to send a request to the Volcengine Redis service
19/// to modify the allow list of a specific Redis database instance.
20pub struct ApiModifyAllowListRedis;
21
22/// Implementation of methods for the `ApiModifyAllowListRedis` struct.
23/// This implementation provides the necessary logic to construct and send a request to the Volcengine Redis service
24/// to modify the allow list of a Redis database instance, as well as handle the response.
25impl ApiModifyAllowListRedis {
26    /// Public method to modify the allow list of a Redis database instance.
27    ///
28    /// # Arguments
29    /// - `&self`: Reference to the current instance of `ApiModifyAllowListRedis`.
30    /// - `redis`: Reference to a `Redis` instance, which contains client information, configuration, and handles.
31    /// - `request`: A `ModifyAllowListReq` structure containing the request parameters.
32    ///
33    /// # Returns
34    /// - `Result<redis_allow::ModifyAllowListResp, error::Error>`: On success, returns a `ModifyAllowListResp` structure containing the response from the Redis service.
35    ///   On failure, returns an `error::Error` indicating the cause of the failure.
36    pub async fn new_modify_allow_list(
37        &self,
38        redis: &redis::Redis,
39        request: redis_allow::RedisModifyAllowListReq,
40    ) -> Result<redis_allow::RedisModifyAllowListResp, error::Error> {
41        // Delegate the request handling to the private method `new_modify_allow_list_request`.
42        self.new_modify_allow_list_request(redis, request).await
43    }
44
45    /// Private method to handle the request to modify the allow list of a Redis database instance.
46    ///
47    /// This method constructs the request operation, builds the request, sends it to the Volcengine Redis service,
48    /// and parses the response.
49    ///
50    /// # Arguments
51    /// - `&self`: Reference to the current instance of `ApiModifyAllowListRedis`.
52    /// - `redis`: Reference to a `Redis` instance, which contains client information, configuration, and handles.
53    /// - `request`: A `ModifyAllowListReq` structure containing the request parameters.
54    ///
55    /// # Returns
56    /// - `Result<redis_allow::ModifyAllowListResp, error::Error>`: On success, returns a `ModifyAllowListResp` structure containing the response from the Redis service.
57    ///   On failure, returns an `error::Error` indicating the cause of the failure.
58    async fn new_modify_allow_list_request(
59        &self,
60        redis: &redis::Redis,
61        request: redis_allow::RedisModifyAllowListReq,
62    ) -> Result<redis_allow::RedisModifyAllowListResp, error::Error> {
63        // Define the request operation with the specific operation name, HTTP method, and path.
64        // The operation name corresponds to the "ModifyAllowList" action in the Volcengine Redis service.
65        let request_operation = operation::Operation::builder()
66            .with_operation_name(
67                operation_config::operation_name::OperationName::RedisOperation(
68                    operation_config::operation_name_redis::OperationNameRedis::ModifyAllowList,
69                ),
70            )
71            .with_operation_http_method(
72                operation_config::operation_http_method::OperationHttpMethod::POST,
73            )
74            .with_operation_http_path(
75                operation_config::operation_http_path::OperationHttpPath::Default,
76            )
77            .build()?;
78
79        // Build the Volcengine request using the client information, configuration, handles, and the defined operation.
80        let response = request::Request::builder()
81            .with_client_info(&redis.client.client_info)
82            .with_config(&redis.client.config)
83            .with_handles(&redis.client.handles)
84            .with_operation(&request_operation)
85            .build()?
86            .send(request)
87            .await?;
88
89        // Convert the response into a structured format defined by the SDK's protobuf definitions.
90        // Initialize a default response structure for load balancer descriptions.
91        let mut resp =
92            volcengine_sdk_protobuf::protobuf::redis_allow::RedisModifyAllowListResp::default();
93        // Populate the response structure with data from the actual response.
94        resp.to_struct(response).await?;
95        // Return the structured response successfully.
96        return Ok(resp);
97    }
98}