Skip to content

Commit

Permalink
feat: implementing knowledge endpoint (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagojez authored Jan 28, 2025
1 parent 066a93e commit a01407d
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 4 deletions.
35 changes: 35 additions & 0 deletions api/src/logic/knowledge.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use super::{read, HookExt, PublicExt, RequestExt};
use crate::server::{AppState, AppStores};
use axum::{routing::get, Router};
use entities::{Id, MongoStore};
use fake::Dummy;
use serde::{Deserialize, Serialize};
use std::sync::Arc;

pub fn get_router() -> Router<Arc<AppState>> {
Router::new()
.route("/", get(read::<ReadRequest, Knowledge>))
.route("/:id", get(read::<ReadRequest, Knowledge>))
}

struct ReadRequest;

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Dummy)]
#[serde(rename_all = "camelCase")]
pub struct Knowledge {
#[serde(rename = "_id")]
pub id: Id,
pub connection_platform: String,
pub title: String,
pub knowledge: Option<String>,
}

impl HookExt<Knowledge> for ReadRequest {}
impl PublicExt<Knowledge> for ReadRequest {}
impl RequestExt for ReadRequest {
type Output = Knowledge;

fn get_store(stores: AppStores) -> MongoStore<Self::Output> {
stores.knowledge
}
}
1 change: 1 addition & 0 deletions api/src/logic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod connection_oauth_definition;
pub mod event_access;
pub mod event_callback;
pub mod events;
pub mod knowledge;
pub mod metrics;
pub mod oauth;
pub mod openapi;
Expand Down
2 changes: 2 additions & 0 deletions api/src/logic/passthrough.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ pub async fn passthrough_request(
)
.await?;

tracing::info!("Executing {} request on {}", method, uri.path());

let destination = Destination {
platform: connection.platform.clone(),
action: Action::Passthrough {
Expand Down
4 changes: 3 additions & 1 deletion api/src/router/secured_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use crate::{
connection_model_schema::{
public_get_connection_model_schema, PublicGetConnectionModelSchema,
},
event_access, events, metrics, oauth, passthrough, secrets, unified, vault_connection,
event_access, events, knowledge, metrics, oauth, passthrough, secrets, unified,
vault_connection,
},
middleware::{
header_auth,
Expand Down Expand Up @@ -36,6 +37,7 @@ pub async fn get_router(state: &Arc<AppState>) -> Router<Arc<AppState>> {
.nest("/connections", connection::get_router())
.nest("/event-access", event_access::get_router())
.nest("/events", events::get_router())
.nest("/knowledge", knowledge::get_router())
.nest("/metrics", metrics::get_router())
.nest("/oauth", oauth::get_router())
.nest("/passthrough", passthrough::get_router())
Expand Down
8 changes: 7 additions & 1 deletion api/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::{
domain::{ConnectionsConfig, K8sMode, Metric},
helper::{K8sDriver, K8sDriverImpl, K8sDriverLogger},
logic::{connection_oauth_definition::FrontendOauthConnectionDefinition, openapi::OpenAPIData},
logic::{
connection_oauth_definition::FrontendOauthConnectionDefinition, knowledge::Knowledge,
openapi::OpenAPIData,
},
router,
};
use anyhow::{anyhow, Context, Result};
Expand Down Expand Up @@ -50,6 +53,7 @@ pub struct AppStores {
pub public_connection: MongoStore<PublicConnection>,
pub public_connection_details: MongoStore<PublicConnectionDetails>,
pub public_model_schema: MongoStore<PublicConnectionModelSchema>,
pub knowledge: MongoStore<Knowledge>,
pub secrets: MongoStore<Secret>,
pub settings: MongoStore<Settings>,
}
Expand Down Expand Up @@ -105,6 +109,7 @@ impl Server {
let connection_config = MongoStore::new(&db, &Store::ConnectionDefinitions).await?;
let event_access = MongoStore::new(&db, &Store::EventAccess).await?;
let event = MongoStore::new(&db, &Store::Events).await?;
let knowledge = MongoStore::new(&db, &Store::ConnectionModelDefinitions).await?;
let clients = MongoStore::new(&db, &Store::Clients).await?;
let secrets_store = MongoStore::<Secret>::new(&db, &Store::Secrets).await?;

Expand Down Expand Up @@ -152,6 +157,7 @@ impl Server {
public_connection_details,
connection_config,
event_access,
knowledge,
event,
clients,
};
Expand Down
1 change: 1 addition & 0 deletions entities/src/domain/constant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub const PAGE_SIZE_KEY: &str = "pageSize";
pub const PAGINATION_KEY: &str = "pagination";
pub const STATUS_HEADER_KEY: &str = "response-status";
pub const META_KEY: &str = "meta";
pub const ACTION_KEY: &str = "action";

// Database constants
pub const MAX_LIMIT: usize = 100;
Expand Down
5 changes: 3 additions & 2 deletions unified/src/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,11 @@ fn build_unified_response(
tracing::info!("No response body to map for this action. ID: {}", config.id);
}

let mut builder = Response::builder();

// Insert passthrough data if needed
if is_passthrough {
builder = builder.header(ACTION_KEY.to_string(), config.title.to_string());
if let Some(passthrough) = passthrough {
if let Value::Object(ref mut resp) = response {
resp.insert(PASSTHROUGH_KEY.to_string(), passthrough);
Expand Down Expand Up @@ -747,8 +750,6 @@ fn build_unified_response(
resp.insert(META_KEY.to_string(), metadata_value.as_value().clone());
}

let mut builder = Response::builder();

if status.is_success() {
builder = builder
.header::<&'static str, HeaderValue>(STATUS_HEADER_KEY, status.as_u16().into())
Expand Down

0 comments on commit a01407d

Please sign in to comment.