@extrahorizon/exh-cli 1.12.0-dev-144-b9d0b5a → 1.12.0-dev-146-310460f
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/build/commands/login.js +2 -22
- package/build/commands/sync.d.ts +1 -1
- package/build/commands/sync.js +3 -46
- package/build/commands/whoami.js +3 -10
- package/build/helpers/util.d.ts +1 -0
- package/build/helpers/util.js +11 -1
- package/build/services/auth.d.ts +2 -0
- package/build/services/auth.js +40 -0
- package/build/services/sync.d.ts +10 -0
- package/build/services/sync.js +53 -0
- package/build/services/tasks/taskConfig.d.ts +1 -1
- package/build/services/tasks/taskConfig.js +1 -7
- package/package.json +1 -1
package/build/commands/login.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const fs = require("fs/promises");
|
|
5
|
-
const chalk = require("chalk");
|
|
6
|
-
const constants_1 = require("../constants");
|
|
7
|
-
const exh_1 = require("../exh");
|
|
8
4
|
const util_1 = require("../helpers/util");
|
|
5
|
+
const authService = require("../services/auth");
|
|
9
6
|
exports.command = 'login';
|
|
10
7
|
exports.desc = 'Retrieve credentials from ExH';
|
|
11
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
@@ -37,23 +34,6 @@ const builder = (yargs) => (0, util_1.epilogue)(yargs).options({
|
|
|
37
34
|
});
|
|
38
35
|
exports.builder = builder;
|
|
39
36
|
const handler = async ({ host, email, password, consumerKey, consumerSecret }) => {
|
|
40
|
-
|
|
41
|
-
const response = await sdk.auth.authenticate({
|
|
42
|
-
email,
|
|
43
|
-
password,
|
|
44
|
-
});
|
|
45
|
-
try {
|
|
46
|
-
await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
|
|
47
|
-
}
|
|
48
|
-
catch (err) {
|
|
49
|
-
await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
|
|
50
|
-
}
|
|
51
|
-
await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
|
|
52
|
-
API_OAUTH_CONSUMER_KEY=${consumerKey}
|
|
53
|
-
API_OAUTH_CONSUMER_SECRET=${consumerSecret}
|
|
54
|
-
API_OAUTH_TOKEN=${response.token}
|
|
55
|
-
API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
|
|
56
|
-
`);
|
|
57
|
-
console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
|
|
37
|
+
await authService.login(host, email, password, consumerKey, consumerSecret);
|
|
58
38
|
};
|
|
59
39
|
exports.handler = handler;
|
package/build/commands/sync.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare const builder: (yargs: any) => import("yargs").Argv<import("yargs
|
|
|
49
49
|
default: boolean;
|
|
50
50
|
};
|
|
51
51
|
}>>;
|
|
52
|
-
export declare const handler: (
|
|
52
|
+
export declare const handler: (options: {
|
|
53
53
|
path?: string;
|
|
54
54
|
schemas?: boolean;
|
|
55
55
|
tasks?: boolean;
|
package/build/commands/sync.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
4
|
const fs = require("fs/promises");
|
|
6
5
|
const ospath = require("path");
|
|
7
|
-
const chalk = require("chalk");
|
|
8
6
|
const repoConfig_1 = require("../helpers/repoConfig");
|
|
9
7
|
const util_1 = require("../helpers/util");
|
|
10
|
-
const
|
|
11
|
-
const localizationService = require("../services/localizations");
|
|
12
|
-
const schemaService = require("../services/schemas");
|
|
13
|
-
const taskService = require("../services/tasks");
|
|
14
|
-
const templateService = require("../services/templates");
|
|
8
|
+
const syncService = require("../services/sync");
|
|
15
9
|
exports.command = 'sync';
|
|
16
10
|
exports.desc = 'Sync your ExH configuration to the cloud environment';
|
|
17
11
|
const builder = (yargs) => (0, util_1.epilogue)(yargs)
|
|
@@ -79,44 +73,7 @@ If not, the local directory is assumed with a default configuration which assume
|
|
|
79
73
|
return true;
|
|
80
74
|
});
|
|
81
75
|
exports.builder = builder;
|
|
82
|
-
const handler = async (
|
|
83
|
-
|
|
84
|
-
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath);
|
|
85
|
-
const syncAll = !(schemas || tasks || templates || dispatchers || localizations);
|
|
86
|
-
if ((syncAll || schemas) && cfg.schemas) {
|
|
87
|
-
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
88
|
-
for (const schema of cfg.schemas) {
|
|
89
|
-
await schemaService.sync(ospath.join(targetPath, schema), undefined, false, ignoreSchemaVerificationErrors);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
if ((syncAll || templates) && cfg.templates) {
|
|
93
|
-
console.log(chalk.green('\n ⚙️ Syncing templates...'));
|
|
94
|
-
for (const template of cfg.templates) {
|
|
95
|
-
await templateService.sync(ospath.join(targetPath, template));
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if ((syncAll || tasks) && cfg.tasks) {
|
|
99
|
-
console.log(chalk.green('\n ⚙️ Syncing tasks...'));
|
|
100
|
-
for (const task of cfg.tasks) {
|
|
101
|
-
await taskService.sync({ path: ospath.join(targetPath, task) });
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if ((syncAll || localizations) && cfg.localizations) {
|
|
105
|
-
console.log(chalk.green('\n ⚙️ Syncing localizations...'));
|
|
106
|
-
for (const localization of cfg.localizations) {
|
|
107
|
-
await localizationService.sync(ospath.join(targetPath, localization));
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
if ((syncAll || dispatchers)) {
|
|
111
|
-
const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
|
|
112
|
-
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
113
|
-
if (isValidPath) {
|
|
114
|
-
console.log(chalk.green('\n ⚙️ Syncing dispatchers...'));
|
|
115
|
-
await dispatcherService.sync(dispatchersPath, cleanDispatchers);
|
|
116
|
-
}
|
|
117
|
-
else if (dispatchers) {
|
|
118
|
-
console.log(chalk.yellow('Warning: dispatchers.json not found'));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
76
|
+
const handler = async (options) => {
|
|
77
|
+
await syncService.sync(options);
|
|
121
78
|
};
|
|
122
79
|
exports.handler = handler;
|
package/build/commands/whoami.js
CHANGED
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handler = exports.builder = exports.desc = exports.command = void 0;
|
|
4
4
|
const util_1 = require("../helpers/util");
|
|
5
|
-
const
|
|
5
|
+
const authService = require("../services/auth");
|
|
6
6
|
exports.command = 'whoami';
|
|
7
7
|
exports.desc = 'Shows the currently logged in user';
|
|
8
8
|
const builder = (yargs) => (0, util_1.epilogue)(yargs);
|
|
9
9
|
exports.builder = builder;
|
|
10
|
-
const handler = async function
|
|
11
|
-
|
|
12
|
-
if (!host) {
|
|
13
|
-
console.log('No ExH cluster host was found in the configuration.');
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
console.log('You are targeting:', host);
|
|
17
|
-
const currentUser = await authRepository.fetchMe();
|
|
18
|
-
console.log('You are logged in as:', currentUser.email);
|
|
10
|
+
const handler = async function whoami() {
|
|
11
|
+
await authService.whoami();
|
|
19
12
|
};
|
|
20
13
|
exports.handler = handler;
|
package/build/helpers/util.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export declare function epilogue(y: yargs.Argv): yargs.Argv;
|
|
|
3
3
|
export declare function asyncExec(cmd: string): Promise<string>;
|
|
4
4
|
export declare function loadAndAssertCredentials(): void;
|
|
5
5
|
export declare function getSwaggerDocumentationUrl(subPath: string): string;
|
|
6
|
+
export declare function ajvValidate<T>(schema: any, data: any): asserts data is T;
|
|
6
7
|
export declare function getAjvErrorStrings(errors: any[]): string[];
|
package/build/helpers/util.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getAjvErrorStrings = exports.getSwaggerDocumentationUrl = exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
|
|
3
|
+
exports.getAjvErrorStrings = exports.ajvValidate = exports.getSwaggerDocumentationUrl = exports.loadAndAssertCredentials = exports.asyncExec = exports.epilogue = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
const fs = require("fs");
|
|
6
6
|
const path = require("path");
|
|
7
|
+
const ajv_1 = require("ajv");
|
|
7
8
|
const chalk = require("chalk");
|
|
8
9
|
const constants_1 = require("../constants");
|
|
9
10
|
const error_1 = require("./error");
|
|
@@ -80,6 +81,15 @@ function getSwaggerDocumentationUrl(subPath) {
|
|
|
80
81
|
throw new Error(`Unknown CLI version format: ${packageVersion}`);
|
|
81
82
|
}
|
|
82
83
|
exports.getSwaggerDocumentationUrl = getSwaggerDocumentationUrl;
|
|
84
|
+
function ajvValidate(schema, data) {
|
|
85
|
+
const validate = new ajv_1.default().compile(schema);
|
|
86
|
+
const valid = validate(data);
|
|
87
|
+
if (!valid) {
|
|
88
|
+
const errors = getAjvErrorStrings(validate.errors);
|
|
89
|
+
throw new Error(errors[0] || 'Unknown config validation error');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ajvValidate = ajvValidate;
|
|
83
93
|
function getAjvErrorStrings(errors) {
|
|
84
94
|
return errors.map(error => {
|
|
85
95
|
let message = '';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.whoami = exports.login = void 0;
|
|
4
|
+
const fs = require("fs/promises");
|
|
5
|
+
const chalk = require("chalk");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const exh_1 = require("../exh");
|
|
8
|
+
const authRepository = require("../repositories/auth");
|
|
9
|
+
async function login(host, email, password, consumerKey, consumerSecret) {
|
|
10
|
+
const sdk = (0, exh_1.sdkInitOnly)(host, consumerKey, consumerSecret);
|
|
11
|
+
const response = await sdk.auth.authenticate({
|
|
12
|
+
email,
|
|
13
|
+
password,
|
|
14
|
+
});
|
|
15
|
+
try {
|
|
16
|
+
await fs.stat(constants_1.EXH_CONFIG_FILE_DIR);
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
await fs.mkdir(constants_1.EXH_CONFIG_FILE_DIR);
|
|
20
|
+
}
|
|
21
|
+
await fs.writeFile(constants_1.EXH_CONFIG_FILE, `API_HOST=${host}
|
|
22
|
+
API_OAUTH_CONSUMER_KEY=${consumerKey}
|
|
23
|
+
API_OAUTH_CONSUMER_SECRET=${consumerSecret}
|
|
24
|
+
API_OAUTH_TOKEN=${response.token}
|
|
25
|
+
API_OAUTH_TOKEN_SECRET=${response.tokenSecret}
|
|
26
|
+
`);
|
|
27
|
+
console.log(chalk.green('Wrote credentials to', constants_1.EXH_CONFIG_FILE));
|
|
28
|
+
}
|
|
29
|
+
exports.login = login;
|
|
30
|
+
async function whoami() {
|
|
31
|
+
const host = authRepository.getHost();
|
|
32
|
+
if (!host) {
|
|
33
|
+
console.log('No ExH cluster host was found in the configuration.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
console.log('You are targeting:', host);
|
|
37
|
+
const currentUser = await authRepository.fetchMe();
|
|
38
|
+
console.log('You are logged in as:', currentUser.email);
|
|
39
|
+
}
|
|
40
|
+
exports.whoami = whoami;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function sync({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }: {
|
|
2
|
+
path?: string;
|
|
3
|
+
schemas?: boolean;
|
|
4
|
+
tasks?: boolean;
|
|
5
|
+
templates?: boolean;
|
|
6
|
+
dispatchers?: boolean;
|
|
7
|
+
cleanDispatchers?: boolean;
|
|
8
|
+
localizations?: boolean;
|
|
9
|
+
ignoreSchemaVerificationErrors?: boolean;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sync = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const ospath = require("path");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
const repoConfig_1 = require("../helpers/repoConfig");
|
|
8
|
+
const dispatcherService = require("../services/dispatchers");
|
|
9
|
+
const localizationService = require("../services/localizations");
|
|
10
|
+
const schemaService = require("../services/schemas");
|
|
11
|
+
const taskService = require("../services/tasks");
|
|
12
|
+
const templateService = require("../services/templates");
|
|
13
|
+
async function sync({ path, schemas, tasks, templates, dispatchers, cleanDispatchers, localizations, ignoreSchemaVerificationErrors, }) {
|
|
14
|
+
const targetPath = path || '.';
|
|
15
|
+
const cfg = await (0, repoConfig_1.getRepoConfig)(targetPath);
|
|
16
|
+
const syncAll = !(schemas || tasks || templates || dispatchers || localizations);
|
|
17
|
+
if ((syncAll || schemas) && cfg.schemas) {
|
|
18
|
+
console.log(chalk.green('\n ⚙️ Syncing schemas ...'));
|
|
19
|
+
for (const schema of cfg.schemas) {
|
|
20
|
+
await schemaService.sync(ospath.join(targetPath, schema), undefined, false, ignoreSchemaVerificationErrors);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if ((syncAll || templates) && cfg.templates) {
|
|
24
|
+
console.log(chalk.green('\n ⚙️ Syncing templates...'));
|
|
25
|
+
for (const template of cfg.templates) {
|
|
26
|
+
await templateService.sync(ospath.join(targetPath, template));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if ((syncAll || tasks) && cfg.tasks) {
|
|
30
|
+
console.log(chalk.green('\n ⚙️ Syncing tasks...'));
|
|
31
|
+
for (const task of cfg.tasks) {
|
|
32
|
+
await taskService.sync({ path: ospath.join(targetPath, task) });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if ((syncAll || localizations) && cfg.localizations) {
|
|
36
|
+
console.log(chalk.green('\n ⚙️ Syncing localizations...'));
|
|
37
|
+
for (const localization of cfg.localizations) {
|
|
38
|
+
await localizationService.sync(ospath.join(targetPath, localization));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if ((syncAll || dispatchers)) {
|
|
42
|
+
const dispatchersPath = ospath.join(targetPath, 'dispatchers.json');
|
|
43
|
+
const isValidPath = (0, fs_1.existsSync)(dispatchersPath);
|
|
44
|
+
if (isValidPath) {
|
|
45
|
+
console.log(chalk.green('\n ⚙️ Syncing dispatchers...'));
|
|
46
|
+
await dispatcherService.sync(dispatchersPath, cleanDispatchers);
|
|
47
|
+
}
|
|
48
|
+
else if (dispatchers) {
|
|
49
|
+
console.log(chalk.yellow('Warning: dispatchers.json not found'));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.sync = sync;
|
|
@@ -24,6 +24,6 @@ export interface TaskConfig {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
export declare function assertExecutionPermission(mode: string): asserts mode is permissionModes | undefined;
|
|
27
|
-
export declare function validateConfig(config:
|
|
27
|
+
export declare function validateConfig(config: any): Promise<boolean>;
|
|
28
28
|
export declare function loadSingleConfigFile(path: string): Promise<TaskConfig>;
|
|
29
29
|
export declare function getValidatedConfigIterator({ path, name, code, entryPoint, runtime, description, timeLimit, memoryLimit, executionPermission, env, defaultPriority }: any): AsyncGenerator<TaskConfig>;
|
|
@@ -4,7 +4,6 @@ exports.getValidatedConfigIterator = exports.loadSingleConfigFile = exports.vali
|
|
|
4
4
|
const assert_1 = require("assert");
|
|
5
5
|
const fs = require("fs/promises");
|
|
6
6
|
const ospath = require("path");
|
|
7
|
-
const ajv_1 = require("ajv");
|
|
8
7
|
const taskConfigSchema = require("../../config-json-schemas/TaskConfig.json");
|
|
9
8
|
const util_1 = require("../../helpers/util");
|
|
10
9
|
var permissionModes;
|
|
@@ -52,12 +51,7 @@ function replaceConfigVariables(config) {
|
|
|
52
51
|
return result;
|
|
53
52
|
}
|
|
54
53
|
async function validateConfig(config) {
|
|
55
|
-
|
|
56
|
-
const valid = validate(config);
|
|
57
|
-
if (!valid) {
|
|
58
|
-
const errors = (0, util_1.getAjvErrorStrings)(validate.errors);
|
|
59
|
-
throw new Error(errors[0] || 'Unknown config validation error');
|
|
60
|
-
}
|
|
54
|
+
(0, util_1.ajvValidate)(taskConfigSchema, config);
|
|
61
55
|
try {
|
|
62
56
|
await fs.access(config.path);
|
|
63
57
|
}
|