Skip to content

Commit 7cdab34

Browse files
committed
feat: allow read config file
1 parent a6e7f8d commit 7cdab34

File tree

4 files changed

+73
-2
lines changed

4 files changed

+73
-2
lines changed

Cargo.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

subgraph-radio/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ metrics = "0.21.0"
5353
opentelemetry = { version = "0.19.0", features = ["rt-tokio", "trace"] }
5454
tracing-opentelemetry = "0.18.0"
5555
clap = { version = "4.3.1", features = ["derive", "env"] }
56+
confy = "0.5.1"
5657

5758
[dev-dependencies]
5859
criterion = { version = "0.4", features = ["async", "async_futures"] }

subgraph-radio/src/config.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,18 @@ pub struct Config {
5353
impl Config {
5454
/// Parse config arguments
5555
pub fn args() -> Self {
56-
// TODO: load config file before parse (maybe add new level of subcommands)
57-
let config = Config::parse();
56+
let config = if let Ok(file_path) = std::env::var("CONFIG_FILE") {
57+
confy::load_path::<Config>(file_path.clone()).unwrap_or_else(|e| {
58+
panic!(
59+
"{} file cannot be parsed into Config: {}",
60+
file_path.clone(),
61+
e
62+
)
63+
})
64+
} else {
65+
Config::parse()
66+
};
67+
5868
std::env::set_var("RUST_LOG", config.radio_infrastructure().log_level.clone());
5969
// Enables tracing under RUST_LOG variable
6070
init_tracing(config.radio_infrastructure().log_format.to_string()).expect("Could not set up global default subscriber for logger, check environmental variable `RUST_LOG` or the CLI input `log-level`");

template.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[graph_stack]
2+
graph_node_status_endpoint = 'http://localhost:8030/graphql'
3+
indexer_address = '0xgossipssssssssssssssssssssssssssssssssss'
4+
registry_subgraph = 'https://api.thegraph.com/subgraphs/name/hopeyen/graphcast-registry-goerli'
5+
network_subgraph = 'https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-goerli'
6+
private_key = 'abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh'
7+
indexer_management_server_endpoint = 'http://127.0.0.1:18000'
8+
9+
[waku]
10+
boot_node_addresses = []
11+
12+
[radio_infrastructure]
13+
graphcast_network = 'Testnet'
14+
topics = ['QmacQnSgia4iDPWHpeY6aWxesRFdb8o5DKZUx96zZqEWrB']
15+
coverage = 'Comprehensive'
16+
auto_upgrade = 'Comprehensive'
17+
collect_message_duration = 10
18+
slack_token = 'xoxb-1231231231231-2312312312312-3abcabcabcabacabcabcabca'
19+
metrics_host = '0.0.0.0'
20+
server_host = '0.0.0.0'
21+
server_port = 7700
22+
persistence_file_path = 'wooooooow.json'
23+
radio_name = 'subgraph-radio'
24+
id_validation = 'ValidAddress'
25+
topic_update_interval = 600
26+
log_level = 'warn,hyper=off,graphcast_sdk=debug,subgraph_radio=debug'
27+
log_format = 'Pretty'

0 commit comments

Comments
 (0)