volcengine_rust_sdk/volcengine/client/config.rs
1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-18 10:33:04
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-05 14:16:56
6 * @Description: Client configuration for Volcengine API
7 */
8use crate::volcengine::config;
9use crate::volcengine::request::handles;
10
11/// Struct representing the client configuration for accessing Volcengine services.
12///
13/// This struct holds the configuration settings necessary to interact with various
14/// Volcengine services, including authentication information, request handling,
15/// endpoint URL, and region-specific details for signing requests.
16///
17/// The `Config` struct is crucial for managing connections to Volcengine APIs and
18/// contains all required settings to authenticate and make requests to the desired service.
19///
20/// # Fields:
21/// - `config`: Holds the detailed configuration required for authentication and other settings.
22/// - `handles`: Manages the handles or sessions for handling requests to the Volcengine services.
23/// - `endpoint`: The URL of the service endpoint for accessing the service.
24/// - `signing_region`: The region to be used for signing API requests.
25/// - `signing_name`: The name of the service to be used for signing the requests.
26/// - `signing_name_derived`: A flag indicating whether the signing name is derived from metadata or explicitly modeled.
27#[derive(Debug, Clone)]
28pub struct Config {
29 /// The configuration details for the client, including authentication and settings.
30 pub config: config::Config,
31
32 /// Handles associated with the client, likely for request handling or session management.
33 pub handles: handles::Handles,
34
35 /// The endpoint URL for the specific Volcengine service.
36 pub endpoint: String,
37
38 /// The region used for signing requests.
39 pub signing_region: String,
40
41 /// The service name used for signing requests.
42 pub signing_name: String,
43
44 /// A flag indicating whether the signing name was derived from metadata
45 /// but was not explicitly modeled in the service configuration.
46 pub signing_name_derived: bool,
47}
48
49/// Enum representing the available service names for the Volcengine API client.
50///
51/// This enum is used to define the different services that are accessible through
52/// the Volcengine API, including services such as IAM, ECS, VPC, RDS, Redis, and CLB.
53/// Each variant represents a distinct service that can be used by the API client
54/// to make requests to the corresponding Volcengine API endpoint.
55///
56/// # Variants:
57/// - `Iam`: The Identity and Access Management (IAM) service.
58/// - `Ecs`: The Elastic Compute Service (ECS).
59/// - `Vpc`: The Virtual Private Cloud (VPC) service.
60/// - `Rds`: The Relational Database Service (RDS) for MySQL-based databases.
61/// - `Redis`: The Redis service.
62/// - `Clb`: The Cloud Load Balancer (CLB) service.
63#[derive(Debug, Clone)]
64pub enum ClientServiceName {
65 Iam, // Identity and Access Management (IAM) service
66 Ecs, // Elastic Compute Service (ECS) service
67 Vpc, // Virtual Private Cloud (VPC) service
68 Rds, // Relational Database Service (RDS) - specifically MySQL
69 Redis, // Redis service
70 Clb, // CLB service
71}
72
73/**
74 * Implementation block for the `ClientServiceName` enum.
75 * This block contains methods that provide functionality
76 * for working with the `ClientServiceName` enum.
77 * @author: Jerry.Yang
78 * @date: 2024-11-08 11:00:02
79 * @return: None
80 */
81impl ClientServiceName {
82 /// Converts the `ClientServiceName` enum variant to a string representation.
83 ///
84 /// This method returns a string slice (`&str`) that corresponds to the service name
85 /// associated with the specific `ClientServiceName` variant. This is useful for
86 /// easily converting the enum variant into a string that can be used for making
87 /// API requests, logging, or other purposes where a string representation of the
88 /// service name is required.
89 ///
90 /// # Returns
91 /// Returns a `&str` representing the service name in lowercase.
92 ///
93 /// # Example
94 /// ```rust
95 /// let service_name = ClientServiceName::Iam.as_str();
96 /// assert_eq!(service_name, "iam");
97 /// ```
98 pub fn as_str(&self) -> &str {
99 match self {
100 ClientServiceName::Iam => "iam", // IAM service
101 ClientServiceName::Ecs => "ecs", // ECS service
102 ClientServiceName::Vpc => "vpc", // VPC service
103 ClientServiceName::Rds => "rds_mysql", // MySQL-based RDS service
104 ClientServiceName::Redis => "redis", // Redis service
105 ClientServiceName::Clb => "clb", // CLB service
106 }
107 }
108}