From 23015139b9d356606f2b67fbfb61abed4613669e Mon Sep 17 00:00:00 2001 From: David Prothero Date: Tue, 9 Apr 2019 11:28:21 -0700 Subject: [PATCH] Refactor messages out of SecureStorage --- .vscode/launch.json | 8 ++++++++ src/commands/project/add.js | 12 ++++++++++-- test/commands/project/add.test.js | 4 +++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index c8f3c17e3..3036dcc55 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -6,6 +6,14 @@ "name": "Launch Program", "program": "${workspaceFolder}/bin/run", "console": "externalTerminal" + }, + { + "type": "node", + "request": "launch", + "name": "Mocha Tests", + "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha", + "args": ["-u", "tdd", "--timeout", "999999", "--colors", "${workspaceFolder}/test/**/*.test.js"], + "internalConsoleOptions": "openOnSessionStart" } ] } diff --git a/src/commands/project/add.js b/src/commands/project/add.js index 10cd7f2c9..682071e63 100644 --- a/src/commands/project/add.js +++ b/src/commands/project/add.js @@ -4,6 +4,13 @@ const twilio = require('twilio'); const { BaseCommand, TwilioClientCommand } = require('@twilio/cli-core').baseCommands; const { CLIRequestClient } = require('@twilio/cli-core').services; +const { STORAGE_LOCATIONS } = require('@twilio/cli-core').services.secureStorage; + +const FRIENDLY_STORAGE_LOCATIONS = { + [STORAGE_LOCATIONS.KEYCHAIN]: 'in your keychain', + [STORAGE_LOCATIONS.WIN_CRED_VAULT]: 'in the Windows credential vault', + [STORAGE_LOCATIONS.LIBSECRET]: 'using libsecret' +}; class ProjectAdd extends BaseCommand { constructor(argv, config, secureStorage) { @@ -134,8 +141,9 @@ class ProjectAdd extends BaseCommand { await this.configFile.save(this.userConfig); this.logger.info( - `Created API Key ${apiKey.sid} and stored the secret ${this.secureStorage.platformDescription}.` + - ` See: https://www.twilio.com/console/runtime/api-keys/${apiKey.sid}` + `Created API Key ${apiKey.sid} and stored the secret ${ + FRIENDLY_STORAGE_LOCATIONS[this.secureStorage.storageLocation] + }. See: https://www.twilio.com/console/runtime/api-keys/${apiKey.sid}` ); } } diff --git a/test/commands/project/add.test.js b/test/commands/project/add.test.js index 1be5d98c8..5fffb611b 100644 --- a/test/commands/project/add.test.js +++ b/test/commands/project/add.test.js @@ -40,7 +40,9 @@ describe('commands', () => { await ctx.testCmd.run(); expect(ctx.stdout).to.equal(''); expect(ctx.stderr).to.contain('Saved default.'); - expect(ctx.stderr).to.contain(`Created API Key ${constants.FAKE_API_KEY} and stored the secret `); + expect(ctx.stderr).to.contain( + `Created API Key ${constants.FAKE_API_KEY} and stored the secret using libsecret` + ); expect(ctx.stderr).to.contain( `See: https://www.twilio.com/console/runtime/api-keys/${constants.FAKE_API_KEY}` );