1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
* @Author: Jerry.Yang
* @Date: 2024-11-05 10:47:46
* @LastEditors: Jerry.Yang
* @LastEditTime: 2025-02-19 14:24:42
* @Description: API endpoint to create a database endpoint.
*/
use crate::service::rds;
use crate::volcengine::error::error;
use crate::volcengine::request::operation;
use crate::volcengine::request::operation_config;
use crate::volcengine::request::request;
use crate::volcengine::request::request::RequestVolcengine;
use crate::volcengine::request::response::ApiResponse;
use volcengine_sdk_protobuf::protobuf::rds_endpoint;
/// `ApiCreateDbEndpointRds` is a struct designed to encapsulate the functionality
/// for creating a database endpoint in RDS (Relational Database Service).
/// This struct provides methods to interact with the Volcengine RDS service,
/// specifically for creating database endpoints.
pub struct ApiCreateDbEndpointRds;
/// Implementation of methods for the `ApiCreateDbEndpointRds` struct.
/// This `impl` block contains the logic for creating a database endpoint,
/// including defining the request operation, building the request,
/// sending it to the service, and parsing the response.
impl ApiCreateDbEndpointRds {
/// Public method to create a new database endpoint.
/// This method is intended to be called by external clients
/// to initiate the creation of a database endpoint.
///
/// # Arguments
/// - `&self`: Reference to the current instance.
/// - `rds`: Reference to an RDS instance (contains client configuration and handles).
/// - `request`: A Protobuf request structure for creating a database endpoint.
///
/// # Returns
/// Returns a Protobuf response structure if successful, or an error.
pub async fn new_create_db_endpoint(
&self,
rds: &rds::Rds,
request: rds_endpoint::CreateDbEndpointReq,
) -> Result<rds_endpoint::CreateDbEndpointResp, error::Error> {
// Delegate the request handling to the private method
self.new_create_db_endpoint_request(rds, request).await
}
/// Private method to handle the actual request to create a database endpoint.
/// This method is responsible for defining the request operation,
/// building the request, sending it to the service, and parsing the response.
///
/// # Arguments
/// - `&self`: Reference to the current instance.
/// - `rds`: Reference to an RDS instance (contains client configuration and handles).
/// - `request`: A Protobuf request structure for creating a database endpoint.
///
/// # Returns
/// Returns a Protobuf response structure if successful, or an error.
async fn new_create_db_endpoint_request(
&self,
rds: &rds::Rds,
request: rds_endpoint::CreateDbEndpointReq,
) -> Result<rds_endpoint::CreateDbEndpointResp, error::Error> {
// Define the request operation with specific HTTP method, path, and operation name
let request_operation = operation::Operation::builder()
.with_operation_name(
operation_config::operation_name::OperationName::RdsOperation(
operation_config::operation_name_rds::OperationNameRds::CreateDBEndpoint,
),
)
.with_operation_http_method(
operation_config::operation_http_method::OperationHttpMethod::POST,
)
.with_operation_http_path(
operation_config::operation_http_path::OperationHttpPath::Default,
)
.build()
.expect("Failed to build request operation"); // Ensure the operation is valid
// Build the Volcengine request using client information, configuration, handles, and the defined operation
let response = request::Request::builder()
.with_client_info(&rds.client.client_info) // Set client information
.with_config(&rds.client.config) // Set configuration
.with_handles(&rds.client.handles) // Set handles
.with_operation(&request_operation) // Set the operation
.build()?
.send(request)
.await?;
// Convert the response into a structured format defined by the SDK's protobuf definitions.
// Initialize a default response structure for load balancer descriptions.
let mut resp =
volcengine_sdk_protobuf::protobuf::rds_endpoint::CreateDbEndpointResp::default();
// Populate the response structure with data from the actual response.
resp.to_struct(response).await?;
// Return the structured response successfully.
return Ok(resp);
}
}