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.
Files changed (155) hide show
  1. package/README.md +1 -0
  2. package/lib/appsail-utils.d.ts +1 -1
  3. package/lib/appsail-utils.js +170 -129
  4. package/lib/authentication/credential.d.ts +2 -1
  5. package/lib/authentication/credential.js +20 -3
  6. package/lib/authentication/crypt.d.ts +7 -3
  7. package/lib/authentication/crypt.js +87 -16
  8. package/lib/authentication/index.js +1 -0
  9. package/lib/authentication/key-manager.d.ts +7 -0
  10. package/lib/authentication/key-manager.js +62 -0
  11. package/lib/authentication/login.js +20 -20
  12. package/lib/bin/catalyst.js +1 -15
  13. package/lib/client.d.ts +3 -1
  14. package/lib/client.js +16 -5
  15. package/lib/command_needs/rc.js +13 -3
  16. package/lib/commands/appsail/add.js +10 -0
  17. package/lib/commands/client/delete.js +18 -6
  18. package/lib/commands/client/setup.js +7 -0
  19. package/lib/commands/deploy/index.js +3 -3
  20. package/lib/commands/deploy/slate.js +65 -4
  21. package/lib/commands/functions/add.js +7 -0
  22. package/lib/commands/functions/delete.js +22 -4
  23. package/lib/commands/functions/execute.js +39 -71
  24. package/lib/commands/functions/setup.js +13 -0
  25. package/lib/commands/functions/shell.js +15 -1
  26. package/lib/commands/iac/import.js +2 -2
  27. package/lib/commands/init.js +34 -20
  28. package/lib/commands/login.js +1 -0
  29. package/lib/commands/pull.js +22 -1
  30. package/lib/commands/serve.js +2 -1
  31. package/lib/commands/slate/create.js +7 -4
  32. package/lib/commands/slate/link.js +11 -5
  33. package/lib/commands/slate/unlink.js +7 -0
  34. package/lib/commands/zest/generate/index.js +28 -35
  35. package/lib/deploy/features/appsail/index.js +2 -1
  36. package/lib/deploy/features/slate.d.ts +3 -1
  37. package/lib/deploy/features/slate.js +204 -5
  38. package/lib/docs/client-utils.toml +0 -5
  39. package/lib/docs/command_needs/rc.toml +9 -1
  40. package/lib/docs/commands/client/delete.toml +4 -0
  41. package/lib/docs/commands/deploy/slate.toml +3 -0
  42. package/lib/docs/commands/functions/delete.toml +10 -0
  43. package/lib/docs/commands/functions/execute.toml +1 -16
  44. package/lib/docs/commands/functions/setup.toml +3 -0
  45. package/lib/docs/commands/functions/shell.toml +8 -0
  46. package/lib/docs/commands/init.toml +3 -0
  47. package/lib/docs/commands/pull.toml +6 -0
  48. package/lib/docs/commands/slate/unlink.toml +6 -0
  49. package/lib/docs/execute/command-utils.toml +14 -0
  50. package/lib/docs/execute/execute-input-resolver.toml +37 -0
  51. package/lib/docs/init/features/project.toml +20 -0
  52. package/lib/docs/init/util/client.toml +4 -0
  53. package/lib/docs/prompt/index.toml +15 -0
  54. package/lib/docs/pull/features/apig.toml +6 -0
  55. package/lib/docs/pull/features/client.toml +20 -0
  56. package/lib/docs/pull/features/functions/index.toml +24 -0
  57. package/lib/endpoints/lib/slate.d.ts +14 -1
  58. package/lib/endpoints/lib/slate.js +35 -0
  59. package/lib/error/context-help.js +1 -1
  60. package/lib/error/index.js +9 -13
  61. package/lib/execute/command-utils.d.ts +5 -0
  62. package/lib/execute/command-utils.js +86 -0
  63. package/lib/execute/execute-input-resolver.d.ts +29 -0
  64. package/lib/execute/execute-input-resolver.js +207 -0
  65. package/lib/execute/index.d.ts +4 -1
  66. package/lib/execute/index.js +3 -2
  67. package/lib/fn-utils/lib/integ.js +22 -17
  68. package/lib/index.js +1 -0
  69. package/lib/init/dependencies/package-json.js +11 -7
  70. package/lib/init/features/appsail/index.js +75 -26
  71. package/lib/init/features/appsail/prompt-fields.d.ts +43 -0
  72. package/lib/init/features/appsail/prompt-fields.js +55 -0
  73. package/lib/init/features/appsail/utils/custom-runtime.d.ts +3 -0
  74. package/lib/init/features/appsail/utils/custom-runtime.js +161 -0
  75. package/lib/init/features/appsail/{utils.d.ts → utils/index.d.ts} +2 -2
  76. package/lib/init/features/appsail/utils/index.js +170 -0
  77. package/lib/init/features/client/index.js +4 -3
  78. package/lib/init/features/client/initializers/angular.js +3 -2
  79. package/lib/init/features/client/initializers/react.js +4 -3
  80. package/lib/init/features/client/prompt-fields.d.ts +37 -0
  81. package/lib/init/features/client/prompt-fields.js +48 -0
  82. package/lib/init/features/functions/index.js +37 -8
  83. package/lib/init/features/functions/languages/java.js +42 -7
  84. package/lib/init/features/functions/languages/node.js +42 -10
  85. package/lib/init/features/functions/languages/python.js +42 -7
  86. package/lib/init/features/functions/prompt-fields.d.ts +25 -0
  87. package/lib/init/features/functions/prompt-fields.js +34 -0
  88. package/lib/init/features/project.js +41 -6
  89. package/lib/init/features/slate/index.js +2 -0
  90. package/lib/init/features/slate/prompt-fields.d.ts +31 -0
  91. package/lib/init/features/slate/prompt-fields.js +41 -0
  92. package/lib/init/index.js +2 -1
  93. package/lib/init/util/client.js +11 -8
  94. package/lib/init/util/common.d.ts +2 -0
  95. package/lib/init/util/common.js +33 -3
  96. package/lib/init/util/prompt-fields.d.ts +7 -0
  97. package/lib/init/util/prompt-fields.js +13 -0
  98. package/lib/internal/command.d.ts +3 -0
  99. package/lib/internal/command.js +26 -3
  100. package/lib/migration/global/1.27.0.d.ts +2 -0
  101. package/lib/migration/global/1.27.0.js +39 -0
  102. package/lib/prompt/choice.d.ts +2 -0
  103. package/lib/prompt/choice.js +24 -0
  104. package/lib/prompt/cli-option-key.d.ts +1 -0
  105. package/lib/prompt/cli-option-key.js +10 -0
  106. package/lib/prompt/index.d.ts +6 -22
  107. package/lib/prompt/index.js +264 -67
  108. package/lib/prompt/overwrite-prompt.d.ts +11 -0
  109. package/lib/prompt/overwrite-prompt.js +16 -0
  110. package/lib/prompt/question-factory.d.ts +34 -0
  111. package/lib/prompt/question-factory.js +41 -0
  112. package/lib/prompt/register-fields.d.ts +24 -0
  113. package/lib/prompt/register-fields.js +37 -0
  114. package/lib/pull/features/apig.js +57 -6
  115. package/lib/pull/features/client.js +107 -24
  116. package/lib/pull/features/functions/index.js +100 -4
  117. package/lib/pull/index.js +1 -1
  118. package/lib/pull/utils.d.ts +13 -0
  119. package/lib/pull/utils.js +20 -0
  120. package/lib/repl-server.d.ts +4 -0
  121. package/lib/repl-server.js +9 -0
  122. package/lib/serve/features/appsail.js +2 -45
  123. package/lib/serve/server/lib/master/index.js +3 -3
  124. package/lib/serve/server/lib/slate/static-server.js +2 -2
  125. package/lib/serve/server/lib/web_client/server.js +2 -2
  126. package/lib/shell/format-functions.d.ts +4 -0
  127. package/lib/shell/format-functions.js +59 -0
  128. package/lib/shell/index.js +18 -0
  129. package/lib/util_modules/config/lib/appsail.d.ts +3 -2
  130. package/lib/util_modules/config/lib/appsail.js +21 -5
  131. package/lib/util_modules/config/lib/slate.d.ts +19 -0
  132. package/lib/util_modules/config-store.d.ts +1 -0
  133. package/lib/util_modules/config-store.js +29 -10
  134. package/lib/util_modules/constants/index.d.ts +0 -1
  135. package/lib/util_modules/constants/index.js +1 -3
  136. package/lib/util_modules/constants/lib/urls.d.ts +2 -0
  137. package/lib/util_modules/constants/lib/urls.js +4 -0
  138. package/lib/util_modules/dc.d.ts +6 -1
  139. package/lib/util_modules/dc.js +21 -8
  140. package/lib/util_modules/env.d.ts +3 -0
  141. package/lib/util_modules/env.js +41 -0
  142. package/lib/util_modules/fs/lib/sync.d.ts +1 -0
  143. package/lib/util_modules/fs/lib/sync.js +19 -0
  144. package/lib/util_modules/logger/utils.d.ts +1 -0
  145. package/lib/util_modules/logger/utils.js +5 -1
  146. package/lib/util_modules/option.d.ts +1 -0
  147. package/lib/util_modules/option.js +8 -0
  148. package/lib/util_modules/{server.js → server/index.js} +3 -3
  149. package/lib/util_modules/server/needed-scopes.d.ts +1 -0
  150. package/lib/util_modules/{constants/lib → server}/needed-scopes.js +7 -7
  151. package/package.json +3 -2
  152. package/lib/init/features/appsail/utils.js +0 -273
  153. package/lib/util_modules/constants/lib/needed-scopes.d.ts +0 -4
  154. /package/lib/docs/{dc.toml → util_modules/dc.toml} +0 -0
  155. /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.
@@ -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>): Promise<Array<TAppSailDetails>>;
3
+ export declare function validateAppSail(targDetails: Array<TAppSailDetails>, resolveLocalRuntime?: boolean): [Promise<Array<TAppSailDetails>>, Record<string, string>];
@@ -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
- return __awaiter(this, void 0, void 0, function* () {
103
- let isSocket;
104
- const getImageInfo = (target) => __awaiter(this, void 0, void 0, function* () {
105
- switch (true) {
106
- case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker): {
107
- const imgTag = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.docker, '');
108
- return (0, image_1.inspectImage)(imgTag);
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
- case target.source.startsWith(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive): {
111
- const imgTar = target.source.replace(appsail_1.CONTAINER_IMAGE_PROTOCOLS.dockerArchive, '');
112
- const isFile = yield fs_1.ASYNC.fileExists(imgTar);
113
- if (!isFile) {
114
- throw new error_1.default('Invalid image tar path: ' + imgTar, { exit: 1 });
115
- }
116
- return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
117
- var _a;
118
- try {
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
- const traversedDigests = new Set();
133
- const resolveImageManifestPath = (manifestIndex, sourceFile) => __awaiter(this, void 0, void 0, function* () {
134
- var _a;
135
- const imageDescriptor = (_a = manifestIndex.manifests) === null || _a === void 0 ? void 0 : _a.find((manifest) => {
136
- if (!(manifest === null || manifest === void 0 ? void 0 : manifest.digest)) {
137
- return false;
138
- }
139
- if (!manifest.mediaType) {
140
- return true;
141
- }
142
- return (OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(manifest.mediaType) ||
143
- OCI_IMAGE_INDEX_MEDIA_TYPES.includes(manifest.mediaType));
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
- const nestedIndex = yield fs_1.ASYNC.readStreamAsJSON(nestedIndexStream);
162
- if (nestedIndex.schemaVersion !== 2) {
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 resolveImageManifestPath(nestedIndex, nestedIndexPath);
146
+ return (OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(manifest.mediaType) ||
147
+ OCI_IMAGE_INDEX_MEDIA_TYPES.includes(manifest.mediaType));
166
148
  });
167
- const imageManifestPath = yield resolveImageManifestPath(indexJson, 'index.json');
168
- const imageManifestStream = yield (0, image_1.getTarEntry)(imgTar, imageManifestPath);
169
- if (!imageManifestStream) {
170
- throw new error_1.default(`Corrupted image tar :: image manifest ${imageManifestPath} not found in the tar`, { exit: 1 });
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
- const imageManifest = yield fs_1.ASYNC.readStreamAsJSON(imageManifestStream);
173
- if (imageManifest.schemaVersion !== 2) {
174
- throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unsupported schemaVersion', { exit: 1 });
155
+ if (!imageDescriptor.mediaType ||
156
+ OCI_IMAGE_MANIFEST_MEDIA_TYPES.includes(imageDescriptor.mediaType)) {
157
+ return getBlobPathFromDigest(imageDescriptor.digest, sourceFile);
175
158
  }
176
- const configDigest = (_a = imageManifest.config) === null || _a === void 0 ? void 0 : _a.digest;
177
- if (!configDigest) {
178
- throw new error_1.default('Corrupted image tar :: invalid image manifest file. Unable to identify the config blob', { exit: 1 });
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 configBlobPath = getBlobPathFromDigest(configDigest, imageManifestPath);
181
- const configFileStream = yield (0, image_1.getTarEntry)(imgTar, configBlobPath);
182
- if (!configFileStream) {
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
- const configFile = yield fs_1.ASYNC.readStreamAsJSON(configFileStream);
186
- resolve(configFile);
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
- catch (er) {
189
- er instanceof error_1.default
190
- ? reject(er)
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
- default: {
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 arch = 'architecture' in imgInfo
225
- ? imgInfo.architecture
226
- : imgInfo.Architecture;
227
- if ((arch === null || arch === void 0 ? void 0 : arch.toLowerCase()) !== 'amd64') {
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
- targ.validity = {
237
- valid: false,
238
- reason: er instanceof error_1.default ? er.message : (0, util_1.inspect)(er)
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
- if (((_a = targ.config) === null || _a === void 0 ? void 0 : _a.platform) !== 'war' && !((_b = targ.config) === null || _b === void 0 ? void 0 : _b.command)) {
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: 'Start-up command missing'
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
- return Promise.all(_details);
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 crypt;
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 tokenObj = Credential.crypt.decrypt(encryptedToken);
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 (typeof decryptToken === 'string') {
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.crypt = new crypt_1.default('ZC_TRAM');
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
- private cryptAlgo;
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(password) {
6
- this.encryptionKey = password;
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 = Buffer.from(value, 'hex');
11
- if (data.slice(16, 17).toString() !== ':') {
21
+ let data;
22
+ try {
23
+ data = Buffer.from(value, 'hex');
24
+ }
25
+ catch (err) {
12
26
  return value;
13
27
  }
14
- const initializationVector = data.slice(0, 16);
15
- const password = (0, crypto_1.pbkdf2Sync)(this.encryptionKey, initializationVector.toString(), 1000, 32, 'sha512');
16
- const decipher = (0, crypto_1.createDecipheriv)(this.cryptAlgo, password, initializationVector);
17
- data = Buffer.concat([decipher.update(data.slice(17)), decipher.final()]);
18
- return this._deserialize(data.toString());
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)(16);
23
- const password = (0, crypto_1.pbkdf2Sync)(this.encryptionKey, initializationVector.toString(), 1000, 32, 'sha512');
24
- const cipher = (0, crypto_1.createCipheriv)(this.cryptAlgo, password, initializationVector);
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
- cipher.update(Buffer.from(data)),
29
- cipher.final()
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.slice(16, 17).toString() === ':') {
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,7 @@
1
+ declare class KeyManager {
2
+ private static cachedKey;
3
+ private static get keyFilePath();
4
+ static getEncryptionKey(): Buffer;
5
+ private static _lockDownPermissions;
6
+ }
7
+ export default KeyManager;