@extrahorizon/exh-cli 1.9.0-feat-90-3dff47e → 1.9.0
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
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Specify the permissions your task needs
|
|
6
6
|
* The CLI automatically creates a user, role, and credentials for your task
|
|
7
7
|
* These credentials are injected as environment variables into the task automatically
|
|
8
|
+
* If you want to migrate your existing tasks to use this feature, see the [migration guide](https://docs.extrahorizon.com/extrahorizon/migration-guides/execution-credentials-for-tasks).
|
|
8
9
|
|
|
9
10
|
### v1.8.2
|
|
10
11
|
* Updated the ExH SDK to `8.6.0` to fix a security warning from `axios`
|
|
@@ -90,6 +90,13 @@ async function validateConfig(config) {
|
|
|
90
90
|
else {
|
|
91
91
|
throw new Error('Code path not specified');
|
|
92
92
|
}
|
|
93
|
+
if (config.executionCredentials && config.environment) {
|
|
94
|
+
const restrictedProperties = ['API_HOST', 'API_OAUTH_CONSUMER_KEY', 'API_OAUTH_CONSUMER_SECRET', 'API_OAUTH_TOKEN', 'API_OAUTH_TOKEN_SECRET'];
|
|
95
|
+
const foundProperties = Object.keys(config.environment).filter(key => restrictedProperties.includes(key));
|
|
96
|
+
if (foundProperties.length > 0) {
|
|
97
|
+
throw new Error(`❌ Environment variables [${foundProperties.join(', ')}] may not be provided when using executionCredentials`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
93
100
|
assertExecutionPermission(config.executionPermission);
|
|
94
101
|
return true;
|
|
95
102
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.syncFunctionUser = exports.zipFileFromDirectory = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const os_1 = require("os");
|
|
6
|
+
const javascript_sdk_1 = require("@extrahorizon/javascript-sdk");
|
|
6
7
|
const archiver = require("archiver");
|
|
7
8
|
const chalk = require("chalk");
|
|
8
9
|
const uuid_1 = require("uuid");
|
|
@@ -62,10 +63,21 @@ async function syncFunctionUser(sdk, data) {
|
|
|
62
63
|
currentFunction?.environmentVariables?.API_OAUTH_CONSUMER_KEY?.value &&
|
|
63
64
|
currentFunction?.environmentVariables?.API_OAUTH_CONSUMER_SECRET?.value);
|
|
64
65
|
if (!hasExistingCredentials) {
|
|
65
|
-
throw new Error('❌
|
|
66
|
+
throw new Error('❌ The user for the task-config.json executionCredentials exists, but no credentials were found in the Function environmentVariables');
|
|
67
|
+
}
|
|
68
|
+
const taskUserSdk = (0, javascript_sdk_1.createOAuth1Client)({
|
|
69
|
+
host: currentFunction.environmentVariables.API_HOST.value,
|
|
70
|
+
tokenSecret: currentFunction.environmentVariables.API_OAUTH_TOKEN_SECRET.value,
|
|
71
|
+
token: currentFunction.environmentVariables.API_OAUTH_TOKEN.value,
|
|
72
|
+
consumerKey: currentFunction.environmentVariables.API_OAUTH_CONSUMER_KEY.value,
|
|
73
|
+
consumerSecret: currentFunction.environmentVariables.API_OAUTH_CONSUMER_SECRET.value,
|
|
74
|
+
});
|
|
75
|
+
const taskUser = await taskUserSdk.users.me();
|
|
76
|
+
if (taskUser.id !== user.id) {
|
|
77
|
+
throw new Error(`❌ The credentials found in the Function (${taskUser.email}) do not match the user found for the task-config.json executionCredentials (${user.email})`);
|
|
66
78
|
}
|
|
67
79
|
console.log(chalk.white('⚙️ Reusing existing user credentials...'));
|
|
68
|
-
const userRole = user.roles
|
|
80
|
+
const userRole = user.roles?.find(({ name }) => name === roleName);
|
|
69
81
|
if (!userRole) {
|
|
70
82
|
await assignRoleToUser(sdk, user.id, role.id);
|
|
71
83
|
}
|
package/build/helpers/util.js
CHANGED
|
@@ -38,10 +38,9 @@ async function asyncExec(cmd) {
|
|
|
38
38
|
exports.asyncExec = asyncExec;
|
|
39
39
|
function loadAndAssertCredentials() {
|
|
40
40
|
const credentials = {};
|
|
41
|
-
let credentialsFile;
|
|
42
41
|
let errorMessage = '';
|
|
43
42
|
try {
|
|
44
|
-
credentialsFile = fs.readFileSync(constants_1.EXH_CONFIG_FILE, 'utf-8');
|
|
43
|
+
const credentialsFile = fs.readFileSync(constants_1.EXH_CONFIG_FILE, 'utf-8');
|
|
45
44
|
const credentialFileLines = credentialsFile.split(/\r?\n/);
|
|
46
45
|
for (const credentialFileLine of credentialFileLines) {
|
|
47
46
|
const [key, value] = credentialFileLine.split('=');
|