@adobe/aio-cli-plugin-api-mesh 5.2.3 → 5.2.4-alpha.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/oclif.manifest.json +1 -1
- package/package.json +5 -10
- package/src/commands/{api-mesh.js → PLUGINNAME/__tests__/index.test.js} +15 -13
- package/src/commands/PLUGINNAME/index.js +32 -0
- package/src/commands/api-mesh/__tests__/cache-purge.test.js +2 -2
- package/src/commands/api-mesh/__tests__/create.test.js +9 -21
- package/src/commands/api-mesh/__tests__/delete.test.js +2 -2
- package/src/commands/api-mesh/__tests__/describe.test.js +2 -2
- package/src/commands/api-mesh/__tests__/get-log-forwarding.test.js +149 -0
- package/src/commands/api-mesh/__tests__/get.test.js +2 -2
- package/src/commands/api-mesh/__tests__/log-get-bulk.test.js +2 -2
- package/src/commands/api-mesh/__tests__/log-get.test.js +2 -2
- package/src/commands/api-mesh/__tests__/log-list.test.js +2 -2
- package/src/commands/api-mesh/__tests__/run.test.js +67 -193
- package/src/commands/api-mesh/__tests__/set-log-forwarding.test.js +246 -0
- package/src/commands/api-mesh/__tests__/status.test.js +2 -2
- package/src/commands/api-mesh/__tests__/update.test.js +4 -6
- package/src/commands/api-mesh/cache/purge.js +1 -1
- package/src/commands/api-mesh/config/get/log-forwarding.js +78 -0
- package/src/commands/api-mesh/config/set/log-forwarding.js +156 -0
- package/src/commands/api-mesh/create.js +4 -3
- package/src/commands/api-mesh/delete.js +1 -1
- package/src/commands/api-mesh/describe.js +1 -1
- package/src/commands/api-mesh/get.js +1 -1
- package/src/commands/api-mesh/log-get-bulk.js +1 -1
- package/src/commands/api-mesh/log-get.js +1 -1
- package/src/commands/api-mesh/log-list.js +1 -1
- package/src/commands/api-mesh/run.js +162 -208
- package/src/commands/api-mesh/source/__tests__/install.test.js +2 -2
- package/src/commands/api-mesh/source/install.js +1 -1
- package/src/commands/api-mesh/status.js +1 -1
- package/src/commands/api-mesh/update.js +4 -3
- package/src/helpers.js +29 -20
- package/src/{worker.js → index.js} +7 -9
- package/src/lib/{devConsole.js → smsClient.js} +186 -1
- package/src/server.js +32 -74
- package/src/utils.js +46 -10
- package/src/wranglerServer.js +80 -0
- package/src/meshArtifact.js +0 -231
- package/src/project.js +0 -56
- package/src/wranglerCli.js +0 -54
- package/wrangler.toml +0 -13
|
@@ -13,7 +13,6 @@ const { Command } = require('@oclif/core');
|
|
|
13
13
|
const {
|
|
14
14
|
portNoFlag,
|
|
15
15
|
debugFlag,
|
|
16
|
-
inspectPortNoFlag,
|
|
17
16
|
selectFlag,
|
|
18
17
|
envFileFlag,
|
|
19
18
|
secretsFlag,
|
|
@@ -36,17 +35,10 @@ const {
|
|
|
36
35
|
writeSecretsFile,
|
|
37
36
|
} = require('../../helpers');
|
|
38
37
|
const logger = require('../../classes/logger');
|
|
39
|
-
const { getMeshId, getMeshArtifact } = require('../../lib/
|
|
38
|
+
const { getMeshId, getMeshArtifact } = require('../../lib/smsClient');
|
|
40
39
|
require('dotenv').config();
|
|
41
|
-
const {
|
|
42
|
-
const {
|
|
43
|
-
resolveOriginalSources,
|
|
44
|
-
copyBuiltMeshToPackage,
|
|
45
|
-
BUILT_MESH_ARTIFACT_DIRECTORY,
|
|
46
|
-
safeDelete,
|
|
47
|
-
getBuiltMeshTenantDirectory,
|
|
48
|
-
} = require('../../project');
|
|
49
|
-
const { resolveRelativeSources } = require('../../meshArtifact');
|
|
40
|
+
const { runServer } = require('../../server');
|
|
41
|
+
const { fixPlugins } = require('../../fixPlugins');
|
|
50
42
|
|
|
51
43
|
const { validateMesh, buildMesh, compileMesh } = meshBuilder.default;
|
|
52
44
|
|
|
@@ -63,7 +55,6 @@ class RunCommand extends Command {
|
|
|
63
55
|
|
|
64
56
|
static flags = {
|
|
65
57
|
port: portNoFlag,
|
|
66
|
-
inspectPort: inspectPortNoFlag,
|
|
67
58
|
debug: debugFlag,
|
|
68
59
|
env: envFileFlag,
|
|
69
60
|
autoConfirmAction: autoConfirmActionFlag,
|
|
@@ -75,219 +66,182 @@ class RunCommand extends Command {
|
|
|
75
66
|
|
|
76
67
|
static examples = [];
|
|
77
68
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
* @returns {Promise<void>}
|
|
81
|
-
* @throws {Error} when project is not set up correctly
|
|
82
|
-
*/
|
|
83
|
-
async validateCwd() {
|
|
84
|
-
//Ensure that current directory includes package.json
|
|
85
|
-
if (!fs.existsSync(path.join(process.cwd(), 'package.json'))) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
'`aio api-mesh run` cannot be executed because there is no package.json file in the current directory. Use `aio api-mesh init` to set up a package.',
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Handle remote mesh artifact
|
|
94
|
-
* @returns {Promise<string>} Mesh identifier
|
|
95
|
-
* @throws {Error} when failure retrieving remote mesh artifact
|
|
96
|
-
*/
|
|
97
|
-
async handleRemoteMeshArtifact() {
|
|
98
|
-
const { imsOrgCode, projectId, workspaceId, workspaceName } = await initSdk({});
|
|
99
|
-
|
|
100
|
-
// Get the mesh identifier for the workspace
|
|
101
|
-
let meshId;
|
|
102
|
-
try {
|
|
103
|
-
meshId = await getMeshId(imsOrgCode, projectId, workspaceId, workspaceName);
|
|
104
|
-
} catch (err) {
|
|
105
|
-
throw new Error(
|
|
106
|
-
`Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
await getMeshArtifact(imsOrgCode, projectId, workspaceId, workspaceName, meshId);
|
|
112
|
-
} catch (err) {
|
|
113
|
-
throw new Error(
|
|
114
|
-
`Unable to retrieve mesh. Please check the details and try again. RequestId: ${global.requestId}`,
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
try {
|
|
119
|
-
await setUpTenantFiles(meshId);
|
|
120
|
-
} catch (err) {
|
|
121
|
-
throw new Error('Failed to install downloaded mesh');
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Resolve relative sources in built mesh for local development
|
|
125
|
-
const builtMeshTenantDir = getBuiltMeshTenantDirectory(meshId);
|
|
126
|
-
await resolveRelativeSources(builtMeshTenantDir);
|
|
127
|
-
|
|
128
|
-
this.log('Successfully downloaded mesh');
|
|
129
|
-
|
|
130
|
-
return meshId;
|
|
131
|
-
}
|
|
69
|
+
async run() {
|
|
70
|
+
await initRequestId();
|
|
132
71
|
|
|
133
|
-
|
|
134
|
-
* Handle local mesh configuration
|
|
135
|
-
* @param args {unknown} Arguments
|
|
136
|
-
* @param flags {unknown} Flags
|
|
137
|
-
* @returns {Promise<string>}
|
|
138
|
-
* @throws {Error} when failure building local mesh artifact
|
|
139
|
-
*/
|
|
140
|
-
async handleLocalMeshConfig(args, flags) {
|
|
141
|
-
if (!args.file) {
|
|
142
|
-
throw new Error('Missing file path. Run aio api-mesh run --help for more info.');
|
|
143
|
-
}
|
|
72
|
+
logger.info(`RequestId: ${global.requestId}`);
|
|
144
73
|
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
//Read the mesh input file
|
|
148
|
-
let inputMeshData = await readFileContents(args.file, this, 'mesh');
|
|
149
|
-
let data;
|
|
150
|
-
|
|
151
|
-
// TODO: Should we check for secrets in use when no secrets file provided?
|
|
152
|
-
if (checkPlaceholders(inputMeshData)) {
|
|
153
|
-
this.log('The provided mesh contains placeholders. Starting mesh interpolation process.');
|
|
154
|
-
data = await validateAndInterpolateMesh(inputMeshData, envFilePath, this);
|
|
155
|
-
} else {
|
|
156
|
-
try {
|
|
157
|
-
data = JSON.parse(inputMeshData);
|
|
158
|
-
} catch (err) {
|
|
159
|
-
this.log(err.message);
|
|
160
|
-
throw new Error('Input mesh file is not a valid JSON. Please check the file provided.');
|
|
161
|
-
}
|
|
162
|
-
}
|
|
74
|
+
const { args, flags } = await this.parse(RunCommand);
|
|
75
|
+
const secretsFilePath = await flags.secrets;
|
|
163
76
|
|
|
164
|
-
|
|
77
|
+
//Initialize the meshId based on
|
|
78
|
+
let meshId = null;
|
|
165
79
|
|
|
166
80
|
try {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
81
|
+
//Ensure that current directory includes package.json
|
|
82
|
+
if (fs.existsSync(path.join(process.cwd(), 'package.json'))) {
|
|
83
|
+
//If select flag is present then getMeshId for the specified org
|
|
84
|
+
if (flags.select) {
|
|
85
|
+
const { imsOrgCode, projectId, workspaceId, workspaceName } = await initSdk({});
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
meshId = await getMeshId(imsOrgCode, projectId, workspaceId, workspaceName);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
throw new Error(
|
|
91
|
+
`Unable to get mesh ID. Please check the details and try again. RequestId: ${global.requestId}`,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
await getMeshArtifact(imsOrgCode, projectId, workspaceId, workspaceName, meshId);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Unable to retrieve mesh. Please check the details and try again. RequestId: ${global.requestId}`,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await setUpTenantFiles(meshId);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
throw new Error('Failed to install downloaded mesh');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.log('Successfully downloaded mesh');
|
|
110
|
+
} else {
|
|
111
|
+
if (!args.file) {
|
|
112
|
+
throw new Error('Missing file path. Run aio api-mesh run --help for more info.');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const envFilePath = await flags.env;
|
|
116
|
+
|
|
117
|
+
//Read the mesh input file
|
|
118
|
+
let inputMeshData = await readFileContents(args.file, this, 'mesh');
|
|
119
|
+
let data;
|
|
120
|
+
|
|
121
|
+
if (checkPlaceholders(inputMeshData)) {
|
|
122
|
+
this.log(
|
|
123
|
+
'The provided mesh contains placeholders. Starting mesh interpolation process.',
|
|
124
|
+
);
|
|
125
|
+
data = await validateAndInterpolateMesh(inputMeshData, envFilePath, this);
|
|
126
|
+
} else {
|
|
127
|
+
try {
|
|
128
|
+
data = JSON.parse(inputMeshData);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
this.log(err.message);
|
|
131
|
+
throw new Error(
|
|
132
|
+
'Input mesh file is not a valid JSON. Please check the file provided.',
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
let filesList = [];
|
|
138
|
+
|
|
139
|
+
try {
|
|
140
|
+
filesList = getFilesInMeshConfig(data, args.file);
|
|
141
|
+
} catch (err) {
|
|
142
|
+
this.log(err.message);
|
|
143
|
+
throw new Error('Input mesh config is not valid.');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// if local files are present, import them in files array in meshConfig
|
|
147
|
+
if (filesList.length) {
|
|
148
|
+
try {
|
|
149
|
+
// minification of js will not be done for run command if debugging is enabled
|
|
150
|
+
data = await importFiles(
|
|
151
|
+
data,
|
|
152
|
+
filesList,
|
|
153
|
+
args.file,
|
|
154
|
+
flags.autoConfirmAction,
|
|
155
|
+
!flags.debug,
|
|
156
|
+
);
|
|
157
|
+
} catch (err) {
|
|
158
|
+
this.log(err.message);
|
|
159
|
+
throw new Error(
|
|
160
|
+
'Unable to import the files in the mesh config. Please check the file and try again.',
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//Generating unique mesh id
|
|
166
|
+
meshId = 'testMesh';
|
|
167
|
+
|
|
168
|
+
await validateMesh(data.meshConfig);
|
|
169
|
+
await buildMesh(meshId, data.meshConfig);
|
|
170
|
+
await compileMesh(meshId);
|
|
171
|
+
}
|
|
172
|
+
let portNo;
|
|
173
|
+
//secrets management
|
|
174
|
+
if (secretsFilePath) {
|
|
175
|
+
try {
|
|
176
|
+
await validateSecretsFile(secretsFilePath);
|
|
177
|
+
const stringifiedSecrets = await interpolateSecrets(secretsFilePath, this);
|
|
178
|
+
await writeSecretsFile(stringifiedSecrets, meshId);
|
|
179
|
+
} catch (error) {
|
|
180
|
+
this.log(error.message);
|
|
181
|
+
this.error('Unable to import secrets. Please check the file and try again.');
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
await this.copyMeshContent(meshId);
|
|
186
|
+
|
|
187
|
+
//To set the port number using the environment file
|
|
188
|
+
if (process.env.PORT !== undefined) {
|
|
189
|
+
if (isNaN(process.env.PORT) || !Number.isInteger(parseInt(process.env.PORT))) {
|
|
190
|
+
throw new Error('PORT value in the .env file is not a valid integer');
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
portNo = process.env.PORT;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
//To set the port number as the provided value in the command
|
|
197
|
+
if (flags.port !== undefined) {
|
|
198
|
+
portNo = flags.port;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
//To set the default port to 5000
|
|
202
|
+
if (!portNo) {
|
|
203
|
+
portNo = 5000;
|
|
204
|
+
}
|
|
205
|
+
this.log(`Starting server on port : ${portNo}`);
|
|
206
|
+
await runServer(portNo);
|
|
207
|
+
this.log(`Server is running on http://localhost:${portNo}/graphql`);
|
|
208
|
+
} else {
|
|
187
209
|
throw new Error(
|
|
188
|
-
'
|
|
210
|
+
'`aio api-mesh run` cannot be executed because there is no package.json file in the current directory. Use `aio api-mesh init` to set up a package.',
|
|
189
211
|
);
|
|
190
212
|
}
|
|
213
|
+
} catch (error) {
|
|
214
|
+
this.error(error.message);
|
|
191
215
|
}
|
|
192
|
-
// Empty mesh-artifact directory
|
|
193
|
-
safeDelete(BUILT_MESH_ARTIFACT_DIRECTORY);
|
|
194
|
-
|
|
195
|
-
//Generating unique mesh id
|
|
196
|
-
const meshId = 'testMesh';
|
|
197
|
-
await validateMesh(data.meshConfig);
|
|
198
|
-
await buildMesh(meshId, data.meshConfig);
|
|
199
|
-
await compileMesh(meshId);
|
|
200
|
-
|
|
201
|
-
// Resolve relative sources in built mesh for local development
|
|
202
|
-
const builtMeshTenantDir = getBuiltMeshTenantDirectory(meshId);
|
|
203
|
-
await resolveRelativeSources(builtMeshTenantDir);
|
|
204
|
-
await resolveOriginalSources(builtMeshTenantDir, localFileOverrides);
|
|
205
|
-
|
|
206
|
-
return meshId;
|
|
207
216
|
}
|
|
208
217
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
'PORT value in the .env file is not a valid integer',
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
if (process.env.INSPECT_PORT !== undefined) {
|
|
217
|
-
flags.inspectPort = this.parseInt(
|
|
218
|
-
process.env.INSPECT_PORT,
|
|
219
|
-
'INSPECT_PORT value in the .env file is not a valid integer',
|
|
220
|
-
);
|
|
218
|
+
async copyMeshContent(meshId) {
|
|
219
|
+
// Remove mesh artifact directory if exists
|
|
220
|
+
if (fs.existsSync('.mesh')) {
|
|
221
|
+
fs.rmSync('.mesh', { recursive: true });
|
|
221
222
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
* @param errorMessage {string?} Optional error message when parsing fails
|
|
228
|
-
* @returns {number}
|
|
229
|
-
* @throws {Error} when value is not a valid integer
|
|
230
|
-
*/
|
|
231
|
-
parseInt(value, errorMessage) {
|
|
232
|
-
const int = parseInt(value);
|
|
233
|
-
if (isNaN(int) || !Number.isInteger(int)) {
|
|
234
|
-
throw new Error(errorMessage || `Value is not a valid integer`);
|
|
223
|
+
// Move built mesh artifact to expect directory
|
|
224
|
+
fs.renameSync(`mesh-artifact/${meshId}`, '.mesh');
|
|
225
|
+
// Remove tenant files directory if exists
|
|
226
|
+
if (fs.existsSync('tenantFiles')) {
|
|
227
|
+
fs.rmSync('tenantFiles', { recursive: true });
|
|
235
228
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
* @param secretsFilePath {string} File path to secrets
|
|
242
|
-
* @param meshId {string} Mesh identifier
|
|
243
|
-
* @returns {Promise<void>}
|
|
244
|
-
*/
|
|
245
|
-
async handleSecretsFeature(secretsFilePath, meshId) {
|
|
246
|
-
if (secretsFilePath) {
|
|
247
|
-
try {
|
|
248
|
-
await validateSecretsFile(secretsFilePath);
|
|
249
|
-
const stringifiedSecrets = await interpolateSecrets(secretsFilePath, this);
|
|
250
|
-
await writeSecretsFile(stringifiedSecrets, meshId);
|
|
251
|
-
} catch (error) {
|
|
252
|
-
this.log(error.message);
|
|
253
|
-
this.error('Unable to import secrets. Please check the file and try again.');
|
|
254
|
-
}
|
|
229
|
+
// Move built tenant files if exists
|
|
230
|
+
if (fs.existsSync('mesh-artifact/tenantFiles')) {
|
|
231
|
+
// Tenant files included in the bundle for runtime/dynamic imports
|
|
232
|
+
fs.cpSync('mesh-artifact/tenantFiles', '.mesh/tenantFiles', { recursive: true });
|
|
233
|
+
fs.renameSync('mesh-artifact/tenantFiles', 'tenantFiles');
|
|
255
234
|
}
|
|
256
|
-
}
|
|
257
235
|
|
|
258
|
-
|
|
259
|
-
try {
|
|
260
|
-
await initRequestId();
|
|
261
|
-
logger.info(`RequestId: ${global.requestId}`);
|
|
262
|
-
|
|
263
|
-
const { args, flags } = await this.parse(RunCommand);
|
|
264
|
-
await this.validateCwd();
|
|
265
|
-
this.updateFlagsFromEnv(flags);
|
|
266
|
-
|
|
267
|
-
// Use remote or local mesh artifact
|
|
268
|
-
let meshId;
|
|
269
|
-
if (flags.select) {
|
|
270
|
-
meshId = await this.handleRemoteMeshArtifact();
|
|
271
|
-
} else {
|
|
272
|
-
meshId = await this.handleLocalMeshConfig(args, flags);
|
|
273
|
-
}
|
|
236
|
+
await fixPlugins('.mesh/index.js');
|
|
274
237
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (secretsFilePath) {
|
|
278
|
-
await this.handleSecretsFeature(secretsFilePath, meshId);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const builtMeshTenantDir = getBuiltMeshTenantDirectory(meshId);
|
|
282
|
-
await copyBuiltMeshToPackage(builtMeshTenantDir);
|
|
283
|
-
|
|
284
|
-
start(this, flags.port, flags.debug, flags.inspectPort);
|
|
285
|
-
if (flags.debug) {
|
|
286
|
-
this.log(`Debugging enabled on inspect port: ${flags.inspectPort}`);
|
|
287
|
-
}
|
|
288
|
-
} catch (error) {
|
|
289
|
-
this.error(error.message);
|
|
238
|
+
if (fs.existsSync(`${__dirname}/../../../.mesh`)) {
|
|
239
|
+
fs.rmSync(`${__dirname}/../../../.mesh`, { recursive: true });
|
|
290
240
|
}
|
|
241
|
+
// At this time the bundle and build files must be copied out to the plugin directory
|
|
242
|
+
fs.cpSync('.mesh', `${__dirname}/../../../.mesh`, { recursive: true });
|
|
243
|
+
// Tenant files used at build time
|
|
244
|
+
fs.cpSync('tenantFiles', `${__dirname}/../../../tenantFiles`, { recursive: true });
|
|
291
245
|
}
|
|
292
246
|
}
|
|
293
247
|
|
|
@@ -20,13 +20,13 @@ const mockSources = { '0.0.1-test-03': mockSourceTest03v1Fixture };
|
|
|
20
20
|
jest.mock('source-registry-storage-adapter');
|
|
21
21
|
jest.mock('../../../../helpers');
|
|
22
22
|
const InstallCommand = require('../install');
|
|
23
|
-
const { getMeshId, getMesh, updateMesh } = require('../../../../lib/
|
|
23
|
+
const { getMeshId, getMesh, updateMesh } = require('../../../../lib/smsClient');
|
|
24
24
|
const mockGetMeshConfig = require('../../../__fixtures__/sample_mesh.json');
|
|
25
25
|
const selectedOrg = { id: '1234', code: 'CODE1234@AdobeOrg', name: 'ORG01', type: 'entp' };
|
|
26
26
|
const selectedProject = { id: '5678', title: 'Project01' };
|
|
27
27
|
const selectedWorkspace = { id: '123456789', title: 'Workspace01' };
|
|
28
28
|
global.requestId = 'dummy_request_id';
|
|
29
|
-
jest.mock('../../../../lib/
|
|
29
|
+
jest.mock('../../../../lib/smsClient');
|
|
30
30
|
mockAdapter.mockImplementation(() => ({
|
|
31
31
|
get: jest.fn().mockResolvedValue(mockSources[`0.0.1-test-03`]),
|
|
32
32
|
getList: jest.fn().mockImplementation(() => mockMetadataFixture),
|
|
@@ -18,7 +18,7 @@ const config = require('@adobe/aio-lib-core-config');
|
|
|
18
18
|
const logger = require('../../../classes/logger');
|
|
19
19
|
const { readFile } = require('fs/promises');
|
|
20
20
|
const chalk = require('chalk');
|
|
21
|
-
const { getMeshId, getMesh, updateMesh } = require('../../../lib/
|
|
21
|
+
const { getMeshId, getMesh, updateMesh } = require('../../../lib/smsClient');
|
|
22
22
|
const JsonInterpolate = require('json-interpolate');
|
|
23
23
|
|
|
24
24
|
class InstallCommand extends Command {
|
|
@@ -2,7 +2,7 @@ const { Command } = require('@oclif/core');
|
|
|
2
2
|
|
|
3
3
|
const logger = require('../../classes/logger');
|
|
4
4
|
const { initRequestId, initSdk } = require('../../helpers');
|
|
5
|
-
const { getMeshId, getMesh, getMeshDeployments } = require('../../lib/
|
|
5
|
+
const { getMeshId, getMesh, getMeshDeployments } = require('../../lib/smsClient');
|
|
6
6
|
const { ignoreCacheFlag } = require('../../utils');
|
|
7
7
|
|
|
8
8
|
require('dotenv').config();
|
|
@@ -26,7 +26,7 @@ const {
|
|
|
26
26
|
validateSecretsFile,
|
|
27
27
|
encryptSecrets,
|
|
28
28
|
} = require('../../utils');
|
|
29
|
-
const { getMeshId, updateMesh, getPublicEncryptionKey } = require('../../lib/
|
|
29
|
+
const { getMeshId, updateMesh, getPublicEncryptionKey } = require('../../lib/smsClient');
|
|
30
30
|
|
|
31
31
|
class UpdateCommand extends Command {
|
|
32
32
|
static args = [{ name: 'file' }];
|
|
@@ -106,7 +106,7 @@ class UpdateCommand extends Command {
|
|
|
106
106
|
// if local files are present, import them in files array in meshConfig
|
|
107
107
|
if (filesList.length) {
|
|
108
108
|
try {
|
|
109
|
-
|
|
109
|
+
data = await importFiles(data, filesList, args.file, flags.autoConfirmAction);
|
|
110
110
|
} catch (err) {
|
|
111
111
|
this.log(err.message);
|
|
112
112
|
this.error('Unable to import the files in the mesh config. Check the file and try again.');
|
|
@@ -119,7 +119,8 @@ class UpdateCommand extends Command {
|
|
|
119
119
|
await validateSecretsFile(secretsFilePath);
|
|
120
120
|
const secretsData = await interpolateSecrets(secretsFilePath, this);
|
|
121
121
|
const publicKey = await getPublicEncryptionKey(imsOrgCode);
|
|
122
|
-
|
|
122
|
+
const encryptedSecrets = await encryptSecrets(publicKey, secretsData);
|
|
123
|
+
data.secrets = encryptedSecrets;
|
|
123
124
|
} catch (err) {
|
|
124
125
|
this.log(err.message);
|
|
125
126
|
this.error('Unable to import secrets. Check the file and try again.');
|
package/src/helpers.js
CHANGED
|
@@ -445,7 +445,7 @@ async function initRequestId() {
|
|
|
445
445
|
* Function to run the CLI Y/N prompt to confirm the user's action
|
|
446
446
|
*
|
|
447
447
|
* @param {string} message
|
|
448
|
-
* @returns
|
|
448
|
+
* @returns boolean
|
|
449
449
|
*/
|
|
450
450
|
async function promptConfirm(message) {
|
|
451
451
|
const prompt = inquirer.createPromptModule({ output: process.stderr });
|
|
@@ -505,6 +505,7 @@ async function promptSelect(message, choices) {
|
|
|
505
505
|
* Function to run the CLI selectable list
|
|
506
506
|
*
|
|
507
507
|
* @param {string} message - prompt message
|
|
508
|
+
* @param {object[]} choices - list of options
|
|
508
509
|
* @returns {object[]} - selected options
|
|
509
510
|
*/
|
|
510
511
|
async function promptInput(message) {
|
|
@@ -519,15 +520,31 @@ async function promptInput(message) {
|
|
|
519
520
|
return selected.item;
|
|
520
521
|
}
|
|
521
522
|
|
|
523
|
+
/**
|
|
524
|
+
* Function to prompt for a secret/password input that masks the characters
|
|
525
|
+
*
|
|
526
|
+
* @param {string} message - prompt message
|
|
527
|
+
* @returns {Promise<string>} - the entered secret value
|
|
528
|
+
*/
|
|
529
|
+
async function promptInputSecret(message) {
|
|
530
|
+
const selected = await inquirer.prompt([
|
|
531
|
+
{
|
|
532
|
+
name: 'item',
|
|
533
|
+
message,
|
|
534
|
+
type: 'password',
|
|
535
|
+
},
|
|
536
|
+
]);
|
|
537
|
+
|
|
538
|
+
return selected.item;
|
|
539
|
+
}
|
|
540
|
+
|
|
522
541
|
/**
|
|
523
542
|
* Import the files in the files array in meshConfig
|
|
524
543
|
*
|
|
525
544
|
* @param data MeshConfig
|
|
526
|
-
* @param
|
|
545
|
+
* @param filesList List of files in meshConfig
|
|
527
546
|
* @param meshConfigName MeshConfigName
|
|
528
547
|
* @param autoConfirmActionFlag The user won't be prompted any questions, if this flag is set
|
|
529
|
-
* @param shouldMinifyJS
|
|
530
|
-
* @returns Promise<{{ data, localFileOverrides: string[] }}>
|
|
531
548
|
*/
|
|
532
549
|
async function importFiles(
|
|
533
550
|
data,
|
|
@@ -590,38 +607,29 @@ async function importFiles(
|
|
|
590
607
|
);
|
|
591
608
|
}
|
|
592
609
|
|
|
593
|
-
// Result of override resolution
|
|
594
|
-
const localFileOverrides = {};
|
|
595
610
|
for (let i = 0; i < overrideArr.length; i++) {
|
|
596
|
-
const fileName = overrideArr[i].fileName;
|
|
597
611
|
shouldOverride = await promptConfirm(
|
|
598
|
-
`Do you want to override the ${path.basename(fileName)} file?`,
|
|
612
|
+
`Do you want to override the ${path.basename(overrideArr[i].fileName)} file?`,
|
|
599
613
|
);
|
|
600
614
|
|
|
601
615
|
if (shouldOverride) {
|
|
602
616
|
resultData = updateFilesArray(
|
|
603
617
|
resultData,
|
|
604
|
-
fileName,
|
|
618
|
+
overrideArr[i].fileName,
|
|
605
619
|
meshConfigName,
|
|
606
620
|
overrideArr[i].index,
|
|
607
621
|
shouldMinifyJS,
|
|
608
622
|
);
|
|
609
|
-
localFileOverrides[fileName] = true;
|
|
610
|
-
} else {
|
|
611
|
-
localFileOverrides[fileName] = false;
|
|
612
623
|
}
|
|
613
624
|
}
|
|
614
625
|
|
|
615
|
-
return
|
|
616
|
-
data: resultData,
|
|
617
|
-
localFileOverrides,
|
|
618
|
-
};
|
|
626
|
+
return resultData;
|
|
619
627
|
}
|
|
620
628
|
|
|
621
629
|
/**loads the pupa module dynamically and then interpolates the raw data from mesh file with object data
|
|
622
|
-
* @param data
|
|
623
|
-
* @param obj
|
|
624
|
-
* @returns {object}
|
|
630
|
+
* @param {data}
|
|
631
|
+
* @param {obj}
|
|
632
|
+
* @returns {object} having interpolationStatus, missingKeys and interpolatedMesh
|
|
625
633
|
*/
|
|
626
634
|
|
|
627
635
|
async function interpolateMesh(data, obj) {
|
|
@@ -855,7 +863,7 @@ async function processFileConfig(config) {
|
|
|
855
863
|
* This function sets up the tenantFiles used in a particular mesh config
|
|
856
864
|
* into the tenantFiles folder
|
|
857
865
|
*
|
|
858
|
-
* @param
|
|
866
|
+
* @param config
|
|
859
867
|
*/
|
|
860
868
|
async function setUpTenantFiles(meshId) {
|
|
861
869
|
if (fs.existsSync(path.resolve(process.cwd(), 'mesh-artifact', meshId, 'files.json'))) {
|
|
@@ -959,6 +967,7 @@ module.exports = {
|
|
|
959
967
|
objToString,
|
|
960
968
|
promptInput,
|
|
961
969
|
promptConfirm,
|
|
970
|
+
promptInputSecret,
|
|
962
971
|
getLibConsoleCLI,
|
|
963
972
|
getDevConsoleConfig,
|
|
964
973
|
initSdk,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ServedTier, addServedHeader } from './served';
|
|
2
|
-
import { buildServer } from './server';
|
|
3
2
|
import { bindedlogger as logger } from './utils/logger';
|
|
4
3
|
import { getRequestId } from './utils/requestId';
|
|
4
|
+
import { buildServer } from './wranglerServer';
|
|
5
5
|
|
|
6
6
|
let server;
|
|
7
7
|
|
|
@@ -21,10 +21,10 @@ export default {
|
|
|
21
21
|
const { MESH_ID: meshId, LOG_LEVEL: logLevel } = env;
|
|
22
22
|
const loggerInstance = logger({ logLevel, meshId, requestId });
|
|
23
23
|
const meshArtifacts = await import('../.mesh');
|
|
24
|
-
const
|
|
24
|
+
const rawMesh = await import('../.mesh/.meshrc.json');
|
|
25
25
|
|
|
26
26
|
if (!server) {
|
|
27
|
-
server = await this.buildAndCacheServer(env, loggerInstance, meshArtifacts,
|
|
27
|
+
server = await this.buildAndCacheServer(env, loggerInstance, meshArtifacts, rawMesh);
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
loggerInstance.debug('WORKER HOT: Fetching via worker');
|
|
@@ -34,13 +34,11 @@ export default {
|
|
|
34
34
|
},
|
|
35
35
|
/**
|
|
36
36
|
* Build and cache mesh instance/server in global variable.
|
|
37
|
-
* @param env
|
|
38
|
-
* @param
|
|
39
|
-
* @param meshArtifacts Mesh artifact
|
|
40
|
-
* @param meshConfig Mesh config
|
|
37
|
+
* @param env
|
|
38
|
+
* @param loggerInstance
|
|
41
39
|
*/
|
|
42
|
-
async buildAndCacheServer(env,
|
|
43
|
-
server = await buildServer(
|
|
40
|
+
async buildAndCacheServer(env, loggerInstance, meshArtifacts, meshConfig) {
|
|
41
|
+
server = await buildServer(loggerInstance, env, meshArtifacts, meshConfig);
|
|
44
42
|
return server;
|
|
45
43
|
},
|
|
46
44
|
};
|