Skip to content

Commit

Permalink
Removing sensitive data from connection configuration (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez authored May 6, 2024
1 parent 08f718e commit d742cc1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
9 changes: 7 additions & 2 deletions api/src/endpoints/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,21 @@ pub async fn delete_connection(
Path(id): Path<String>,
State(state): State<Arc<AppState>>,
) -> Result<Json<DeleteResponse>, (StatusCode, Json<ErrorResponse>)> {
let Json(found_connection) = delete::<CreateConnectionPayload, Connection>(
let response = delete::<CreateConnectionPayload, Connection>(
Some(Extension(user_event_access.clone())),
Path(id.clone()),
State(state.clone()),
)
.await?;

let connection = serde_json::from_value::<Connection>(response.0.clone()).map_err(|e| {
error!("Error deserializing connection in delete: {:?}", e);
bad_request!("Invalid connection")
})?;

let partial_cursor_key = format!(
"{}::{}::{}",
user_event_access.ownership.id, id, found_connection.key
user_event_access.ownership.id, id, connection.key
);

let mongo_regex = Regex {
Expand Down
12 changes: 6 additions & 6 deletions api/src/endpoints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub async fn create<T, U>(
event_access: Option<Extension<Arc<EventAccess>>>,
State(state): State<Arc<AppState>>,
Json(req): Json<T>,
) -> ApiResult<U>
) -> Result<Json<Value>, ApiError>
where
T: RequestExt<Output = U> + HookExt<U> + PublicExt<U> + 'static,
U: Serialize + DeserializeOwned + Unpin + Sync + Send + Debug + 'static,
Expand All @@ -154,7 +154,7 @@ where
})
.ok();

Ok(Json(output))
Ok(Json(T::public(output)))
}
Err(e) => {
error!("Error creating object: {e}");
Expand All @@ -176,7 +176,7 @@ pub async fn read<T, U>(
event_access: Option<Extension<Arc<EventAccess>>>,
query: Option<Query<BTreeMap<String, String>>>,
State(state): State<Arc<AppState>>,
) -> Result<Json<ReadResponse<U>>, ApiError>
) -> Result<Json<ReadResponse<Value>>, ApiError>
where
T: RequestExt<Output = U> + PublicExt<U> + 'static,
U: Serialize + DeserializeOwned + Unpin + Sync + Send + Debug + 'static,
Expand All @@ -202,7 +202,7 @@ where

let res = match try_join!(count, find) {
Ok((total, rows)) => ReadResponse {
rows,
rows: rows.into_iter().map(T::public).collect(),
skip: query.skip,
limit: query.limit,
total,
Expand Down Expand Up @@ -340,7 +340,7 @@ pub async fn delete<T, U>(
event_access: Option<Extension<Arc<EventAccess>>>,
Path(id): Path<String>,
State(state): State<Arc<AppState>>,
) -> ApiResult<U>
) -> Result<Json<Value>, ApiError>
where
T: RequestExt<Output = U> + PublicExt<U> + 'static,
U: Serialize + DeserializeOwned + Unpin + Sync + Send + 'static,
Expand Down Expand Up @@ -378,7 +378,7 @@ where
)
.await
{
Ok(_) => Ok(Json(res)),
Ok(_) => Ok(Json(T::public(res))),
Err(e) => {
error!("Could not update record in store: {e}");
Err(internal_server_error!())
Expand Down
18 changes: 15 additions & 3 deletions api/src/routes/public.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::{
endpoints::{
connection_definition, connection_model_schema, connection_oauth_definition,
event_access::create_event_access_for_new_user, openapi, read_cached,
common_enum, common_model, connection_definition, connection_model_schema,
connection_oauth_definition, event_access::create_event_access_for_new_user, openapi, read,
read_cached,
},
middleware::jwt_auth::{self, JwtState},
server::AppState,
Expand All @@ -11,7 +12,9 @@ use axum::{
routing::{get, post},
Router,
};
use integrationos_domain::connection_definition::ConnectionDefinition;
use integrationos_domain::{
common_model::CommonModel, connection_definition::ConnectionDefinition,
};
use std::sync::Arc;
use tower_http::trace::TraceLayer;

Expand Down Expand Up @@ -40,6 +43,15 @@ pub fn get_router(state: &Arc<AppState>) -> Router<Arc<AppState>> {
"/connection-data/models/:platform_name",
get(connection_model_schema::get_platform_models),
)
.nest(
"/sdk",
Router::new()
.route(
"/common-models",
get(read::<common_model::CreateRequest, CommonModel>),
)
.route("/common-enums", get(common_enum::read)),
)
.route(
"/connection-data/:model/:platform_name",
get(connection_definition::public_get_connection_details),
Expand Down

0 comments on commit d742cc1

Please sign in to comment.