From c14481bb777fc4433f1ac714c770435259b277b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Mon, 14 Oct 2024 14:50:36 +0100 Subject: [PATCH] allow nym-api to control bind address with CLI --- nym-api/src/support/cli/init.rs | 6 ++++++ nym-api/src/support/cli/run.rs | 6 ++++++ nym-api/src/support/config/mod.rs | 3 +++ nym-api/src/support/config/override.rs | 7 +++++++ 4 files changed, 22 insertions(+) diff --git a/nym-api/src/support/cli/init.rs b/nym-api/src/support/cli/init.rs index 10ce41b6f9..a51933f150 100644 --- a/nym-api/src/support/cli/init.rs +++ b/nym-api/src/support/cli/init.rs @@ -4,6 +4,7 @@ use crate::support::config::default_config_filepath; use crate::support::config::helpers::initialise_new; use anyhow::bail; +use std::net::SocketAddr; #[derive(clap::Args, Debug)] pub(crate) struct Args { @@ -51,6 +52,11 @@ pub(crate) struct Args { /// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement #[clap(long, requires = "enable_monitor")] pub(crate) monitor_credentials_mode: bool, + + /// Socket address this api will use for binding its http API. + /// default: `127.0.0.1:8080` in `debug` builds and `0.0.0.0:8080` in `release` + #[clap(long)] + pub(crate) bind_address: Option, // #[clap(short, long, default_value_t = OutputFormat::default())] // output: OutputFormat, } diff --git a/nym-api/src/support/cli/run.rs b/nym-api/src/support/cli/run.rs index 08e8d49f94..c3fabc81e1 100644 --- a/nym-api/src/support/cli/run.rs +++ b/nym-api/src/support/cli/run.rs @@ -35,6 +35,7 @@ use nym_config::defaults::NymNetworkDetails; use nym_sphinx::receiver::SphinxMessageReceiver; use nym_task::TaskManager; use nym_validator_client::nyxd::Coin; +use std::net::SocketAddr; use std::sync::Arc; use tokio_util::sync::CancellationToken; use tracing::{error, info}; @@ -86,6 +87,11 @@ pub(crate) struct Args { /// default: None - config value will be used instead #[clap(long)] pub(crate) monitor_credentials_mode: Option, + + /// Socket address this api will use for binding its http API. + /// default: `127.0.0.1:8080` in `debug` builds and `0.0.0.0:8080` in `release` + #[clap(long)] + pub(crate) bind_address: Option, } async fn start_nym_api_tasks_axum(config: &Config) -> anyhow::Result { diff --git a/nym-api/src/support/config/mod.rs b/nym-api/src/support/config/mod.rs index 235464dc0a..8d1809668f 100644 --- a/nym-api/src/support/config/mod.rs +++ b/nym-api/src/support/config/mod.rs @@ -169,6 +169,9 @@ impl Config { if let Some(monitor_credentials_mode) = args.monitor_credentials_mode { self.network_monitor.debug.disabled_credentials_mode = !monitor_credentials_mode } + if let Some(http_bind_address) = args.bind_address { + self.base.bind_address = http_bind_address + } self } diff --git a/nym-api/src/support/config/override.rs b/nym-api/src/support/config/override.rs index dea892d2a9..059d0f8136 100644 --- a/nym-api/src/support/config/override.rs +++ b/nym-api/src/support/config/override.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only use crate::support::cli::{init, run}; +use std::net::SocketAddr; // Configuration that can be overridden. pub(crate) struct OverrideConfig { @@ -26,6 +27,10 @@ pub(crate) struct OverrideConfig { /// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement pub(crate) monitor_credentials_mode: Option, + + /// Socket address this api will use for binding its http API. + /// default: `127.0.0.1:8080` in `debug` builds and `0.0.0.0:8080` in `release` + pub(crate) bind_address: Option, } impl From for OverrideConfig { @@ -38,6 +43,7 @@ impl From for OverrideConfig { enable_zk_nym: Some(args.enable_zk_nym), announce_address: args.announce_address, monitor_credentials_mode: Some(args.monitor_credentials_mode), + bind_address: args.bind_address, } } } @@ -52,6 +58,7 @@ impl From for OverrideConfig { enable_zk_nym: args.enable_zk_nym, announce_address: args.announce_address, monitor_credentials_mode: args.monitor_credentials_mode, + bind_address: args.bind_address, } } }