volcengine_rust_sdk/service/vpc/
service_vpc.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-29 17:29:44
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-06 14:38:16
6 * @Description: Implementation of the VPC service, providing methods for managing VPCs and subnets.
7 */
8use super::{Vpc, VpcService};
9use crate::service::vpc::api_describe_subnets;
10use crate::service::vpc::api_describe_vpcs;
11use crate::volcengine::client::client;
12use crate::volcengine::client::client_info;
13use crate::volcengine::client::config as client_config;
14use crate::volcengine::common;
15use crate::volcengine::error::error;
16use crate::volcengine::request::handles;
17use crate::volcengine::session::session;
18
19/// Implementation of the VpcService trait for the Vpc struct.
20/// This implementation provides the necessary logic to interact with the Volcengine VPC service,
21/// including creating a new VPC service instance, describing VPCs, and describing subnets.
22impl VpcService for Vpc {
23    /// Creates a new VPC service instance from a given session.
24    ///
25    /// # Arguments
26    /// - `session`: The session object containing the necessary configuration and credentials.
27    ///
28    /// # Returns
29    /// - `Result<Self, error::Error>`: On success, returns a new instance of the Vpc struct.
30    ///   On failure, returns an error indicating the cause of the failure.
31    fn new_vpc(session: session::Session) -> Result<Self, error::Error> {
32        // Create a new client configuration for the VPC service.
33        let client_config = session.new_client_config(client_config::ClientServiceName::Vpc);
34
35        // Build the client information with the required parameters.
36        let client_info = client_info::ClientInfo::builder()
37            .with_service_name(client_config::ClientServiceName::Vpc)
38            .with_api_version(common::COMMON_VERSION_2020_04_01)
39            .with_signing_region(&client_config.signing_region)
40            .build()?;
41
42        // Initialize the request handles.
43        let request_handles = handles::Handles {};
44
45        // Build the client with the provided information.
46        let client = client::Client::builder()
47            .with_client_info(&client_info)
48            .with_config(&client_config)
49            .with_handles(&request_handles)
50            .build()?;
51
52        // Return the new VPC service instance.
53        Ok(Vpc { client: client })
54    }
55
56    /// Describes VPCs.
57    ///
58    /// # Arguments
59    /// - `&self`: Reference to the current VPC service instance.
60    /// - `request`: The request structure containing the parameters for describing VPCs.
61    ///
62    /// # Returns
63    /// - `Result<volcengine_sdk_protobuf::protobuf::vpc_vpc::DescribeVpcsResp, error::Error>`: On success, returns the response from the VPC service.
64    ///   On failure, returns an error indicating the cause of the failure.
65    async fn new_describe_vpcs(
66        &self,
67        request: volcengine_sdk_protobuf::protobuf::vpc_vpc::DescribeVpcsReq,
68    ) -> Result<volcengine_sdk_protobuf::protobuf::vpc_vpc::DescribeVpcsResp, error::Error> {
69        api_describe_vpcs::ApiDescribeVpcsVpc
70            .new_describe_vpcs(self, request)
71            .await
72    }
73
74    /// Describes VPC subnets.
75    ///
76    /// # Arguments
77    /// - `&self`: Reference to the current VPC service instance.
78    /// - `request`: The request structure containing the parameters for describing VPC subnets.
79    ///
80    /// # Returns
81    /// - `Result<volcengine_sdk_protobuf::protobuf::vpc_subnet::DescribeSubnetsResp, error::Error>`: On success, returns the response from the VPC service.
82    ///   On failure, returns an error indicating the cause of the failure.
83    async fn new_describe_subnets(
84        &self,
85        request: volcengine_sdk_protobuf::protobuf::vpc_subnet::DescribeSubnetsReq,
86    ) -> Result<volcengine_sdk_protobuf::protobuf::vpc_subnet::DescribeSubnetsResp, error::Error>
87    {
88        api_describe_subnets::ApiDescribeSubnetsVpc
89            .new_describe_subnets(self, request)
90            .await
91    }
92}