Skip to main content

trino_rust_client/
auth.rs

1use std::fmt;
2
3#[derive(Clone)]
4pub enum Auth {
5    Basic(String, Option<String>),
6    Jwt(String),
7}
8
9impl Auth {
10    pub fn new_basic(username: impl ToString, password: Option<impl ToString>) -> Auth {
11        Auth::Basic(username.to_string(), password.map(|p| p.to_string()))
12    }
13
14    pub fn new_jwt(token: impl ToString) -> Auth {
15        Auth::Jwt(token.to_string())
16    }
17}
18
19impl fmt::Debug for Auth {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match self {
22            Auth::Basic(name, _) => f
23                .debug_struct("BasicAuth")
24                .field("username", name)
25                .field("password", &"******")
26                .finish(),
27
28            Auth::Jwt(_) => f.debug_struct("JwtAuth").field("token", &"******").finish(),
29        }
30    }
31}