From e59a9a59b6428b6bb9b0014c76093e72b2b67fed Mon Sep 17 00:00:00 2001 From: Fran Arbanas Date: Wed, 9 Oct 2024 13:15:38 +0200 Subject: [PATCH 1/2] feat: add env feature to clap and change variables to be available as env variables as well --- nym-api/Cargo.toml | 2 +- nym-api/src/support/cli/init.rs | 17 +++++++++-------- nym-api/src/support/cli/mod.rs | 4 ++-- nym-api/src/support/cli/run.rs | 17 +++++++++-------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/nym-api/Cargo.toml b/nym-api/Cargo.toml index 194be8cc2d..f408e1f3ba 100644 --- a/nym-api/Cargo.toml +++ b/nym-api/Cargo.toml @@ -22,7 +22,7 @@ bip39 = { workspace = true } bincode.workspace = true bloomfilter = { workspace = true } cfg-if = { workspace = true } -clap = { workspace = true, features = ["cargo", "derive"] } +clap = { workspace = true, features = ["cargo", "derive", "env"] } console-subscriber = { workspace = true, optional = true } # validator-api needs to be built with RUSTFLAGS="--cfg tokio_unstable" dirs = { workspace = true } futures = { workspace = true } diff --git a/nym-api/src/support/cli/init.rs b/nym-api/src/support/cli/init.rs index 10ce41b6f9..ca67b43c12 100644 --- a/nym-api/src/support/cli/init.rs +++ b/nym-api/src/support/cli/init.rs @@ -9,27 +9,27 @@ use anyhow::bail; pub(crate) struct Args { /// Id of the nym-api we want to initialise. if unspecified, a default value will be used. /// default: "default" - #[clap(long, default_value = "default")] + #[clap(long, default_value = "default", env)] pub(crate) id: String, /// Specifies whether network monitoring is enabled on this API /// default: false - #[clap(short = 'm', long)] + #[clap(short = 'm', long, env)] pub(crate) enable_monitor: bool, /// Specifies whether network rewarding is enabled on this API /// default: false - #[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic")] + #[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic", env)] pub(crate) enable_rewarding: bool, /// Endpoint to nyxd instance used for contract information. /// default: http://localhost:26657 - #[clap(long)] + #[clap(long, env)] pub(crate) nyxd_validator: Option, /// Mnemonic of the network monitor used for sending rewarding and zk-nyms transactions /// default: None - #[clap(long)] + #[clap(long, env)] pub(crate) mnemonic: Option, /// Flag to indicate whether credential signer authority is enabled on this API @@ -38,18 +38,19 @@ pub(crate) struct Args { long, requires = "mnemonic", requires = "announce_address", - alias = "enable_coconut" + alias = "enable_coconut", + env )] pub(crate) enable_zk_nym: bool, /// Announced address that is going to be put in the DKG contract where zk-nym clients will connect /// to obtain their credentials /// default: None - #[clap(long)] + #[clap(long, env)] pub(crate) announce_address: Option, /// 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")] + #[clap(long, requires = "enable_monitor", env)] pub(crate) monitor_credentials_mode: bool, // #[clap(short, long, default_value_t = OutputFormat::default())] // output: OutputFormat, diff --git a/nym-api/src/support/cli/mod.rs b/nym-api/src/support/cli/mod.rs index 6667adccc6..483361a758 100644 --- a/nym-api/src/support/cli/mod.rs +++ b/nym-api/src/support/cli/mod.rs @@ -20,11 +20,11 @@ fn pretty_build_info_static() -> &'static str { #[clap(author = "Nymtech", version, long_version = pretty_build_info_static(), about)] pub(crate) struct Cli { /// Path pointing to an env file that configures the Nym API. - #[clap(short, long)] + #[clap(short, long, env)] pub(crate) config_env_file: Option, /// A no-op flag included for consistency with other binaries (and compatibility with nymvisor, oops) - #[clap(long)] + #[clap(long, env)] pub(crate) no_banner: bool, #[clap(subcommand)] diff --git a/nym-api/src/support/cli/run.rs b/nym-api/src/support/cli/run.rs index a19d2c1c29..a12a1dc81c 100644 --- a/nym-api/src/support/cli/run.rs +++ b/nym-api/src/support/cli/run.rs @@ -9,27 +9,27 @@ use cfg_if::cfg_if; pub(crate) struct Args { /// Id of the nym-api we want to run.if unspecified, a default value will be used. /// default: "default" - #[clap(long, default_value = "default")] + #[clap(long, default_value = "default", env)] pub(crate) id: String, /// Specifies whether network monitoring is enabled on this API /// default: None - config value will be used instead - #[clap(short = 'm', long)] + #[clap(short = 'm', long, env)] pub(crate) enable_monitor: Option, /// Specifies whether network rewarding is enabled on this API /// default: None - config value will be used instead - #[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic")] + #[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic", env)] pub(crate) enable_rewarding: Option, /// Endpoint to nyxd instance used for contract information. /// default: None - config value will be used instead - #[clap(long)] + #[clap(long, env)] pub(crate) nyxd_validator: Option, /// Mnemonic of the network monitor used for sending rewarding and zk-nyms transactions /// default: None - config value will be used instead - #[clap(long)] + #[clap(long, env)] pub(crate) mnemonic: Option, /// Flag to indicate whether coconut signer authority is enabled on this API @@ -38,19 +38,20 @@ pub(crate) struct Args { long, requires = "mnemonic", requires = "announce_address", - alias = "enable_coconut" + alias = "enable_coconut", + env )] pub(crate) enable_zk_nym: Option, /// Announced address that is going to be put in the DKG contract where zk-nym clients will connect /// to obtain their credentials /// default: None - config value will be used instead - #[clap(long)] + #[clap(long, env)] pub(crate) announce_address: Option, /// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement /// default: None - config value will be used instead - #[clap(long)] + #[clap(long, env)] pub(crate) monitor_credentials_mode: Option, } From a1e75e1dfffa87a87770fd99b55a21d13ec6b198 Mon Sep 17 00:00:00 2001 From: Fran Arbanas Date: Wed, 9 Oct 2024 13:24:28 +0200 Subject: [PATCH 2/2] change env var naming to be consistent with nym-node --- nym-api/src/support/cli/init.rs | 26 ++++++++++++++++++-------- nym-api/src/support/cli/mod.rs | 4 ++-- nym-api/src/support/cli/run.rs | 22 ++++++++++++++-------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/nym-api/src/support/cli/init.rs b/nym-api/src/support/cli/init.rs index ca67b43c12..f3c47eb6a5 100644 --- a/nym-api/src/support/cli/init.rs +++ b/nym-api/src/support/cli/init.rs @@ -9,27 +9,33 @@ use anyhow::bail; pub(crate) struct Args { /// Id of the nym-api we want to initialise. if unspecified, a default value will be used. /// default: "default" - #[clap(long, default_value = "default", env)] + #[clap(long, default_value = "default", env = "NYMAPI_ID_ARG")] pub(crate) id: String, /// Specifies whether network monitoring is enabled on this API /// default: false - #[clap(short = 'm', long, env)] + #[clap(short = 'm', long, env = "NYMAPI_ENABLE_MONITOR_ARG")] pub(crate) enable_monitor: bool, /// Specifies whether network rewarding is enabled on this API /// default: false - #[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic", env)] + #[clap( + short = 'r', + long, + requires = "enable_monitor", + requires = "mnemonic", + env = "NYMAPI_ENABLE_REWARDING_ARG" + )] pub(crate) enable_rewarding: bool, /// Endpoint to nyxd instance used for contract information. /// default: http://localhost:26657 - #[clap(long, env)] + #[clap(long, env = "NYMAPI_NYXD_VALIDATOR_ARG")] pub(crate) nyxd_validator: Option, /// Mnemonic of the network monitor used for sending rewarding and zk-nyms transactions /// default: None - #[clap(long, env)] + #[clap(long, env = "NYMAPI_MNEMONIC_ARG")] pub(crate) mnemonic: Option, /// Flag to indicate whether credential signer authority is enabled on this API @@ -39,18 +45,22 @@ pub(crate) struct Args { requires = "mnemonic", requires = "announce_address", alias = "enable_coconut", - env + env = "NYMAPI_ENABLE_ZK_NYM_ARG" )] pub(crate) enable_zk_nym: bool, /// Announced address that is going to be put in the DKG contract where zk-nym clients will connect /// to obtain their credentials /// default: None - #[clap(long, env)] + #[clap(long, env = "NYMAPI_ANNOUNCE_ADDRESS_NYM_ARG")] pub(crate) announce_address: Option, /// 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", env)] + #[clap( + long, + requires = "enable_monitor", + env = "NYMAPI_MONITOR_CREDENTIALS_MODE_ARG" + )] pub(crate) monitor_credentials_mode: bool, // #[clap(short, long, default_value_t = OutputFormat::default())] // output: OutputFormat, diff --git a/nym-api/src/support/cli/mod.rs b/nym-api/src/support/cli/mod.rs index 483361a758..7ba0b6411f 100644 --- a/nym-api/src/support/cli/mod.rs +++ b/nym-api/src/support/cli/mod.rs @@ -20,11 +20,11 @@ fn pretty_build_info_static() -> &'static str { #[clap(author = "Nymtech", version, long_version = pretty_build_info_static(), about)] pub(crate) struct Cli { /// Path pointing to an env file that configures the Nym API. - #[clap(short, long, env)] + #[clap(short, long, env = "NYMAPI_CONFIG_ENV_FILE_ARG")] pub(crate) config_env_file: Option, /// A no-op flag included for consistency with other binaries (and compatibility with nymvisor, oops) - #[clap(long, env)] + #[clap(long, env = "NYMAPI_NO_BANNER_ARG")] pub(crate) no_banner: bool, #[clap(subcommand)] diff --git a/nym-api/src/support/cli/run.rs b/nym-api/src/support/cli/run.rs index a12a1dc81c..e5e1849ac9 100644 --- a/nym-api/src/support/cli/run.rs +++ b/nym-api/src/support/cli/run.rs @@ -9,27 +9,33 @@ use cfg_if::cfg_if; pub(crate) struct Args { /// Id of the nym-api we want to run.if unspecified, a default value will be used. /// default: "default" - #[clap(long, default_value = "default", env)] + #[clap(long, default_value = "default", env = "NYMAPI_ID_ARG")] pub(crate) id: String, /// Specifies whether network monitoring is enabled on this API /// default: None - config value will be used instead - #[clap(short = 'm', long, env)] + #[clap(short = 'm', long, env = "NYMAPI_ENABLE_MONITOR_ARG")] pub(crate) enable_monitor: Option, /// Specifies whether network rewarding is enabled on this API /// default: None - config value will be used instead - #[clap(short = 'r', long, requires = "enable_monitor", requires = "mnemonic", env)] + #[clap( + short = 'r', + long, + requires = "enable_monitor", + requires = "mnemonic", + env = "NYMAPI_ENABLE_REWARDING_ARG" + )] pub(crate) enable_rewarding: Option, /// Endpoint to nyxd instance used for contract information. /// default: None - config value will be used instead - #[clap(long, env)] + #[clap(long, env = "NYMAPI_NYXD_VALIDATOR_ARG")] pub(crate) nyxd_validator: Option, /// Mnemonic of the network monitor used for sending rewarding and zk-nyms transactions /// default: None - config value will be used instead - #[clap(long, env)] + #[clap(long, env = "NYMAPI_MNEMONIC_ARG")] pub(crate) mnemonic: Option, /// Flag to indicate whether coconut signer authority is enabled on this API @@ -39,19 +45,19 @@ pub(crate) struct Args { requires = "mnemonic", requires = "announce_address", alias = "enable_coconut", - env + env = "NYMAPI_ENABLE_ZK_NYM_ARG" )] pub(crate) enable_zk_nym: Option, /// Announced address that is going to be put in the DKG contract where zk-nym clients will connect /// to obtain their credentials /// default: None - config value will be used instead - #[clap(long, env)] + #[clap(long, env = "NYMAPI_ANNOUNCE_ADDRESS_ARG")] pub(crate) announce_address: Option, /// Set this nym api to work in a enabled credentials that would attempt to use gateway with the bandwidth credential requirement /// default: None - config value will be used instead - #[clap(long, env)] + #[clap(long, env = "NYMAPI_MONITOR_CREDENTIALS_MODE_ARG")] pub(crate) monitor_credentials_mode: Option, }