Update config keys, add port

This commit is contained in:
Xiretza 2024-02-10 13:25:33 +00:00
parent 03bcb4df90
commit d8b79ae852
4 changed files with 20 additions and 12 deletions

View file

@ -1,4 +1,5 @@
padlock_secret = ""
padlock-secret = ""
port = 80
[database]
connection_string = "sqlite://sqlite.db"
connection-string = "sqlite://sqlite.db"

View file

@ -3,27 +3,32 @@ use serde::Deserialize;
use crate::secrets::PadlockGenerationSecret;
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct Config {
database: DatabaseConfig,
#[serde(default)]
auth_backends: Vec<AuthBackend>,
#[serde(with = "hex::serde")]
padlock_secret: PadlockGenerationSecret,
pub padlock_secret: PadlockGenerationSecret,
pub port: u16,
pub database: DatabaseConfig,
#[serde(default)]
pub auth_backends: Vec<AuthBackendConfig>,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct DatabaseConfig {
connection_string: String,
pub connection_string: String,
}
#[derive(Debug, Clone, Deserialize)]
#[serde(tag = "type")]
pub enum AuthBackend {
pub enum AuthBackendConfig {
#[serde(rename = "LDAP")]
Ldap(LdapBackendConfig),
}
#[derive(Debug, Clone, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct LdapBackendConfig {
server_address: String,
pub server_address: String,
}

View file

@ -77,7 +77,7 @@ async fn main() -> Result<()> {
let config = load_config(&args.config).await?;
tokio::spawn(server::run()).await??;
tokio::spawn(server::run(config.port)).await??;
Ok(())
}

View file

@ -1,3 +1,5 @@
use std::net::Ipv6Addr;
use axum::{
extract::Query,
http::StatusCode,
@ -13,7 +15,7 @@ use crate::auth::{AuthenticationError, UserServerKeyGenerator};
use crate::secrets::{Password, ServerHash, UserToken};
#[instrument]
pub async fn run() -> color_eyre::Result<()> {
pub async fn run(port: u16) -> color_eyre::Result<()> {
let app = Router::new()
.route("/tls-check/success", get(|| async { "OK" }))
.route("/api-login", post(api_login))
@ -21,7 +23,7 @@ pub async fn run() -> color_eyre::Result<()> {
"/generate-user-server-key-2",
post(generate_user_server_key_2),
);
let listener = tokio::net::TcpListener::bind("[::]:8080").await?;
let listener = tokio::net::TcpListener::bind((Ipv6Addr::UNSPECIFIED, port)).await?;
axum::serve(listener, app).await?;
Ok(())