Add server config route
This commit is contained in:
@@ -18,6 +18,11 @@ pub struct AppConfig {
|
||||
#[clap(short, long, env)]
|
||||
pub proxy_ip: Option<String>,
|
||||
|
||||
/// Unsecure : for development, bypass authentication, using the account with the given
|
||||
/// email address by default
|
||||
#[clap(long, env)]
|
||||
unsecure_auto_login_email: Option<String>,
|
||||
|
||||
/// Secret key, used to secure some resources. Must be randomly generated
|
||||
#[clap(short = 'S', long, env, default_value = "")]
|
||||
secret: String,
|
||||
@@ -54,6 +59,10 @@ pub struct AppConfig {
|
||||
)]
|
||||
pub oidc_configuration_url: String,
|
||||
|
||||
/// OpenID provider name
|
||||
#[arg(long, env, default_value = "3rd party provider")]
|
||||
pub oidc_provider_name: String,
|
||||
|
||||
/// OpenID client ID
|
||||
#[arg(long, env, default_value = "foo")]
|
||||
pub oidc_client_id: String,
|
||||
@@ -103,6 +112,14 @@ impl AppConfig {
|
||||
&ARGS
|
||||
}
|
||||
|
||||
/// Get auto login email (if not empty)
|
||||
pub fn unsecure_auto_login_email(&self) -> Option<&str> {
|
||||
match self.unsecure_auto_login_email.as_deref() {
|
||||
None | Some("") => None,
|
||||
s => s,
|
||||
}
|
||||
}
|
||||
|
||||
/// Get app secret
|
||||
pub fn secret(&self) -> &str {
|
||||
let mut secret = self.secret.as_str();
|
||||
@@ -118,6 +135,11 @@ impl AppConfig {
|
||||
secret
|
||||
}
|
||||
|
||||
/// Check if auth is disabled
|
||||
pub fn is_auth_disabled(&self) -> bool {
|
||||
self.unsecure_auto_login_email().is_some()
|
||||
}
|
||||
|
||||
/// Get Redis connection configuration
|
||||
pub fn redis_connection_string(&self) -> String {
|
||||
format!(
|
||||
@@ -136,6 +158,7 @@ impl AppConfig {
|
||||
client_id: self.oidc_client_id.as_str(),
|
||||
client_secret: self.oidc_client_secret.as_str(),
|
||||
configuration_url: self.oidc_configuration_url.as_str(),
|
||||
name: self.oidc_provider_name.as_str(),
|
||||
redirect_url: self
|
||||
.oidc_redirect_url
|
||||
.replace("APP_ORIGIN", &self.website_origin),
|
||||
@@ -169,6 +192,7 @@ impl AppConfig {
|
||||
|
||||
#[derive(Debug, Clone, serde::Serialize)]
|
||||
pub struct OIDCProvider<'a> {
|
||||
pub name: &'a str,
|
||||
pub client_id: &'a str,
|
||||
pub client_secret: &'a str,
|
||||
pub configuration_url: &'a str,
|
||||
|
||||
Reference in New Issue
Block a user