Skip to main content

ave_bridge/settings/
command.rs

1use std::env;
2
3use clap::{ArgAction, Parser};
4
5#[derive(Parser, Debug)]
6#[command(version, about, long_about = None)]
7pub struct Args {
8    /// Path to the file containing the settings you want to use
9    #[arg(short = 'c', long, default_value_t = String::default())]
10    pub config_path: String,
11
12    /// Password to be used for the creation of the cryptographic material, if not specified, the password of the environment variable 'AVE_PASSWORD' will be used.
13    #[arg(short = 'k', long, default_value_t = String::default())]
14    pub key_password: String,
15
16    /// Password to be used for the creation of the cryptographic material, if not specified, the password of the environment variable 'AVE_PASSWORD' will be used.
17    #[arg(short = 'a', long, default_value_t = String::default())]
18    pub auth_password: String,
19
20    /// Password to be used to auth for sinks.
21    #[arg(short = 's', long, default_value_t = String::default())]
22    pub sink_password: String,
23
24    /// API key to be used for sink authentication (alternative to password-based auth).
25    #[arg(short = 'S', long, default_value_t = String::default())]
26    pub sink_api_key: String,
27
28    /// Start the node in safe mode, disabling mutating operations.
29    #[arg(short = 'm', long, action = ArgAction::SetTrue)]
30    pub safe_mode: bool,
31}
32
33pub fn build_sink_password() -> String {
34    env::var("AVE_SINK_PASSWORD").unwrap_or_default()
35}
36
37pub fn build_sink_api_key() -> String {
38    env::var("AVE_SINK_API_KEY").unwrap_or_default()
39}
40
41pub fn build_auth_password() -> String {
42    env::var("AVE_AUTH_PASSWORD").unwrap_or_default()
43}
44
45pub fn build_key_password() -> String {
46    env::var("AVE_KEY_PASSWORD").unwrap_or_default()
47}
48
49pub fn build_config_path() -> String {
50    env::var("AVE_CONFIG").unwrap_or_default()
51}
52
53pub fn build_safe_mode() -> Option<bool> {
54    let value = env::var("AVE_SAFE_MODE").ok()?;
55    match value.trim().to_ascii_lowercase().as_str() {
56        "1" | "true" | "yes" | "on" => Some(true),
57        "0" | "false" | "no" | "off" => Some(false),
58        _ => None,
59    }
60}