volcengine_rust_sdk/volcengine/credentials/
credentials.rs

1/*
2 * @Author: Jerry.Yang
3 * @Date: 2024-10-17 10:34:24
4 * @LastEditors: Jerry.Yang
5 * @LastEditTime: 2025-02-05 14:15:55
6 * @Description: credentials
7 */
8/// Represents the authentication credentials required to access Volcengine services.
9///
10/// This struct holds the necessary credentials used for authenticating API requests  
11/// to Volcengine. These credentials are typically provided by the service and must  
12/// be securely managed to prevent unauthorized access.
13///
14/// # Fields
15/// - `access_key_id` (`String`): The access key ID associated with the user or application.
16///   This key acts as a unique identifier for authentication.
17/// - `secret_access_key` (`String`): The secret access key associated with the access key ID.
18///   This key must be kept secure, as it is used to sign API requests.
19///
20/// # Security Considerations
21/// - The `secret_access_key` should **never** be exposed in logs, environment variables,  
22///   or source code repositories.
23/// - Always use secure storage mechanisms, such as environment variables, secrets management  
24///   tools, or encrypted configuration files, to store credentials.
25/// - Rotate credentials periodically to minimize security risks.
26///
27/// # Example Usage
28/// ```rust
29/// let creds = Credentials {
30///     access_key_id: "your-access-key-id".to_string(),
31///     secret_access_key: "your-secret-access-key".to_string(),
32/// };
33///
34/// println!("Access Key ID: {}", creds.access_key_id);
35/// ```
36///
37/// This struct is often used in conjunction with authentication mechanisms when making  
38/// API requests to Volcengine services.
39#[derive(Debug, Clone)]
40pub struct Credentials {
41    /// The access key ID for authentication.
42    pub access_key_id: String,
43
44    /// The secret access key for authentication (must be kept secure).
45    pub secret_access_key: String,
46}
47
48/// Represents a set of credentials used for authenticating API requests.
49///
50/// This struct holds the access key ID and secret access key required for signing
51/// requests and authenticating with the API service. These credentials are used
52/// to prove the identity of the user or application making the requests and to
53/// ensure that the requests are authorized.
54///
55/// The `Credentials` struct provides a simple, efficient way to manage the credentials
56/// needed for accessing protected resources in the Volcengine API, and it is typically
57/// used in API client configurations where authentication is necessary.
58///
59/// # Example
60/// ```rust
61/// let creds = Credentials::new("your-access-key-id", "your-secret-access-key");
62/// println!("Access Key ID: {}", creds.access_key_id);
63/// println!("Secret Access Key: {}", creds.secret_access_key);
64/// ```
65/// This example demonstrates how to create a new instance of the `Credentials` struct
66/// using the `new` method, providing the required access key ID and secret access key.
67impl Credentials {
68    /// Creates a new instance of the `Credentials` struct.
69    ///
70    /// This constructor method takes in the access key ID and the secret access key
71    /// as string slices (`&str`) and returns a new `Credentials` instance with these values.
72    ///
73    /// # Parameters
74    /// - `access_key_id` (`&str`): The access key ID associated with the user or application.  
75    ///   This is used for identifying the user or system when making API requests.
76    /// - `secret_access_key` (`&str`): The secret access key that corresponds to the access key ID.  
77    ///   This is used for signing the requests to ensure the authenticity of the caller.
78    ///
79    /// # Returns
80    /// Returns a new `Credentials` instance (`Self`) containing the provided access key ID and
81    /// secret access key as `String` values.
82    ///
83    /// # Example
84    /// ```rust
85    /// let creds = Credentials::new("your-access-key-id", "your-secret-access-key");
86    /// println!("Access Key ID: {}", creds.access_key_id);
87    /// println!("Secret Access Key: {}", creds.secret_access_key);
88    /// ```
89    pub fn new(access_key_id: &str, secret_access_key: &str) -> Self {
90        Credentials {
91            access_key_id: access_key_id.to_string(),
92            secret_access_key: secret_access_key.to_string(),
93        }
94    }
95}