zcatalyst-cli 1.26.1 → 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/appsail-utils.d.ts +1 -1
- package/lib/appsail-utils.js +170 -129
- 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/appsail/index.js +2 -1
- 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/features/appsail.js +2 -45
- 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 +21 -5
- 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.
|
package/lib/appsail-utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { TAppSailDetails } from './util_modules/config/lib/appsail';
|
|
2
2
|
export declare function filterTargets(allTargets: Array<TAppSailDetails>): Array<TAppSailDetails>;
|
|
3
|
-
export declare function validateAppSail(targDetails: Array<TAppSailDetails
|
|
3
|
+
export declare function validateAppSail(targDetails: Array<TAppSailDetails>, resolveLocalRuntime?: boolean): [Promise<Array<TAppSailDetails>>, Record<string, string>];
|
package/lib/appsail-utils.js
CHANGED
|
@@ -24,6 +24,10 @@ const container_1 = require("./util_modules/container");
|
|
|
24
24
|
const image_1 = require("@zcatalyst/container-plugin/out/endpoints/image");
|
|
25
25
|
const fs_1 = require("./util_modules/fs");
|
|
26
26
|
const util_1 = require("util");
|
|
27
|
+
const node_1 = require("./fn-utils/lib/node");
|
|
28
|
+
const java_1 = require("./fn-utils/lib/java");
|
|
29
|
+
const ensure_python_1 = require("./init/dependencies/python/ensure-python");
|
|
30
|
+
const path_1 = require("path");
|
|
27
31
|
const OCI_IMAGE_INDEX_MEDIA_TYPES = [
|
|
28
32
|
'application/vnd.oci.image.index.v1+json',
|
|
29
33
|
'application/vnd.docker.distribution.manifest.list.v2+json'
|
|
@@ -98,158 +102,195 @@ function filterTargets(allTargets) {
|
|
|
98
102
|
}
|
|
99
103
|
return allTargets;
|
|
100
104
|
}
|
|
101
|
-
function validateAppSail(targDetails) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
function validateAppSail(targDetails, resolveLocalRuntime = true) {
|
|
106
|
+
let isSocket;
|
|
107
|
+
const binPathMap = {};
|
|
108
|
+
const getImageInfo = (target) => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
switch (true) {
|
|
110
|
+
case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker): {
|
|
111
|
+
const imgTag = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker, '');
|
|
112
|
+
return (0, image_1.inspectImage)(imgTag);
|
|
113
|
+
}
|
|
114
|
+
case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive): {
|
|
115
|
+
const imgTar = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive, '');
|
|
116
|
+
const isFile = yield fs_1.ASYNC.fileExists(imgTar);
|
|
117
|
+
if (!isFile) {
|
|
118
|
+
throw new error_1.default('Invalid image tar path: ' + imgTar, { exit: 1 });
|
|
109
119
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const manifestJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'manifest.json');
|
|
120
|
-
const repositoriesStream = yield (0, image_1.getTarEntry)(imgTar, 'repositories');
|
|
121
|
-
const indexJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'index.json');
|
|
122
|
-
if (!indexJsonStream) {
|
|
123
|
-
if (manifestJsonStream || repositoriesStream) {
|
|
124
|
-
throw new error_1.default('Legacy docker-archive format is not supported. Only OCI-compliant docker-archive formats (pure OCI or hybrid OCI) are supported.', { exit: 1 });
|
|
125
|
-
}
|
|
126
|
-
throw new error_1.default('Corrupted image tar :: required OCI metadata index.json not found in the tar', { exit: 1 });
|
|
127
|
-
}
|
|
128
|
-
const indexJson = yield fs_1.ASYNC.readStreamAsJSON(indexJsonStream);
|
|
129
|
-
if (indexJson.schemaVersion !== 2) {
|
|
130
|
-
throw new error_1.default('Corrupted image tar :: invalid index.json file. Unsupported schemaVersion', { exit: 1 });
|
|
120
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
var _a;
|
|
122
|
+
try {
|
|
123
|
+
const manifestJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'manifest.json');
|
|
124
|
+
const repositoriesStream = yield (0, image_1.getTarEntry)(imgTar, 'repositories');
|
|
125
|
+
const indexJsonStream = yield (0, image_1.getTarEntry)(imgTar, 'index.json');
|
|
126
|
+
if (!indexJsonStream) {
|
|
127
|
+
if (manifestJsonStream || repositoriesStream) {
|
|
128
|
+
throw new error_1.default('Legacy docker-archive format is not supported. Only OCI-compliant docker-archive formats (pure OCI or hybrid OCI) are supported.', { exit: 1 });
|
|
131
129
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
145
|
-
if (!(imageDescriptor === null || imageDescriptor === void 0 ? void 0 : imageDescriptor.digest)) {
|
|
146
|
-
throw new error_1.default(`Corrupted image tar :: invalid ${sourceFile} file. Unable to identify image manifest`, { exit: 1 });
|
|
147
|
-
}
|
|
148
|
-
if (traversedDigests.has(imageDescriptor.digest)) {
|
|
149
|
-
throw new error_1.default(`Corrupted image tar :: circular descriptor reference found for digest ${imageDescriptor.digest}`, { exit: 1 });
|
|
150
|
-
}
|
|
151
|
-
if (!imageDescriptor.mediaType ||
|
|
152
|
-
OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(imageDescriptor.mediaType)) {
|
|
153
|
-
return getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
|
|
154
|
-
}
|
|
155
|
-
traversedDigests.add(imageDescriptor.digest);
|
|
156
|
-
const nestedIndexPath = getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
|
|
157
|
-
const nestedIndexStream = yield (0, image_1.getTarEntry)(imgTar, nestedIndexPath);
|
|
158
|
-
if (!nestedIndexStream) {
|
|
159
|
-
throw new error_1.default(`Corrupted image tar :: nested image index ${nestedIndexPath} not found in the tar`, { exit: 1 });
|
|
130
|
+
throw new error_1.default('Corrupted image tar :: required OCI metadata index.json not found in the tar', { exit: 1 });
|
|
131
|
+
}
|
|
132
|
+
const indexJson = yield fs_1.ASYNC.readStreamAsJSON(indexJsonStream);
|
|
133
|
+
if (indexJson.schemaVersion !== 2) {
|
|
134
|
+
throw new error_1.default('Corrupted image tar :: invalid index.json file. Unsupported schemaVersion', { exit: 1 });
|
|
135
|
+
}
|
|
136
|
+
const traversedDigests = new Set();
|
|
137
|
+
const resolveImageManifestPath = (manifestIndex, sourceFile) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
var _a;
|
|
139
|
+
const imageDescriptor = (_a = manifestIndex.manifests) === null || _a === void 0 ? void 0 : _a.find((manifest) => {
|
|
140
|
+
if (!(manifest === null || manifest === void 0 ? void 0 : manifest.digest)) {
|
|
141
|
+
return false;
|
|
160
142
|
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
throw new error_1.default(`Corrupted image tar :: invalid nested image index ${nestedIndexPath}. Unsupported schemaVersion`, { exit: 1 });
|
|
143
|
+
if (!manifest.mediaType) {
|
|
144
|
+
return true;
|
|
164
145
|
}
|
|
165
|
-
return
|
|
146
|
+
return (OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(manifest.mediaType) ||
|
|
147
|
+
OCI_IMAGE_INDEX_MEDIA_TYPES.includes(manifest.mediaType));
|
|
166
148
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
149
|
+
if (!(imageDescriptor === null || imageDescriptor === void 0 ? void 0 : imageDescriptor.digest)) {
|
|
150
|
+
throw new error_1.default(`Corrupted image tar :: invalid ${sourceFile} file. Unable to identify image manifest`, { exit: 1 });
|
|
151
|
+
}
|
|
152
|
+
if (traversedDigests.has(imageDescriptor.digest)) {
|
|
153
|
+
throw new error_1.default(`Corrupted image tar :: circular descriptor reference found for digest ${imageDescriptor.digest}`, { exit: 1 });
|
|
171
154
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
155
|
+
if (!imageDescriptor.mediaType ||
|
|
156
|
+
OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(imageDescriptor.mediaType)) {
|
|
157
|
+
return getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
|
|
175
158
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
159
|
+
traversedDigests.add(imageDescriptor.digest);
|
|
160
|
+
const nestedIndexPath = getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
|
|
161
|
+
const nestedIndexStream = yield (0, image_1.getTarEntry)(imgTar, nestedIndexPath);
|
|
162
|
+
if (!nestedIndexStream) {
|
|
163
|
+
throw new error_1.default(`Corrupted image tar :: nested image index ${nestedIndexPath} not found in the tar`, { exit: 1 });
|
|
179
164
|
}
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
throw new error_1.default(`Corrupted image tar :: config blob ${configBlobPath} not found in the tar`, { exit: 1 });
|
|
165
|
+
const nestedIndex = yield fs_1.ASYNC.readStreamAsJSON(nestedIndexStream);
|
|
166
|
+
if (nestedIndex.schemaVersion !== 2) {
|
|
167
|
+
throw new error_1.default(`Corrupted image tar :: invalid nested image index ${nestedIndexPath}. Unsupported schemaVersion`, { exit: 1 });
|
|
184
168
|
}
|
|
185
|
-
|
|
186
|
-
|
|
169
|
+
return resolveImageManifestPath(nestedIndex, nestedIndexPath);
|
|
170
|
+
});
|
|
171
|
+
const imageManifestPath = yield resolveImageManifestPath(indexJson, 'index.json');
|
|
172
|
+
const imageManifestStream = yield (0, image_1.getTarEntry)(imgTar, imageManifestPath);
|
|
173
|
+
if (!imageManifestStream) {
|
|
174
|
+
throw new error_1.default(`Corrupted image tar :: image manifest ${imageManifestPath} not found in the tar`, { exit: 1 });
|
|
187
175
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
: reject(error_1.default.getErrorInstance(er));
|
|
176
|
+
const imageManifest = yield fs_1.ASYNC.readStreamAsJSON(imageManifestStream);
|
|
177
|
+
if (imageManifest.schemaVersion !== 2) {
|
|
178
|
+
throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unsupported schemaVersion', { exit: 1 });
|
|
192
179
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
throw new error_1.default('Unsupported image source: ' + target.source, { exit: 1 });
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
const _details = targDetails.map((targ) => __awaiter(this, void 0, void 0, function* () {
|
|
201
|
-
var _a, _b;
|
|
202
|
-
if (targ.validity.valid) {
|
|
203
|
-
if (targ.runtime === 'custom') {
|
|
204
|
-
if (isSocket === undefined) {
|
|
205
|
-
isSocket = yield (0, container_1.isSocketAccessible)(false);
|
|
206
|
-
}
|
|
207
|
-
if (isSocket === false) {
|
|
208
|
-
targ.validity = {
|
|
209
|
-
valid: false,
|
|
210
|
-
reason: 'ZCatalyst-CLI is unable to communicate with the Container runtime'
|
|
211
|
-
};
|
|
212
|
-
return targ;
|
|
213
|
-
}
|
|
214
|
-
try {
|
|
215
|
-
const imgInfo = (yield getImageInfo(targ));
|
|
216
|
-
const os = 'os' in imgInfo ? imgInfo.os : imgInfo.Os;
|
|
217
|
-
if ((os === null || os === void 0 ? void 0 : os.toLowerCase()) !== 'linux') {
|
|
218
|
-
targ.validity = {
|
|
219
|
-
valid: false,
|
|
220
|
-
reason: 'container image should be Linux based'
|
|
221
|
-
};
|
|
222
|
-
return targ;
|
|
180
|
+
const configDigest = (_a = imageManifest.config) === null || _a === void 0 ? void 0 : _a.digest;
|
|
181
|
+
if (!configDigest) {
|
|
182
|
+
throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unable to identify the config blob', { exit: 1 });
|
|
223
183
|
}
|
|
224
|
-
const
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
targ.validity = {
|
|
229
|
-
valid: false,
|
|
230
|
-
reason: 'container image should be amd64 based'
|
|
231
|
-
};
|
|
232
|
-
return targ;
|
|
184
|
+
const configBlobPath = getBlobPathFromDigest(configDigest, imageManifestPath);
|
|
185
|
+
const configFileStream = yield (0, image_1.getTarEntry)(imgTar, configBlobPath);
|
|
186
|
+
if (!configFileStream) {
|
|
187
|
+
throw new error_1.default(`Corrupted image tar :: config blob ${configBlobPath} not found in the tar`, { exit: 1 });
|
|
233
188
|
}
|
|
189
|
+
const configFile = yield fs_1.ASYNC.readStreamAsJSON(configFileStream);
|
|
190
|
+
resolve(configFile);
|
|
234
191
|
}
|
|
235
192
|
catch (er) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
};
|
|
193
|
+
er instanceof error_1.default
|
|
194
|
+
? reject(er)
|
|
195
|
+
: reject(error_1.default.getErrorInstance(er));
|
|
240
196
|
}
|
|
197
|
+
}));
|
|
198
|
+
}
|
|
199
|
+
default: {
|
|
200
|
+
throw new error_1.default('Unsupported image source: ' + target.source, { exit: 1 });
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
const _details = targDetails.map((targ) => __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
var _a, _b, _c;
|
|
206
|
+
if (!targ.validity.valid) {
|
|
207
|
+
return targ;
|
|
208
|
+
}
|
|
209
|
+
if (targ.runtime === 'custom') {
|
|
210
|
+
if (isSocket === undefined) {
|
|
211
|
+
isSocket = yield (0, container_1.isSocketAccessible)(false);
|
|
212
|
+
}
|
|
213
|
+
if (isSocket === false) {
|
|
214
|
+
targ.validity = {
|
|
215
|
+
valid: false,
|
|
216
|
+
reason: 'ZCatalyst-CLI is unable to communicate with the Container runtime'
|
|
217
|
+
};
|
|
218
|
+
return targ;
|
|
219
|
+
}
|
|
220
|
+
try {
|
|
221
|
+
const imgInfo = (yield getImageInfo(targ));
|
|
222
|
+
const os = 'os' in imgInfo ? imgInfo.os : imgInfo.Os;
|
|
223
|
+
if ((os === null || os === void 0 ? void 0 : os.toLowerCase()) !== 'linux') {
|
|
224
|
+
targ.validity = {
|
|
225
|
+
valid: false,
|
|
226
|
+
reason: 'container image should be Linux based'
|
|
227
|
+
};
|
|
241
228
|
return targ;
|
|
242
229
|
}
|
|
243
|
-
|
|
230
|
+
const arch = 'architecture' in imgInfo
|
|
231
|
+
? imgInfo.architecture
|
|
232
|
+
: imgInfo.Architecture;
|
|
233
|
+
if ((arch === null || arch === void 0 ? void 0 : arch.toLowerCase()) !== 'amd64') {
|
|
244
234
|
targ.validity = {
|
|
245
235
|
valid: false,
|
|
246
|
-
reason: '
|
|
236
|
+
reason: 'container image should be amd64 based'
|
|
247
237
|
};
|
|
248
238
|
return targ;
|
|
249
239
|
}
|
|
250
240
|
}
|
|
241
|
+
catch (er) {
|
|
242
|
+
targ.validity = {
|
|
243
|
+
valid: false,
|
|
244
|
+
reason: er instanceof error_1.default ? er.message : (0, util_1.inspect)(er)
|
|
245
|
+
};
|
|
246
|
+
}
|
|
251
247
|
return targ;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const stack = (_a = targ.config) === null || _a === void 0 ? void 0 : _a.stack;
|
|
251
|
+
if (!stack) {
|
|
252
|
+
throw new error_1.default(`Stack is not defined for AppSail target ${targ.name}`, {
|
|
253
|
+
exit: 2
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
if (((_b = targ.config) === null || _b === void 0 ? void 0 : _b.platform) !== 'war' && !((_c = targ.config) === null || _c === void 0 ? void 0 : _c.command)) {
|
|
257
|
+
throw new error_1.default(`Start-up command missing for AppSail target ${targ.name}`, {
|
|
258
|
+
exit: 2
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
if (resolveLocalRuntime === false) {
|
|
262
|
+
return targ;
|
|
263
|
+
}
|
|
264
|
+
if (binPathMap[stack]) {
|
|
265
|
+
return targ;
|
|
266
|
+
}
|
|
267
|
+
switch (true) {
|
|
268
|
+
case stack.startsWith('node'): {
|
|
269
|
+
binPathMap[stack] = yield (0, node_1.ensureNodeVersion)(stack, true);
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case stack.startsWith('java'): {
|
|
273
|
+
const javaBinPath = yield (0, java_1.ensureJava)(stack);
|
|
274
|
+
if (!javaBinPath) {
|
|
275
|
+
throw new error_1.default(`Invalid bin path for ${stack}`, { exit: 1 });
|
|
276
|
+
}
|
|
277
|
+
binPathMap[stack] = javaBinPath;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
case stack.startsWith('python'): {
|
|
281
|
+
const stackVersion = stack.replace('python_', '');
|
|
282
|
+
const pyExe = yield (0, ensure_python_1.ensurePython)(stackVersion.replace('_', '.'), false, true);
|
|
283
|
+
binPathMap[stack] = (0, path_1.dirname)(pyExe);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
catch (err) {
|
|
289
|
+
const error = error_1.default.getErrorInstance(err);
|
|
290
|
+
targ.validity.valid = false;
|
|
291
|
+
targ.validity.reason = error.message;
|
|
292
|
+
}
|
|
293
|
+
return targ;
|
|
294
|
+
}));
|
|
295
|
+
return [Promise.all(_details), binPathMap];
|
|
255
296
|
}
|
|
@@ -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);
|