diff --git a/Cargo.toml b/Cargo.toml index 658da43..0dff8f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ aws-smithy-http = "0.54" aws-smithy-types = "0.54" aws-types = "0.54" axum = { version = "0.6", features = ["headers"] } +clap = { version = "4.2.1", features = ["derive", "env"] } http = "*" hyper = { version = "0.14", features = ["full"] } maligned = "0.2.1" diff --git a/src/main.rs b/src/main.rs index 26cf9f8..28ded89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ //! * [ndarray] provides [NumPy](https://numpy.orgq)-like n-dimensional arrays used in numerical //! computation. +use clap::Parser; use tokio::signal; use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt}; @@ -34,15 +35,28 @@ mod operations; mod s3_client; mod validated_json; +/// S3 Active Storage Proxy command line interface +#[derive(Debug, Parser)] +struct CommandLineArgs { + /// The IP address on which the proxy should listen + #[arg(long, default_value = "0.0.0.0", env = "S3_ACTIVE_STORAGE_HOST")] + host: String, + /// The port to which the proxy should bind + #[arg(long, default_value_t = 8080, env = "S3_ACTIVE_STORAGE_PORT")] + port: u16, +} + /// Application entry point #[tokio::main] async fn main() { + let args = CommandLineArgs::parse(); + init_tracing(); let router = app::router(); - // run it with hyper on localhost:8080 - axum::Server::bind(&"0.0.0.0:8080".parse().unwrap()) + // run it with hyper + axum::Server::bind(&format!("{}:{}", args.host, args.port).parse().unwrap()) .serve(router.into_make_service()) .with_graceful_shutdown(shutdown_signal()) .await