1- use super :: { delete, read, PublicExt , RequestExt } ;
1+ use super :: { delete, read, PublicExt , ReadResponse , RequestExt } ;
22use 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} ;
1010use anyhow:: { bail, Result } ;
1111use 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+ }
0 commit comments