@@ -80,6 +80,40 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
80
80
} ) ) ;
81
81
}
82
82
83
+ /**
84
+ * Fetch all credentials for a given workspace
85
+ * @param {string } options.workspaceId
86
+ * @returns {Promise<[{{
87
+ * secretId: string,
88
+ * secretName: string,
89
+ * componentIds: string[],
90
+ * }}]> }
91
+ */
92
+ async fetchAllSecretsForWorkspace ( options : any = { } ) {
93
+ const { workspaceId } = options ;
94
+ if ( ! workspaceId ) throw new Error ( `workspaceId not provided, can't fetch secrets` )
95
+ const secrets = await this . makeRequest ( { method : 'GET' , url : `/workspaces/${ workspaceId } /secrets` } ) ;
96
+ const resp : any = [ ] ;
97
+
98
+ for ( const secret of secrets . data ) {
99
+ const secretId = secret . id ;
100
+ const secretName = secret . attributes . name . trim ( ) ;
101
+ let componentIds : any = [ ] ;
102
+ try {
103
+ if ( secret . relationships . component ) componentIds . push ( secret . relationships . component . data . id ) ;
104
+ if ( secret . relationships . auth_client ) {
105
+ const clientId = secret . relationships . auth_client . data . id ;
106
+ const clientResponse = await this . makeRequest ( { method : 'GET' , url : `/auth-clients/${ clientId } ` } ) ;
107
+ componentIds = clientResponse . data . relationships . components . data . map ( x => x . id ) ;
108
+ }
109
+ } catch ( e : any ) {
110
+ this . emitter . logger . info ( `Can't find related to secret component - ${ e . message } ` )
111
+ }
112
+ resp . push ( { secretId, secretName, componentIds } ) ;
113
+ }
114
+ return resp ;
115
+ }
116
+
83
117
/**
84
118
* Fetch All Components Accessible From a Given Workspace
85
119
* @param {string } options.contractId Contract ID
@@ -147,10 +181,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
147
181
const workspaces = await this . fetchWorkspaceList ( { } ) ;
148
182
if ( ! workspaceId ) {
149
183
const nonFlatFlows = await mapLimit ( workspaces , realSplitFactor ,
150
- async workspace => this . fetchAllFlowsForWorkspace ( {
151
- parallelCalls : parallelizationPerTask ,
152
- workspaceId : workspace . workspaceId ,
153
- } ) ) ;
184
+ async workspace => this . fetchAllFlowsForWorkspace ( { parallelCalls : parallelizationPerTask , workspaceId : workspace . workspaceId } ) ) ;
154
185
flows = nonFlatFlows . flat ( ) ;
155
186
} else {
156
187
flows = await this . fetchAllFlowsForWorkspace ( {
@@ -244,7 +275,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
244
275
/* eslint-disable-next-line no-param-reassign */
245
276
soFar [ contract . id ] = contract ;
246
277
return soFar ;
247
- } , { } ) ;
278
+ } , { } ) ;
248
279
249
280
const nonFlatWorkspaces = await mapLimit (
250
281
contracts ,
@@ -521,7 +552,7 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
521
552
/* eslint-disable-next-line no-param-reassign */
522
553
soFar [ sample . sampleId ] = sample . sample ;
523
554
return soFar ;
524
- } , { } ) ;
555
+ } , { } ) ;
525
556
flow . attributes . graph . nodes
526
557
. filter ( node => node . selected_data_samples )
527
558
. forEach ( ( node ) => {
@@ -562,6 +593,20 @@ export class PlatformApiLogicClient extends PlatformApiRestClient {
562
593
}
563
594
} ) ;
564
595
596
+ const secretsList = await this . fetchAllSecretsForWorkspace ( {
597
+ workspaceId : flow . relationships . workspace . data . id ,
598
+ } ) ;
599
+ flow . attributes . graph . nodes . forEach ( ( node ) => {
600
+ if ( node . secret_id ) {
601
+ const matchingSecrets = secretsList . filter ( secret => secret . secretId === node . secret_id ) ;
602
+ if ( matchingSecrets . length !== 1 ) throw new Error ( 'Expected a single matching secret' ) ;
603
+ /* eslint-disable-next-line no-param-reassign */
604
+ node . secret_id = {
605
+ secretId : matchingSecrets [ 0 ] . secretId ,
606
+ secretName : matchingSecrets [ 0 ] . secretName ,
607
+ } ;
608
+ }
609
+ } ) ;
565
610
// Enrich command and component Id fields
566
611
flow . attributes . graph . nodes . forEach ( ( node ) => {
567
612
const commandParts = node . command . split ( / [ / : @ ] / ) ;
0 commit comments