This is an automated email from the ASF dual-hosted git repository. alexkli pushed a commit to branch dotenv in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git
commit f3e59bf827ffc30fc2e2f372e41688a84005b7f2 Author: Alexander Klimetschek <[email protected]> AuthorDate: Wed Jul 15 22:30:46 2020 -0700 in verbose mode log where openwhisk credentials are picked up from --- src/debugger.js | 4 ---- src/wskprops.js | 25 +++++++++++++++++++++---- test/test.js | 4 ++++ 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/debugger.js b/src/debugger.js index f2e1596..e3b282e 100644 --- a/src/debugger.js +++ b/src/debugger.js @@ -54,10 +54,6 @@ class Debugger { this.actionName = argv.action; this.wskProps = wskprops.get(); - if (Object.keys(this.wskProps).length === 0) { - log.error(`Error: Missing openwhisk credentials. Found no ~/.wskprops file or WSK_* environment variable.`); - process.exit(1); - } if (argv.ignoreCerts) { this.wskProps.ignore_certs = true; } diff --git a/src/wskprops.js b/src/wskprops.js index 4f4c8fb..4ea744d 100644 --- a/src/wskprops.js +++ b/src/wskprops.js @@ -21,20 +21,23 @@ 'use strict'; +const log = require('./log'); + const path = require('path'); const fs = require('fs-extra'); const ENV_PARAMS = ['OW_APIHOST', 'OW_AUTH', 'OW_NAMESPACE', 'OW_APIGW_ACCESS_TOKEN']; -function getWskPropsFile() { +function getWskPropsUserHomeFile() { const Home = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']; - return process.env.WSK_CONFIG_FILE || path.format({ dir: Home, base: '.wskprops' }); + return path.format({ dir: Home, base: '.wskprops' }); } function readWskPropsFile() { - const wskFilePath = getWskPropsFile(); + const wskFilePath = process.env.WSK_CONFIG_FILE || getWskPropsUserHomeFile(); if (fs.existsSync(wskFilePath)) { + log.verbose(`Using openwhisk credentials from ${wskFilePath}${process.env.WSK_CONFIG_FILE ? " (set by WSK_CONFIG_FILE)" : ""}`); return fs.readFileSync(wskFilePath, 'utf8'); } else { return null; @@ -57,9 +60,19 @@ function getWskProps() { function getWskEnvProps() { const envProps = {}; + let authEnvVar; ENV_PARAMS.forEach((envName) => { - if (process.env[envName]) envProps[envName.slice(3).toLowerCase()] = process.env[envName]; + if (process.env[envName]) { + const key = envName.slice(3).toLowerCase(); + envProps[key] = process.env[envName]; + if (key === "auth" || key === "api_key") { + authEnvVar = envName; + } + } }); + if (authEnvVar) { + log.verbose(`Using openwhisk credential from ${authEnvVar} environment variable`); + } return envProps; } @@ -70,6 +83,10 @@ module.exports = { props.api_key = props.auth; delete props.auth; } + if (Object.keys(props).length === 0) { + log.error(`Error: Missing openwhisk credentials. Found no ~/.wskprops file or WSK_* environment variable.`); + process.exit(1); + } return props; }, ENV_PARAMS, diff --git a/test/test.js b/test/test.js index 3d501ea..ce8904d 100644 --- a/test/test.js +++ b/test/test.js @@ -41,7 +41,11 @@ function isDockerInstalled() { } async function beforeEach() { + delete process.env.OW_AUTH; + delete process.env.OW_NAMESPACE; + delete process.env.OW_APIHOST; process.env.WSK_CONFIG_FILE = path.join(process.cwd(), "test/wskprops"); + openwhisk = nock(FAKE_OPENWHISK_SERVER); mockOpenwhiskSwagger(openwhisk);
