Skip to content
Open
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,10 @@ test.docker-compose.yml
fluvio-data/
fluvio-metadata/
mongo-data/

#Deployment files
deployment.yaml
k8s/

# Scripts
*.py
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,28 @@ To stop the docker containers, simply run:
pica stop
```

### Testing API Locally

To test the API locally, a JWT token is required. Ensure the `connections-api` service is built and running with the latest changes before generating the token.

1. Build and run the `connections-api` service:
```bash
docker compose build connections-api
docker compose up connections-api
```

2. Install the required dependencies:
```bash
cd scripts
npm install
```

3. Generate the token:
```bash
node generate_jwt_token.js
```



## License

Expand Down
4 changes: 4 additions & 0 deletions api/src/domain/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ pub struct ConnectionsConfig {
/// This is the admin secret for the API. Be sure this value is not the one use to generate
/// tokens for the users as it gives access to sensitive admin endpoints.
pub jwt_secret: String,
#[envconfig(from = "BUILDABLE_SECRET", default = "")]
/// The buildable secret used for core tokens (isBuildableCore: true).
/// Combined with JWT_SECRET to verify tokens from typescript-services.
pub buildable_secret: String,
#[envconfig(from = "CONNECTIONS_URL", default = "http://localhost:3005")]
/// Same as self url, but this may vary in a k8s environment hence it's a separate config
pub connections_url: String,
Expand Down
124 changes: 122 additions & 2 deletions api/src/logic/connection_definition.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use super::{create, delete, read, update, HookExt, PublicExt, ReadResponse, RequestExt};
use super::{
create, read, update, HookExt, PublicExt, ReadResponse, RequestExt, SuccessResponse,
};
use crate::{
helper::shape_mongo_filter,
router::ServerResponse,
Expand Down Expand Up @@ -43,8 +45,101 @@ pub fn get_router() -> Router<Arc<AppState>> {
.route(
"/:id",
patch(update::<CreateRequest, ConnectionDefinition>)
.delete(delete::<CreateRequest, ConnectionDefinition>),
.delete(delete_by_connection_definition_id),
)
}

pub async fn delete_by_connection_definition_id(
Path(id): Path<String>,
State(state): State<Arc<AppState>>,
) -> Result<Json<ServerResponse<SuccessResponse>>, PicaError> {
let stores = &state.app_stores;

// 1. ConnectionDefinition
stores
.connection_config
.collection
.delete_one(
doc! {
"_id": &id
},
)
.await
.map_err(|e| {
error!("Error deleting connection definition: {e}");
e
})?;

// 2. ConnectionModelDefinition
stores
.model_config
.collection
.delete_many(
doc! {
"connectionDefinitionId": &id
},
)
.await
.map_err(|e| {
error!("Error deleting connection model definitions: {e}");
e
})?;

// 3. ConnectionModelSchema
stores
.model_schema
.collection
.delete_many(
doc! {
"connectionDefinitionId": &id
},
)
.await
.map_err(|e| {
error!("Error deleting connection model schemas: {e}");
e
})?;

// 4. PlatformData
stores
.platform
.collection
.delete_many(
doc! {
"connectionDefinitionId": &id
},
)
.await
.map_err(|e| {
error!("Error deleting platform data: {e}");
e
})?;

// 5. Settings
stores
.settings
.update_many(
doc! {
"connectedPlatforms.connectionDefinitionId": &id
},
doc! {
"$pull": {
"connectedPlatforms": {
"connectionDefinitionId": &id
}
}
},
)
.await
.map_err(|e| {
error!("Error updating settings: {e}");
e
})?;

Ok(Json(ServerResponse::new(
"delete",
SuccessResponse { success: true },
)))
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Dummy)]
Expand Down Expand Up @@ -387,6 +482,31 @@ impl RequestExt for CreateRequest {
record.platform.clone_from(&self.platform);
record.multi_env = self.multi_env;
record.record_metadata.active = self.active;

// Update authentication fields
let auth_secrets: Vec<AuthSecret> = self
.authentication
.iter()
.map(|item| AuthSecret {
name: item.name.to_string(),
})
.collect();

let connection_form_items: Vec<FormDataItem> = self
.authentication
.iter()
.map(|item| FormDataItem {
name: item.name.clone(),
r#type: item.r#type.clone(),
label: item.label.clone(),
placeholder: item.placeholder.clone(),
})
.collect();

record.auth_secrets = auth_secrets;
record.auth_method.clone_from(&self.auth_method);
record.frontend.connection_form.form_data = connection_form_items;

record
}

Expand Down
Loading
Loading