Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing sensitive data from connection configuration #16

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion api/src/endpoints/common_model.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -51,6 +51,8 @@ pub struct CreateRequest {
pub primary: bool,
}

impl PublicExt<CommonModel> for CreateRequest {}

#[async_trait]
impl HookExt<CommonModel> for CreateRequest {
async fn after_create_hook(
Expand Down
26 changes: 25 additions & 1 deletion api/src/endpoints/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{delete, read, RequestExt};
use super::{delete, read, PublicExt, RequestExt};
use crate::{
api_payloads::{DeleteResponse, ErrorResponse, UpdateResponse},
bad_request,
Expand All @@ -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,
Expand Down Expand Up @@ -92,6 +93,29 @@ async fn test_connection(
Ok(())
}

impl PublicExt<Connection> 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;

Expand Down
4 changes: 3 additions & 1 deletion api/src/endpoints/connection_definition.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -67,6 +68,7 @@ pub struct CreateRequest {
}

impl HookExt<ConnectionDefinition> for CreateRequest {}
impl PublicExt<ConnectionDefinition> for CreateRequest {}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/connection_model_definition.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -299,6 +299,7 @@ pub struct CreateRequest {
}

impl HookExt<ConnectionModelDefinition> for CreateRequest {}
impl PublicExt<ConnectionModelDefinition> for CreateRequest {}

impl RequestExt for CreateRequest {
type Output = ConnectionModelDefinition;
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/connection_model_schema.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -84,6 +84,7 @@ pub struct CreateRequest {
}

impl HookExt<ConnectionModelSchema> for CreateRequest {}
impl PublicExt<ConnectionModelSchema> for CreateRequest {}

impl RequestExt for CreateRequest {
type Output = ConnectionModelSchema;
Expand Down
5 changes: 4 additions & 1 deletion api/src/endpoints/connection_oauth_definition.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -48,6 +50,7 @@ pub struct CreateRequest {
}

impl HookExt<ConnectionOAuthDefinition> for CreateRequest {}
impl PublicExt<ConnectionOAuthDefinition> for CreateRequest {}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/event_access.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{delete, read, RequestExt};
use super::{delete, read, PublicExt, RequestExt};
use crate::{
api_payloads::ErrorResponse,
bad_request,
Expand Down Expand Up @@ -64,6 +64,7 @@ impl RequestExt for CreateEventAccessRequest {
stores.event_access
}
}
impl PublicExt<EventAccess> for CreateEventAccessRequest {}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Validate)]
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/events.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +13,7 @@ pub fn get_router() -> Router<Arc<AppState>> {
#[derive(Serialize, Deserialize)]
pub struct CreateEventRequest;

impl PublicExt<Event> for CreateEventRequest {}
impl RequestExt for CreateEventRequest {
type Output = Event;

Expand Down
16 changes: 13 additions & 3 deletions api/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,13 +117,22 @@ where
}
}

pub trait PublicExt<Input>
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<T, U>(
event_access: Option<Extension<Arc<EventAccess>>>,
State(state): State<Arc<AppState>>,
Json(req): Json<T>,
) -> ApiResult<U>
where
T: RequestExt<Output = U> + HookExt<U> + 'static,
T: RequestExt<Output = U> + HookExt<U> + PublicExt<U> + 'static,
U: Serialize + DeserializeOwned + Unpin + Sync + Send + Debug + 'static,
{
let output = event_access
Expand Down Expand Up @@ -168,7 +178,7 @@ pub async fn read<T, U>(
State(state): State<Arc<AppState>>,
) -> Result<Json<ReadResponse<U>>, ApiError>
where
T: RequestExt<Output = U> + 'static,
T: RequestExt<Output = U> + PublicExt<U> + 'static,
U: Serialize + DeserializeOwned + Unpin + Sync + Send + Debug + 'static,
{
let query = shape_mongo_filter(
Expand Down Expand Up @@ -332,7 +342,7 @@ pub async fn delete<T, U>(
State(state): State<Arc<AppState>>,
) -> ApiResult<U>
where
T: RequestExt<Output = U> + 'static,
T: RequestExt<Output = U> + PublicExt<U> + 'static,
U: Serialize + DeserializeOwned + Unpin + Sync + Send + 'static,
{
let store = T::get_store(state.app_stores.clone());
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/pipeline.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,6 +44,7 @@ pub struct CreatePipelineRequest {
}

impl HookExt<Pipeline> for CreatePipelineRequest {}
impl PublicExt<Pipeline> for CreatePipelineRequest {}

impl RequestExt for CreatePipelineRequest {
type Output = Pipeline;
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/platform.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -40,6 +40,7 @@ pub struct CreateRequest {
}

impl HookExt<PlatformData> for CreateRequest {}
impl PublicExt<PlatformData> for CreateRequest {}

impl RequestExt for CreateRequest {
type Output = PlatformData;
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/platform_page.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand Down Expand Up @@ -54,6 +54,7 @@ pub struct CreateRequest {
}

impl HookExt<PlatformPage> for CreateRequest {}
impl PublicExt<PlatformPage> for CreateRequest {}

pub async fn create_platform_page(
event_access: Option<Extension<Arc<EventAccess>>>,
Expand Down
3 changes: 2 additions & 1 deletion api/src/endpoints/transactions.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +13,7 @@ pub fn get_router() -> Router<Arc<AppState>> {
#[derive(Serialize, Deserialize)]
pub struct TransactionCrud;

impl PublicExt<Transaction> for TransactionCrud {}
impl RequestExt for TransactionCrud {
type Output = Transaction;

Expand Down
Loading