@@ -15,6 +15,7 @@ import { Result, Rule, Severity } from '../../rules-engine/types'
15
15
import Plugin , { ConfiguredPlugin , PluginManager } from '../types'
16
16
import DgraphDataProcessor from '../../rules-engine/data-processors/dgraph-data-processor'
17
17
import DataProcessor from '../../rules-engine/data-processors/data-processor'
18
+ import getLinkedData from '../../utils/data'
18
19
19
20
export default class PolicyPackPlugin extends Plugin {
20
21
constructor ( {
@@ -272,60 +273,6 @@ export default class PolicyPackPlugin extends Plugin {
272
273
}
273
274
}
274
275
275
- private getLinkedData ( { providerData } : { providerData : ProviderData } ) : any {
276
- const linkedData = { }
277
- const allEntities = providerData ?. entities || [ ]
278
- const allConnections = providerData ?. connections || { }
279
- const entitiesById : { [ key : string ] : any } = { }
280
-
281
- for ( const entity of allEntities ) {
282
- // AddawsEc2Input! => queryawsEc2
283
- const mutationName = / (?< = \[ ) ( .* ?) (? = \] ) /
284
- . exec ( entity . mutation as any ) [ 0 ]
285
- . replace ( 'Add' , 'query' )
286
- . replace ( 'Input!' , '' )
287
-
288
- linkedData [ mutationName ] = entity . data
289
-
290
- for ( const entityData of entity . data ) {
291
- entitiesById [ entityData . id ] = entityData
292
- // eslint-disable-next-line no-underscore-dangle
293
- entityData . __typename = mutationName . replace ( 'query' , '' ) // or entity.name?
294
- }
295
- }
296
-
297
- // connect data on a second pass
298
- for ( const entityId of Object . keys ( allConnections ) ) {
299
- const entityConnections = allConnections [ entityId ]
300
- const entity = entitiesById [ entityId ]
301
- if ( ! entity ) {
302
- // eslint-disable-next-line no-continue
303
- continue
304
- }
305
- for ( const conn of entityConnections ) {
306
- const targetEntity = entitiesById [ conn . id ]
307
- if ( ! targetEntity ) {
308
- // eslint-disable-next-line no-continue
309
- continue
310
- }
311
- if ( conn . relation === 'child' ) {
312
- if ( ! entity [ conn . field ] ) {
313
- entity [ conn . field ] = [ ]
314
- }
315
- entity [ conn . field ] . push ( targetEntity )
316
- // inverse relation
317
- // const inverseConnField = this.schemasMap[entity.__typename] || 'account' // @TODO: account doesn't have a name
318
- // if (!targetEntity[inverseConnField]) {
319
- // targetEntity[inverseConnField] = []
320
- // }
321
- // targetEntity[inverseConnField].push(entity)
322
- } // else parent relation.. is not used atm
323
- }
324
- }
325
-
326
- return linkedData
327
- }
328
-
329
276
async execute ( {
330
277
storageRunning,
331
278
storageEngine,
@@ -368,7 +315,8 @@ export default class PolicyPackPlugin extends Plugin {
368
315
mergeSchemas ( currentSchema , findingsSchema ) ,
369
316
] )
370
317
371
- const linkedData = this . getLinkedData ( { providerData } )
318
+ // Format metadata and link connections
319
+ const linkedData = getLinkedData ( providerData )
372
320
373
321
const findings = await this . executeRule ( {
374
322
data : linkedData ,
0 commit comments