1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//!
//! Basic and Token Authentication Credentials
//!
/// Credentials used to authenticate at the InfluxDB server
#[derive(Debug)]
pub enum Credentials
{
/// HTTP Basic authentication pattern. This pattern authenticates at the server and receives
/// back the token to use for subsequent queries against the API.
Basic {
/// Username to authenticate with.
user: String,
/// Password to provide for authentication.
passwd: String,
/// Internally keeps track of the token provided by DB after basic auth.
cookie: Option<String>
},
/// Provide token generated directly in the InfluxDB GUI or CLI.
Token {
/// Token to provide for authorization
token: String
},
}
impl Credentials
{
/// User and password for HTTP basic auth at the server API
pub fn from_basic(user: &str, passwd: &str) -> Self
{
Self::Basic {
user: user.to_owned(),
passwd: passwd.to_owned(),
cookie: None,
}
}
/// Token to utilize for requests at the server API
pub fn from_token(token: &str) -> Self
{
Self::Token {
token: token.to_owned(),
}
}
}