From e4b82bbe68fc443b6369549bfd49f2a70e66650c Mon Sep 17 00:00:00 2001 From: Paul Krishnamurthy Date: Wed, 29 May 2024 13:03:22 -0400 Subject: [PATCH 1/3] feat: add verified status to connection model definitions --- .../endpoints/connection_model_definition.rs | 6 +++ .../tests/api_tests/passthrough_tests.rs | 51 ++++++++++++++++++- .../tests/api_tests/test_server/mod.rs | 1 + .../tests/api_tests/unified_tests.rs | 1 + .../connection/connection_model_definition.rs | 3 ++ .../src/service/client/caller_client.rs | 2 + .../client/unified_destination_client.rs | 7 +++ integrationos-event/tests/mock_destination.rs | 1 + 8 files changed, 71 insertions(+), 1 deletion(-) diff --git a/integrationos-api/src/endpoints/connection_model_definition.rs b/integrationos-api/src/endpoints/connection_model_definition.rs index 9f411ea6..0322abb6 100644 --- a/integrationos-api/src/endpoints/connection_model_definition.rs +++ b/integrationos-api/src/endpoints/connection_model_definition.rs @@ -296,6 +296,7 @@ pub struct CreateRequest { pub is_default_crud_mapping: Option, pub mapping: Option, pub paths: Option, + pub verified: Option, } impl HookExt for CreateRequest {} @@ -344,6 +345,7 @@ impl RequestExt for CreateRequest { is_default_crud_mapping: self.is_default_crud_mapping, mapping: self.mapping.clone(), record_metadata: Default::default(), + verified: self.verified.unwrap_or(false), }; record.record_metadata.version = self.version.clone(); Some(record) @@ -387,6 +389,10 @@ impl RequestExt for CreateRequest { record.extractor_config.clone_from(&self.extractor_config); record.record_metadata.version = self.version.clone(); + if let Some(verified) = self.verified { + record.verified = verified; + } + record } diff --git a/integrationos-api/tests/api_tests/passthrough_tests.rs b/integrationos-api/tests/api_tests/passthrough_tests.rs index dacda9ea..c08d6126 100644 --- a/integrationos-api/tests/api_tests/passthrough_tests.rs +++ b/integrationos-api/tests/api_tests/passthrough_tests.rs @@ -68,6 +68,7 @@ async fn test_passthrough_api() { responses: vec![], is_default_crud_mapping: None, mapping: None, + verified: Some(true), }; let create_model_definition_response = server @@ -82,6 +83,28 @@ async fn test_passthrough_api() { assert_eq!(create_model_definition_response.code, StatusCode::OK); + let unverified_create_model_definition_payload = CreateConnectionModelDefinitionRequest { + verified: Some(false), + path: "invoices".to_string(), + ..create_model_definition_payload.clone() + }; + + let create_unverified_model_definition_response = server + .send_request::( + "v1/connection-model-definitions", + Method::POST, + Some(&server.live_key), + Some(&serde_json::to_value(&unverified_create_model_definition_payload).unwrap()), + ) + .await + .unwrap(); + + assert_eq!( + create_unverified_model_definition_response.code, + StatusCode::OK + ); + + // Test a passthrough API call for a verified connection model definition let call_universal_api = server .send_request_with_headers::( "v1/passthrough/customers", @@ -103,11 +126,37 @@ async fn test_passthrough_api() { .await .expect("Failed to call universal API"); - // assert_eq!(call_universal_api.code, StatusCode::OK); assert_eq!( call_universal_api.data, serde_json::from_str::(&response_body).unwrap() ); + // Test a passthrough API call for an unverified connection model definition + let call_unverified_passthrough_endpoint = server + .send_request_with_headers::( + "v1/passthrough/invoices", + Method::GET, + Some(&server.live_key), + None, + Some( + vec![ + (CONTENT_TYPE.to_string(), "application/json".to_string()), + ( + "x-integrationos-connection-key".to_string(), + connection.key.to_string(), + ), + ] + .into_iter() + .collect(), + ), + ) + .await + .expect("Connection Model Definition is not verified."); + + assert_eq!( + call_unverified_passthrough_endpoint.code, + StatusCode::BAD_REQUEST + ); + mock.assert_async().await; } diff --git a/integrationos-api/tests/api_tests/test_server/mod.rs b/integrationos-api/tests/api_tests/test_server/mod.rs index 58515888..6bc12084 100644 --- a/integrationos-api/tests/api_tests/test_server/mod.rs +++ b/integrationos-api/tests/api_tests/test_server/mod.rs @@ -530,6 +530,7 @@ impl TestServer { ), to_common_model: Some("function mapCrudRequest(data) { return data; }".to_string()), }), + verified: Some(true), }; let res = self diff --git a/integrationos-api/tests/api_tests/unified_tests.rs b/integrationos-api/tests/api_tests/unified_tests.rs index 20f65857..5b567457 100644 --- a/integrationos-api/tests/api_tests/unified_tests.rs +++ b/integrationos-api/tests/api_tests/unified_tests.rs @@ -580,6 +580,7 @@ async fn create_connection_model_definition( responses: vec![], is_default_crud_mapping: None, mapping: Some(mapping.clone()), + verified: Some(true), }; let create_model_definition_response = server diff --git a/integrationos-domain/src/domain/connection/connection_model_definition.rs b/integrationos-domain/src/domain/connection/connection_model_definition.rs index da5f657f..61f853d3 100644 --- a/integrationos-domain/src/domain/connection/connection_model_definition.rs +++ b/integrationos-domain/src/domain/connection/connection_model_definition.rs @@ -48,6 +48,9 @@ pub struct ConnectionModelDefinition { #[serde(flatten, default)] pub record_metadata: RecordMetadata, + + #[serde(default)] + pub verified: bool, } #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] diff --git a/integrationos-domain/src/service/client/caller_client.rs b/integrationos-domain/src/service/client/caller_client.rs index f72ed01f..cafe1fcb 100644 --- a/integrationos-domain/src/service/client/caller_client.rs +++ b/integrationos-domain/src/service/client/caller_client.rs @@ -171,6 +171,7 @@ mod tests { record_metadata: Default::default(), is_default_crud_mapping: None, mapping: None, + verified: true, }; let client = Client::new(); @@ -244,6 +245,7 @@ mod tests { record_metadata: Default::default(), is_default_crud_mapping: None, mapping: None, + verified: true, }; let client = Client::new(); diff --git a/integrationos-domain/src/service/client/unified_destination_client.rs b/integrationos-domain/src/service/client/unified_destination_client.rs index c9b0aba8..0155a6af 100644 --- a/integrationos-domain/src/service/client/unified_destination_client.rs +++ b/integrationos-domain/src/service/client/unified_destination_client.rs @@ -1093,6 +1093,13 @@ impl UnifiedDestination { Err(e) => Err(InternalError::connection_error(e.message().as_ref(), None)), }?; + if !config.verified { + return Err(InternalError::invalid_argument( + "Connection Model Definition is not verified.", + None, + )); + } + let secret = self .secrets_cache .try_get_with_by_ref(&connection, async { diff --git a/integrationos-event/tests/mock_destination.rs b/integrationos-event/tests/mock_destination.rs index f00c4ca5..08fbd944 100644 --- a/integrationos-event/tests/mock_destination.rs +++ b/integrationos-event/tests/mock_destination.rs @@ -83,6 +83,7 @@ pub async fn seed_db(config: &EventCoreConfig, base_url: String) -> Id { record_metadata: Default::default(), is_default_crud_mapping: None, mapping: None, + verified: true, }; db.collection("connection-model-definitions") From a8db5e95fce0ddb46e72129de7a8b86ba0c7984d Mon Sep 17 00:00:00 2001 From: Paul Krishnamurthy Date: Wed, 29 May 2024 13:22:45 -0400 Subject: [PATCH 2/3] chore: return ApplicationError::not_found for verified CMD lookup --- integrationos-unified/src/unified.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integrationos-unified/src/unified.rs b/integrationos-unified/src/unified.rs index 33d6822a..ec2b4519 100644 --- a/integrationos-unified/src/unified.rs +++ b/integrationos-unified/src/unified.rs @@ -24,7 +24,7 @@ use integrationos_domain::{ hashed_secret::HashedSecret, id::{prefix::IdPrefix, Id}, prelude::{CryptoExt, MongoStore, TimedExt}, - Connection, ErrorMeta, IntegrationOSError, Store, + ApplicationError, Connection, ErrorMeta, IntegrationOSError, Store, }; use js_sandbox_ios::Script; use moka::future::Cache; @@ -974,8 +974,8 @@ impl UnifiedDestination { }?; if !config.verified { - return Err(InternalError::invalid_argument( - "Connection Model Definition is not verified.", + return Err(ApplicationError::not_found( + "Verified Connection Model Definition", None, )); } From 5839ca3bf69942fad05302ad228ef29f77ad180c Mon Sep 17 00:00:00 2001 From: Paul Krishnamurthy Date: Wed, 29 May 2024 14:49:15 -0400 Subject: [PATCH 3/3] refactor: rename verified status to supported on Connection Model Definition --- .../src/endpoints/connection_model_definition.rs | 8 ++++---- integrationos-api/tests/api_tests/passthrough_tests.rs | 10 +++++----- integrationos-api/tests/api_tests/test_server/mod.rs | 2 +- integrationos-api/tests/api_tests/unified_tests.rs | 2 +- .../domain/connection/connection_model_definition.rs | 2 +- .../src/service/client/caller_client.rs | 4 ++-- integrationos-event/tests/mock_destination.rs | 2 +- integrationos-unified/src/unified.rs | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/integrationos-api/src/endpoints/connection_model_definition.rs b/integrationos-api/src/endpoints/connection_model_definition.rs index 0322abb6..bbe45576 100644 --- a/integrationos-api/src/endpoints/connection_model_definition.rs +++ b/integrationos-api/src/endpoints/connection_model_definition.rs @@ -296,7 +296,7 @@ pub struct CreateRequest { pub is_default_crud_mapping: Option, pub mapping: Option, pub paths: Option, - pub verified: Option, + pub supported: Option, } impl HookExt for CreateRequest {} @@ -345,7 +345,7 @@ impl RequestExt for CreateRequest { is_default_crud_mapping: self.is_default_crud_mapping, mapping: self.mapping.clone(), record_metadata: Default::default(), - verified: self.verified.unwrap_or(false), + supported: self.supported.unwrap_or(false), }; record.record_metadata.version = self.version.clone(); Some(record) @@ -389,8 +389,8 @@ impl RequestExt for CreateRequest { record.extractor_config.clone_from(&self.extractor_config); record.record_metadata.version = self.version.clone(); - if let Some(verified) = self.verified { - record.verified = verified; + if let Some(supported) = self.supported { + record.supported = supported; } record diff --git a/integrationos-api/tests/api_tests/passthrough_tests.rs b/integrationos-api/tests/api_tests/passthrough_tests.rs index c08d6126..0c3f7870 100644 --- a/integrationos-api/tests/api_tests/passthrough_tests.rs +++ b/integrationos-api/tests/api_tests/passthrough_tests.rs @@ -68,7 +68,7 @@ async fn test_passthrough_api() { responses: vec![], is_default_crud_mapping: None, mapping: None, - verified: Some(true), + supported: Some(true), }; let create_model_definition_response = server @@ -84,7 +84,7 @@ async fn test_passthrough_api() { assert_eq!(create_model_definition_response.code, StatusCode::OK); let unverified_create_model_definition_payload = CreateConnectionModelDefinitionRequest { - verified: Some(false), + supported: Some(false), path: "invoices".to_string(), ..create_model_definition_payload.clone() }; @@ -124,7 +124,7 @@ async fn test_passthrough_api() { ), ) .await - .expect("Failed to call universal API"); + .expect("Failed to call passthrough API"); assert_eq!( call_universal_api.data, @@ -151,11 +151,11 @@ async fn test_passthrough_api() { ), ) .await - .expect("Connection Model Definition is not verified."); + .expect("Failed to call the passthrough API"); assert_eq!( call_unverified_passthrough_endpoint.code, - StatusCode::BAD_REQUEST + StatusCode::NOT_FOUND ); mock.assert_async().await; diff --git a/integrationos-api/tests/api_tests/test_server/mod.rs b/integrationos-api/tests/api_tests/test_server/mod.rs index 6bc12084..175aff69 100644 --- a/integrationos-api/tests/api_tests/test_server/mod.rs +++ b/integrationos-api/tests/api_tests/test_server/mod.rs @@ -530,7 +530,7 @@ impl TestServer { ), to_common_model: Some("function mapCrudRequest(data) { return data; }".to_string()), }), - verified: Some(true), + supported: Some(true), }; let res = self diff --git a/integrationos-api/tests/api_tests/unified_tests.rs b/integrationos-api/tests/api_tests/unified_tests.rs index 5b567457..40a32142 100644 --- a/integrationos-api/tests/api_tests/unified_tests.rs +++ b/integrationos-api/tests/api_tests/unified_tests.rs @@ -580,7 +580,7 @@ async fn create_connection_model_definition( responses: vec![], is_default_crud_mapping: None, mapping: Some(mapping.clone()), - verified: Some(true), + supported: Some(true), }; let create_model_definition_response = server diff --git a/integrationos-domain/src/domain/connection/connection_model_definition.rs b/integrationos-domain/src/domain/connection/connection_model_definition.rs index 61f853d3..1b7527df 100644 --- a/integrationos-domain/src/domain/connection/connection_model_definition.rs +++ b/integrationos-domain/src/domain/connection/connection_model_definition.rs @@ -50,7 +50,7 @@ pub struct ConnectionModelDefinition { pub record_metadata: RecordMetadata, #[serde(default)] - pub verified: bool, + pub supported: bool, } #[derive(Debug, Clone, Eq, PartialEq, Hash, Deserialize, Serialize)] diff --git a/integrationos-domain/src/service/client/caller_client.rs b/integrationos-domain/src/service/client/caller_client.rs index cafe1fcb..d1a87de3 100644 --- a/integrationos-domain/src/service/client/caller_client.rs +++ b/integrationos-domain/src/service/client/caller_client.rs @@ -171,7 +171,7 @@ mod tests { record_metadata: Default::default(), is_default_crud_mapping: None, mapping: None, - verified: true, + supported: true, }; let client = Client::new(); @@ -245,7 +245,7 @@ mod tests { record_metadata: Default::default(), is_default_crud_mapping: None, mapping: None, - verified: true, + supported: true, }; let client = Client::new(); diff --git a/integrationos-event/tests/mock_destination.rs b/integrationos-event/tests/mock_destination.rs index 08fbd944..5be442a8 100644 --- a/integrationos-event/tests/mock_destination.rs +++ b/integrationos-event/tests/mock_destination.rs @@ -83,7 +83,7 @@ pub async fn seed_db(config: &EventCoreConfig, base_url: String) -> Id { record_metadata: Default::default(), is_default_crud_mapping: None, mapping: None, - verified: true, + supported: true, }; db.collection("connection-model-definitions") diff --git a/integrationos-unified/src/unified.rs b/integrationos-unified/src/unified.rs index ec2b4519..ea578634 100644 --- a/integrationos-unified/src/unified.rs +++ b/integrationos-unified/src/unified.rs @@ -973,9 +973,9 @@ impl UnifiedDestination { Err(e) => Err(InternalError::connection_error(e.message().as_ref(), None)), }?; - if !config.verified { + if !config.supported { return Err(ApplicationError::not_found( - "Verified Connection Model Definition", + "Supported Connection Model Definition", None, )); }