From 4fb9468100b6f92eba802822fc12f6bcb02b0aa6 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 21 Apr 2020 11:41:41 +0100 Subject: [PATCH] make backwards compatible list command --- CHANGELOG.md | 7 +++++++ README.md | 3 +++ main.js | 1 + package.json | 2 +- src/command-handler.js | 16 +++++++++++----- 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 399ac84..e1966e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 08f7079..b84d917 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/main.js b/main.js index a1c8041..dd90881 100644 --- a/main.js +++ b/main.js @@ -156,6 +156,7 @@ async function run(commandName, commandProps) { case "list": output = await commandHandler.getList({ type, + alias: commandProps.alias, tdxConfigs, env: process.env, }); diff --git a/package.json b/package.json index 4b73d02..4dac48a 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/command-handler.js b/src/command-handler.js index 4b8f94d..671ace3 100644 --- a/src/command-handler.js +++ b/src/command-handler.js @@ -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"); }