Skip to main content

securitydept_creds/
config.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{BasicAuthCred, StaticTokenAuthCred};
4
5/// Configuration for Basic Authentication.
6#[derive(Debug, Clone, Deserialize, Serialize)]
7pub struct BasicAuthCredsConfig<Creds>
8where
9    Creds: BasicAuthCred,
10{
11    /// List of allowed credentials.
12    #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
13    pub users: Vec<Creds>,
14}
15
16impl<Creds> Default for BasicAuthCredsConfig<Creds>
17where
18    Creds: BasicAuthCred,
19{
20    fn default() -> Self {
21        Self { users: Vec::new() }
22    }
23}
24
25impl<Creds> BasicAuthCredsConfig<Creds>
26where
27    Creds: BasicAuthCred,
28{
29    /// Validate the configuration.
30    pub fn validate(&self) -> Result<(), crate::error::CredsError> {
31        Ok(())
32    }
33}
34
35#[derive(Debug, Clone, Deserialize, Serialize)]
36pub struct StaticTokenAuthCredsConfig<Creds>
37where
38    Creds: StaticTokenAuthCred + Clone,
39{
40    /// List of allowed credentials.
41    #[serde(default = "Vec::new", skip_serializing_if = "Vec::is_empty")]
42    pub tokens: Vec<Creds>,
43}
44
45impl<Creds> Default for StaticTokenAuthCredsConfig<Creds>
46where
47    Creds: StaticTokenAuthCred + Clone,
48{
49    fn default() -> Self {
50        Self { tokens: Vec::new() }
51    }
52}
53
54impl<Creds> StaticTokenAuthCredsConfig<Creds>
55where
56    Creds: StaticTokenAuthCred + Clone,
57{
58    /// Validate the configuration.
59    pub fn validate(&self) -> Result<(), crate::error::CredsError> {
60        Ok(())
61    }
62}