Skip to main content

iota_cluster_test/
config.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use std::{fmt, path::PathBuf};
6
7use clap::*;
8use regex::Regex;
9
10#[derive(Parser, Clone, ValueEnum, Debug)]
11pub enum Env {
12    Devnet,
13    Testnet,
14    CustomRemote,
15    NewLocal,
16}
17
18#[derive(derive_more::Debug, Parser)]
19#[command(name = "")]
20pub struct ClusterTestOpt {
21    #[arg(value_enum)]
22    pub env: Env,
23    #[arg(long)]
24    pub faucet_address: Option<String>,
25    #[arg(long)]
26    pub fullnode_address: Option<String>,
27    #[arg(long)]
28    pub epoch_duration_ms: Option<u64>,
29    /// URL for the indexer RPC server
30    #[arg(long)]
31    pub indexer_address: Option<String>,
32    /// URL for the Indexer Postgres DB
33    #[arg(long)]
34    #[debug("{}", ObfuscatedPgAddress(pg_address))]
35    pub pg_address: Option<String>,
36    #[arg(long)]
37    pub config_dir: Option<PathBuf>,
38    /// URL for the indexer RPC server
39    #[arg(long)]
40    pub graphql_address: Option<String>,
41}
42
43// This is not actually dead, but rust thinks it is because it is only used in
44// the derive macro above.
45#[allow(dead_code)]
46struct ObfuscatedPgAddress<'a>(&'a Option<String>);
47
48impl std::fmt::Display for ObfuscatedPgAddress<'_> {
49    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50        match self.0 {
51            None => write!(f, "None"),
52            Some(val) => {
53                write!(
54                    f,
55                    "{}",
56                    Regex::new(r":.*@")
57                        .unwrap()
58                        .replace_all(val.as_str(), ":*****@")
59                )
60            }
61        }
62    }
63}
64
65impl ClusterTestOpt {
66    pub fn new_local() -> Self {
67        Self {
68            env: Env::NewLocal,
69            faucet_address: None,
70            fullnode_address: None,
71            epoch_duration_ms: None,
72            indexer_address: None,
73            pg_address: None,
74            config_dir: None,
75            graphql_address: None,
76        }
77    }
78}