diff --git a/signal-gateway-bin/src/admin_http/mod.rs b/signal-gateway-bin/src/admin_http/mod.rs index 9264d76..1ab3f50 100644 --- a/signal-gateway-bin/src/admin_http/mod.rs +++ b/signal-gateway-bin/src/admin_http/mod.rs @@ -15,10 +15,13 @@ use std::time::Duration; #[conf(serde)] pub struct AdminHttpConfig { /// URL to POST admin commands to - #[conf(long, env = "ADMIN_HTTP_URL")] + #[conf(long, env)] 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 - #[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, } diff --git a/signal-gateway-bin/src/main.rs b/signal-gateway-bin/src/main.rs index 51bef8d..69dce09 100644 --- a/signal-gateway-bin/src/main.rs +++ b/signal-gateway-bin/src/main.rs @@ -2,7 +2,7 @@ #![deny(missing_docs)] -use conf::{Conf, Subcommands}; +use conf::Conf; use hyper::service::service_fn; use hyper_util::{rt::TokioIo, server::conn::auto}; use signal_gateway::{CommandRouter, Gateway, GatewayConfig, Handling}; @@ -21,14 +21,6 @@ use syslog::SyslogConfig; pub mod json; 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. #[derive(Conf, Debug)] #[conf(serde, test)] @@ -48,9 +40,9 @@ pub struct Config { syslog: Option, #[conf(flatten, prefix)] json: Option, - /// Optional handler for admin messages that don't match built-in commands. - #[conf(subcommands)] - admin_handler: Option, + /// Optional HTTP endpoint for forwarding admin messages. + #[conf(flatten, prefix)] + admin_http: Option, #[conf(flatten, serde(flatten))] gateway: GatewayConfig, } @@ -115,12 +107,11 @@ async fn main() -> Result<(), Box> { .route("--help", Handling::Help) .route("-h", Handling::Help); - // Add custom handler for "#" prefix if configured - if let Some(admin_handler) = config.admin_handler { - let handler = match admin_handler { - AdminHandlerCommand::AdminHttp(config) => config.into_handler(), - }; - router_builder = router_builder.route("#", Handling::Custom(handler)); + // Add admin HTTP handler with its configured prefix + if let Some(admin_http) = config.admin_http { + let prefix = admin_http.command_prefix.clone(); + let handler = admin_http.into_handler(); + router_builder = router_builder.route(prefix, Handling::Custom(handler)); } // Add gateway commands for "/" prefix