Skip to content

Commit cc95962

Browse files
author
Marco Franceschi
committed
feat: Reverted changes to keep upgrade all command
1 parent 4bd1bd7 commit cc95962

18 files changed

Lines changed: 323 additions & 175 deletions

File tree

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,9 @@
119119
"run:scan:aws": "cross-env NODE_ENV=development ./bin/run scan aws",
120120
"run:launch": "cross-env NODE_ENV=development ./bin/run launch",
121121
"run:teardown": "cross-env NODE_ENV=development ./bin/run teardown",
122-
"run:install": "cross-env NODE_ENV=test ./bin/run install",
123-
"run:add": "cross-env NODE_ENV=test ./bin/run add",
124-
"run:remove": "cross-env NODE_ENV=test ./bin/run remove",
125-
"run:list": "cross-env NODE_ENV=test ./bin/run list",
126122
"run:update": "cross-env NODE_ENV=test ./bin/run update",
123+
"run:provider": "cross-env NODE_ENV=test ./bin/run provider",
124+
"run:policy": "cross-env NODE_ENV=test ./bin/run policy",
127125
"test": "cross-env CG_DEBUG=-1 NODE_ENV=test jest --coverage=true --detectOpenHandles --runInBand --forceExit",
128126
"test:debug": "cross-env CG_DEBUG=5 NODE_ENV=test jest --coverage=false --detectOpenHandles --runInBand --forceExit",
129127
"version": "oclif-dev readme && git add README.md",

src/commands/base.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,16 @@ Run ${chalk.italic.green('npm i -g @cloudgraph/cli')} to install`)
345345
// or simply return the parent class error handling
346346
return super.catch(err)
347347
}
348+
349+
getLockFile(): any {
350+
const lockPath = path.join(this.config.configDir, '.cloud-graph.lock.json')
351+
try {
352+
const lockFile = cosmiconfigSync('cloud-graph').load(lockPath)
353+
return lockFile?.config ?? {}
354+
} catch (error: any) {
355+
this.logger.info('No lock file found for Cloud Graph')
356+
this.logger.debug(error)
357+
return {}
358+
}
359+
}
348360
}

src/commands/operation.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default abstract class OperationBaseCommand extends Command {
7171

7272
async installPlugin(type: PluginType): Promise<void> {
7373
const manager = this.getPluginManager(type)
74-
const lockFile = manager.getLockFile()
74+
const lockFile = this.getLockFile()
7575
if (isEmpty(lockFile?.[type])) {
7676
this.logger.info(
7777
`No ${messages[type]?.plural} found in lock file, have you added any?`
@@ -94,7 +94,7 @@ export default abstract class OperationBaseCommand extends Command {
9494
} = this.parse(OperationBaseCommand)
9595
const allPlugins = argv
9696
const manager = this.getPluginManager(type)
97-
const lockFile = manager.getLockFile()
97+
const lockFile = this.getLockFile()
9898
const plugins = []
9999

100100
if (isEmpty(allPlugins)) {
@@ -139,7 +139,7 @@ export default abstract class OperationBaseCommand extends Command {
139139
const { argv } = this.parse(OperationBaseCommand)
140140
const allPlugins = argv
141141
const manager = this.getPluginManager(type)
142-
const lockFile = manager.getLockFile()
142+
const lockFile = this.getLockFile()
143143

144144
if (isEmpty(lockFile?.[type])) {
145145
this.logger.info(
@@ -208,8 +208,7 @@ export default abstract class OperationBaseCommand extends Command {
208208
async list(type: PluginType): Promise<void> {
209209
const { argv } = this.parse(OperationBaseCommand)
210210
const allPlugins = argv
211-
const manager = this.getPluginManager(type)
212-
const lockFile = manager.getLockFile()
211+
const lockFile = this.getLockFile()
213212
if (isEmpty(lockFile?.[type])) {
214213
this.logger.info(
215214
`No ${messages[type]?.plural} found, have you installed any?`

src/commands/policy/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Command from '../base'
2+
3+
export default class PolicyIndex extends Command {
4+
static description =
5+
'Commands to manage policy pack modules, run $ cg policy for more info.'
6+
7+
static strict = false
8+
9+
static hidden = false
10+
11+
static flags = {
12+
...Command.flags,
13+
}
14+
15+
static args = Command.args
16+
17+
async run(): Promise<void> {
18+
this.logger.info('cg policy is a topic not a command')
19+
}
20+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { PluginType } from '@cloudgraph/sdk'
22

33
import OperationBaseCommand from '../operation'
44

5-
export default class UpdatePolicy extends OperationBaseCommand {
6-
static description = 'Update currently installed policy packs'
5+
export default class UpgradePolicy extends OperationBaseCommand {
6+
static description = 'Upgrade currently installed policy packs'
77

88
static aliases = ['update:pp']
99

1010
static examples = [
11-
'$ cg update policy',
12-
'$ cg update policy aws-cis-1.2.0',
13-
'$ cg update policy aws-cis-1.2.0@0.12.0',
11+
'$ cg upgrade policy',
12+
'$ cg upgrade policy aws-cis-1.2.0',
13+
'$ cg upgrade policy aws-cis-1.2.0@0.12.0',
1414
]
1515

1616
static strict = false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import OperationBaseCommand from '../operation'
55
export default class AddProvider extends OperationBaseCommand {
66
static description = 'Add new providers'
77

8-
static aliases = ['add:p']
8+
static aliases = ['add']
99

1010
static examples = ['$ cg add provider aws', '$ cg add provider aws@0.12.0']
1111

0 commit comments

Comments
 (0)