@extrahorizon/exh-cli 1.8.1 → 1.8.2-dev-74-994b4dc

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Extra Horizon CLI changelog
2
2
 
3
+ ### v1.8.2
4
+ * Updated the ExH SDK to `8.6.0` to fix a security warning from `axios`
5
+
3
6
  ### v1.8.1
4
7
  * Updated the supported Task Service runtime options
5
8
 
package/build/exh.js CHANGED
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sdkAuth = exports.sdkInitOnly = void 0;
4
- const fs = require("fs");
5
4
  const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
6
- const constants_1 = require("./constants");
5
+ const util_1 = require("./helpers/util");
7
6
  let sdk = null;
8
7
  function sdkInitOnly(apiHost, consumerKey, consumerSecret) {
9
8
  sdk = (0, javascript_sdk_1.createOAuth1Client)({
@@ -15,46 +14,16 @@ function sdkInitOnly(apiHost, consumerKey, consumerSecret) {
15
14
  }
16
15
  exports.sdkInitOnly = sdkInitOnly;
17
16
  async function sdkAuth() {
18
- let credentials = {};
19
- let haveCredFile = false;
20
- const needed = ['API_HOST', 'API_OAUTH_CONSUMER_KEY', 'API_OAUTH_CONSUMER_SECRET', 'API_OAUTH_TOKEN', 'API_OAUTH_TOKEN_SECRET'];
21
- const error = missing => {
22
- let message = 'Failed to retrieve all credentials. ';
23
- if (!haveCredFile) {
24
- message += 'Couldn\'t open ~/.exh/credentials. ';
25
- }
26
- if (missing.length) {
27
- message += `Missing properties: ${missing.join(',')}`;
28
- }
29
- throw new Error(message);
30
- };
31
- try {
32
- const credentialsFile = fs.readFileSync(constants_1.EXH_CONFIG_FILE, 'utf-8');
33
- haveCredFile = true;
34
- credentials = credentialsFile
35
- .split(/\r?\n/).map(l => l.split(/=/)).filter(i => i.length === 2)
36
- .reduce((r, v) => { r[v[0].trim()] = v[1].trim(); return r; }, {});
37
- for (const k of Object.keys(credentials)) {
38
- if (!process.env[k]) {
39
- process.env[k] = credentials[k];
40
- }
41
- }
42
- }
43
- catch (err) { }
44
- needed.forEach(v => { credentials[v] = process.env[v] ?? credentials[v]; });
45
- const missingProperties = needed.filter(p => credentials[p] === undefined);
46
- if (missingProperties.length) {
47
- error(missingProperties);
48
- }
17
+ (0, util_1.loadAndAssertCredentials)();
49
18
  sdk = (0, javascript_sdk_1.createOAuth1Client)({
50
- consumerKey: credentials.API_OAUTH_CONSUMER_KEY,
51
- consumerSecret: credentials.API_OAUTH_CONSUMER_SECRET,
52
- host: credentials.API_HOST,
19
+ host: process.env.API_HOST,
20
+ consumerKey: process.env.API_OAUTH_CONSUMER_KEY,
21
+ consumerSecret: process.env.API_OAUTH_CONSUMER_SECRET,
53
22
  });
54
23
  try {
55
24
  await sdk.auth.authenticate({
56
- token: credentials.API_OAUTH_TOKEN,
57
- tokenSecret: credentials.API_OAUTH_TOKEN_SECRET,
25
+ token: process.env.API_OAUTH_TOKEN,
26
+ tokenSecret: process.env.API_OAUTH_TOKEN_SECRET,
58
27
  });
59
28
  }
60
29
  catch (err) {
@@ -1,3 +1,4 @@
1
1
  import * as yargs from 'yargs';
2
2
  export declare function epilogue(y: yargs.Argv): yargs.Argv;
3
3
  export declare function asyncExec(cmd: string): Promise<string>;
4
+ export declare function loadAndAssertCredentials(): void;
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.asyncExec = exports.epilogue = void 0;
3
+ exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
4
4
  const child_process_1 = require("child_process");
5
+ const fs = require("fs");
5
6
  const chalk = require("chalk");
7
+ const constants_1 = require("../constants");
6
8
  const error_1 = require("./error");
7
9
  function epilogue(y) {
8
10
  return y.epilogue('Visit https://docs.extrahorizon.com/extrahorizon-cli/ for more information.').fail((msg, err, argv) => {
@@ -34,3 +36,33 @@ async function asyncExec(cmd) {
34
36
  });
35
37
  }
36
38
  exports.asyncExec = asyncExec;
39
+ function loadAndAssertCredentials() {
40
+ const credentials = {};
41
+ let credentialsFile;
42
+ let errorMessage = '';
43
+ try {
44
+ credentialsFile = fs.readFileSync(constants_1.EXH_CONFIG_FILE, 'utf-8');
45
+ }
46
+ catch (e) {
47
+ errorMessage += 'Couldn\'t open ~/.exh/credentials. ';
48
+ }
49
+ const credentialFileLines = credentialsFile.split(/\r?\n/);
50
+ for (const credentialFileLine of credentialFileLines) {
51
+ const [key, value] = credentialFileLine.split('=');
52
+ if (key && value) {
53
+ credentials[key.trim()] = value.trim();
54
+ }
55
+ }
56
+ const requiredEnvVariables = ['API_HOST', 'API_OAUTH_CONSUMER_KEY', 'API_OAUTH_CONSUMER_SECRET', 'API_OAUTH_TOKEN', 'API_OAUTH_TOKEN_SECRET'];
57
+ for (const key of requiredEnvVariables) {
58
+ if (credentials[key] && !process.env[key]) {
59
+ process.env[key] = credentials[key];
60
+ }
61
+ }
62
+ const missingEnvironmentVariables = requiredEnvVariables.filter(key => !process.env[key]);
63
+ if (missingEnvironmentVariables.length > 0) {
64
+ errorMessage += `Missing environment variables: ${missingEnvironmentVariables.join(',')}`;
65
+ throw new Error(`Failed to retrieve all credentials. ${errorMessage}`);
66
+ }
67
+ }
68
+ exports.loadAndAssertCredentials = loadAndAssertCredentials;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extrahorizon/exh-cli",
3
- "version": "1.8.1",
3
+ "version": "1.8.2-dev-74-994b4dc",
4
4
  "main": "build/index.js",
5
5
  "exports": "./build/index.js",
6
6
  "license": "MIT",
@@ -15,6 +15,7 @@
15
15
  "clean": "rimraf build",
16
16
  "build": "yarn clean && tsc",
17
17
  "test": "jest",
18
+ "test:ci": "jest --silent",
18
19
  "lint": "eslint src tests --ext .ts"
19
20
  },
20
21
  "bin": {
@@ -40,7 +41,7 @@
40
41
  "typescript": "4.5.5"
41
42
  },
42
43
  "dependencies": {
43
- "@extrahorizon/javascript-sdk": "^8.4.1",
44
+ "@extrahorizon/javascript-sdk": "^8.6.0",
44
45
  "ajv": "^8.11.0",
45
46
  "archiver": "^5.3.1",
46
47
  "chalk": "^4.0.0",