diff --git a/Cargo.lock b/Cargo.lock index 9e2db942..0afc26a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1659,9 +1659,9 @@ dependencies = [ [[package]] name = "integrationos-domain" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10979a5f9f49b10ac4cf02c88e11a9e795aebb9fb9d5926d1dd7d4f7e44f9823" +checksum = "f9a6bebef0d5aa4e358110a038a839ef39f26e25cc3e21b773a147c396550dfb" dependencies = [ "aes", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 03b06d41..d7e23d0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ futures-util = "0.3.28" handlebars = "4.4.0" http = "1.1.0" http-serde-ext = "1.0.2" -integrationos-domain = "3.0.1" +integrationos-domain = "3.0.3" js-sandbox-ios = "0.1.0" jsonpath_lib = "0.3.0" jsonwebtoken = "8.3.0" diff --git a/api/src/endpoints/mod.rs b/api/src/endpoints/mod.rs index aba428b6..f17ae407 100644 --- a/api/src/endpoints/mod.rs +++ b/api/src/endpoints/mod.rs @@ -38,6 +38,7 @@ pub mod oauth; pub mod openapi; pub mod passthrough; pub mod pipeline; +pub mod platform; pub mod transactions; pub mod unified; diff --git a/api/src/endpoints/platform.rs b/api/src/endpoints/platform.rs new file mode 100644 index 00000000..08c775a7 --- /dev/null +++ b/api/src/endpoints/platform.rs @@ -0,0 +1,72 @@ +use super::{create, delete, read, update, CrudHook, CrudRequest}; +use crate::server::{AppState, AppStores}; +use axum::{ + routing::{patch, post}, + Router, +}; +use integrationos_domain::{ + algebra::MongoStore, + id::{prefix::IdPrefix, Id}, + ownership::Owners, + PlatformData, +}; +use mongodb::bson::doc; +use serde::{Deserialize, Serialize}; +use std::sync::Arc; + +pub fn get_router() -> Router> { + Router::new() + .route( + "/", + post(create::).get(read::), + ) + .route( + "/:id", + patch(update::) + .delete(delete::), + ) +} + +#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)] +#[cfg_attr(feature = "dummy", derive(fake::Dummy))] +#[serde(rename_all = "camelCase")] +pub struct CreateRequest { + pub connection_definition_id: Id, + pub name: String, + pub url: String, + pub version: String, + pub ownership: Owners, + pub analyzed: bool, +} + +impl CrudHook for CreateRequest {} + +impl CrudRequest for CreateRequest { + type Output = PlatformData; + + fn output(&self) -> Option { + Some(Self::Output { + id: Id::now(IdPrefix::Platform), + connection_definition_id: self.connection_definition_id, + name: self.name.clone(), + url: self.url.clone(), + platform_version: self.version.clone(), + ownership: self.ownership.clone(), + analyzed: self.analyzed, + record_metadata: Default::default(), + }) + } + + fn update(&self, record: &mut Self::Output) { + record.connection_definition_id = self.connection_definition_id; + record.name = self.name.clone(); + record.url = self.url.clone(); + record.platform_version = self.version.clone(); + record.ownership = self.ownership.clone(); + record.analyzed = self.analyzed; + } + + fn get_store(stores: AppStores) -> MongoStore { + stores.platform.clone() + } +} diff --git a/api/src/routes/private.rs b/api/src/routes/private.rs index ff63ebe7..c4372222 100644 --- a/api/src/routes/private.rs +++ b/api/src/routes/private.rs @@ -2,7 +2,7 @@ use crate::{ endpoints::{ common_model, connection_definition, connection_model_definition::{self, test_connection_model_definition}, - connection_model_schema, connection_oauth_definition, openapi, + connection_model_schema, connection_oauth_definition, openapi, platform, }, middleware::jwt_auth::{self, JwtState}, server::AppState, @@ -34,6 +34,7 @@ pub async fn get_router(state: &Arc) -> Router> { "/connection-model-schemas", connection_model_schema::get_router(), ) + .nest("/platforms", platform::get_router()) .nest("/common-models", common_model::get_router()); routes diff --git a/api/src/routes/protected.rs b/api/src/routes/protected.rs index 49c080cf..c1dfc7db 100644 --- a/api/src/routes/protected.rs +++ b/api/src/routes/protected.rs @@ -10,9 +10,7 @@ use crate::{ }, server::AppState, }; -use axum::{ - error_handling::HandleErrorLayer, middleware::from_fn_with_state, Router, -}; +use axum::{error_handling::HandleErrorLayer, middleware::from_fn_with_state, Router}; use http::HeaderName; use std::{iter::once, sync::Arc}; use tower::{filter::FilterLayer, ServiceBuilder}; diff --git a/api/src/server.rs b/api/src/server.rs index e946840f..b65ceebd 100644 --- a/api/src/server.rs +++ b/api/src/server.rs @@ -21,7 +21,7 @@ use integrationos_domain::{ cursor::Cursor, event_access::EventAccess, stage::Stage, - Connection, Event, Pipeline, Store, Transaction, + Connection, Event, Pipeline, PlatformData, Store, Transaction, }; use moka::future::Cache; use mongodb::{options::UpdateOptions, Client, Database}; @@ -42,6 +42,7 @@ pub struct AppStores { pub common_enum: MongoStore, pub connection: MongoStore, pub public_connection_details: MongoStore, + pub platform: MongoStore, pub settings: MongoStore, pub connection_config: MongoStore, pub pipeline: MongoStore, @@ -101,6 +102,7 @@ impl Server { let common_model = MongoStore::new(&db, &Store::CommonModels).await?; let common_enum = MongoStore::new(&db, &Store::CommonEnums).await?; let connection = MongoStore::new(&db, &Store::Connections).await?; + let platform = MongoStore::new(&db, &Store::Platforms).await?; let public_connection_details = MongoStore::new(&db, &Store::PublicConnectionDetails).await?; let settings = MongoStore::new(&db, &Store::Settings).await?; @@ -127,6 +129,7 @@ impl Server { frontend_oauth_config, model_schema, public_model_schema, + platform, settings, common_model, common_enum,