allow nym-api to control bind address with CLI

This commit is contained in:
Jędrzej Stuczyński
2024-10-14 14:50:36 +01:00
parent 16edca21b0
commit c14481bb77
4 changed files with 22 additions and 0 deletions
+6
View File
@@ -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<SocketAddr>,
// #[clap(short, long, default_value_t = OutputFormat::default())]
// output: OutputFormat,
}
+6
View File
@@ -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<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<SocketAddr>,
}
async fn start_nym_api_tasks_axum(config: &Config) -> anyhow::Result<ShutdownHandles> {
+3
View File
@@ -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
}
+7
View File
@@ -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<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`
pub(crate) bind_address: Option<SocketAddr>,
}
impl From<init::Args> for OverrideConfig {
@@ -38,6 +43,7 @@ impl From<init::Args> 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<run::Args> 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,
}
}
}