Skip to main content

kibana_sync/client/
auth.rs

1//! Authentication types for the Kibana client.
2
3/// Authentication credentials for Kibana.
4#[derive(Clone, Debug, Eq, PartialEq)]
5pub enum Auth {
6    /// Use an API key authentication via headers.
7    Apikey(String),
8    /// Use username and password authentication via Basic Auth headers.
9    Basic(String, String),
10    /// Don't use any authentication.
11    None,
12}
13
14impl Auth {
15    /// Create API key authentication.
16    pub fn api_key(apikey: impl Into<String>) -> Self {
17        Self::Apikey(apikey.into())
18    }
19
20    /// Create Basic authentication.
21    pub fn basic(username: impl Into<String>, password: impl Into<String>) -> Self {
22        Self::Basic(username.into(), password.into())
23    }
24}
25
26impl std::fmt::Display for Auth {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            Self::Apikey(_) => write!(f, "Apikey"),
30            Self::Basic(_, _) => write!(f, "Basic"),
31            Self::None => write!(f, "None"),
32        }
33    }
34}