Skip to content

Commit

Permalink
make backwards compatible list command
Browse files Browse the repository at this point in the history
  • Loading branch information
mereacre committed Apr 21, 2020
1 parent 1343f25 commit 4fb9468
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on
and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.3] - 2020-04-21

### Changed

### Fixed
- Make list command require an input alias so that it is backwards compatible with other code

## [1.0.2] - 2020-04-20

### Changed
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ Outputs the current tdx config for the default or a given alias name ```name```.
Usage
```bash
tdxcli list aliases
tdxcli list aliases --alias=name
tdxcli list secrets
tdxcli list secrets --alias=name

```
The first command lists all configured aliases. The second command lists all secrets in base64 for each configured alias.

Expand Down
1 change: 1 addition & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ async function run(commandName, commandProps) {
case "list":
output = await commandHandler.getList({
type,
alias: commandProps.alias,
tdxConfigs,
env: process.env,
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nqminds/nqm-tdx-terminal-cli",
"version": "1.0.2",
"version": "1.0.3",
"description": "Command-line interface for accessing the TDX API",
"main": "main.js",
"directories": {
Expand Down
16 changes: 11 additions & 5 deletions src/command-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,25 @@ class CommandHandler {
}
}

async getList({type, tdxConfigs, env}) {
async getList({type, alias, tdxConfigs, env}) {
const aliases = getAliasesArray(tdxConfigs);
const aliasIdx = aliases.indexOf(alias)
if (alias && aliasIdx < 0) {
throw Error("Unknown alias name");
}

switch (type) {
case "":
case "aliases":
return aliases;
return (alias) ? aliases[aliasIdx] : aliases;
case "secrets":
return aliases.reduce(
(result, alias) => {
result[alias] = env[getSecretAliasName(alias)] || "";
const secrets = aliases.reduce(
(result, aliasName) => {
result[aliasName] = env[getSecretAliasName(aliasName)] || "";
return result;
}, {}
);
return (alias) ? secrets[alias] : secrets;
default:
throw Error("Wrong input list type");
}
Expand Down

0 comments on commit 4fb9468

Please sign in to comment.