Skip to content

Commit ef54ece

Browse files
authored
feat: add connector description to vault connections list (#297)
1 parent 935576e commit ef54ece

File tree

2 files changed

+115
-36
lines changed

2 files changed

+115
-36
lines changed

api/src/logic/connection.rs

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use super::{delete, read, PublicExt, RequestExt};
1+
use super::{delete, read, PublicExt, ReadResponse, RequestExt};
22
use crate::{
3-
helper::{DeploymentSpecParams, ServiceName, ServiceSpecParams},
3+
helper::{shape_mongo_filter, DeploymentSpecParams, ServiceName, ServiceSpecParams},
44
logic::event_access::{
55
generate_event_access, get_client_throughput, CreateEventAccessPayloadWithOwnership,
66
},
@@ -9,7 +9,7 @@ use crate::{
99
};
1010
use anyhow::{bail, Result};
1111
use axum::{
12-
extract::{Path, State},
12+
extract::{Path, Query, State},
1313
routing::{delete as axum_delete, get, patch, post},
1414
Extension, Json, Router,
1515
};
@@ -26,6 +26,7 @@ use osentities::{
2626
connection_definition::{ConnectionDefinition, ConnectionDefinitionType},
2727
database::{DatabasePodConfig, PostgresConfig},
2828
database_secret::DatabaseConnectionSecret,
29+
domain::configuration::environment::Environment,
2930
domain::connection::SanitizedConnection,
3031
event_access::EventAccess,
3132
id::{prefix::IdPrefix, Id},
@@ -651,3 +652,108 @@ pub async fn delete_connection(
651652
}),
652653
)))
653654
}
655+
656+
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
657+
#[serde(rename_all = "camelCase")]
658+
pub struct VaultConnection {
659+
#[serde(rename = "_id")]
660+
pub id: Id,
661+
pub platform_version: String,
662+
pub name: Option<String>,
663+
pub r#type: ConnectionType,
664+
pub key: Arc<str>,
665+
pub environment: Environment,
666+
pub platform: Arc<str>,
667+
pub identity: Option<String>,
668+
pub identity_type: Option<ConnectionIdentityType>,
669+
pub description: String,
670+
#[serde(flatten, default)]
671+
pub record_metadata: RecordMetadata,
672+
}
673+
674+
pub async fn get_vault_connections(
675+
Extension(access): Extension<Arc<EventAccess>>,
676+
headers: HeaderMap,
677+
query: Option<Query<BTreeMap<String, String>>>,
678+
State(state): State<Arc<AppState>>,
679+
) -> Result<Json<ServerResponse<ReadResponse<VaultConnection>>>, PicaError> {
680+
let mongo_query = shape_mongo_filter(query, Some(access), Some(headers));
681+
682+
let connections = state
683+
.app_stores
684+
.connection
685+
.get_many(
686+
Some(mongo_query.filter.clone()),
687+
None,
688+
None,
689+
Some(mongo_query.limit),
690+
Some(mongo_query.skip),
691+
)
692+
.await
693+
.map_err(|e| {
694+
error!("Error fetching connections: {:?}", e);
695+
e
696+
})?;
697+
698+
let mut vault_connections = Vec::new();
699+
700+
for connection in connections {
701+
let connection_definition = match state
702+
.app_stores
703+
.connection_config
704+
.get_one_by_id(&connection.connection_definition_id.to_string())
705+
.await
706+
{
707+
Ok(Some(definition)) => definition,
708+
Ok(None) => {
709+
// Skip connections with missing definitions
710+
error!(
711+
"Connection definition with id {} not found",
712+
connection.connection_definition_id
713+
);
714+
continue;
715+
}
716+
Err(e) => {
717+
error!("Error fetching connection definition: {:?}", e);
718+
continue;
719+
}
720+
};
721+
722+
let description = connection_definition.frontend.spec.description;
723+
724+
let vault_connection = VaultConnection {
725+
id: connection.id,
726+
platform_version: connection.platform_version,
727+
name: connection.name,
728+
r#type: connection.r#type,
729+
key: connection.key,
730+
environment: connection.environment,
731+
platform: connection.platform,
732+
identity: connection.identity,
733+
identity_type: connection.identity_type,
734+
description,
735+
record_metadata: connection.record_metadata,
736+
};
737+
738+
vault_connections.push(vault_connection);
739+
}
740+
741+
let total = state
742+
.app_stores
743+
.connection
744+
.count(mongo_query.filter, None)
745+
.await
746+
.map_err(|e| {
747+
error!("Error counting connections: {:?}", e);
748+
e
749+
})?;
750+
751+
let response = ReadResponse {
752+
rows: vault_connections,
753+
skip: mongo_query.skip,
754+
limit: mongo_query.limit,
755+
total,
756+
};
757+
758+
Ok(Json(ServerResponse::new("Vault Connections", response)))
759+
}

api/src/logic/vault_connection.rs

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,18 @@
1-
use super::{
2-
connection::{create_connection, delete_connection, update_connection},
3-
read, PublicExt, RequestExt,
1+
use super::connection::{
2+
create_connection, delete_connection, get_vault_connections, update_connection,
43
};
5-
use crate::server::{AppState, AppStores};
4+
use crate::server::AppState;
65
use axum::{
76
routing::{delete, get, patch, post},
87
Router,
98
};
10-
use mongodb::bson::doc;
11-
use osentities::{algebra::MongoStore, id::Id, ConnectionIdentityType, PublicConnection};
12-
use serde::{Deserialize, Serialize};
13-
use std::{collections::HashMap, sync::Arc};
14-
use validator::Validate;
9+
10+
use std::sync::Arc;
1511

1612
pub fn get_router() -> Router<Arc<AppState>> {
1713
Router::new()
1814
.route("/", post(create_connection))
19-
.route(
20-
"/",
21-
get(read::<CreatePublicConnectionPayload, PublicConnection>),
22-
)
2315
.route("/:id", patch(update_connection))
2416
.route("/:id", delete(delete_connection))
25-
}
26-
27-
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Validate)]
28-
#[serde(rename_all = "camelCase")]
29-
pub struct CreatePublicConnectionPayload {
30-
pub connection_definition_id: Id,
31-
pub auth_form_data: HashMap<String, String>,
32-
pub active: bool,
33-
pub identity: Option<String>,
34-
pub identity_type: Option<ConnectionIdentityType>,
35-
}
36-
37-
impl PublicExt<PublicConnection> for CreatePublicConnectionPayload {}
38-
39-
impl RequestExt for CreatePublicConnectionPayload {
40-
type Output = PublicConnection;
41-
42-
fn get_store(stores: AppStores) -> MongoStore<Self::Output> {
43-
stores.public_connection
44-
}
17+
.route("/", get(get_vault_connections))
4518
}

0 commit comments

Comments
 (0)