Skip to content

Commit 61c92a0

Browse files
committed
Merge branch 'feature/CG-428' into 'master'
feat(plugins): Enhance plugins commands code Closes CG-428 See merge request auto-cloud/cloudgraph/cli!180
2 parents 6a2697e + a9fbb03 commit 61c92a0

20 files changed

Lines changed: 506 additions & 398 deletions

README.md

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,6 +1339,7 @@ There are some common errors you may see when running CloudGraph that are usuall
13391339
* [`cg scan [PROVIDER]`](#cg-scan-provider)
13401340
* [`cg serve [PROVIDER]`](#cg-serve-provider)
13411341
* [`cg teardown [PROVIDER]`](#cg-teardown-provider)
1342+
* [`cg update [PROVIDER]`](#cg-update-provider)
13421343

13431344
## `cg help [COMMAND]`
13441345

@@ -1479,9 +1480,13 @@ OPTIONS
14791480
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
14801481
--dev Turn on developer mode
14811482
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1483+
--no-save Set to not alter lock file, just delete plugin
14821484
--no-serve Set to not serve a query engine
14831485
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
14841486
1487+
ALIASES
1488+
$ cg add policy
1489+
14851490
EXAMPLES
14861491
$ cg policy add aws-cis-1.2.0
14871492
$ cg policy add aws-cis-1.2.0@0.12.0
@@ -1506,9 +1511,13 @@ OPTIONS
15061511
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
15071512
--dev Turn on developer mode
15081513
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1514+
--no-save Set to not alter lock file, just delete plugin
15091515
--no-serve Set to not serve a query engine
15101516
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
15111517
1518+
ALIASES
1519+
$ cg install policy
1520+
15121521
EXAMPLE
15131522
$ cg policy install
15141523
```
@@ -1532,9 +1541,15 @@ OPTIONS
15321541
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
15331542
--dev Turn on developer mode
15341543
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1544+
--no-save Set to not alter lock file, just delete plugin
15351545
--no-serve Set to not serve a query engine
15361546
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
15371547
1548+
ALIASES
1549+
$ cg ls policy
1550+
$ cg list policy
1551+
$ cg ls policy
1552+
15381553
EXAMPLES
15391554
$ cg policy list
15401555
$ cg policy list aws
@@ -1563,6 +1578,14 @@ OPTIONS
15631578
--no-serve Set to not serve a query engine
15641579
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
15651580
1581+
ALIASES
1582+
$ cg remove policy
1583+
$ cg policy remove
1584+
$ cg policy rm
1585+
$ cg del policy
1586+
$ cg rm policy
1587+
$ cg del policy
1588+
15661589
EXAMPLES
15671590
$ cg policy delete
15681591
$ cg policy delete aws-cis-1.2.0
@@ -1588,13 +1611,14 @@ OPTIONS
15881611
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
15891612
--dev Turn on developer mode
15901613
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1614+
--no-save Set to not alter lock file, just delete plugin
15911615
--no-serve Set to not serve a query engine
15921616
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
15931617
15941618
EXAMPLES
15951619
$ cg policy update
15961620
$ cg policy update aws-cis-1.2.0
1597-
$cg policy update aws-cis-1.2.0@0.12.0
1621+
$ cg policy update aws-cis-1.2.0@0.12.0
15981622
```
15991623

16001624
_See code: [src/commands/policy/update.ts](https://github.com/cloudgraphdev/cli/blob/v0.16.12/src/commands/policy/update.ts)_
@@ -1639,11 +1663,12 @@ OPTIONS
16391663
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
16401664
--dev Turn on developer mode
16411665
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1666+
--no-save Set to not alter lock file, just delete plugin
16421667
--no-serve Set to not serve a query engine
16431668
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
16441669
16451670
ALIASES
1646-
$ cg add
1671+
$ cg add provider
16471672
16481673
EXAMPLES
16491674
$ cg provider add aws
@@ -1669,11 +1694,12 @@ OPTIONS
16691694
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
16701695
--dev Turn on developer mode
16711696
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1697+
--no-save Set to not alter lock file, just delete plugin
16721698
--no-serve Set to not serve a query engine
16731699
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
16741700
16751701
ALIASES
1676-
$ cg install
1702+
$ cg install provider
16771703
16781704
EXAMPLE
16791705
$ cg provider install
@@ -1698,13 +1724,14 @@ OPTIONS
16981724
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
16991725
--dev Turn on developer mode
17001726
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1727+
--no-save Set to not alter lock file, just delete plugin
17011728
--no-serve Set to not serve a query engine
17021729
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
17031730
17041731
ALIASES
1705-
$ cg provider ls
1706-
$ cg list
1707-
$ cg ls
1732+
$ cg ls provider
1733+
$ cg list provider
1734+
$ cg ls provider
17081735
17091736
EXAMPLES
17101737
$ cg provider list
@@ -1735,11 +1762,12 @@ OPTIONS
17351762
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
17361763
17371764
ALIASES
1738-
$ cg remove
1739-
$ cg rm
1740-
$ cg del
1765+
$ cg remove provider
1766+
$ cg provider remove
17411767
$ cg provider rm
1742-
$ cg provider del
1768+
$ cg del provider
1769+
$ cg rm provider
1770+
$ cg del provider
17431771
17441772
EXAMPLES
17451773
$ cg provider delete
@@ -1766,16 +1794,14 @@ OPTIONS
17661794
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
17671795
--dev Turn on developer mode
17681796
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1797+
--no-save Set to not alter lock file, just delete plugin
17691798
--no-serve Set to not serve a query engine
17701799
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
17711800
1772-
ALIASES
1773-
$ cg update
1774-
17751801
EXAMPLES
17761802
$ cg provider update
17771803
$ cg provider update aws
1778-
$cg provider update aws@0.12.0
1804+
$ cg provider update aws@0.12.0
17791805
```
17801806

17811807
_See code: [src/commands/provider/update.ts](https://github.com/cloudgraphdev/cli/blob/v0.16.12/src/commands/provider/update.ts)_
@@ -1852,4 +1878,34 @@ EXAMPLES
18521878
```
18531879

18541880
_See code: [src/commands/teardown.ts](https://github.com/cloudgraphdev/cli/blob/v0.16.12/src/commands/teardown.ts)_
1881+
1882+
## `cg update [PROVIDER]`
1883+
1884+
Upgrade currently installed plugins.
1885+
1886+
```
1887+
USAGE
1888+
$ cg update [PROVIDER]
1889+
1890+
OPTIONS
1891+
-P, --policies=policies Policy Packs to execute during scan
1892+
-d, --dgraph=dgraph Set where dgraph is running (default localhost:8997)
1893+
-l, --version-limit=version-limit Limit the amount of version folders stored on the filesystem (default 10)
1894+
-p, --port=port Set port to serve query engine
1895+
-q, --query-engine=playground|altair Query engine to launch
1896+
-s, --storage=dgraph Select a storage engine to use. Currently only supports Dgraph
1897+
--dev Turn on developer mode
1898+
--directory=directory Set the folder where CloudGraph will store data. (default cg)
1899+
--no-save Set to not alter lock file, just delete plugin
1900+
--no-serve Set to not serve a query engine
1901+
--use-roles Set to true to use roleARNs instead of profiles for AWS credentials
1902+
1903+
ALIASES
1904+
$ cg update
1905+
1906+
EXAMPLE
1907+
$ cg update
1908+
```
1909+
1910+
_See code: [src/commands/update.ts](https://github.com/cloudgraphdev/cli/blob/v0.16.12/src/commands/update.ts)_
18551911
<!-- commandsstop -->

package.json

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"bugs": "https://github.com/cloudgraphdev/cli/issues",
1717
"dependencies": {
18-
"@cloudgraph/sdk": "^0.10.4",
18+
"@cloudgraph/sdk": "0.10.4",
1919
"@graphql-tools/load-files": "^6.3.2",
2020
"@graphql-tools/merge": "^8.2.0",
2121
"@oclif/command": "^1",
@@ -119,16 +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:provider:install": "cross-env NODE_ENV=test ./bin/run provider install",
123-
"run:provider:add": "cross-env NODE_ENV=test ./bin/run provider add",
124-
"run:provider:remove": "cross-env NODE_ENV=test ./bin/run provider remove",
125-
"run:provider:list": "cross-env NODE_ENV=test ./bin/run provider list",
126-
"run:provider:update": "cross-env NODE_ENV=test ./bin/run provider update",
127-
"run:policy:install": "cross-env NODE_ENV=test ./bin/run policy install",
128-
"run:policy:add": "cross-env NODE_ENV=test ./bin/run policy add",
129-
"run:policy:remove": "cross-env NODE_ENV=test ./bin/run policy remove",
130-
"run:policy:list": "cross-env NODE_ENV=test ./bin/run policy list",
131-
"run:policy:update": "cross-env NODE_ENV=test ./bin/run policy update",
122+
"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",
132125
"test": "cross-env CG_DEBUG=-1 NODE_ENV=test jest --coverage=true --detectOpenHandles --runInBand --forceExit",
133126
"test:debug": "cross-env CG_DEBUG=5 NODE_ENV=test jest --coverage=false --detectOpenHandles --runInBand --forceExit",
134127
"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
}

0 commit comments

Comments
 (0)