From d8b79ae852b88dafd69e130198a496d86dbc17f8 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Sat, 10 Feb 2024 13:25:33 +0000 Subject: [PATCH] Update config keys, add port --- config.toml.example | 5 +++-- src/config.rs | 19 ++++++++++++------- src/main.rs | 2 +- src/server.rs | 6 ++++-- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/config.toml.example b/config.toml.example index 554359f..533c30d 100644 --- a/config.toml.example +++ b/config.toml.example @@ -1,4 +1,5 @@ -padlock_secret = "" +padlock-secret = "" +port = 80 [database] -connection_string = "sqlite://sqlite.db" +connection-string = "sqlite://sqlite.db" diff --git a/src/config.rs b/src/config.rs index 03d7410..086bec9 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, #[serde(with = "hex::serde")] - padlock_secret: PadlockGenerationSecret, + pub padlock_secret: PadlockGenerationSecret, + pub port: u16, + + pub database: DatabaseConfig, + #[serde(default)] + pub auth_backends: Vec, } #[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, } diff --git a/src/main.rs b/src/main.rs index 932ab71..7846794 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(()) } diff --git a/src/server.rs b/src/server.rs index 9370578..ffbcd43 100644 --- a/src/server.rs +++ b/src/server.rs @@ -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(())