From 150282df06095c35a15a12fc7edd351868582d7b Mon Sep 17 00:00:00 2001 From: Jonni Liljamo Date: Mon, 11 Nov 2024 13:32:21 +0200 Subject: [PATCH] feat(worker): config from CLI --- README.md | 1 - emerwen-worker/src/main.rs | 20 ++++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 20d65e2..6337e6a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ tldr: gRPC was easier lmao. ## What's next (short-term TODO) -- Worker configuration with CLI args. - Actually checking auth tokens. - Master database (redb?) - Master web UI (leptos + leptos_oidc) for configuring workers. diff --git a/emerwen-worker/src/main.rs b/emerwen-worker/src/main.rs index 0ad5f05..3e381e8 100644 --- a/emerwen-worker/src/main.rs +++ b/emerwen-worker/src/main.rs @@ -19,6 +19,14 @@ struct Args { /// Enable debug logging #[arg(long)] debug: bool, + + /// Address of the Master + #[arg(long, default_value = "http://127.0.0.1:8000")] + master_address: String, + + /// Auth token + #[arg(long, default_value = "avain_perkele")] + auth_token: String, } #[tokio::main] @@ -46,15 +54,15 @@ async fn main() -> Result<(), Box> { info!("Starting emerwen worker..."); debug!("Hello, debug!"); - // TODO: token from cli, also addr from cli + let channel = Channel::builder(args.master_address.parse()?) + .connect() + .await?; - // Client is cheap to clone, clone one to every monitoring task + // Client is cheap to clone. let mut client = EmerwenProtocolClient::with_interceptor( - Channel::from_static("http://127.0.0.1:8000") - .connect() - .await?, + channel, AuthInterceptor { - token: "Bearer avain_perkele".parse()?, + token: format!("Bearer {}", args.auth_token).parse()?, }, ); -- 2.44.1