@@ -3,6 +3,20 @@ import { isEmpty, uniqBy } from 'lodash'
3
3
4
4
import OperationBaseCommand from '../operation'
5
5
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
+
6
20
export default class AddPolicy extends OperationBaseCommand {
7
21
static description = 'Add new policy packs'
8
22
@@ -28,37 +42,35 @@ export default class AddPolicy extends OperationBaseCommand {
28
42
} = installedPolicy
29
43
30
44
// 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 = { }
61
68
}
69
+ config . cloudGraph . plugins [ PluginType . PolicyPack ] = uniqBy (
70
+ configuredPolicies ,
71
+ 'name'
72
+ )
73
+ this . saveCloudGraphConfigFile ( config )
62
74
}
63
75
} catch ( error ) {
64
76
this . logger . debug ( error )
0 commit comments