MCPcopy Create free account
hub / github.com/cloudgraphdev/cli / run

Method run

src/commands/policy/add.ts:21–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19 static hidden = false
20
21 async run(): Promise<void> {
22 try {
23 const installedPolicies = await this.add(PluginType.PolicyPack)
24
25 for (const installedPolicy of installedPolicies) {
26 const {
27 key,
28 plugin: { default: { provider } } = { default: { provider: '' } },
29 } = installedPolicy
30
31 // Save policy to CG config file
32 const config = this.getCGConfig() || DEFAULT_CG_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)
61 }
62 } catch (error) {
63 this.logger.debug(error)
64 }
65 }
66}

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected