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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
* @Author: Jerry.Yang
* @Date: 2024-10-16 17:41:31
* @LastEditors: Jerry.Yang
* @LastEditTime: 2025-02-05 14:08:39
* @Description: Utility configuration for Volcengine.
*/
use cratecredentials; // Importing the Credentials struct
use crateerror; // Importing the custom Error type
/// Represents the configuration settings required for connecting to Volcengine services.
///
/// The `Config` struct holds essential parameters such as the service region, endpoint,
/// SSL settings, and authentication credentials. It is designed to be used with a builder
/// pattern (`ConfigBuilder`) to allow flexible and structured configuration.
///
/// # Fields
/// - `region` (`String`): Specifies the geographical region for the service.
/// - `endpoint` (`String`): The base URL of the API service. If manually set, this overrides
/// the default endpoint.
/// - `disable_ssl` (`bool`): Determines whether SSL/TLS is disabled.
/// - `true`: SSL is disabled (not recommended for production).
/// - `false`: SSL is enabled for secure communication.
/// - `credentials` (`credentials::Credentials`): Stores authentication credentials,
/// including access keys and secret keys, required for making API requests.
///
/// # Example
/// ```rust
/// let config = Config {
/// region: "us-west-2".to_string(),
/// endpoint: "https://api.volcengine.com".to_string(),
/// disable_ssl: false,
/// credentials: credentials::Credentials::new("access_key", "secret_key"),
/// };
/// ```
/// Implementation of the `Config` struct, providing utility methods
/// for managing application configuration settings.
///
/// This implementation includes a builder method to facilitate
/// constructing a `Config` instance step-by-step using the `ConfigBuilder`.
///
/// ## Key Functionalities
/// - `builder()`: Returns a new `ConfigBuilder` instance with default values,
/// allowing users to set configuration properties before building a `Config` object.
///
/// The `Config` struct encapsulates essential configuration parameters such as
/// service region, endpoint URL, SSL settings, and authentication credentials.
/// This implementation ensures that configuration objects are created in
/// a structured and validated manner.
/// A builder for constructing a `Config` instance in a structured manner.
///
/// The `ConfigBuilder` struct allows users to set configuration parameters individually,
/// ensuring required fields are provided before building the final `Config` instance.
///
/// # Fields
/// - `region` (`Option<String>`): Optional region value.
/// - `endpoint` (`Option<String>`): Optional endpoint value.
/// - `disable_ssl` (`Option<bool>`): Optional SSL flag.
/// - `credentials` (`Option<credentials::Credentials>`): Optional authentication credentials.
/// Provides a default implementation for `ConfigBuilder`,
/// initializing all fields to `None`.
///
/// This implementation ensures that when a `ConfigBuilder` instance is created
/// without any parameters, it starts with no predefined values. The user can
/// then set specific fields as needed before calling `build()`.
///
/// ## Default Values
/// - `region`: `None` (must be provided if required for the configuration)
/// - `endpoint`: `None` (must be provided if required for the configuration)
/// - `disable_ssl`: `None` (defaults to `false` if not explicitly set)
/// - `credentials`: `None` (mandatory; `build()` will return an error if not provided)
///
/// Using the builder pattern with a default constructor allows flexibility
/// while enforcing validation rules in the `build()` method.
/// Implementation of the `ConfigBuilder` struct, which provides a fluent interface
/// for constructing a `Config` instance step-by-step.
///
/// The builder pattern allows for greater flexibility when creating configuration objects
/// by enabling method chaining to set individual parameters. This approach ensures
/// that required fields are validated before the final `Config` instance is created.
///
/// ## Example Usage
/// ```rust
/// use crate::volcengine::config::Config;
///
/// let config = Config::builder()
/// .with_region("us-east-1")
/// .with_endpoint("https://example.com")
/// .with_disable_ssl(true)
/// .with_credentials(credentials)
/// .build()
/// .expect("Failed to build config");
/// ```
///
/// Each setter method in `ConfigBuilder` accepts an argument, modifies the corresponding
/// field, and returns `self` to allow method chaining. The `build` method performs final
/// validation and returns a `Config` instance or an error if mandatory fields are missing.