use serde::Serialize;
use crate::dex::HTTP_PORT;
#[derive(Serialize)]
pub struct Storage {
#[serde(rename = "type")]
storage_type: String,
config: StorageConfig,
}
impl Storage {
pub fn sqlite() -> Self {
Self {
storage_type: String::from("sqlite3"),
config: StorageConfig {
file: String::from("/etc/dex/dex.db"),
},
}
}
}
#[derive(Serialize)]
pub struct StorageConfig {
file: String,
}
#[derive(Serialize)]
pub struct Config {
pub issuer: String,
pub storage: Storage,
pub web: Web,
#[serde(rename = "staticClients")]
pub static_clients: Vec<PrivateClient>,
#[serde(rename = "enablePasswordDB")]
pub enable_password_db: bool,
#[serde(rename = "staticPasswords")]
pub static_passwords: Vec<User>,
#[serde(skip_serializing_if = "Option::is_none")]
pub oauth2: Option<OAuth2>,
}
#[derive(Serialize)]
pub struct Web {
pub http: String,
}
impl Web {
pub fn http() -> Self {
Self {
http: format!(":{HTTP_PORT}"),
}
}
}
#[derive(Serialize)]
pub struct OAuth2 {
#[serde(rename = "passwordConnector")]
password_connector: String,
}
impl OAuth2 {
pub fn allow_password_grant() -> Self {
Self {
password_connector: String::from("local"),
}
}
}
#[derive(Serialize, Clone)]
pub struct PrivateClient {
pub id: String,
pub name: String,
#[serde(rename = "redirectURIs")]
pub redirect_uris: Vec<String>,
pub secret: String,
}
impl PrivateClient {
pub fn simple_client() -> Self {
Self {
id: String::from("client"),
name: String::from("Client"),
redirect_uris: vec![String::from("http://localhost/oidc-callback")],
secret: String::from("secret"),
}
}
}
#[derive(Serialize, Clone)]
pub struct User {
pub email: String,
pub hash: String,
pub username: String,
#[serde(rename = "userID")]
pub user_id: String,
}
impl User {
pub fn simple_user() -> Self {
Self {
email: String::from("user@example.org"),
username: String::from("User"),
hash: String::from("$2y$10$l.yOBo5a8m1TnfVuvj/gX.y3vvnHiQs0G59rEwIVU2blgcqkUDLjS"),
user_id: String::from("user"),
}
}
}