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 iota_genesis_builder::SnapshotUrl;
9use regex::Regex;
10
11#[derive(Parser, Clone, ValueEnum, Debug)]
12pub enum Env {
13    Devnet,
14    Testnet,
15    CustomRemote,
16    NewLocal,
17}
18
19#[derive(derive_more::Debug, Parser)]
20#[command(name = "")]
21pub struct ClusterTestOpt {
22    #[arg(value_enum)]
23    pub env: Env,
24    #[arg(long)]
25    pub faucet_address: Option<String>,
26    #[arg(long)]
27    pub fullnode_address: Option<String>,
28    #[arg(long)]
29    pub epoch_duration_ms: Option<u64>,
30    /// URL for the indexer RPC server
31    #[arg(long)]
32    pub indexer_address: Option<String>,
33    /// URL for the Indexer Postgres DB
34    #[arg(long)]
35    #[debug("{}", ObfuscatedPgAddress(pg_address))]
36    pub pg_address: Option<String>,
37    #[arg(long)]
38    pub config_dir: Option<PathBuf>,
39    /// URL for the indexer RPC server
40    #[arg(long)]
41    pub graphql_address: Option<String>,
42    /// Locations for local migration snapshots.
43    #[arg(long, name = "path", num_args(0..))]
44    pub local_migration_snapshots: Vec<PathBuf>,
45    /// Remote migration snapshots.
46    #[arg(long, name = "iota|<full-url>", num_args(0..))]
47    pub remote_migration_snapshots: Vec<SnapshotUrl>,
48}
49
50// This is not actually dead, but rust thinks it is because it is only used in
51// the derive macro above.
52#[allow(dead_code)]
53struct ObfuscatedPgAddress<'a>(&'a Option<String>);
54
55impl std::fmt::Display for ObfuscatedPgAddress<'_> {
56    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
57        match self.0 {
58            None => write!(f, "None"),
59            Some(val) => {
60                write!(
61                    f,
62                    "{}",
63                    Regex::new(r":.*@")
64                        .unwrap()
65                        .replace_all(val.as_str(), ":*****@")
66                )
67            }
68        }
69    }
70}
71
72impl ClusterTestOpt {
73    pub fn new_local() -> Self {
74        Self {
75            env: Env::NewLocal,
76            faucet_address: None,
77            fullnode_address: None,
78            epoch_duration_ms: None,
79            indexer_address: None,
80            pg_address: None,
81            config_dir: None,
82            graphql_address: None,
83            local_migration_snapshots: Default::default(),
84            remote_migration_snapshots: Default::default(),
85        }
86    }
87}