From 04b485202815629400282ae01748de1b0e750d82 Mon Sep 17 00:00:00 2001 From: VG Date: Thu, 5 Oct 2023 13:28:24 +0800 Subject: [PATCH] chore: remove option --- dozer-cli/src/cli/init.rs | 4 ++-- dozer-ingestion/src/connectors/mod.rs | 2 +- .../object_store/tests/local_storage_tests.rs | 4 ++-- .../object_store/tests/test_utils.rs | 20 ++++++++-------- .../connectors/object_store/local_storage.rs | 4 ++-- dozer-types/src/ingestion_types.rs | 10 +++++--- dozer-types/src/tests/eth_yaml_deserialize.rs | 24 ++++++++----------- json_schemas/connections.json | 12 ++++------ json_schemas/dozer.json | 12 ++++------ 9 files changed, 42 insertions(+), 50 deletions(-) diff --git a/dozer-cli/src/cli/init.rs b/dozer-cli/src/cli/init.rs index b21d43cce8..8be266b086 100644 --- a/dozer-cli/src/cli/init.rs +++ b/dozer-cli/src/cli/init.rs @@ -99,11 +99,11 @@ pub fn generate_connection(connection_name: &str) -> Connection { topics: vec![], }; let ethereum_config = EthConfig { - provider: Some(EthProviderConfig::Log(EthLogConfig { + provider: EthProviderConfig::Log(EthLogConfig { wss_url: "wss://link".to_owned(), filter: Some(eth_filter), contracts: vec![], - })), + }), }; let connection: Connection = Connection { name: "ethereum".to_owned(), diff --git a/dozer-ingestion/src/connectors/mod.rs b/dozer-ingestion/src/connectors/mod.rs index f11fb79730..6c69c83f7e 100644 --- a/dozer-ingestion/src/connectors/mod.rs +++ b/dozer-ingestion/src/connectors/mod.rs @@ -214,7 +214,7 @@ pub fn get_connector(connection: Connection) -> Result, Conne Ok(Box::new(PostgresConnector::new(postgres_config))) } #[cfg(feature = "ethereum")] - ConnectionConfig::Ethereum(eth_config) => match eth_config.provider.unwrap() { + ConnectionConfig::Ethereum(eth_config) => match eth_config.provider { dozer_types::ingestion_types::EthProviderConfig::Log(log_config) => { Ok(Box::new(EthLogConnector::new(log_config, connection.name))) } diff --git a/dozer-ingestion/src/connectors/object_store/tests/local_storage_tests.rs b/dozer-ingestion/src/connectors/object_store/tests/local_storage_tests.rs index e0fa4948d6..4c033ff3d5 100644 --- a/dozer-ingestion/src/connectors/object_store/tests/local_storage_tests.rs +++ b/dozer-ingestion/src/connectors/object_store/tests/local_storage_tests.rs @@ -388,9 +388,9 @@ fn test_unsupported_format() { #[tokio::test] async fn test_missing_directory() { let mut local_storage = get_local_storage_config("unsupported", ""); - local_storage.details = Some(LocalDetails { + local_storage.details = LocalDetails { path: "not_existing_path".to_string(), - }); + }; let connector = ObjectStoreConnector::new(local_storage); let tables = connector diff --git a/dozer-ingestion/src/connectors/object_store/tests/test_utils.rs b/dozer-ingestion/src/connectors/object_store/tests/test_utils.rs index 78a538ee7c..dc14346728 100644 --- a/dozer-ingestion/src/connectors/object_store/tests/test_utils.rs +++ b/dozer-ingestion/src/connectors/object_store/tests/test_utils.rs @@ -8,9 +8,9 @@ pub fn get_local_storage_config(typ: &str, prefix: &str) -> LocalStorage { match typ { "parquet" => match prefix { "" => LocalStorage { - details: Some(LocalDetails { + details: LocalDetails { path: p.to_str().unwrap().to_string(), - }), + }, tables: vec![Table { config: Some(TableConfig::Parquet(ParquetConfig { extension: typ.to_string(), @@ -21,9 +21,9 @@ pub fn get_local_storage_config(typ: &str, prefix: &str) -> LocalStorage { }], }, &_ => LocalStorage { - details: Some(LocalDetails { + details: LocalDetails { path: p.to_str().unwrap().to_string(), - }), + }, tables: vec![Table { config: Some(TableConfig::Parquet(ParquetConfig { extension: typ.to_string(), @@ -36,9 +36,9 @@ pub fn get_local_storage_config(typ: &str, prefix: &str) -> LocalStorage { }, "csv" => match prefix { "" => LocalStorage { - details: Some(LocalDetails { + details: LocalDetails { path: p.to_str().unwrap().to_string(), - }), + }, tables: vec![Table { config: Some(TableConfig::CSV(CsvConfig { extension: typ.to_string(), @@ -49,9 +49,9 @@ pub fn get_local_storage_config(typ: &str, prefix: &str) -> LocalStorage { }], }, &_ => LocalStorage { - details: Some(LocalDetails { + details: LocalDetails { path: p.to_str().unwrap().to_string(), - }), + }, tables: vec![Table { config: Some(TableConfig::CSV(CsvConfig { extension: typ.to_string(), @@ -63,9 +63,9 @@ pub fn get_local_storage_config(typ: &str, prefix: &str) -> LocalStorage { }, }, &_ => LocalStorage { - details: Some(LocalDetails { + details: LocalDetails { path: p.to_str().unwrap().to_string(), - }), + }, tables: vec![Table { config: None, name: String::new(), diff --git a/dozer-ingestion/tests/test_suite/connectors/object_store/local_storage.rs b/dozer-ingestion/tests/test_suite/connectors/object_store/local_storage.rs index 4689590aa0..0e33001039 100644 --- a/dozer-ingestion/tests/test_suite/connectors/object_store/local_storage.rs +++ b/dozer-ingestion/tests/test_suite/connectors/object_store/local_storage.rs @@ -86,9 +86,9 @@ fn create_connector( writer.close().expect("Failed to close writer"); let local_storage = LocalStorage { - details: Some(LocalDetails { + details: LocalDetails { path: temp_dir.path().to_str().expect("Non-UTF8 path").to_string(), - }), + }, tables: vec![Table { config: Some(TableConfig::Parquet(ParquetConfig { path: table_name.to_string(), diff --git a/dozer-types/src/ingestion_types.rs b/dozer-types/src/ingestion_types.rs index 35631dfbdb..ddb2935714 100644 --- a/dozer-types/src/ingestion_types.rs +++ b/dozer-types/src/ingestion_types.rs @@ -77,7 +77,7 @@ pub enum GrpcConfigSchemas { #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Hash, JsonSchema, Default)] pub struct EthConfig { - pub provider: Option, + pub provider: EthProviderConfig, } #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Hash, JsonSchema)] @@ -86,6 +86,11 @@ pub enum EthProviderConfig { Trace(EthTraceConfig), } +impl Default for EthProviderConfig { + fn default() -> Self { + EthProviderConfig::Log(EthLogConfig::default()) + } +} #[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Clone, Hash, JsonSchema, Default)] pub struct EthLogConfig { @@ -117,8 +122,7 @@ impl EthConfig { pub fn convert_to_table(&self) -> PrettyTable { let mut table = table!(); - let provider = self.provider.as_ref().expect("Must provide provider"); - match provider { + match &self.provider { EthProviderConfig::Log(log) => { table.add_row(row!["provider", "logs"]); table.add_row(row!["wss_url", format!("{:?}", log.wss_url)]); diff --git a/dozer-types/src/tests/eth_yaml_deserialize.rs b/dozer-types/src/tests/eth_yaml_deserialize.rs index 2c176c1dda..a3e77942f4 100644 --- a/dozer-types/src/tests/eth_yaml_deserialize.rs +++ b/dozer-types/src/tests/eth_yaml_deserialize.rs @@ -22,13 +22,11 @@ fn standard() { topics: vec![], }; let expected_eth_config = EthConfig { - provider: Some(crate::ingestion_types::EthProviderConfig::Log( - EthLogConfig { - filter: Some(expected_eth_filter), - wss_url: "wss://link".to_owned(), - contracts: vec![], - }, - )), + provider: crate::ingestion_types::EthProviderConfig::Log(EthLogConfig { + filter: Some(expected_eth_filter), + wss_url: "wss://link".to_owned(), + contracts: vec![], + }), }; let expected = ConnectionConfig::Ethereum(expected_eth_config); assert_eq!(expected, deserializer_result); @@ -51,13 +49,11 @@ fn config_without_empty_array() { topics: vec![], }; let expected_eth_config = EthConfig { - provider: Some(crate::ingestion_types::EthProviderConfig::Log( - EthLogConfig { - wss_url: "wss://link".to_owned(), - filter: Some(expected_eth_filter), - contracts: vec![], - }, - )), + provider: crate::ingestion_types::EthProviderConfig::Log(EthLogConfig { + wss_url: "wss://link".to_owned(), + filter: Some(expected_eth_filter), + contracts: vec![], + }), }; let expected = ConnectionConfig::Ethereum(expected_eth_config); assert_eq!(expected, deserializer_result); diff --git a/json_schemas/connections.json b/json_schemas/connections.json index a01a549b06..9474e5c4ea 100644 --- a/json_schemas/connections.json +++ b/json_schemas/connections.json @@ -79,16 +79,12 @@ "$schema": "http://json-schema.org/draft-07/schema#", "title": "EthConfig", "type": "object", + "required": [ + "provider" + ], "properties": { "provider": { - "anyOf": [ - { - "$ref": "#/definitions/EthProviderConfig" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/EthProviderConfig" } }, "definitions": { diff --git a/json_schemas/dozer.json b/json_schemas/dozer.json index c684c1c56b..4a6baffe90 100644 --- a/json_schemas/dozer.json +++ b/json_schemas/dozer.json @@ -713,16 +713,12 @@ }, "EthConfig": { "type": "object", + "required": [ + "provider" + ], "properties": { "provider": { - "anyOf": [ - { - "$ref": "#/definitions/EthProviderConfig" - }, - { - "type": "null" - } - ] + "$ref": "#/definitions/EthProviderConfig" } } },