Skip to content

Commit

Permalink
Removing sensitive data from connection configuration (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez authored May 17, 2024
1 parent 1300391 commit 87363e0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
22 changes: 20 additions & 2 deletions api/src/endpoints/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub async fn create_connection(
Extension(user_event_access): Extension<Arc<EventAccess>>,
State(state): State<Arc<AppState>>,
Json(req): Json<CreateConnectionPayload>,
) -> Result<Json<Connection>, (StatusCode, Json<ErrorResponse>)> {
) -> Result<Json<SanitizedConnection>, (StatusCode, Json<ErrorResponse>)> {
if let Err(validation_errors) = req.validate() {
return Err(bad_request!(format!(
"Invalid payload: {:?}",
Expand Down Expand Up @@ -246,7 +246,25 @@ pub async fn create_connection(
internal_server_error!()
})?;

Ok(Json(connection))
// TODO: This should be a From impl on integrationosdomain::connection
Ok(Json(SanitizedConnection {
id: connection.id,
platform_version: connection.platform_version,
connection_definition_id: connection.connection_definition_id,
r#type: connection.r#type,
name: connection.name,
key: connection.key,
group: connection.group,
environment: connection.environment,
platform: connection.platform,
secrets_service_id: connection.secrets_service_id,
event_access_id: connection.event_access_id,
settings: connection.settings,
throughput: connection.throughput,
ownership: connection.ownership,
oauth: connection.oauth,
record_metadata: connection.record_metadata,
}))
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Validate)]
Expand Down
6 changes: 3 additions & 3 deletions api/tests/api_tests/test_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use integrationos_domain::{
event_access::EventAccess,
event_type::EventType,
get_secret_request::GetSecretRequest,
AccessKey, Claims, Connection, IntegrationOSError, Store,
AccessKey, Claims, Connection, IntegrationOSError, SanitizedConnection, Store,
};
use jsonwebtoken::EncodingKey;
use mockito::{Matcher, Server as MockServer, ServerGuard};
Expand Down Expand Up @@ -357,7 +357,7 @@ impl TestServer {
pub async fn create_connection(
&mut self,
environment: Environment,
) -> (Connection, ConnectionModelDefinition) {
) -> (SanitizedConnection, ConnectionModelDefinition) {
let (key, access_key) = match environment {
Environment::Live => (self.live_key.as_ref(), &self.live_access_key),
Environment::Development => (self.live_key.as_ref(), &self.test_access_key),
Expand Down Expand Up @@ -475,7 +475,7 @@ impl TestServer {
};

let res = self
.send_request::<CreateConnectionPayload, Connection>(
.send_request::<CreateConnectionPayload, SanitizedConnection>(
"v1/connections",
http::Method::POST,
Some(key),
Expand Down
14 changes: 6 additions & 8 deletions api/tests/api_tests/unified_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ use http::{
Method, StatusCode,
};
use integrationos_domain::{
api_model_config::{AuthMethod, SamplesInput, SchemasInput},
connection_model_definition::{ConnectionModelDefinition, CrudAction, CrudMapping},
connection_model_schema::{ConnectionModelSchema, Mappings},
environment::Environment,
id::{prefix::IdPrefix, Id},
{
api_model_config::{AuthMethod, SamplesInput, SchemasInput},
connection_model_definition::{ConnectionModelDefinition, CrudAction, CrudMapping},
connection_model_schema::{ConnectionModelSchema, Mappings},
environment::Environment,
Connection,
},
Connection, SanitizedConnection,
};
use mockito::Mock;
use serde_json::Value;
Expand Down Expand Up @@ -527,7 +525,7 @@ async fn test_unified_metrics() {

async fn create_connection_model_definition(
server: &mut TestServer,
connection: &Connection,
connection: &SanitizedConnection,
mapping: CrudMapping,
) -> Mock {
let secret_key = Faker.fake::<String>();
Expand Down

0 comments on commit 87363e0

Please sign in to comment.