diff --git a/indexer/src/main.rs b/indexer/src/main.rs index 745d1233..1785c4d3 100644 --- a/indexer/src/main.rs +++ b/indexer/src/main.rs @@ -45,14 +45,21 @@ pub struct Cli { #[serde(tag = "type", rename_all = "snake_case")] #[serde(deny_unknown_fields)] pub enum DbConfig { - Postgres { database_url: String }, + Postgres { + #[serde(default = "get_env_db_url")] + database_url: String + }, } #[derive(Debug, Clone, Deserialize)] #[serde(tag = "type", rename_all = "snake_case")] #[serde(deny_unknown_fields)] pub enum SinkConfig { - Cardano { db: DbConfig, network: String }, + Cardano { + db: DbConfig, + #[serde(default = "get_env_network")] + network: String, + }, } pub enum Network {} @@ -76,6 +83,16 @@ pub struct Config { start_block: Option, } +fn get_env_db_url() -> String { + std::env::var("DATABASE_URL") + .expect("env DATABASE_URL not found and config did not specify sink.db.database_url") +} + +fn get_env_network() -> String { + std::env::var("NETWORK") + .expect("env NETWORK not found and config did not specify sink.network") +} + #[allow(unreachable_patterns)] #[tokio::main] async fn main() -> anyhow::Result<()> {