Skip to content

Commit

Permalink
feat: allow read config file
Browse files Browse the repository at this point in the history
  • Loading branch information
hopeyen committed Aug 10, 2023
1 parent a6e7f8d commit 7cdab34
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 2 deletions.
33 changes: 33 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions subgraph-radio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ metrics = "0.21.0"
opentelemetry = { version = "0.19.0", features = ["rt-tokio", "trace"] }
tracing-opentelemetry = "0.18.0"
clap = { version = "4.3.1", features = ["derive", "env"] }
confy = "0.5.1"

[dev-dependencies]
criterion = { version = "0.4", features = ["async", "async_futures"] }
Expand Down
14 changes: 12 additions & 2 deletions subgraph-radio/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,18 @@ pub struct Config {
impl Config {
/// Parse config arguments
pub fn args() -> Self {
// TODO: load config file before parse (maybe add new level of subcommands)
let config = Config::parse();
let config = if let Ok(file_path) = std::env::var("CONFIG_FILE") {
confy::load_path::<Config>(file_path.clone()).unwrap_or_else(|e| {
panic!(
"{} file cannot be parsed into Config: {}",
file_path.clone(),
e
)
})
} else {
Config::parse()
};

std::env::set_var("RUST_LOG", config.radio_infrastructure().log_level.clone());
// Enables tracing under RUST_LOG variable
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`");
Expand Down
27 changes: 27 additions & 0 deletions template.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[graph_stack]
graph_node_status_endpoint = 'http://localhost:8030/graphql'
indexer_address = '0xgossipssssssssssssssssssssssssssssssssss'
registry_subgraph = 'https://api.thegraph.com/subgraphs/name/hopeyen/graphcast-registry-goerli'
network_subgraph = 'https://api.thegraph.com/subgraphs/name/graphprotocol/graph-network-goerli'
private_key = 'abcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefghabcdefgh'
indexer_management_server_endpoint = 'http://127.0.0.1:18000'

[waku]
boot_node_addresses = []

[radio_infrastructure]
graphcast_network = 'Testnet'
topics = ['QmacQnSgia4iDPWHpeY6aWxesRFdb8o5DKZUx96zZqEWrB']
coverage = 'Comprehensive'
auto_upgrade = 'Comprehensive'
collect_message_duration = 10
slack_token = 'xoxb-1231231231231-2312312312312-3abcabcabcabacabcabcabca'
metrics_host = '0.0.0.0'
server_host = '0.0.0.0'
server_port = 7700
persistence_file_path = 'wooooooow.json'
radio_name = 'subgraph-radio'
id_validation = 'ValidAddress'
topic_update_interval = 600
log_level = 'warn,hyper=off,graphcast_sdk=debug,subgraph_radio=debug'
log_format = 'Pretty'

0 comments on commit 7cdab34

Please sign in to comment.