Skip to content

Commit 2ff55d0

Browse files
authored
Merge pull request #12 from cloudgraphdev/beta
RELEASE: 0.19.0
2 parents e0fe15f + 16c6528 commit 2ff55d0

File tree

11 files changed

+324
-246
lines changed

11 files changed

+324
-246
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1+
# [0.19.0-beta.1](https://github.com/cloudgraphdev/sdk/compare/0.18.1...0.19.0-beta.1) (2022-05-02)
2+
3+
4+
### Bug Fixes
5+
6+
* Fixed empty rules edge case ([4953a6c](https://github.com/cloudgraphdev/sdk/commit/4953a6ce10b9e41d5f569f80fcdbed6db88be0b8))
7+
8+
9+
### Features
10+
11+
* Considered edge cases for aws provider extra fields ([ab75afa](https://github.com/cloudgraphdev/sdk/commit/ab75afa8bfeb0949e053bb38440cae5ce1628ded))
12+
* Reduced mutations payload ([f931f91](https://github.com/cloudgraphdev/sdk/commit/f931f91c8df7a856f68d631bf801666a4f0a7ab6))
13+
* Refactored RulesEngine to improve mutations performance ([af20dea](https://github.com/cloudgraphdev/sdk/commit/af20dea938b83e79c714114747ebd08b0284ba38))
14+
15+
# [0.19.0-alpha.1](https://github.com/cloudgraphdev/sdk/compare/0.18.1...0.19.0-alpha.1) (2022-04-25)
16+
17+
18+
### Bug Fixes
19+
20+
* Fixed empty rules edge case ([4953a6c](https://github.com/cloudgraphdev/sdk/commit/4953a6ce10b9e41d5f569f80fcdbed6db88be0b8))
21+
22+
23+
### Features
24+
25+
* Considered edge cases for aws provider extra fields ([ab75afa](https://github.com/cloudgraphdev/sdk/commit/ab75afa8bfeb0949e053bb38440cae5ce1628ded))
26+
* Reduced mutations payload ([f931f91](https://github.com/cloudgraphdev/sdk/commit/f931f91c8df7a856f68d631bf801666a4f0a7ab6))
27+
* Refactored RulesEngine to improve mutations performance ([af20dea](https://github.com/cloudgraphdev/sdk/commit/af20dea938b83e79c714114747ebd08b0284ba38))
28+
129
## [0.18.1](https://gitlab.com/auto-cloud/cloudgraph/sdk/compare/0.18.0...0.18.1) (2022-03-23)
230

331

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudgraph/sdk",
3-
"version": "0.18.1",
3+
"version": "0.19.0-beta.1",
44
"description": "SDK for cloud graph providers and cli",
55
"main": "dist/src/index.js",
66
"types": "dist/src/index.d.ts",
@@ -66,4 +66,4 @@
6666
"git add --force"
6767
]
6868
}
69-
}
69+
}

src/plugins/policyPack/index.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,18 @@ export default class PolicyPackPlugin extends Plugin {
186186
}
187187

188188
// TODO: Generalize data processor moving storage module to SDK with its interfaces
189-
private getDataProcessor({
190-
entity,
191-
provider,
192-
}: {
193-
entity: string
194-
provider: string
189+
private getDataProcessor(config: {
190+
providerName: string
191+
entityName: string
192+
typenameToFieldMap?: { [tn: string]: string }
193+
extraFields?: string[]
195194
}): DataProcessor {
196-
const dataProcessorKey = `${provider}${entity}`
195+
const dataProcessorKey = `${config.providerName}${config.entityName}`
197196
if (this.dataProcessors[dataProcessorKey]) {
198197
return this.dataProcessors[dataProcessorKey]
199198
}
200199

201-
const dataProcessor = new DgraphDataProcessor(provider, entity)
200+
const dataProcessor = new DgraphDataProcessor(config)
202201
this.dataProcessors[dataProcessorKey] = dataProcessor
203202
return dataProcessor
204203
}
@@ -256,14 +255,17 @@ export default class PolicyPackPlugin extends Plugin {
256255
continue // eslint-disable-line no-continue
257256
}
258257

259-
// Initialize RulesEngine
260-
const rulesEngine = new RulesEngine({
258+
// Initialize Data Processor
259+
const dataProcessor = this.getDataProcessor({
261260
providerName: this.provider.name,
262261
entityName: policyPackPlugin.entity,
263262
typenameToFieldMap: resourceTypeNamesToFieldsMap,
264263
extraFields: policyPackPlugin.extraFields,
265264
})
266265

266+
// Initialize RulesEngine
267+
const rulesEngine = new RulesEngine(dataProcessor)
268+
267269
this.policyPacksPlugins[policyPack] = {
268270
engine: rulesEngine,
269271
entity: policyPackPlugin.entity,
@@ -318,14 +320,8 @@ export default class PolicyPackPlugin extends Plugin {
318320
storageEngine,
319321
})
320322

321-
// Data Processor
322-
const dataProcessor = this.getDataProcessor({
323-
entity,
324-
provider: this.provider.name,
325-
})
326-
327323
// Prepare mutations
328-
const mutations = dataProcessor.prepareMutations(findings)
324+
const mutations = engine.prepareMutations(findings, rules)
329325

330326
// Save connections
331327
processConnectionsBetweenEntities({
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
import { Entity } from '../../types'
2-
import { RuleFinding } from '../types'
2+
import { Rule, RuleFinding } from '../types'
33

44
export default interface DataProcessor {
5+
readonly typenameToFieldMap: { [typeName: string]: string }
6+
7+
readonly extraFields: string[]
8+
9+
/**
10+
* Returns an GraphQL schema build dynamically based on the provider and existing resources
11+
* @returns new schemas and extensions for existing ones
12+
*/
13+
getSchema: () => string[]
14+
515
/**
616
* Transforms RuleFinding array into a mutation array for GraphQL
717
* @param findings resulted findings during rules execution
818
* @returns {Entity[]} Array of generated mutations
919
*/
10-
prepareMutations: (findings: RuleFinding[]) => Entity[]
20+
prepareFindingsMutations: (findings: RuleFinding[]) => Entity[]
21+
22+
/**
23+
* Transforms Rules array into a mutation array for GraphQL
24+
* @param rules rules metadata
25+
* @returns {Entity[]} Array of generated mutations
26+
*/
27+
prepareRulesMetadataMutations: (rules: Rule[]) => Entity[]
1128
}

0 commit comments

Comments
 (0)