@fishawack/lab-env 5.9.0-beta.4 → 5.9.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/cli.js CHANGED
@@ -174,6 +174,7 @@ const args = hideBin(process.argv);
174
174
  "prune",
175
175
  "sync-secrets",
176
176
  "server-status",
177
+ "force-managed-updates",
177
178
  ].forEach((d) =>
178
179
  cli.command(...require(`./commands/create/cmds/${d}.js`)),
179
180
  );
@@ -0,0 +1,689 @@
1
+ const _ = require("../../../globals.js");
2
+ const inquirer = require("inquirer");
3
+ const eb = require("../services/aws/elasticbeanstalk.js");
4
+ const { setAWSClientDefaults } = require("../services/aws/misc.js");
5
+ const { colorize, Spinner } = require("../libs/utilities");
6
+ const { client, region } = require("../libs/prompts.js");
7
+ const semver = require("semver");
8
+
9
+ async function resolveScope(argv, key, choices) {
10
+ if (argv[key]) return [argv[key]];
11
+ if (argv.all) return choices;
12
+
13
+ const { all } = await inquirer.prompt([
14
+ {
15
+ type: "confirm",
16
+ name: "all",
17
+ message: `Scan all ${key}s?`,
18
+ default: true,
19
+ },
20
+ ]);
21
+ if (all) return choices;
22
+
23
+ const { selected } = await inquirer.prompt([
24
+ {
25
+ type: "checkbox",
26
+ name: "selected",
27
+ message: `Which ${key}s would you like to scan?`,
28
+ choices,
29
+ validate: (input) =>
30
+ input.length > 0 || `Select at least one ${key}`,
31
+ },
32
+ ]);
33
+ return selected;
34
+ }
35
+
36
+ function label(target) {
37
+ return `${target.client} / ${target.region} / ${target.environment.EnvironmentName}`;
38
+ }
39
+
40
+ function isActive(action) {
41
+ return ["Pending", "Running", "Unknown"].includes(action.Status);
42
+ }
43
+
44
+ function scanStatus(actions, platform) {
45
+ const branchState = platform?.PlatformBranchLifecycleState?.toLowerCase();
46
+ const scheduled = actions.some(
47
+ (action) =>
48
+ action.ActionType === "PlatformUpdate" &&
49
+ action.Status === "Scheduled",
50
+ );
51
+ const updates = scheduled
52
+ ? "scheduled platform update available"
53
+ : "no scheduled platform updates";
54
+ if (branchState === "retired")
55
+ return colorize(
56
+ `Retired platform branch; migration required - ${updates}`,
57
+ "error",
58
+ );
59
+ if (branchState === "deprecated")
60
+ return colorize(
61
+ `Deprecated platform branch; migration recommended - ${updates}`,
62
+ "warning",
63
+ );
64
+ if (actions.some(isActive))
65
+ return colorize(
66
+ `Managed action in progress or status unknown - ${updates}`,
67
+ "info",
68
+ );
69
+ if (scheduled)
70
+ return colorize("Scheduled platform update available", "warning");
71
+ if (
72
+ branchState === "supported" &&
73
+ platform.PlatformStatus === "Ready" &&
74
+ platform.PlatformLifecycleState?.toLowerCase() === "recommended"
75
+ ) {
76
+ return colorize(
77
+ "Up to date (AWS recommended platform for this branch); no scheduled platform updates",
78
+ "success",
79
+ );
80
+ }
81
+ if (branchState === "supported" && platform.PlatformStatus === "Ready") {
82
+ return colorize(
83
+ "Not on AWS recommended platform version; no scheduled platform updates",
84
+ "warning",
85
+ );
86
+ }
87
+ return colorize(
88
+ `No scheduled platform updates; platform currency unverified${branchState ? ` (branch: ${branchState})` : ""}`,
89
+ "warning",
90
+ );
91
+ }
92
+
93
+ function matchesPlatform(platformName, filter) {
94
+ if (!filter) return true;
95
+ const phrase = filter
96
+ .trim()
97
+ .replace(/\s+/g, " ")
98
+ .replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
99
+ return new RegExp(`(^|[^a-z0-9_.])${phrase}(?=$|[^a-z0-9_.])`, "i").test(
100
+ platformName.replace(/\s+/g, " "),
101
+ );
102
+ }
103
+
104
+ function newerPlatforms(current, versions) {
105
+ if (
106
+ current?.PlatformBranchLifecycleState?.toLowerCase() !== "supported" ||
107
+ !semver.valid(current.PlatformVersion)
108
+ )
109
+ return {};
110
+ const newer = versions
111
+ .filter(
112
+ (version) =>
113
+ version.PlatformArn &&
114
+ version.PlatformBranchName === current.PlatformBranchName &&
115
+ version.PlatformStatus === "Ready" &&
116
+ version.PlatformBranchLifecycleState?.toLowerCase() ===
117
+ "supported" &&
118
+ (!current.PlatformOwner ||
119
+ version.PlatformOwner === current.PlatformOwner) &&
120
+ semver.valid(version.PlatformVersion) &&
121
+ !semver.prerelease(version.PlatformVersion) &&
122
+ semver.gt(version.PlatformVersion, current.PlatformVersion),
123
+ )
124
+ .sort((first, second) =>
125
+ semver.rcompare(first.PlatformVersion, second.PlatformVersion),
126
+ );
127
+ return {
128
+ patch: newer.find(
129
+ (version) =>
130
+ semver.major(version.PlatformVersion) ===
131
+ semver.major(current.PlatformVersion) &&
132
+ semver.minor(version.PlatformVersion) ===
133
+ semver.minor(current.PlatformVersion),
134
+ ),
135
+ risky: newer.find(
136
+ (version) =>
137
+ semver.major(version.PlatformVersion) !==
138
+ semver.major(current.PlatformVersion) ||
139
+ semver.minor(version.PlatformVersion) !==
140
+ semver.minor(current.PlatformVersion),
141
+ ),
142
+ };
143
+ }
144
+
145
+ async function scan(clients, regions, filter) {
146
+ const targets = [];
147
+ const report = [];
148
+ for (const clientName of clients) {
149
+ for (const regionName of regions) {
150
+ setAWSClientDefaults(clientName, regionName);
151
+ const spinner = new Spinner(
152
+ `Scanning ${clientName} / ${regionName}`,
153
+ true,
154
+ );
155
+ const platforms = new Map();
156
+ const branches = new Map();
157
+ let matched = 0;
158
+ try {
159
+ const environments = await eb.listAccountEnvironments();
160
+ for (const environment of environments) {
161
+ spinner.ora.text = `Scanning ${clientName} / ${regionName} / ${environment.EnvironmentName}`;
162
+ if (
163
+ filter &&
164
+ environment.SolutionStackName &&
165
+ !matchesPlatform(environment.SolutionStackName, filter)
166
+ )
167
+ continue;
168
+ const target = {
169
+ client: clientName,
170
+ region: regionName,
171
+ environment,
172
+ };
173
+ try {
174
+ let platformInfo = {
175
+ platform: null,
176
+ detail: "Platform ARN unavailable; support status unverified",
177
+ };
178
+ if (environment.PlatformArn) {
179
+ if (!platforms.has(environment.PlatformArn)) {
180
+ try {
181
+ platforms.set(environment.PlatformArn, {
182
+ platform:
183
+ await eb.describePlatformVersion(
184
+ environment.PlatformArn,
185
+ ),
186
+ });
187
+ } catch (error) {
188
+ platforms.set(environment.PlatformArn, {
189
+ platform: null,
190
+ detail: `Platform lookup failed: ${error.message}`,
191
+ });
192
+ process.exitCode = 1;
193
+ }
194
+ }
195
+ platformInfo = platforms.get(
196
+ environment.PlatformArn,
197
+ );
198
+ }
199
+ const platformName =
200
+ platformInfo.platform?.SolutionStackName ||
201
+ environment.SolutionStackName ||
202
+ environment.PlatformArn;
203
+ if (
204
+ !matchesPlatform(
205
+ platformInfo.platform?.SolutionStackName ||
206
+ environment.SolutionStackName ||
207
+ "",
208
+ filter,
209
+ )
210
+ )
211
+ continue;
212
+ matched++;
213
+ const actions = await eb.getManagedActions(
214
+ environment.EnvironmentId,
215
+ );
216
+ const current = platformInfo.platform;
217
+ const scheduled = actions.some(
218
+ (action) =>
219
+ action.ActionType === "PlatformUpdate" &&
220
+ action.Status === "Scheduled",
221
+ );
222
+ let available = {};
223
+ let discoveryError;
224
+ if (
225
+ !scheduled &&
226
+ !actions.some(isActive) &&
227
+ current?.PlatformBranchLifecycleState?.toLowerCase() ===
228
+ "supported" &&
229
+ current.PlatformBranchName &&
230
+ semver.valid(current.PlatformVersion)
231
+ ) {
232
+ if (!branches.has(current.PlatformBranchName)) {
233
+ try {
234
+ branches.set(current.PlatformBranchName, {
235
+ versions:
236
+ await eb.listBranchPlatformVersions(
237
+ current.PlatformBranchName,
238
+ ),
239
+ });
240
+ } catch (error) {
241
+ branches.set(current.PlatformBranchName, {
242
+ error: `Available version lookup failed: ${error.message}`,
243
+ });
244
+ process.exitCode = 1;
245
+ }
246
+ }
247
+ const branch = branches.get(
248
+ current.PlatformBranchName,
249
+ );
250
+ discoveryError = branch.error;
251
+ available = newerPlatforms(
252
+ current,
253
+ branch.versions || [],
254
+ );
255
+ }
256
+ const status = available.patch
257
+ ? colorize(
258
+ `Direct patch available: ${current.PlatformVersion} -> ${available.patch.PlatformVersion} (uses configured update policy)`,
259
+ "warning",
260
+ )
261
+ : scanStatus(actions, current);
262
+ const risky = available.risky
263
+ ? `\n ${colorize(`Higher-risk minor/major update: ${current.PlatformVersion} -> ${available.risky.PlatformVersion} (report only; review manually)`, "error")}`
264
+ : "";
265
+ report.push(
266
+ `${colorize(environment.ApplicationName, "info")}\n ${label(target)}\n ${status}${platformName ? `\n ${platformName}` : ""}${risky}${platformInfo.detail ? `\n ${colorize(platformInfo.detail, platformInfo.detail.startsWith("Platform lookup failed:") ? "error" : "warning")}` : ""}${discoveryError ? `\n ${colorize(discoveryError, "error")}` : ""}`,
267
+ );
268
+ if (available.patch) {
269
+ targets.push({
270
+ ...target,
271
+ platform: available.patch,
272
+ action: {
273
+ ActionDescription: `Direct patch update ${current.PlatformVersion} -> ${available.patch.PlatformVersion} (${current.PlatformBranchName})`,
274
+ },
275
+ });
276
+ }
277
+ for (const action of actions) {
278
+ if (
279
+ action.ActionType === "PlatformUpdate" &&
280
+ action.Status === "Scheduled"
281
+ ) {
282
+ targets.push({ ...target, action });
283
+ }
284
+ }
285
+ } catch (error) {
286
+ report.push(
287
+ `${colorize(environment.ApplicationName, "info")}\n ${label(target)}\n ${colorize(`Update status unverified: ${error.message}`, "error")}`,
288
+ );
289
+ spinner.ora.stop();
290
+ console.log(
291
+ colorize(
292
+ `Could not scan ${environment.EnvironmentName}: ${error.message}`,
293
+ "error",
294
+ ),
295
+ );
296
+ process.exitCode = 1;
297
+ }
298
+ }
299
+ spinner.ora.succeed(
300
+ `Scanned ${clientName} / ${regionName}: ${environments.length} environments${filter ? ` (${matched} matching "${filter}")` : ""}`,
301
+ );
302
+ } catch (error) {
303
+ spinner.ora.fail(
304
+ `Could not scan ${clientName} / ${regionName}: ${error.message}`,
305
+ );
306
+ process.exitCode = 1;
307
+ }
308
+ }
309
+ }
310
+ if (report.length) {
311
+ console.log(`\n${colorize("Environment scan report:", "title")}`);
312
+ console.log(
313
+ ` ${colorize("Up to date", "success")} | ${colorize("Update available / warning", "warning")} | ${colorize("Retired / error / higher risk", "error")} | ${colorize("In progress / unknown", "info")}\n`,
314
+ );
315
+ report.forEach((entry) => console.log(` ${entry}\n`));
316
+ console.log("");
317
+ }
318
+ return targets;
319
+ }
320
+
321
+ async function preflight(target) {
322
+ const environments = await eb.listAccountEnvironments();
323
+ let selectedAction;
324
+ let selectedEnvironment;
325
+ let selectedActions;
326
+ for (const environment of environments) {
327
+ const actions = await eb.getManagedActions(environment.EnvironmentId);
328
+ if (
329
+ ["Updating", "Aborting", "Launching"].includes(environment.Status)
330
+ ) {
331
+ return `Environment ${environment.EnvironmentName} is ${environment.Status} in this account/region`;
332
+ }
333
+ if (actions.some(isActive)) {
334
+ return "An existing managed action is in progress or has unknown status in this account/region";
335
+ }
336
+ if (environment.EnvironmentId === target.environment.EnvironmentId) {
337
+ selectedEnvironment = environment;
338
+ selectedActions = actions;
339
+ selectedAction = actions.find(
340
+ (action) => action.ActionId === target.action.ActionId,
341
+ );
342
+ }
343
+ }
344
+ if (!selectedEnvironment) return "Environment no longer exists";
345
+ if (selectedEnvironment.Status !== "Ready")
346
+ return `Environment is ${selectedEnvironment.Status}, not Ready`;
347
+ if (target.platform) {
348
+ if (selectedEnvironment.PlatformArn !== target.environment.PlatformArn)
349
+ return "Current platform changed since scanning; scan again";
350
+ if (
351
+ selectedActions.some(
352
+ (action) =>
353
+ action.ActionType === "PlatformUpdate" &&
354
+ action.Status === "Scheduled",
355
+ )
356
+ )
357
+ return "A managed platform update is now scheduled; scan again";
358
+ const current = await eb.describePlatformVersion(
359
+ selectedEnvironment.PlatformArn,
360
+ );
361
+ const destination = await eb.describePlatformVersion(
362
+ target.platform.PlatformArn,
363
+ );
364
+ if (
365
+ !current ||
366
+ !destination ||
367
+ newerPlatforms(current, [destination]).patch?.PlatformArn !==
368
+ target.platform.PlatformArn
369
+ ) {
370
+ return "Selected destination is no longer a verified same-branch patch-only update";
371
+ }
372
+ return null;
373
+ }
374
+ if (
375
+ selectedAction?.Status !== "Scheduled" ||
376
+ selectedAction.ActionType !== "PlatformUpdate"
377
+ ) {
378
+ return "Selected platform update is no longer scheduled";
379
+ }
380
+ return null;
381
+ }
382
+
383
+ async function monitor(target, spinner, timeout, interrupted, position) {
384
+ const started = Date.now();
385
+ while (Date.now() - started < timeout * 60000) {
386
+ if (interrupted()) throw new Error("Interrupted by operator");
387
+ const history = await eb.getManagedActionHistory(
388
+ target.environment.EnvironmentId,
389
+ target.action.ActionId,
390
+ );
391
+ if (history && ["Completed", "Failed"].includes(history.Status))
392
+ return history;
393
+ const actions = await eb.getManagedActions(
394
+ target.environment.EnvironmentId,
395
+ );
396
+ const action = actions.find(
397
+ (item) => item.ActionId === target.action.ActionId,
398
+ );
399
+ const status =
400
+ history?.Status === "Unknown" || action?.Status === "Unknown"
401
+ ? "AWS status unknown; awaiting confirmation"
402
+ : action?.Status || "awaiting action history";
403
+ spinner.ora.text = `${position} ${label(target)} - ${status} - ${Math.floor((Date.now() - started) / 1000)}s elapsed`;
404
+ await new Promise((resolve) => setTimeout(resolve, 15000));
405
+ }
406
+ throw new Error(`Monitoring timed out after ${timeout} minutes`);
407
+ }
408
+
409
+ async function monitorPlatformUpdate(
410
+ target,
411
+ spinner,
412
+ timeout,
413
+ interrupted,
414
+ position,
415
+ started,
416
+ ) {
417
+ const monitoringStarted = Date.now();
418
+ while (Date.now() - monitoringStarted < timeout * 60000) {
419
+ if (interrupted()) throw new Error("Interrupted by operator");
420
+ const response = await eb.describeEnvironment(
421
+ target.environment.EnvironmentName,
422
+ );
423
+ const environment = response.Environments?.find(
424
+ (item) => item.EnvironmentId === target.environment.EnvironmentId,
425
+ );
426
+ if (
427
+ !environment ||
428
+ ["Terminated", "Terminating"].includes(environment.Status)
429
+ )
430
+ throw new Error(
431
+ "Environment disappeared or is terminating during platform update",
432
+ );
433
+ const events = await eb.getEnvironmentUpdateEvents(
434
+ environment.EnvironmentId,
435
+ started,
436
+ );
437
+ const completed = events.some((event) =>
438
+ /environment update completed successfully/i.test(
439
+ event.Message || "",
440
+ ),
441
+ );
442
+ const errors = events.filter((event) => event.Severity === "ERROR");
443
+ if (
444
+ environment.Status === "Ready" &&
445
+ !environment.AbortableOperationInProgress
446
+ ) {
447
+ if (
448
+ completed &&
449
+ environment.PlatformArn === target.platform.PlatformArn
450
+ )
451
+ return { Status: "Completed" };
452
+ if (
453
+ completed &&
454
+ environment.PlatformArn !== target.platform.PlatformArn
455
+ ) {
456
+ return {
457
+ Status: "Failed",
458
+ FailureDescription:
459
+ "Environment update finished without retaining the selected platform (possibly rolled back)",
460
+ };
461
+ }
462
+ if (
463
+ errors.length &&
464
+ environment.DateUpdated &&
465
+ new Date(environment.DateUpdated) > started
466
+ ) {
467
+ return {
468
+ Status: "Failed",
469
+ FailureDescription: errors
470
+ .map((event) => event.Message)
471
+ .join("; "),
472
+ };
473
+ }
474
+ }
475
+ spinner.ora.text = `${position} ${label(target)} - direct patch update: ${environment.Status}; awaiting completion event - ${Math.floor((Date.now() - monitoringStarted) / 1000)}s elapsed`;
476
+ await new Promise((resolve) => setTimeout(resolve, 15000));
477
+ }
478
+ throw new Error(
479
+ `Monitoring timed out after ${timeout} minutes; direct platform update outcome is unconfirmed`,
480
+ );
481
+ }
482
+
483
+ function updateReference(target) {
484
+ return target.platform
485
+ ? `platform ${target.platform.PlatformArn}`
486
+ : `action ${target.action.ActionId}`;
487
+ }
488
+
489
+ async function runQueue(selected, timeout) {
490
+ const results = selected.map((target) => ({
491
+ target,
492
+ status: "Not started",
493
+ }));
494
+ let interrupted = false;
495
+ let activeTarget;
496
+ const onInterrupt = () => {
497
+ interrupted = true;
498
+ console.log(
499
+ `\nStopping the queue. AWS updates are not cancelled.${activeTarget ? ` Check ${label(activeTarget)} (${updateReference(activeTarget)}) in AWS.` : ""}`,
500
+ );
501
+ };
502
+ process.on("SIGINT", onInterrupt);
503
+ try {
504
+ for (const [index, entry] of results.entries()) {
505
+ if (interrupted) break;
506
+ const { target } = entry;
507
+ setAWSClientDefaults(target.client, target.region);
508
+ const spinner = new Spinner(
509
+ `[${index + 1}/${results.length}] Checking ${label(target)}`,
510
+ true,
511
+ );
512
+ try {
513
+ const reason = await preflight(target);
514
+ if (interrupted) break;
515
+ if (reason) {
516
+ entry.status = "Skipped";
517
+ entry.detail = reason;
518
+ spinner.ora.warn(`${label(target)}: ${reason}`);
519
+ continue;
520
+ }
521
+ activeTarget = target;
522
+ entry.status = "Uncertain";
523
+ let history;
524
+ if (target.platform) {
525
+ const requested = new Date(Date.now());
526
+ const response = await eb.updateEnvironmentPlatform(
527
+ target.environment.EnvironmentId,
528
+ target.platform.PlatformArn,
529
+ );
530
+ history = await monitorPlatformUpdate(
531
+ target,
532
+ spinner,
533
+ timeout,
534
+ () => interrupted,
535
+ `[${index + 1}/${results.length}]`,
536
+ response.DateUpdated
537
+ ? new Date(response.DateUpdated)
538
+ : requested,
539
+ );
540
+ } else {
541
+ await eb.applyManagedAction(
542
+ target.environment.EnvironmentId,
543
+ target.action.ActionId,
544
+ );
545
+ history = await monitor(
546
+ target,
547
+ spinner,
548
+ timeout,
549
+ () => interrupted,
550
+ `[${index + 1}/${results.length}]`,
551
+ );
552
+ }
553
+ entry.status = history.Status;
554
+ entry.detail = [history.FailureType, history.FailureDescription]
555
+ .filter(Boolean)
556
+ .join(": ");
557
+ if (history.Status === "Failed") {
558
+ spinner.ora.fail(
559
+ `${label(target)}: ${entry.detail || "Update failed"}`,
560
+ );
561
+ process.exitCode = 1;
562
+ } else {
563
+ spinner.ora.succeed(`${label(target)}: update completed`);
564
+ }
565
+ activeTarget = null;
566
+ } catch (error) {
567
+ entry.status = activeTarget ? "Uncertain" : "Not started";
568
+ entry.detail = error.message;
569
+ spinner.ora.fail(`${label(target)}: ${error.message}`);
570
+ if (activeTarget) {
571
+ console.log(
572
+ `AWS may still be applying ${updateReference(target)}. No further updates will be started; check its status in AWS.`,
573
+ );
574
+ }
575
+ process.exitCode = 1;
576
+ break;
577
+ } finally {
578
+ spinner.ora.stop();
579
+ }
580
+ }
581
+ } finally {
582
+ process.removeListener("SIGINT", onInterrupt);
583
+ if (interrupted) process.exitCode = 130;
584
+ console.log("\nPlatform update summary:");
585
+ for (const entry of results) {
586
+ console.log(
587
+ ` ${entry.status}: ${label(entry.target)}${entry.detail ? ` - ${entry.detail}` : ""}`,
588
+ );
589
+ }
590
+ }
591
+ }
592
+
593
+ module.exports = [
594
+ ["force-managed-updates", "fmu"],
595
+ _.config.preset === "devops"
596
+ ? "Scan and apply managed or patch-only Elastic Beanstalk platform updates"
597
+ : false,
598
+ (yargs) => {
599
+ yargs.option("all", {
600
+ alias: "a",
601
+ describe:
602
+ "Scan all clients and regions (still prompts before applying)",
603
+ type: "boolean",
604
+ default: false,
605
+ });
606
+ yargs.option("client", {
607
+ alias: "c",
608
+ describe: "AWS account to scan",
609
+ type: "string",
610
+ });
611
+ yargs.option("region", {
612
+ alias: "r",
613
+ describe: "AWS region to scan",
614
+ type: "string",
615
+ });
616
+ yargs.option("filter", {
617
+ alias: "f",
618
+ describe:
619
+ "Filter current platform descriptions by a case-insensitive literal phrase",
620
+ type: "string",
621
+ requiresArg: true,
622
+ });
623
+ yargs.option("timeout", {
624
+ describe: "Maximum monitoring time per update, in minutes",
625
+ type: "number",
626
+ default: 120,
627
+ });
628
+ yargs.check((argv) => {
629
+ if (argv.filter !== undefined && !argv.filter.trim()) {
630
+ throw new Error("--filter must be a non-empty platform phrase");
631
+ }
632
+ if (!Number.isFinite(argv.timeout) || argv.timeout <= 0) {
633
+ throw new Error(
634
+ "--timeout must be a positive number of minutes",
635
+ );
636
+ }
637
+ return true;
638
+ });
639
+ },
640
+ async (argv) => {
641
+ const clients = await resolveScope(argv, "client", client.choices);
642
+ const regions = await resolveScope(argv, "region", region.choices);
643
+ const targets = await scan(clients, regions, argv.filter);
644
+ if (!targets.length) {
645
+ console.log(
646
+ `No scheduled managed updates or eligible patch-only platform updates found in successfully scanned environments${argv.filter ? ` matching "${argv.filter}"` : ""}.`,
647
+ );
648
+ return;
649
+ }
650
+ const { selected } = await inquirer.prompt([
651
+ {
652
+ type: "checkbox",
653
+ name: "selected",
654
+ message:
655
+ "Which platform updates should be applied now? (select none to exit)",
656
+ pageSize: 15,
657
+ choices: targets.map((target) => ({
658
+ name: `[${target.platform ? "Direct patch" : "Managed update"}] ${label(target)} / ${target.environment.ApplicationName} - ${target.action.ActionDescription || target.action.ActionId}${target.action.WindowStartTime ? ` (scheduled ${new Date(target.action.WindowStartTime).toISOString()})` : ""}`,
659
+ value: target,
660
+ checked: false,
661
+ })),
662
+ },
663
+ ]);
664
+ if (!selected.length) return;
665
+ console.log("\nSelected updates:");
666
+ selected.forEach((target) =>
667
+ console.log(
668
+ ` ${label(target)} - ${target.action.ActionDescription || target.action.ActionId}`,
669
+ ),
670
+ );
671
+ if (selected.some((target) => target.platform)) {
672
+ console.log(
673
+ colorize(
674
+ "Direct patches use the environment's configured configuration-update policy and health settings. Managed updates use AWS's managed maintenance workflow. This command does not inspect or change those settings.",
675
+ "info",
676
+ ),
677
+ );
678
+ }
679
+ const { confirmed } = await inquirer.prompt([
680
+ {
681
+ type: "confirm",
682
+ name: "confirmed",
683
+ message: `Apply ${selected.length} platform update(s) now, one at a time?`,
684
+ default: false,
685
+ },
686
+ ]);
687
+ if (confirmed) await runQueue(selected, argv.timeout ?? 120);
688
+ },
689
+ ];