@@ -3,6 +3,20 @@ import { isEmpty, uniqBy } from 'lodash'
33
44import OperationBaseCommand from '../operation'
55
6+ const defaultCGConfig = {
7+ cloudGraph : {
8+ plugins : { } ,
9+ storageConfig : {
10+ host : 'localhost' ,
11+ port : '8997' ,
12+ scheme : 'http' ,
13+ } ,
14+ versionLimit : 10 ,
15+ queryEngine : 'playground' ,
16+ port : '5555' ,
17+ } ,
18+ }
19+
620export default class AddPolicy extends OperationBaseCommand {
721 static description = 'Add new policy packs'
822
@@ -28,37 +42,35 @@ export default class AddPolicy extends OperationBaseCommand {
2842 } = installedPolicy
2943
3044 // Save policy to CG config file
31- const config = this . getCGConfig ( )
32- if ( config ) {
33- let configuredPolicies =
34- config . cloudGraph . plugins ?. [ PluginType . PolicyPack ] || [ ]
35- if ( isEmpty ( configuredPolicies ) ) {
36- // Set new Policy Pack Plugin array
37- configuredPolicies = [
38- {
39- name : key ,
40- providers : [ provider ] ,
41- } ,
42- ]
43- } else {
44- // Add policy to Policy Pack Plugin array
45- configuredPolicies = [
46- ...configuredPolicies ,
47- {
48- name : key ,
49- providers : [ provider ] ,
50- } ,
51- ]
52- }
53- if ( ! config . cloudGraph . plugin ) {
54- config . cloudGraph . plugins = { }
55- }
56- config . cloudGraph . plugins [ PluginType . PolicyPack ] = uniqBy (
57- configuredPolicies ,
58- 'name'
59- )
60- this . saveCloudGraphConfigFile ( config )
45+ const config = this . getCGConfig ( ) || defaultCGConfig
46+ let configuredPolicies =
47+ config . cloudGraph . plugins ?. [ PluginType . PolicyPack ] || [ ]
48+ if ( isEmpty ( configuredPolicies ) ) {
49+ // Set new Policy Pack Plugin array
50+ configuredPolicies = [
51+ {
52+ name : key ,
53+ providers : [ provider ] ,
54+ } ,
55+ ]
56+ } else {
57+ // Add policy to Policy Pack Plugin array
58+ configuredPolicies = [
59+ ...configuredPolicies ,
60+ {
61+ name : key ,
62+ providers : [ provider ] ,
63+ } ,
64+ ]
65+ }
66+ if ( ! config . cloudGraph . plugin ) {
67+ config . cloudGraph . plugins = { }
6168 }
69+ config . cloudGraph . plugins [ PluginType . PolicyPack ] = uniqBy (
70+ configuredPolicies ,
71+ 'name'
72+ )
73+ this . saveCloudGraphConfigFile ( config )
6274 }
6375 } catch ( error ) {
6476 this . logger . debug ( error )
0 commit comments