From 456f6079a1435a1ac0849f7377b7a410f1e09eba Mon Sep 17 00:00:00 2001 From: Samuel Gomez Date: Mon, 6 May 2024 18:21:22 +0100 Subject: [PATCH] Removing sensitive data from connection configuration --- api/src/endpoints/common_model.rs | 4 ++- api/src/endpoints/connection.rs | 26 ++++++++++++++++++- api/src/endpoints/connection_definition.rs | 4 ++- .../endpoints/connection_model_definition.rs | 3 ++- api/src/endpoints/connection_model_schema.rs | 3 ++- .../endpoints/connection_oauth_definition.rs | 5 +++- api/src/endpoints/event_access.rs | 3 ++- api/src/endpoints/events.rs | 3 ++- api/src/endpoints/mod.rs | 16 +++++++++--- api/src/endpoints/pipeline.rs | 3 ++- api/src/endpoints/platform.rs | 3 ++- api/src/endpoints/platform_page.rs | 3 ++- api/src/endpoints/transactions.rs | 3 ++- 13 files changed, 64 insertions(+), 15 deletions(-) diff --git a/api/src/endpoints/common_model.rs b/api/src/endpoints/common_model.rs index 19005f60..2c1d199a 100644 --- a/api/src/endpoints/common_model.rs +++ b/api/src/endpoints/common_model.rs @@ -1,4 +1,4 @@ -use super::{create, delete, read, update, ApiResult, HookExt, RequestExt}; +use super::{create, delete, read, update, ApiResult, HookExt, PublicExt, RequestExt}; use crate::{ internal_server_error, not_found, server::{AppState, AppStores}, @@ -51,6 +51,8 @@ pub struct CreateRequest { pub primary: bool, } +impl PublicExt for CreateRequest {} + #[async_trait] impl HookExt for CreateRequest { async fn after_create_hook( diff --git a/api/src/endpoints/connection.rs b/api/src/endpoints/connection.rs index 3a2178af..71dadd23 100644 --- a/api/src/endpoints/connection.rs +++ b/api/src/endpoints/connection.rs @@ -1,4 +1,4 @@ -use super::{delete, read, RequestExt}; +use super::{delete, read, PublicExt, RequestExt}; use crate::{ api_payloads::{DeleteResponse, ErrorResponse, UpdateResponse}, bad_request, @@ -19,6 +19,7 @@ use http::HeaderMap; use integrationos_domain::{ algebra::{MongoStore, StoreExt}, connection_definition::ConnectionDefinition, + domain::connection::SanitizedConnection, event_access::EventAccess, id::{prefix::IdPrefix, Id}, record_metadata::RecordMetadata, @@ -92,6 +93,29 @@ async fn test_connection( Ok(()) } +impl PublicExt for CreateConnectionPayload { + fn public(input: Connection) -> Value { + SanitizedConnection { + id: input.id, + platform_version: input.platform_version, + connection_definition_id: input.connection_definition_id, + r#type: input.r#type, + name: input.name, + key: input.key, + group: input.group, + environment: input.environment, + platform: input.platform, + secrets_service_id: input.secrets_service_id, + event_access_id: input.event_access_id, + settings: input.settings, + throughput: input.throughput, + ownership: input.ownership, + oauth: input.oauth, + record_metadata: input.record_metadata, + } + .to_value() + } +} impl RequestExt for CreateConnectionPayload { type Output = Connection; diff --git a/api/src/endpoints/connection_definition.rs b/api/src/endpoints/connection_definition.rs index 4397bea4..96fa863b 100644 --- a/api/src/endpoints/connection_definition.rs +++ b/api/src/endpoints/connection_definition.rs @@ -1,5 +1,6 @@ use super::{ - create, delete, read, update, ApiResult, CachedRequest, HookExt, ReadResponse, RequestExt, + create, delete, read, update, ApiResult, CachedRequest, HookExt, PublicExt, ReadResponse, + RequestExt, }; use crate::{ internal_server_error, not_found, @@ -67,6 +68,7 @@ pub struct CreateRequest { } impl HookExt for CreateRequest {} +impl PublicExt for CreateRequest {} #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] #[cfg_attr(feature = "dummy", derive(fake::Dummy))] diff --git a/api/src/endpoints/connection_model_definition.rs b/api/src/endpoints/connection_model_definition.rs index 4ea8d1ac..c181d0c8 100644 --- a/api/src/endpoints/connection_model_definition.rs +++ b/api/src/endpoints/connection_model_definition.rs @@ -1,4 +1,4 @@ -use super::{create, delete, read, update, HookExt, RequestExt}; +use super::{create, delete, read, update, HookExt, PublicExt, RequestExt}; use crate::{ api_payloads::ErrorResponse, internal_server_error, not_found, @@ -299,6 +299,7 @@ pub struct CreateRequest { } impl HookExt for CreateRequest {} +impl PublicExt for CreateRequest {} impl RequestExt for CreateRequest { type Output = ConnectionModelDefinition; diff --git a/api/src/endpoints/connection_model_schema.rs b/api/src/endpoints/connection_model_schema.rs index 6850edfd..b91be457 100644 --- a/api/src/endpoints/connection_model_schema.rs +++ b/api/src/endpoints/connection_model_schema.rs @@ -1,4 +1,4 @@ -use super::{create, delete, read, update, ApiResult, HookExt, RequestExt}; +use super::{create, delete, read, update, ApiResult, HookExt, PublicExt, RequestExt}; use crate::{ internal_server_error, server::{AppState, AppStores}, @@ -84,6 +84,7 @@ pub struct CreateRequest { } impl HookExt for CreateRequest {} +impl PublicExt for CreateRequest {} impl RequestExt for CreateRequest { type Output = ConnectionModelSchema; diff --git a/api/src/endpoints/connection_oauth_definition.rs b/api/src/endpoints/connection_oauth_definition.rs index f1c4986d..1f703a65 100644 --- a/api/src/endpoints/connection_oauth_definition.rs +++ b/api/src/endpoints/connection_oauth_definition.rs @@ -1,4 +1,6 @@ -use super::{create, delete, read, update, CachedRequest, HookExt, ReadResponse, RequestExt}; +use super::{ + create, delete, read, update, CachedRequest, HookExt, PublicExt, ReadResponse, RequestExt, +}; use crate::server::{AppState, AppStores}; use axum::{ routing::{patch, post}, @@ -48,6 +50,7 @@ pub struct CreateRequest { } impl HookExt for CreateRequest {} +impl PublicExt for CreateRequest {} #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] #[serde(rename_all = "camelCase")] diff --git a/api/src/endpoints/event_access.rs b/api/src/endpoints/event_access.rs index 661d60c2..b743d88a 100644 --- a/api/src/endpoints/event_access.rs +++ b/api/src/endpoints/event_access.rs @@ -1,4 +1,4 @@ -use super::{delete, read, RequestExt}; +use super::{delete, read, PublicExt, RequestExt}; use crate::{ api_payloads::ErrorResponse, bad_request, @@ -64,6 +64,7 @@ impl RequestExt for CreateEventAccessRequest { stores.event_access } } +impl PublicExt for CreateEventAccessRequest {} #[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Validate)] #[cfg_attr(feature = "dummy", derive(fake::Dummy))] diff --git a/api/src/endpoints/events.rs b/api/src/endpoints/events.rs index 1c970351..f83ac1f1 100644 --- a/api/src/endpoints/events.rs +++ b/api/src/endpoints/events.rs @@ -1,4 +1,4 @@ -use super::{read, RequestExt}; +use super::{read, PublicExt, RequestExt}; use crate::server::{AppState, AppStores}; use axum::{routing::get, Router}; use bson::doc; @@ -13,6 +13,7 @@ pub fn get_router() -> Router> { #[derive(Serialize, Deserialize)] pub struct CreateEventRequest; +impl PublicExt for CreateEventRequest {} impl RequestExt for CreateEventRequest { type Output = Event; diff --git a/api/src/endpoints/mod.rs b/api/src/endpoints/mod.rs index 9079bed9..c601d0c6 100644 --- a/api/src/endpoints/mod.rs +++ b/api/src/endpoints/mod.rs @@ -20,6 +20,7 @@ use integrationos_domain::{ use moka::future::Cache; use mongodb::options::FindOneOptions; use serde::{de::DeserializeOwned, Deserialize, Serialize}; +use serde_json::Value; use std::{collections::BTreeMap, fmt::Debug, sync::Arc}; use tokio::try_join; use tracing::error; @@ -116,13 +117,22 @@ where } } +pub trait PublicExt +where + Input: Serialize + DeserializeOwned + Unpin + Sync + Send + 'static, +{ + fn public(input: Input) -> Value { + serde_json::to_value(input).unwrap_or_default() + } +} + pub async fn create( event_access: Option>>, State(state): State>, Json(req): Json, ) -> ApiResult where - T: RequestExt + HookExt + 'static, + T: RequestExt + HookExt + PublicExt + 'static, U: Serialize + DeserializeOwned + Unpin + Sync + Send + Debug + 'static, { let output = event_access @@ -168,7 +178,7 @@ pub async fn read( State(state): State>, ) -> Result>, ApiError> where - T: RequestExt + 'static, + T: RequestExt + PublicExt + 'static, U: Serialize + DeserializeOwned + Unpin + Sync + Send + Debug + 'static, { let query = shape_mongo_filter( @@ -332,7 +342,7 @@ pub async fn delete( State(state): State>, ) -> ApiResult where - T: RequestExt + 'static, + T: RequestExt + PublicExt + 'static, U: Serialize + DeserializeOwned + Unpin + Sync + Send + 'static, { let store = T::get_store(state.app_stores.clone()); diff --git a/api/src/endpoints/pipeline.rs b/api/src/endpoints/pipeline.rs index ca6b3c16..73cfb3a7 100644 --- a/api/src/endpoints/pipeline.rs +++ b/api/src/endpoints/pipeline.rs @@ -1,4 +1,4 @@ -use super::{create, delete, read, update, HookExt, RequestExt}; +use super::{create, delete, read, update, HookExt, PublicExt, RequestExt}; use crate::server::{AppState, AppStores}; use axum::{routing::post, Router}; use bson::doc; @@ -44,6 +44,7 @@ pub struct CreatePipelineRequest { } impl HookExt for CreatePipelineRequest {} +impl PublicExt for CreatePipelineRequest {} impl RequestExt for CreatePipelineRequest { type Output = Pipeline; diff --git a/api/src/endpoints/platform.rs b/api/src/endpoints/platform.rs index 0211d266..4e9bff05 100644 --- a/api/src/endpoints/platform.rs +++ b/api/src/endpoints/platform.rs @@ -1,4 +1,4 @@ -use super::{create, delete, read, update, HookExt, RequestExt}; +use super::{create, delete, read, update, HookExt, PublicExt, RequestExt}; use crate::server::{AppState, AppStores}; use axum::{ routing::{patch, post}, @@ -40,6 +40,7 @@ pub struct CreateRequest { } impl HookExt for CreateRequest {} +impl PublicExt for CreateRequest {} impl RequestExt for CreateRequest { type Output = PlatformData; diff --git a/api/src/endpoints/platform_page.rs b/api/src/endpoints/platform_page.rs index 742a394c..5d024e26 100644 --- a/api/src/endpoints/platform_page.rs +++ b/api/src/endpoints/platform_page.rs @@ -1,4 +1,4 @@ -use super::{delete, read, update, ApiResult, HookExt, RequestExt}; +use super::{delete, read, update, ApiResult, HookExt, PublicExt, RequestExt}; use crate::{ bad_request, internal_server_error, server::{AppState, AppStores}, @@ -54,6 +54,7 @@ pub struct CreateRequest { } impl HookExt for CreateRequest {} +impl PublicExt for CreateRequest {} pub async fn create_platform_page( event_access: Option>>, diff --git a/api/src/endpoints/transactions.rs b/api/src/endpoints/transactions.rs index 2e12ebdd..1f3df917 100644 --- a/api/src/endpoints/transactions.rs +++ b/api/src/endpoints/transactions.rs @@ -1,4 +1,4 @@ -use super::{read, RequestExt}; +use super::{read, PublicExt, RequestExt}; use crate::server::{AppState, AppStores}; use axum::{routing::get, Router}; use bson::doc; @@ -13,6 +13,7 @@ pub fn get_router() -> Router> { #[derive(Serialize, Deserialize)] pub struct TransactionCrud; +impl PublicExt for TransactionCrud {} impl RequestExt for TransactionCrud { type Output = Transaction;