zcatalyst-cli 1.26.2 → 1.27.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/README.md +1 -0
- package/lib/authentication/credential.d.ts +2 -1
- package/lib/authentication/credential.js +20 -3
- package/lib/authentication/crypt.d.ts +7 -3
- package/lib/authentication/crypt.js +87 -16
- package/lib/authentication/index.js +1 -0
- package/lib/authentication/key-manager.d.ts +7 -0
- package/lib/authentication/key-manager.js +62 -0
- package/lib/authentication/login.js +20 -20
- package/lib/bin/catalyst.js +1 -15
- package/lib/client.d.ts +3 -1
- package/lib/client.js +16 -5
- package/lib/command_needs/rc.js +13 -3
- package/lib/commands/appsail/add.js +10 -0
- package/lib/commands/client/delete.js +18 -6
- package/lib/commands/client/setup.js +7 -0
- package/lib/commands/deploy/index.js +3 -3
- package/lib/commands/deploy/slate.js +65 -4
- package/lib/commands/functions/add.js +7 -0
- package/lib/commands/functions/delete.js +22 -4
- package/lib/commands/functions/execute.js +39 -71
- package/lib/commands/functions/setup.js +13 -0
- package/lib/commands/functions/shell.js +15 -1
- package/lib/commands/iac/import.js +2 -2
- package/lib/commands/init.js +34 -20
- package/lib/commands/login.js +1 -0
- package/lib/commands/pull.js +22 -1
- package/lib/commands/serve.js +2 -1
- package/lib/commands/slate/create.js +7 -4
- package/lib/commands/slate/link.js +11 -5
- package/lib/commands/slate/unlink.js +7 -0
- package/lib/commands/zest/generate/index.js +28 -35
- package/lib/deploy/features/slate.d.ts +3 -1
- package/lib/deploy/features/slate.js +204 -5
- package/lib/docs/client-utils.toml +0 -5
- package/lib/docs/command_needs/rc.toml +9 -1
- package/lib/docs/commands/client/delete.toml +4 -0
- package/lib/docs/commands/deploy/slate.toml +3 -0
- package/lib/docs/commands/functions/delete.toml +10 -0
- package/lib/docs/commands/functions/execute.toml +1 -16
- package/lib/docs/commands/functions/setup.toml +3 -0
- package/lib/docs/commands/functions/shell.toml +8 -0
- package/lib/docs/commands/init.toml +3 -0
- package/lib/docs/commands/pull.toml +6 -0
- package/lib/docs/commands/slate/unlink.toml +6 -0
- package/lib/docs/execute/command-utils.toml +14 -0
- package/lib/docs/execute/execute-input-resolver.toml +37 -0
- package/lib/docs/init/features/project.toml +20 -0
- package/lib/docs/init/util/client.toml +4 -0
- package/lib/docs/prompt/index.toml +15 -0
- package/lib/docs/pull/features/apig.toml +6 -0
- package/lib/docs/pull/features/client.toml +20 -0
- package/lib/docs/pull/features/functions/index.toml +24 -0
- package/lib/endpoints/lib/slate.d.ts +14 -1
- package/lib/endpoints/lib/slate.js +35 -0
- package/lib/error/context-help.js +1 -1
- package/lib/error/index.js +9 -13
- package/lib/execute/command-utils.d.ts +5 -0
- package/lib/execute/command-utils.js +86 -0
- package/lib/execute/execute-input-resolver.d.ts +29 -0
- package/lib/execute/execute-input-resolver.js +207 -0
- package/lib/execute/index.d.ts +4 -1
- package/lib/execute/index.js +3 -2
- package/lib/fn-utils/lib/integ.js +22 -17
- package/lib/index.js +1 -0
- package/lib/init/dependencies/package-json.js +11 -7
- package/lib/init/features/appsail/index.js +75 -26
- package/lib/init/features/appsail/prompt-fields.d.ts +43 -0
- package/lib/init/features/appsail/prompt-fields.js +55 -0
- package/lib/init/features/appsail/utils/custom-runtime.d.ts +3 -0
- package/lib/init/features/appsail/utils/custom-runtime.js +161 -0
- package/lib/init/features/appsail/{utils.d.ts → utils/index.d.ts} +2 -2
- package/lib/init/features/appsail/utils/index.js +170 -0
- package/lib/init/features/client/index.js +4 -3
- package/lib/init/features/client/initializers/angular.js +3 -2
- package/lib/init/features/client/initializers/react.js +4 -3
- package/lib/init/features/client/prompt-fields.d.ts +37 -0
- package/lib/init/features/client/prompt-fields.js +48 -0
- package/lib/init/features/functions/index.js +37 -8
- package/lib/init/features/functions/languages/java.js +42 -7
- package/lib/init/features/functions/languages/node.js +42 -10
- package/lib/init/features/functions/languages/python.js +42 -7
- package/lib/init/features/functions/prompt-fields.d.ts +25 -0
- package/lib/init/features/functions/prompt-fields.js +34 -0
- package/lib/init/features/project.js +41 -6
- package/lib/init/features/slate/index.js +2 -0
- package/lib/init/features/slate/prompt-fields.d.ts +31 -0
- package/lib/init/features/slate/prompt-fields.js +41 -0
- package/lib/init/index.js +2 -1
- package/lib/init/util/client.js +11 -8
- package/lib/init/util/common.d.ts +2 -0
- package/lib/init/util/common.js +33 -3
- package/lib/init/util/prompt-fields.d.ts +7 -0
- package/lib/init/util/prompt-fields.js +13 -0
- package/lib/internal/command.d.ts +3 -0
- package/lib/internal/command.js +26 -3
- package/lib/migration/global/1.27.0.d.ts +2 -0
- package/lib/migration/global/1.27.0.js +39 -0
- package/lib/prompt/choice.d.ts +2 -0
- package/lib/prompt/choice.js +24 -0
- package/lib/prompt/cli-option-key.d.ts +1 -0
- package/lib/prompt/cli-option-key.js +10 -0
- package/lib/prompt/index.d.ts +6 -22
- package/lib/prompt/index.js +264 -67
- package/lib/prompt/overwrite-prompt.d.ts +11 -0
- package/lib/prompt/overwrite-prompt.js +16 -0
- package/lib/prompt/question-factory.d.ts +34 -0
- package/lib/prompt/question-factory.js +41 -0
- package/lib/prompt/register-fields.d.ts +24 -0
- package/lib/prompt/register-fields.js +37 -0
- package/lib/pull/features/apig.js +57 -6
- package/lib/pull/features/client.js +107 -24
- package/lib/pull/features/functions/index.js +100 -4
- package/lib/pull/index.js +1 -1
- package/lib/pull/utils.d.ts +13 -0
- package/lib/pull/utils.js +20 -0
- package/lib/repl-server.d.ts +4 -0
- package/lib/repl-server.js +9 -0
- package/lib/serve/server/lib/master/index.js +3 -3
- package/lib/serve/server/lib/slate/static-server.js +2 -2
- package/lib/serve/server/lib/web_client/server.js +2 -2
- package/lib/shell/format-functions.d.ts +4 -0
- package/lib/shell/format-functions.js +59 -0
- package/lib/shell/index.js +18 -0
- package/lib/util_modules/config/lib/appsail.d.ts +3 -2
- package/lib/util_modules/config/lib/appsail.js +6 -3
- package/lib/util_modules/config/lib/slate.d.ts +19 -0
- package/lib/util_modules/config-store.d.ts +1 -0
- package/lib/util_modules/config-store.js +29 -10
- package/lib/util_modules/constants/index.d.ts +0 -1
- package/lib/util_modules/constants/index.js +1 -3
- package/lib/util_modules/constants/lib/urls.d.ts +2 -0
- package/lib/util_modules/constants/lib/urls.js +4 -0
- package/lib/util_modules/dc.d.ts +6 -1
- package/lib/util_modules/dc.js +21 -8
- package/lib/util_modules/env.d.ts +3 -0
- package/lib/util_modules/env.js +41 -0
- package/lib/util_modules/fs/lib/sync.d.ts +1 -0
- package/lib/util_modules/fs/lib/sync.js +19 -0
- package/lib/util_modules/logger/utils.d.ts +1 -0
- package/lib/util_modules/logger/utils.js +5 -1
- package/lib/util_modules/option.d.ts +1 -0
- package/lib/util_modules/option.js +8 -0
- package/lib/util_modules/{server.js → server/index.js} +3 -3
- package/lib/util_modules/server/needed-scopes.d.ts +1 -0
- package/lib/util_modules/{constants/lib → server}/needed-scopes.js +7 -7
- package/package.json +3 -2
- package/lib/init/features/appsail/utils.js +0 -273
- package/lib/util_modules/constants/lib/needed-scopes.d.ts +0 -4
- /package/lib/docs/{dc.toml → util_modules/dc.toml} +0 -0
- /package/lib/util_modules/{server.d.ts → server/index.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -94,6 +94,7 @@ Command | Description
|
|
|
94
94
|
**functions:setup** | Set up and configure the function directory in your project directory.
|
|
95
95
|
**functions:add** | Add a function of the required stack to the function directory.
|
|
96
96
|
**functions:shell** | Launch a node shell to test emulated functions of any stack or type, other than Advanced I/O functions.
|
|
97
|
+
**functions:execute** | Execute Non-HTTP functions (Cron, Event, Integration, Job) locally. Accepts input via `--input <value>` (inline JSON, file path, or `-` for stdin), or interactively via inputs file.
|
|
97
98
|
**functions:config** | Perform advanced configurations such as memory allocation on a function in your project.
|
|
98
99
|
**functions:delete** | Delete a function from the remote console or the local directory.
|
|
99
100
|
**appsail:add** | Link an already existing AppSail app to Catalyst Project.
|
|
@@ -12,11 +12,12 @@ declare class Credential {
|
|
|
12
12
|
private rToken;
|
|
13
13
|
private client;
|
|
14
14
|
maxExpiry: number;
|
|
15
|
-
private static
|
|
15
|
+
private static _crypt;
|
|
16
16
|
private static isTempCred;
|
|
17
17
|
static globalSelf: null | Credential;
|
|
18
18
|
static oneTimeToken: null | string;
|
|
19
19
|
private static credentialObject;
|
|
20
|
+
private static get crypt();
|
|
20
21
|
constructor(tokenObj: ITokenObject);
|
|
21
22
|
private _getClientForSalt;
|
|
22
23
|
private _getTokenObjFromStore;
|
|
@@ -21,11 +21,18 @@ const js_js_1 = require("../util_modules/js.js");
|
|
|
21
21
|
const index_1 = require("../util_modules/logger/index");
|
|
22
22
|
const api_js_1 = __importDefault(require("../internal/api.js"));
|
|
23
23
|
const crypt_1 = __importDefault(require("./crypt"));
|
|
24
|
+
const key_manager_1 = __importDefault(require("./key-manager"));
|
|
24
25
|
const util_1 = require("util");
|
|
25
26
|
const dc_js_1 = require("../util_modules/dc.js");
|
|
26
27
|
const option_js_1 = require("../util_modules/option.js");
|
|
27
28
|
const path_1 = require("path");
|
|
28
29
|
class Credential {
|
|
30
|
+
static get crypt() {
|
|
31
|
+
if (Credential._crypt === null) {
|
|
32
|
+
Credential._crypt = new crypt_1.default(key_manager_1.default.getEncryptionKey());
|
|
33
|
+
}
|
|
34
|
+
return Credential._crypt;
|
|
35
|
+
}
|
|
29
36
|
constructor(tokenObj) {
|
|
30
37
|
if (tokenObj.token === undefined ||
|
|
31
38
|
js_js_1.JS.isEmpty(tokenObj.token) ||
|
|
@@ -66,9 +73,16 @@ class Credential {
|
|
|
66
73
|
if (encryptedToken === null) {
|
|
67
74
|
return null;
|
|
68
75
|
}
|
|
69
|
-
const
|
|
76
|
+
const decrypted = Credential.crypt.decrypt(encryptedToken);
|
|
77
|
+
if (decrypted === null) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const tokenObj = decrypted;
|
|
70
81
|
const confCredential = new Credential(tokenObj);
|
|
71
82
|
if (this.rToken === confCredential.rToken) {
|
|
83
|
+
if (Credential.crypt.isLegacyEncrypted(encryptedToken)) {
|
|
84
|
+
config_store_js_1.default.set((0, dc_js_1.getActiveDC)() + '.' + pth, Credential.crypt.encrypt(tokenObj));
|
|
85
|
+
}
|
|
72
86
|
return tokenObj;
|
|
73
87
|
}
|
|
74
88
|
return null;
|
|
@@ -195,7 +209,10 @@ class Credential {
|
|
|
195
209
|
let tokenObj;
|
|
196
210
|
if (Credential.crypt.isEncrypted(token)) {
|
|
197
211
|
const decryptToken = Credential.crypt.decrypt(token);
|
|
198
|
-
if (
|
|
212
|
+
if (decryptToken === null) {
|
|
213
|
+
tokenObj = {};
|
|
214
|
+
}
|
|
215
|
+
else if (typeof decryptToken === 'string') {
|
|
199
216
|
tokenObj = {
|
|
200
217
|
token: decryptToken
|
|
201
218
|
};
|
|
@@ -254,7 +271,7 @@ class Credential {
|
|
|
254
271
|
});
|
|
255
272
|
}
|
|
256
273
|
}
|
|
257
|
-
Credential.
|
|
274
|
+
Credential._crypt = null;
|
|
258
275
|
Credential.isTempCred = false;
|
|
259
276
|
Credential.globalSelf = null;
|
|
260
277
|
Credential.oneTimeToken = null;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
declare class Crypt {
|
|
2
2
|
private encryptionKey;
|
|
3
|
-
|
|
4
|
-
constructor(password: string);
|
|
3
|
+
constructor(key: Buffer | string);
|
|
5
4
|
decrypt(value: string): string | {
|
|
6
5
|
[x: string]: unknown;
|
|
7
|
-
};
|
|
6
|
+
} | null;
|
|
8
7
|
encrypt(value: unknown): string;
|
|
9
8
|
isEncrypted(value: string): boolean;
|
|
9
|
+
isLegacyEncrypted(value: string): boolean;
|
|
10
|
+
private _hasMarkerAt;
|
|
11
|
+
private _decryptCurrent;
|
|
12
|
+
private _decryptLegacy;
|
|
13
|
+
private _deriveKey;
|
|
10
14
|
private _serialize;
|
|
11
15
|
private _deserialize;
|
|
12
16
|
}
|
|
@@ -1,39 +1,61 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const crypto_1 = require("crypto");
|
|
4
|
+
const CRYPT_ALGO = 'aes-256-gcm';
|
|
5
|
+
const IV_LENGTH = 12;
|
|
6
|
+
const AUTH_TAG_LENGTH = 16;
|
|
7
|
+
const DERIVED_KEY_LENGTH = 32;
|
|
8
|
+
const PBKDF2_ITERATIONS = 100000;
|
|
9
|
+
const PBKDF2_DIGEST = 'sha512';
|
|
10
|
+
const MIN_PAYLOAD_LENGTH = IV_LENGTH + 1 + AUTH_TAG_LENGTH;
|
|
11
|
+
const LEGACY_CRYPT_ALGO = 'aes-256-cbc';
|
|
12
|
+
const LEGACY_IV_LENGTH = 16;
|
|
13
|
+
const LEGACY_PBKDF2_ITERATIONS = 1000;
|
|
14
|
+
const LEGACY_KEY = 'ZC_TRAM';
|
|
15
|
+
const LEGACY_MIN_PAYLOAD_LENGTH = LEGACY_IV_LENGTH + 1;
|
|
4
16
|
class Crypt {
|
|
5
|
-
constructor(
|
|
6
|
-
this.encryptionKey =
|
|
7
|
-
this.cryptAlgo = 'aes-256-cbc';
|
|
17
|
+
constructor(key) {
|
|
18
|
+
this.encryptionKey = Buffer.isBuffer(key) ? key : Buffer.from(key);
|
|
8
19
|
}
|
|
9
20
|
decrypt(value) {
|
|
10
|
-
let data
|
|
11
|
-
|
|
21
|
+
let data;
|
|
22
|
+
try {
|
|
23
|
+
data = Buffer.from(value, 'hex');
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
12
26
|
return value;
|
|
13
27
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
data
|
|
18
|
-
|
|
28
|
+
if (data.length >= MIN_PAYLOAD_LENGTH && this._hasMarkerAt(data, IV_LENGTH)) {
|
|
29
|
+
return this._decryptCurrent(data);
|
|
30
|
+
}
|
|
31
|
+
if (data.length >= LEGACY_MIN_PAYLOAD_LENGTH && this._hasMarkerAt(data, LEGACY_IV_LENGTH)) {
|
|
32
|
+
return this._decryptLegacy(data);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
19
35
|
}
|
|
20
36
|
encrypt(value) {
|
|
21
37
|
const data = this._serialize(value);
|
|
22
|
-
const initializationVector = (0, crypto_1.randomBytes)(
|
|
23
|
-
const
|
|
24
|
-
const cipher = (0, crypto_1.createCipheriv)(
|
|
38
|
+
const initializationVector = (0, crypto_1.randomBytes)(IV_LENGTH);
|
|
39
|
+
const derivedKey = this._deriveKey(initializationVector);
|
|
40
|
+
const cipher = (0, crypto_1.createCipheriv)(CRYPT_ALGO, derivedKey, initializationVector);
|
|
41
|
+
const encrypted = Buffer.concat([cipher.update(Buffer.from(data)), cipher.final()]);
|
|
42
|
+
const authTag = cipher.getAuthTag();
|
|
25
43
|
const dataBuff = Buffer.concat([
|
|
26
44
|
initializationVector,
|
|
27
45
|
Buffer.from(':'),
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
authTag,
|
|
47
|
+
encrypted
|
|
30
48
|
]);
|
|
31
49
|
return dataBuff.toString('hex');
|
|
32
50
|
}
|
|
33
51
|
isEncrypted(value) {
|
|
34
52
|
try {
|
|
35
53
|
const data = Buffer.from(value, 'hex');
|
|
36
|
-
if (data.
|
|
54
|
+
if (data.length >= MIN_PAYLOAD_LENGTH && this._hasMarkerAt(data, IV_LENGTH)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (data.length >= LEGACY_MIN_PAYLOAD_LENGTH &&
|
|
58
|
+
this._hasMarkerAt(data, LEGACY_IV_LENGTH)) {
|
|
37
59
|
return true;
|
|
38
60
|
}
|
|
39
61
|
}
|
|
@@ -42,6 +64,55 @@ class Crypt {
|
|
|
42
64
|
}
|
|
43
65
|
return false;
|
|
44
66
|
}
|
|
67
|
+
isLegacyEncrypted(value) {
|
|
68
|
+
try {
|
|
69
|
+
const data = Buffer.from(value, 'hex');
|
|
70
|
+
if (data.length >= MIN_PAYLOAD_LENGTH && this._hasMarkerAt(data, IV_LENGTH)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
return (data.length >= LEGACY_MIN_PAYLOAD_LENGTH &&
|
|
74
|
+
this._hasMarkerAt(data, LEGACY_IV_LENGTH));
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
_hasMarkerAt(data, offset) {
|
|
81
|
+
return data.slice(offset, offset + 1).toString() === ':';
|
|
82
|
+
}
|
|
83
|
+
_decryptCurrent(data) {
|
|
84
|
+
const initializationVector = data.slice(0, IV_LENGTH);
|
|
85
|
+
const authTag = data.slice(IV_LENGTH + 1, IV_LENGTH + 1 + AUTH_TAG_LENGTH);
|
|
86
|
+
const cipherText = data.slice(IV_LENGTH + 1 + AUTH_TAG_LENGTH);
|
|
87
|
+
const derivedKey = this._deriveKey(initializationVector);
|
|
88
|
+
try {
|
|
89
|
+
const decipher = (0, crypto_1.createDecipheriv)(CRYPT_ALGO, derivedKey, initializationVector);
|
|
90
|
+
decipher.setAuthTag(authTag);
|
|
91
|
+
const decrypted = Buffer.concat([decipher.update(cipherText), decipher.final()]);
|
|
92
|
+
return this._deserialize(decrypted.toString());
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
_decryptLegacy(data) {
|
|
99
|
+
const initializationVector = data.slice(0, LEGACY_IV_LENGTH);
|
|
100
|
+
const password = (0, crypto_1.pbkdf2Sync)(LEGACY_KEY, initializationVector.toString(), LEGACY_PBKDF2_ITERATIONS, DERIVED_KEY_LENGTH, PBKDF2_DIGEST);
|
|
101
|
+
try {
|
|
102
|
+
const decipher = (0, crypto_1.createDecipheriv)(LEGACY_CRYPT_ALGO, password, initializationVector);
|
|
103
|
+
const decrypted = Buffer.concat([
|
|
104
|
+
decipher.update(data.slice(LEGACY_IV_LENGTH + 1)),
|
|
105
|
+
decipher.final()
|
|
106
|
+
]);
|
|
107
|
+
return this._deserialize(decrypted.toString());
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
_deriveKey(initializationVector) {
|
|
114
|
+
return (0, crypto_1.pbkdf2Sync)(this.encryptionKey, initializationVector, PBKDF2_ITERATIONS, DERIVED_KEY_LENGTH, PBKDF2_DIGEST);
|
|
115
|
+
}
|
|
45
116
|
_serialize(value) {
|
|
46
117
|
return JSON.stringify(value, null, '');
|
|
47
118
|
}
|
|
@@ -152,6 +152,7 @@ function login() {
|
|
|
152
152
|
const localhost = (0, option_js_1.getOptionValue)('localhost', true);
|
|
153
153
|
const result = yield new login_js_1.default(localhost).init();
|
|
154
154
|
activeDC = result.dc;
|
|
155
|
+
(0, dc_js_1.updateActiveDC)(activeDC);
|
|
155
156
|
config_store_js_1.default.set('usage', ans.collectUsage);
|
|
156
157
|
config_store_js_1.default.set(`${activeDC}.user`, result.user);
|
|
157
158
|
config_store_js_1.default.set(`${activeDC}.scopes`, result.scopes);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const os_1 = require("os");
|
|
10
|
+
const config_store_js_1 = __importDefault(require("../util_modules/config-store.js"));
|
|
11
|
+
const KEY_FILE_NAME = '.zcatalyst-cli-key';
|
|
12
|
+
const KEY_BYTE_LENGTH = 32;
|
|
13
|
+
const FILE_MODE = 0o600;
|
|
14
|
+
const DIR_MODE = 0o700;
|
|
15
|
+
class KeyManager {
|
|
16
|
+
static get keyFilePath() {
|
|
17
|
+
const storeDir = config_store_js_1.default.path;
|
|
18
|
+
const baseDir = storeDir && storeDir.length > 0 ? storeDir : (0, os_1.homedir)();
|
|
19
|
+
return (0, path_1.join)(baseDir, KEY_FILE_NAME);
|
|
20
|
+
}
|
|
21
|
+
static getEncryptionKey() {
|
|
22
|
+
if (KeyManager.cachedKey) {
|
|
23
|
+
return KeyManager.cachedKey;
|
|
24
|
+
}
|
|
25
|
+
const filePath = KeyManager.keyFilePath;
|
|
26
|
+
if ((0, fs_1.existsSync)(filePath)) {
|
|
27
|
+
const key = (0, fs_1.readFileSync)(filePath);
|
|
28
|
+
KeyManager._lockDownPermissions(filePath);
|
|
29
|
+
KeyManager.cachedKey = key;
|
|
30
|
+
return key;
|
|
31
|
+
}
|
|
32
|
+
const dir = (0, path_1.dirname)(filePath);
|
|
33
|
+
if (!(0, fs_1.existsSync)(dir)) {
|
|
34
|
+
(0, fs_1.mkdirSync)(dir, { recursive: true, mode: DIR_MODE });
|
|
35
|
+
}
|
|
36
|
+
const key = (0, crypto_1.randomBytes)(KEY_BYTE_LENGTH);
|
|
37
|
+
try {
|
|
38
|
+
(0, fs_1.writeFileSync)(filePath, key, { mode: FILE_MODE, flag: 'wx' });
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err.code === 'EEXIST') {
|
|
42
|
+
const existingKey = (0, fs_1.readFileSync)(filePath);
|
|
43
|
+
KeyManager._lockDownPermissions(filePath);
|
|
44
|
+
KeyManager.cachedKey = existingKey;
|
|
45
|
+
return existingKey;
|
|
46
|
+
}
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
KeyManager._lockDownPermissions(filePath);
|
|
50
|
+
KeyManager.cachedKey = key;
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
53
|
+
static _lockDownPermissions(filePath) {
|
|
54
|
+
try {
|
|
55
|
+
(0, fs_1.chmodSync)(filePath, FILE_MODE);
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
KeyManager.cachedKey = null;
|
|
62
|
+
exports.default = KeyManager;
|
|
@@ -48,7 +48,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
48
48
|
exports.missingScopes = void 0;
|
|
49
49
|
const ansi_colors_1 = require("ansi-colors");
|
|
50
50
|
const http_1 = require("http");
|
|
51
|
-
const
|
|
51
|
+
const index_js_1 = require("../util_modules/server/index.js");
|
|
52
52
|
const open_1 = __importDefault(require("open"));
|
|
53
53
|
const path_1 = require("path");
|
|
54
54
|
const portfinder_1 = require("portfinder");
|
|
@@ -57,9 +57,9 @@ const dc_js_1 = require("../util_modules/dc.js");
|
|
|
57
57
|
const error_js_1 = __importDefault(require("./error.js"));
|
|
58
58
|
const api_js_1 = __importDefault(require("../internal/api.js"));
|
|
59
59
|
const credential_js_1 = __importDefault(require("./credential.js"));
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
60
|
+
const index_js_2 = __importDefault(require("../prompt/index.js"));
|
|
61
|
+
const index_js_3 = __importDefault(require("../throbber/index.js"));
|
|
62
|
+
const index_js_4 = require("../util_modules/constants/index.js");
|
|
63
63
|
const auth_js_1 = __importDefault(require("./constants/auth.js"));
|
|
64
64
|
const dc_type_js_1 = __importDefault(require("../util_modules/constants/lib/dc-type.js"));
|
|
65
65
|
const scopes_js_1 = __importDefault(require("./constants/scopes.js"));
|
|
@@ -68,16 +68,16 @@ const js_js_1 = require("../util_modules/js.js");
|
|
|
68
68
|
const index_1 = require("../util_modules/logger/index");
|
|
69
69
|
const option_js_1 = require("../util_modules/option.js");
|
|
70
70
|
const events_1 = __importDefault(require("events"));
|
|
71
|
-
const
|
|
71
|
+
const index_js_5 = __importDefault(require("../error/index.js"));
|
|
72
72
|
const crypto_1 = require("crypto");
|
|
73
73
|
const env_js_1 = require("../util_modules/env.js");
|
|
74
74
|
exports.missingScopes = {
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
75
|
+
[index_js_4.DC_TYPE.in.value]: getScopes(['dataverse']),
|
|
76
|
+
[index_js_4.DC_TYPE.eu.value]: getScopes(['dataverse']),
|
|
77
|
+
[index_js_4.DC_TYPE.au.value]: getScopes(['dataverse']),
|
|
78
|
+
[index_js_4.DC_TYPE.ca.value]: getScopes(['quick_ml', 'dataverse']),
|
|
79
|
+
[index_js_4.DC_TYPE.sa.value]: getScopes(['quick_ml', 'dataverse']),
|
|
80
|
+
[index_js_4.DC_TYPE.jp.value]: getScopes(['dataverse'])
|
|
81
81
|
};
|
|
82
82
|
function getScopes(keys) {
|
|
83
83
|
return Object.keys(scopes_js_1.default).filter((scope) => keys.some((prefix) => scope.startsWith(prefix)));
|
|
@@ -106,7 +106,7 @@ class Login {
|
|
|
106
106
|
return 'http://localhost:' + port;
|
|
107
107
|
}
|
|
108
108
|
_getLoginUrl(callbackUrl, state) {
|
|
109
|
-
return (
|
|
109
|
+
return (index_js_4.ORIGIN.auth +
|
|
110
110
|
'/oauth/v2/auth?' +
|
|
111
111
|
js_js_1.JS.map({
|
|
112
112
|
client_id: auth_js_1.default.web.id,
|
|
@@ -124,7 +124,7 @@ class Login {
|
|
|
124
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
125
|
const authCodeResponse = yield new api_js_1.default()
|
|
126
126
|
.post('/oauth/v2/token', {
|
|
127
|
-
origin:
|
|
127
|
+
origin: index_js_4.ORIGIN.auth,
|
|
128
128
|
qs: {
|
|
129
129
|
code,
|
|
130
130
|
client_id: auth_js_1.default.web.id,
|
|
@@ -164,7 +164,7 @@ class Login {
|
|
|
164
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
165
165
|
const deviceCodeResponse = yield new api_js_1.default()
|
|
166
166
|
.post('/oauth/v3/device/token', {
|
|
167
|
-
origin:
|
|
167
|
+
origin: index_js_4.ORIGIN.auth,
|
|
168
168
|
qs: {
|
|
169
169
|
client_id: auth_js_1.default.mobile.id,
|
|
170
170
|
client_secret: auth_js_1.default.mobile.secret,
|
|
@@ -240,7 +240,7 @@ class Login {
|
|
|
240
240
|
}
|
|
241
241
|
const userInfoResponse = yield new api_js_1.default()
|
|
242
242
|
.get('/oauth/user/info', {
|
|
243
|
-
origin:
|
|
243
|
+
origin: index_js_4.ORIGIN.auth,
|
|
244
244
|
authNeeded: true
|
|
245
245
|
})
|
|
246
246
|
.catch((err) => {
|
|
@@ -266,11 +266,11 @@ class Login {
|
|
|
266
266
|
(0, index_1.debug)('Error while login with server : ' + err.message);
|
|
267
267
|
}
|
|
268
268
|
this.salt = 'm';
|
|
269
|
-
const throbber =
|
|
269
|
+
const throbber = index_js_3.default.getInstance();
|
|
270
270
|
const throbberName = 'authentication';
|
|
271
271
|
const deviceCodeResponse = yield new api_js_1.default()
|
|
272
272
|
.post('/oauth/v3/device/code', {
|
|
273
|
-
origin:
|
|
273
|
+
origin: index_js_4.ORIGIN.auth,
|
|
274
274
|
qs: {
|
|
275
275
|
client_id: auth_js_1.default.mobile.id,
|
|
276
276
|
scope: js_js_1.JS.values(this._getScopes()).join(' '),
|
|
@@ -356,7 +356,7 @@ class Login {
|
|
|
356
356
|
const queryParamsObj = new url_1.URL(req.url, `http://${req.headers.host}`)
|
|
357
357
|
.searchParams;
|
|
358
358
|
if (queryParamsObj.get('state') !== nonce) {
|
|
359
|
-
throw new
|
|
359
|
+
throw new index_js_5.default('Invalid state param received.', { exit: 2 });
|
|
360
360
|
}
|
|
361
361
|
const code = queryParamsObj !== undefined && queryParamsObj.get('code');
|
|
362
362
|
const _location = queryParamsObj !== undefined && queryParamsObj.get('location');
|
|
@@ -367,7 +367,7 @@ class Login {
|
|
|
367
367
|
typeof location === 'string' &&
|
|
368
368
|
location !== dcRef) {
|
|
369
369
|
(0, index_1.warning)('Your credentials does not match the DC opted!!!');
|
|
370
|
-
const ans = yield
|
|
370
|
+
const ans = yield index_js_2.default.ask(index_js_2.default.question('DC', `Do you wish to continue with login by making ${location.toUpperCase()} DC as active ?`, {
|
|
371
371
|
type: 'confirm',
|
|
372
372
|
defaultAns: true
|
|
373
373
|
}));
|
|
@@ -410,7 +410,7 @@ class Login {
|
|
|
410
410
|
}));
|
|
411
411
|
}
|
|
412
412
|
}));
|
|
413
|
-
const destroyer = new
|
|
413
|
+
const destroyer = new index_js_1.ConnectionDestroyer(server);
|
|
414
414
|
server.listen(port, '127.0.0.1', () => {
|
|
415
415
|
(0, index_1.info)();
|
|
416
416
|
(0, index_1.info)('Visit this URL on this device to log in:');
|
package/lib/bin/catalyst.js
CHANGED
|
@@ -129,18 +129,4 @@ process.on('unhandledRejection', (reason, promise) => {
|
|
|
129
129
|
(0, errorOut_1.default)((0, util_1.inspect)(reason || promise));
|
|
130
130
|
process.exitCode = runtime_store_js_1.default.get('exitCode', 2);
|
|
131
131
|
});
|
|
132
|
-
|
|
133
|
-
if (process.stdin.isTTY) {
|
|
134
|
-
cmdPromise = index_js_1.Catalyst.processArgs(...process.argv);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
let stdin = '';
|
|
138
|
-
process.stdin.on('data', (chunk) => {
|
|
139
|
-
if (chunk !== null) {
|
|
140
|
-
stdin += chunk;
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
process.stdin.on('end', () => {
|
|
144
|
-
cmdPromise = index_js_1.Catalyst.processArgs(...process.argv, stdin.toString().trimEnd());
|
|
145
|
-
});
|
|
146
|
-
}
|
|
132
|
+
const cmdPromise = index_js_1.Catalyst.processArgs(...process.argv);
|
package/lib/client.d.ts
CHANGED
|
@@ -9,11 +9,13 @@ export declare class Client {
|
|
|
9
9
|
processArgs(...args: Array<string>): Promise<Command>;
|
|
10
10
|
getCommand(name: string): Command | null;
|
|
11
11
|
getAllCommandNames(): Array<string>;
|
|
12
|
+
private static execOptionKeyToCliFlag;
|
|
12
13
|
private convertOptions;
|
|
13
|
-
exec(command: string, projectRoot: string, cwd: string, { args, options, inputs }?: {
|
|
14
|
+
exec(command: string, projectRoot: string, cwd: string, { args, options, inputs, nonInteractive }?: {
|
|
14
15
|
args?: Array<string>;
|
|
15
16
|
options?: Record<string, string | boolean | Array<string>>;
|
|
16
17
|
inputs?: Record<string, unknown>;
|
|
18
|
+
nonInteractive?: boolean;
|
|
17
19
|
}): Promise<{
|
|
18
20
|
exitCode: 0 | 1 | 2;
|
|
19
21
|
error?: CatalystError;
|
package/lib/client.js
CHANGED
|
@@ -104,26 +104,37 @@ class Client {
|
|
|
104
104
|
return cmd.name();
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
+
static execOptionKeyToCliFlag(key) {
|
|
108
|
+
if (key === 'nonInteractive') {
|
|
109
|
+
return 'non-interactive';
|
|
110
|
+
}
|
|
111
|
+
return key;
|
|
112
|
+
}
|
|
107
113
|
convertOptions(options) {
|
|
108
114
|
const optionsArr = [];
|
|
109
115
|
Object.entries(options).forEach(([key, value]) => {
|
|
116
|
+
const flag = Client.execOptionKeyToCliFlag(key);
|
|
110
117
|
if (typeof value === 'boolean') {
|
|
111
|
-
value && optionsArr.push('--' +
|
|
118
|
+
value && optionsArr.push('--' + flag);
|
|
112
119
|
return;
|
|
113
120
|
}
|
|
114
|
-
optionsArr.push('--' +
|
|
121
|
+
optionsArr.push('--' + flag);
|
|
115
122
|
optionsArr.push(typeof value === 'string' ? value : value.join(','));
|
|
116
123
|
});
|
|
117
124
|
return optionsArr;
|
|
118
125
|
}
|
|
119
126
|
exec(command_1, projectRoot_1, cwd_1) {
|
|
120
|
-
return __awaiter(this, arguments, void 0, function* (command, projectRoot, cwd, { args = [], options = {}, inputs } = {}) {
|
|
127
|
+
return __awaiter(this, arguments, void 0, function* (command, projectRoot, cwd, { args = [], options = {}, inputs = {}, nonInteractive } = {}) {
|
|
121
128
|
runtime_store_1.default.set('context', {});
|
|
122
129
|
utils_js_1.runtime.set('context', {});
|
|
123
130
|
runtime_store_1.default.set('cwd', cwd);
|
|
124
131
|
runtime_store_1.default.set('project.root', projectRoot);
|
|
125
|
-
runtime_store_1.default.set('prompt', inputs);
|
|
126
|
-
const
|
|
132
|
+
runtime_store_1.default.set('context.prompt', inputs);
|
|
133
|
+
const mergedOptions = Object.assign({}, options);
|
|
134
|
+
if (nonInteractive) {
|
|
135
|
+
mergedOptions.nonInteractive = true;
|
|
136
|
+
}
|
|
137
|
+
const programArgs = [...args, ...this.convertOptions(mergedOptions)];
|
|
127
138
|
this._cli = new commander_1.Command();
|
|
128
139
|
yield this.init(command);
|
|
129
140
|
yield this.processArgs('node', 'catalyst', command, ...programArgs);
|
package/lib/command_needs/rc.js
CHANGED
|
@@ -50,13 +50,23 @@ exports.default = (...args_1) => __awaiter(void 0, [...args_1], void 0, function
|
|
|
50
50
|
const orgApi = yield (0, endpoints_1.orgAPI)();
|
|
51
51
|
if (orgOpt !== null) {
|
|
52
52
|
const orgList = yield orgApi.getAllOrgs();
|
|
53
|
-
const found = orgList.find((org) => org.id + '' === orgOpt);
|
|
53
|
+
const found = orgList.find((org) => org.id + '' === orgOpt || org.name === orgOpt);
|
|
54
54
|
if (!found) {
|
|
55
|
+
if ((0, env_1.isNonInteractiveMode)())
|
|
56
|
+
throw new index_js_1.default('Invalid "org" option supplied', {
|
|
57
|
+
exit: 1,
|
|
58
|
+
errorId: 'RC-7',
|
|
59
|
+
arg: [
|
|
60
|
+
(0, ansi_colors_1.red)(orgOpt),
|
|
61
|
+
(0, ansi_colors_1.italic)('--org'),
|
|
62
|
+
(0, ansi_colors_1.bold)(orgList.map((org) => '* ' + org.name + ' (' + org.id + ')').join('\n'))
|
|
63
|
+
]
|
|
64
|
+
});
|
|
55
65
|
throw new index_js_1.default('Invalid "org" option supplied', {
|
|
56
|
-
exit:
|
|
66
|
+
exit: 1
|
|
57
67
|
});
|
|
58
68
|
}
|
|
59
|
-
runtime_store_1.default.set('project.env.id',
|
|
69
|
+
runtime_store_1.default.set('project.env.id', found.id + '');
|
|
60
70
|
}
|
|
61
71
|
let projectApi = yield (0, endpoints_1.projectAPI)();
|
|
62
72
|
let envApi = yield (0, endpoints_1.envAPI)();
|
|
@@ -51,12 +51,22 @@ const runtime_store_1 = __importDefault(require("../../runtime-store"));
|
|
|
51
51
|
const constants_1 = require("../../util_modules/constants");
|
|
52
52
|
const index_1 = require("../../util_modules/logger/index");
|
|
53
53
|
const scopes_1 = __importDefault(require("../../authentication/constants/scopes"));
|
|
54
|
+
const prompt_fields_1 = require("../../init/features/appsail/prompt-fields");
|
|
55
|
+
const prompt_fields_2 = require("../../init/util/prompt-fields");
|
|
54
56
|
exports.default = new command_1.default('appsail:add')
|
|
55
57
|
.description('Link an already existing AppSail to Catalyst Project')
|
|
56
58
|
.needs('auth', [scopes_1.default.functions])
|
|
57
59
|
.needs('config', { optional: true })
|
|
58
60
|
.needs('rc')
|
|
59
61
|
.ci(false)
|
|
62
|
+
.option(prompt_fields_1.appsailAddPromptFields.get('name'))
|
|
63
|
+
.option(prompt_fields_2.initCommonPromptFields.get('stack'))
|
|
64
|
+
.option(prompt_fields_1.appsailAddPromptFields.get('source'))
|
|
65
|
+
.option(prompt_fields_1.appsailAddPromptFields.get('overwrite'))
|
|
66
|
+
.option(prompt_fields_1.appsailAddPromptFields.get('buildPath'))
|
|
67
|
+
.option(prompt_fields_1.appsailAddPromptFields.get('platform'))
|
|
68
|
+
.option(prompt_fields_1.appsailAddPromptFields.get('command'))
|
|
69
|
+
.option(prompt_fields_1.appsailAddPromptFields.get('port'))
|
|
60
70
|
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
71
|
const config = runtime_store_1.default.get('config');
|
|
62
72
|
yield (yield Promise.resolve().then(() => __importStar(require('../../init/features')))).appsail();
|
|
@@ -27,8 +27,10 @@ const fs_1 = require("../../util_modules/fs");
|
|
|
27
27
|
const js_1 = require("../../util_modules/js");
|
|
28
28
|
const index_1 = require("../../util_modules/logger/index");
|
|
29
29
|
const option_1 = require("../../util_modules/option");
|
|
30
|
-
|
|
30
|
+
const env_1 = require("../../util_modules/env");
|
|
31
|
+
exports.default = new command_1.default('client:delete')
|
|
31
32
|
.description('Delete a version of the client from the remote console or the local directory')
|
|
33
|
+
.argument('[client_version]', 'version of the client to delete')
|
|
32
34
|
.option('--local', 'removes the client from local machine')
|
|
33
35
|
.option('--remote', 'removes the selected client from remote console')
|
|
34
36
|
.needs('auth', [scopes_js_1.default.webapp])
|
|
@@ -48,6 +50,9 @@ exports.default = new command_1.default('client:delete [client_version]')
|
|
|
48
50
|
arg: [(0, ansi_colors_1.bold)('--local'), (0, ansi_colors_1.bold)('--remote')]
|
|
49
51
|
});
|
|
50
52
|
}
|
|
53
|
+
if (!localOpt && !remoteOpt && (0, env_1.isNonInteractiveMode)()) {
|
|
54
|
+
localOpt = true;
|
|
55
|
+
}
|
|
51
56
|
if (!localOpt && !remoteOpt) {
|
|
52
57
|
const locationAns = yield prompt_1.default.ask(prompt_1.default.question('location', 'Choose a location to get more information', {
|
|
53
58
|
type: 'list',
|
|
@@ -77,7 +82,7 @@ exports.default = new command_1.default('client:delete [client_version]')
|
|
|
77
82
|
location: local
|
|
78
83
|
};
|
|
79
84
|
try {
|
|
80
|
-
const configFile = fs_1.ASYNC.readJSONFile(packageJsonFile, {
|
|
85
|
+
const configFile = yield fs_1.ASYNC.readJSONFile(packageJsonFile, {
|
|
81
86
|
checkpath: true
|
|
82
87
|
});
|
|
83
88
|
if (configFile === undefined) {
|
|
@@ -116,6 +121,13 @@ exports.default = new command_1.default('client:delete [client_version]')
|
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
123
|
if (remoteOpt) {
|
|
124
|
+
if ((0, env_1.isNonInteractiveMode)()) {
|
|
125
|
+
throw new index_js_1.default('Remote deletion is not supported in non-interactive mode', {
|
|
126
|
+
exit: 1,
|
|
127
|
+
errorId: 'CDEL-8',
|
|
128
|
+
arg: [(0, ansi_colors_1.bold)('catalyst client:delete --local')]
|
|
129
|
+
});
|
|
130
|
+
}
|
|
119
131
|
const choicesArray = [];
|
|
120
132
|
let historyArr = (yield clientApi.getAllHistory());
|
|
121
133
|
if (js_1.JS.isEmpty(historyArr)) {
|
|
@@ -171,7 +183,7 @@ exports.default = new command_1.default('client:delete [client_version]')
|
|
|
171
183
|
: false
|
|
172
184
|
}));
|
|
173
185
|
});
|
|
174
|
-
const choiceAns = yield prompt_1.default.ask(prompt_1.default.question('
|
|
186
|
+
const choiceAns = yield prompt_1.default.ask(prompt_1.default.question('clientsToDelete', 'Select all the client versions you want to delete', {
|
|
175
187
|
type: 'checkbox',
|
|
176
188
|
choices: choicesArray,
|
|
177
189
|
validate: (answers) => {
|
|
@@ -184,8 +196,8 @@ exports.default = new command_1.default('client:delete [client_version]')
|
|
|
184
196
|
return choicesArray.length > 2;
|
|
185
197
|
}
|
|
186
198
|
}));
|
|
187
|
-
if (choiceAns.
|
|
188
|
-
appsToBeDeleted.push(...choiceAns.
|
|
199
|
+
if (choiceAns.clientsToDelete !== undefined) {
|
|
200
|
+
appsToBeDeleted.push(...choiceAns.clientsToDelete);
|
|
189
201
|
}
|
|
190
202
|
else if (choicesArray.length === 2 && !choicesArray[1].disabled) {
|
|
191
203
|
appsToBeDeleted.push(choicesArray[1].value);
|
|
@@ -204,7 +216,7 @@ exports.default = new command_1.default('client:delete [client_version]')
|
|
|
204
216
|
const consentAns = yield prompt_1.default.ask(prompt_1.default.question('consent', 'Are you sure you want to delete the clients : ' +
|
|
205
217
|
appsToBeDeleted.map((app) => `${app.version}(${app.location})`).join(','), {
|
|
206
218
|
type: 'confirm',
|
|
207
|
-
defaultAns:
|
|
219
|
+
defaultAns: (0, env_1.isNonInteractiveMode)(),
|
|
208
220
|
when: () => {
|
|
209
221
|
return appsToBeDeleted.length > 0;
|
|
210
222
|
}
|