simplify configuration, no more subcommands

This commit is contained in:
Chris Beck
2025-12-08 18:59:22 -07:00
parent 996ed1ed0f
commit 9c7275ed79
2 changed files with 14 additions and 20 deletions
+5 -2
View File
@@ -15,10 +15,13 @@ use std::time::Duration;
#[conf(serde)] #[conf(serde)]
pub struct AdminHttpConfig { pub struct AdminHttpConfig {
/// URL to POST admin commands to /// URL to POST admin commands to
#[conf(long, env = "ADMIN_HTTP_URL")] #[conf(long, env)]
pub url: String, pub url: String,
/// Command prefix that routes messages to this handler
#[conf(long, env, default_value = "#")]
pub command_prefix: String,
/// Timeout for the HTTP request /// Timeout for the HTTP request
#[conf(long, env = "ADMIN_HTTP_TIMEOUT", default_value = "5s", value_parser = conf_extra::parse_duration)] #[conf(long, env, default_value = "5s", value_parser = conf_extra::parse_duration, serde(use_value_parser))]
pub timeout: Duration, pub timeout: Duration,
} }
+9 -18
View File
@@ -2,7 +2,7 @@
#![deny(missing_docs)] #![deny(missing_docs)]
use conf::{Conf, Subcommands}; use conf::Conf;
use hyper::service::service_fn; use hyper::service::service_fn;
use hyper_util::{rt::TokioIo, server::conn::auto}; use hyper_util::{rt::TokioIo, server::conn::auto};
use signal_gateway::{CommandRouter, Gateway, GatewayConfig, Handling}; use signal_gateway::{CommandRouter, Gateway, GatewayConfig, Handling};
@@ -21,14 +21,6 @@ use syslog::SyslogConfig;
pub mod json; pub mod json;
use json::JsonConfig; use json::JsonConfig;
/// Handler for admin messages that don't match built-in commands.
#[derive(Subcommands, Debug)]
#[conf(serde)]
pub enum AdminHandlerCommand {
/// Forward unhandled admin messages to an HTTP endpoint.
AdminHttp(AdminHttpConfig),
}
/// Top-level configuration for signal-gateway. /// Top-level configuration for signal-gateway.
#[derive(Conf, Debug)] #[derive(Conf, Debug)]
#[conf(serde, test)] #[conf(serde, test)]
@@ -48,9 +40,9 @@ pub struct Config {
syslog: Option<SyslogConfig>, syslog: Option<SyslogConfig>,
#[conf(flatten, prefix)] #[conf(flatten, prefix)]
json: Option<JsonConfig>, json: Option<JsonConfig>,
/// Optional handler for admin messages that don't match built-in commands. /// Optional HTTP endpoint for forwarding admin messages.
#[conf(subcommands)] #[conf(flatten, prefix)]
admin_handler: Option<AdminHandlerCommand>, admin_http: Option<AdminHttpConfig>,
#[conf(flatten, serde(flatten))] #[conf(flatten, serde(flatten))]
gateway: GatewayConfig, gateway: GatewayConfig,
} }
@@ -115,12 +107,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.route("--help", Handling::Help) .route("--help", Handling::Help)
.route("-h", Handling::Help); .route("-h", Handling::Help);
// Add custom handler for "#" prefix if configured // Add admin HTTP handler with its configured prefix
if let Some(admin_handler) = config.admin_handler { if let Some(admin_http) = config.admin_http {
let handler = match admin_handler { let prefix = admin_http.command_prefix.clone();
AdminHandlerCommand::AdminHttp(config) => config.into_handler(), let handler = admin_http.into_handler();
}; router_builder = router_builder.route(prefix, Handling::Custom(handler));
router_builder = router_builder.route("#", Handling::Custom(handler));
} }
// Add gateway commands for "/" prefix // Add gateway commands for "/" prefix