From 81b006baba388ce711865d6a678fde3a693491ea Mon Sep 17 00:00:00 2001 From: Theo Butler Date: Mon, 25 Nov 2024 09:45:13 -0500 Subject: [PATCH] fix: remove config serialization --- src/config.rs | 63 ++++++---------------------------- src/main.rs | 5 +-- src/network/subgraph_client.rs | 3 +- 3 files changed, 13 insertions(+), 58 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8b16584b..40b79a30 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,14 +2,11 @@ use std::{ collections::{BTreeMap, HashSet}, - ops::Deref, path::{Path, PathBuf}, - str::FromStr, }; use alloy::primitives::{B256, U256}; use anyhow::Context; -use custom_debug::CustomDebug; use ipnetwork::IpNetwork; use ordered_float::NotNan; use semver::Version; @@ -25,7 +22,7 @@ use crate::{ /// The Graph Gateway configuration. #[serde_as] -#[derive(CustomDebug, Deserialize)] +#[derive(Deserialize)] pub struct Config { #[serde(default)] pub api_keys: Option, @@ -60,8 +57,6 @@ pub struct Config { /// POI blocklist #[serde(default)] pub poi_blocklist: Vec, - /// POI blocklist update interval in minutes (default: 20 minutes) - pub poi_blocklist_update_interval: Option, /// public API port pub port_api: u16, /// private metrics port @@ -85,7 +80,7 @@ where /// /// See [`Config`]'s [`api_keys`](struct.Config.html#structfield.api_keys). #[serde_as] -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] #[serde(untagged)] pub enum ApiKeys { Endpoint { @@ -93,7 +88,7 @@ pub enum ApiKeys { #[serde_as(as = "DisplayFromStr")] url: Url, /// Bearer auth token - auth: Hidden, + auth: String, /// API keys that won't be blocked for non-payment #[serde(default)] special: Vec, @@ -102,7 +97,7 @@ pub enum ApiKeys { Fixed(Vec), } -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] pub struct BlockedIndexer { /// empty array blocks on all deployments pub deployments: Vec, @@ -112,7 +107,7 @@ pub struct BlockedIndexer { /// Attestation configuration. /// /// See [`Config`]'s [`attestations`](struct.Config.html#structfield.attestations). -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] pub struct AttestationConfig { pub chain_id: String, pub dispute_manager: Address, @@ -122,7 +117,7 @@ pub struct AttestationConfig { /// /// See [`Config`]'s [`exchange_rate_provider`](struct.Config.html#structfield.exchange_rate_provider). #[serde_as] -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] #[serde(untagged)] pub enum ExchangeRateProvider { /// Ethereum RPC provider @@ -134,7 +129,7 @@ pub enum ExchangeRateProvider { /// Kafka configuration. /// /// See [`Config`]'s [`kafka`](struct.Config.html#structfield.kafka). -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] pub struct KafkaConfig(BTreeMap); impl Default for KafkaConfig { @@ -167,20 +162,20 @@ impl From for rdkafka::config::ClientConfig { } } -#[derive(Debug, Deserialize)] +#[derive(Deserialize)] pub struct Receipts { /// TAP verifier contract chain pub chain_id: U256, /// Secret key for legacy voucher signing (Scalar) - pub legacy_signer: Option>, + pub legacy_signer: Option, /// TAP signer key - pub signer: Hidden, + pub signer: B256, /// TAP verifier contract address pub verifier: Address, } /// Load the configuration from a JSON file. -pub fn load_from_file(path: &Path) -> Result { +pub fn load_from_file(path: &Path) -> anyhow::Result { let config_content = std::fs::read_to_string(path)?; let config = serde_json::from_str(&config_content)?; Ok(config) @@ -196,39 +191,3 @@ pub fn load_ip_blocklist_from_file(path: &Path) -> anyhow::Result(pub T); - -impl std::fmt::Debug for Hidden { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "HIDDEN") - } -} - -impl FromStr for Hidden { - type Err = T::Err; - fn from_str(s: &str) -> Result { - Ok(Self(s.parse()?)) - } -} - -impl Deref for Hidden { - type Target = T; - fn deref(&self) -> &Self::Target { - &self.0 - } -} diff --git a/src/main.rs b/src/main.rs index 187efd44..73d28ef5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,11 +76,8 @@ async fn main() { .expect("failed to prepare receipt signer"); let signer_address = receipt_signer.address(); - let conf_repr = format!("{conf:?}"); - init_logging("graph-gateway", conf.log_json); tracing::info!("gateway ID: {:?}", signer_address); - tracing::debug!(config = %conf_repr); let http_client = reqwest::Client::builder() .timeout(Duration::from_secs(20)) @@ -348,7 +345,7 @@ async fn init_auth_service( let api_keys = match config { Some(ApiKeys::Endpoint { url, auth, .. }) => { - subgraph_studio::api_keys(http, url, auth.0).await + subgraph_studio::api_keys(http, url, auth).await } Some(ApiKeys::Fixed(api_keys)) => { let api_keys = api_keys.into_iter().map(|k| (k.key.clone(), k)).collect(); diff --git a/src/network/subgraph_client.rs b/src/network/subgraph_client.rs index 98b52093..f17af77f 100644 --- a/src/network/subgraph_client.rs +++ b/src/network/subgraph_client.rs @@ -16,7 +16,6 @@ use url::Url; use crate::{ blocks::Block, - config::Hidden, indexer_client::{IndexerAuth, IndexerClient}, time::unix_timestamp, }; @@ -98,7 +97,7 @@ pub struct TrustedIndexer { #[serde_as(as = "serde_with::DisplayFromStr")] pub url: Url, /// free query auth token - pub auth: Hidden, + pub auth: String, } #[derive(Clone, Debug)]