1use std::fmt;
2
3#[derive(Clone, Eq, PartialEq)]
4pub enum Auth {
5 Tc3(Tc3Auth),
6 None,
7}
8
9#[derive(Clone, Eq, PartialEq)]
10pub struct Tc3Auth {
11 secret_id: String,
12 secret_key: String,
13 token: Option<String>,
14}
15
16impl fmt::Debug for Auth {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 match self {
19 Auth::Tc3(auth) => f.debug_tuple("Auth::Tc3").field(auth).finish(),
20 Auth::None => f.write_str("Auth::None"),
21 }
22 }
23}
24
25impl fmt::Debug for Tc3Auth {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 f.debug_struct("Tc3Auth")
28 .field("secret_id", &"[redacted]")
29 .field("secret_key", &"[redacted]")
30 .field("has_token", &self.token.is_some())
31 .finish()
32 }
33}
34
35impl Auth {
36 pub fn none() -> Self {
37 Self::None
38 }
39
40 pub fn tc3(secret_id: impl Into<String>, secret_key: impl Into<String>) -> Self {
41 Self::Tc3(Tc3Auth {
42 secret_id: secret_id.into(),
43 secret_key: secret_key.into(),
44 token: None,
45 })
46 }
47}
48
49impl Tc3Auth {
50 pub fn with_token(mut self, token: impl Into<String>) -> Self {
51 self.token = Some(token.into());
52 self
53 }
54
55 pub fn secret_id(&self) -> &str {
56 &self.secret_id
57 }
58
59 pub(crate) fn secret_key(&self) -> &str {
60 &self.secret_key
61 }
62
63 pub(crate) fn token(&self) -> Option<&str> {
64 self.token.as_deref()
65 }
66}