Compare commits
3 Commits
738da0aac6
...
af1aafbde6
| Author | SHA1 | Date | |
|---|---|---|---|
|
af1aafbde6
|
|||
|
b4da87231d
|
|||
|
a976f04f7d
|
@@ -7,6 +7,34 @@ use serde::Deserialize;
|
|||||||
/// (Secure cookies can't be set over HTTP. Rough assumption: development is done over HTTP)
|
/// (Secure cookies can't be set over HTTP. Rough assumption: development is done over HTTP)
|
||||||
const DEFAULT_COOKIES_SECURE: bool = cfg!(not(debug_assertions));
|
const DEFAULT_COOKIES_SECURE: bool = cfg!(not(debug_assertions));
|
||||||
|
|
||||||
|
// Simple newtype to avoid showing secrets with `Debug` / `Display`
|
||||||
|
#[derive(Clone, Deserialize)]
|
||||||
|
pub struct SecretString(String);
|
||||||
|
|
||||||
|
impl SecretString {
|
||||||
|
pub fn expose(&self) -> &String {
|
||||||
|
&self.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<String> for SecretString {
|
||||||
|
fn from(s: String) -> Self {
|
||||||
|
Self(s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for SecretString {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "*****")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for SecretString {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "*****")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub struct AuthConfig {
|
pub struct AuthConfig {
|
||||||
pub open_signup: bool,
|
pub open_signup: bool,
|
||||||
@@ -16,11 +44,11 @@ pub struct AuthConfig {
|
|||||||
/// Build a connection URI from parts
|
/// Build a connection URI from parts
|
||||||
fn format_uri(
|
fn format_uri(
|
||||||
scheme: &str,
|
scheme: &str,
|
||||||
username: &Option<String>,
|
username: Option<&String>,
|
||||||
password: &Option<String>,
|
password: Option<&String>,
|
||||||
host: &str,
|
host: &str,
|
||||||
port: &Option<u16>,
|
port: Option<u16>,
|
||||||
path: &Option<String>,
|
path: Option<&String>,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut url = format!("{scheme}://");
|
let mut url = format!("{scheme}://");
|
||||||
|
|
||||||
@@ -64,14 +92,14 @@ impl DatabaseConfig {
|
|||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum DatabaseConnectionConfig {
|
enum DatabaseConnectionConfig {
|
||||||
FromUrl {
|
FromUrl {
|
||||||
url: String,
|
url: SecretString,
|
||||||
},
|
},
|
||||||
FromParts {
|
FromParts {
|
||||||
host: String,
|
host: String,
|
||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
database: Option<String>,
|
database: Option<String>,
|
||||||
username: Option<String>,
|
username: Option<String>,
|
||||||
password: Option<String>,
|
password: Option<SecretString>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,14 +107,21 @@ impl DatabaseConnectionConfig {
|
|||||||
/// Convert this configuration into the Postgres connection URI
|
/// Convert this configuration into the Postgres connection URI
|
||||||
pub fn as_uri(&self) -> String {
|
pub fn as_uri(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::FromUrl { url } => url.clone(),
|
Self::FromUrl { url } => url.expose().clone(),
|
||||||
Self::FromParts {
|
Self::FromParts {
|
||||||
host,
|
host,
|
||||||
port,
|
port,
|
||||||
database,
|
database,
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
} => format_uri("postgres", username, password, host, port, database),
|
} => format_uri(
|
||||||
|
"postgres",
|
||||||
|
username.as_ref(),
|
||||||
|
password.as_ref().map(|s| s.expose()),
|
||||||
|
host,
|
||||||
|
*port,
|
||||||
|
database.as_ref(),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -95,7 +130,7 @@ impl DatabaseConnectionConfig {
|
|||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
enum KeyValStoreConnectionConfig {
|
enum KeyValStoreConnectionConfig {
|
||||||
FromUrl {
|
FromUrl {
|
||||||
url: String,
|
url: SecretString,
|
||||||
},
|
},
|
||||||
FromParts {
|
FromParts {
|
||||||
scheme: Option<String>,
|
scheme: Option<String>,
|
||||||
@@ -103,7 +138,7 @@ enum KeyValStoreConnectionConfig {
|
|||||||
port: Option<u16>,
|
port: Option<u16>,
|
||||||
database: Option<String>,
|
database: Option<String>,
|
||||||
username: Option<String>,
|
username: Option<String>,
|
||||||
password: Option<String>,
|
password: Option<SecretString>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,7 +146,7 @@ impl KeyValStoreConnectionConfig {
|
|||||||
/// Convert this configuration into the Redis connection URI
|
/// Convert this configuration into the Redis connection URI
|
||||||
pub fn as_uri(&self) -> String {
|
pub fn as_uri(&self) -> String {
|
||||||
match self {
|
match self {
|
||||||
Self::FromUrl { url } => url.clone(),
|
Self::FromUrl { url } => url.expose().clone(),
|
||||||
Self::FromParts {
|
Self::FromParts {
|
||||||
scheme,
|
scheme,
|
||||||
host,
|
host,
|
||||||
@@ -121,11 +156,11 @@ impl KeyValStoreConnectionConfig {
|
|||||||
password,
|
password,
|
||||||
} => format_uri(
|
} => format_uri(
|
||||||
scheme.as_deref().unwrap_or("redis"),
|
scheme.as_deref().unwrap_or("redis"),
|
||||||
username,
|
username.as_ref(),
|
||||||
password,
|
password.as_ref().map(|s| s.expose().clone()).as_ref(),
|
||||||
host,
|
host,
|
||||||
port,
|
*port,
|
||||||
database,
|
database.as_ref(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ pub async fn main() -> Result<std::convert::Infallible> {
|
|||||||
.map_err(|e| Error::message_here(e.to_string()))
|
.map_err(|e| Error::message_here(e.to_string()))
|
||||||
.err_context("Failed to load config")?;
|
.err_context("Failed to load config")?;
|
||||||
|
|
||||||
|
tracing::debug!("Loaded configuration: {config:#?}");
|
||||||
|
|
||||||
// Dioxus doesn't expose a way to configure the public path other than this environment
|
// Dioxus doesn't expose a way to configure the public path other than this environment
|
||||||
// variable, and also doesn't provide a way to read what the public path is. As a workaround we
|
// variable, and also doesn't provide a way to read what the public path is. As a workaround we
|
||||||
// expose a config option and set this variable that Dioxus expects.
|
// expose a config option and set this variable that Dioxus expects.
|
||||||
|
|||||||
Reference in New Issue
Block a user