tencent_sdk/core/
credentials.rs

1use std::fmt;
2
3#[derive(Clone, Eq, PartialEq)]
4pub struct Credentials {
5    secret_id: String,
6    secret_key: String,
7    token: Option<String>,
8}
9
10impl fmt::Debug for Credentials {
11    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12        f.debug_struct("Credentials")
13            .field("secret_id", &"[redacted]")
14            .field("secret_key", &"[redacted]")
15            .field("has_token", &self.token.is_some())
16            .finish()
17    }
18}
19
20impl Credentials {
21    pub fn new(secret_id: impl Into<String>, secret_key: impl Into<String>) -> Self {
22        Self {
23            secret_id: secret_id.into(),
24            secret_key: secret_key.into(),
25            token: None,
26        }
27    }
28
29    pub fn with_token(mut self, token: impl Into<String>) -> Self {
30        self.set_token(token);
31        self
32    }
33
34    pub fn secret_id(&self) -> &str {
35        &self.secret_id
36    }
37
38    pub fn secret_key(&self) -> &str {
39        &self.secret_key
40    }
41
42    pub fn token(&self) -> Option<&str> {
43        self.token.as_deref()
44    }
45
46    pub fn set_token(&mut self, token: impl Into<String>) {
47        self.token = Some(token.into());
48    }
49
50    pub fn clear_token(&mut self) {
51        self.token = None;
52    }
53}