@fishawack/lab-env 5.6.1 → 5.7.0-beta.10
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/CHANGELOG.md +136 -0
- package/_Test/boilerplate-adonis.js +1 -1
- package/_Test/boilerplate-craftcms.js +1 -1
- package/_Test/boilerplate-drupal.js +1 -1
- package/_Test/boilerplate-laravel.js +1 -1
- package/_Test/boilerplate-python.js +1 -1
- package/_Test/boilerplate-wordpress.js +1 -1
- package/_Test/boilerplate.js +1 -1
- package/_Test/provision.js +4 -9
- package/_Test/prune.js +8 -5
- package/bitbucket-pipelines.yml +2 -2
- package/cli.js +2 -0
- package/commands/create/cmds/dekey.js +13 -9
- package/commands/create/cmds/deprovision.js +66 -6
- package/commands/create/cmds/diagnose.js +10 -0
- package/commands/create/cmds/key.js +74 -41
- package/commands/create/cmds/provision.js +641 -22
- package/commands/create/cmds/rekey.js +283 -0
- package/commands/create/cmds/sync-secrets.js +198 -0
- package/commands/create/libs/output-credentials.js +59 -0
- package/commands/create/libs/parallel-runner.js +296 -0
- package/commands/create/libs/resolve-operator.js +59 -0
- package/commands/create/libs/utilities.js +75 -8
- package/commands/create/libs/vars.js +273 -377
- package/commands/create/services/aws/acm.js +61 -0
- package/commands/create/services/aws/cloudfront.js +51 -45
- package/commands/create/services/aws/ec2.js +781 -5
- package/commands/create/services/aws/elasticache.js +159 -0
- package/commands/create/services/aws/elasticbeanstalk.js +200 -48
- package/commands/create/services/aws/iam.js +430 -82
- package/commands/create/services/aws/index.js +1598 -100
- package/commands/create/services/aws/opensearch.js +155 -0
- package/commands/create/services/aws/rds.js +272 -0
- package/commands/create/services/aws/s3.js +52 -31
- package/commands/create/services/aws/secretsmanager.js +82 -0
- package/commands/create/services/aws/ses.js +203 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/cron.config +45 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/queue-worker.config +29 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/rds-ssl.config +5 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/laravel/software.config +12 -0
- package/commands/create/templates/elasticbeanstalk/.ebextensions/misc/setvars.config +1 -0
- package/commands/create/templates/elasticbeanstalk/.platform/confighooks/postdeploy/restart_queue.sh +4 -0
- package/commands/create/templates/elasticbeanstalk/.platform/confighooks/postdeploy/rewrite-flush.sh +1 -1
- package/commands/create/templates/elasticbeanstalk/.platform/confighooks/prebuild/setvars.sh +19 -0
- package/commands/create/templates/elasticbeanstalk/.platform/hooks/postdeploy/restart_queue.sh +4 -0
- package/commands/create/templates/elasticbeanstalk/.platform/hooks/prebuild/setvars.sh +19 -0
- package/commands/scan.js +1 -1
- package/core/1/CHANGELOG.md +41 -0
- package/core/1/Dockerfile +3 -3
- package/core/1/bitbucket-pipelines.yml +5 -5
- package/core/1/package.json +1 -1
- package/globals.js +4 -0
- package/package.json +9 -2
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
const logUpdate = require("log-update");
|
|
2
|
+
const chalk = require("chalk");
|
|
3
|
+
const { Spinner } = require("./utilities");
|
|
4
|
+
|
|
5
|
+
const SPINNER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
6
|
+
const MAX_RETRIES = 15;
|
|
7
|
+
const INITIAL_DELAY = 2000;
|
|
8
|
+
const MAX_DELAY = 60000;
|
|
9
|
+
const TASK_TIMEOUT = 120000; // 2 min hard timeout per attempt — prevents hung TCP connections
|
|
10
|
+
|
|
11
|
+
const RETRYABLE_ERRORS = [
|
|
12
|
+
"Throttling",
|
|
13
|
+
"ThrottlingException",
|
|
14
|
+
"TooManyRequestsException",
|
|
15
|
+
"RequestLimitExceeded",
|
|
16
|
+
"ServiceUnavailable",
|
|
17
|
+
"InternalFailure",
|
|
18
|
+
"RequestTimeout",
|
|
19
|
+
"RequestTimeoutException",
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
function isRetryable(err) {
|
|
23
|
+
if (
|
|
24
|
+
RETRYABLE_ERRORS.includes(err.name) ||
|
|
25
|
+
RETRYABLE_ERRORS.includes(err.Code)
|
|
26
|
+
) {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const statusCode = err.$metadata?.httpStatusCode;
|
|
31
|
+
|
|
32
|
+
return statusCode === 429 || statusCode === 503 || statusCode === 500;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function formatElapsed(ms) {
|
|
36
|
+
const secs = Math.floor(ms / 1000);
|
|
37
|
+
if (secs < 60) return `${secs}s`;
|
|
38
|
+
const mins = Math.floor(secs / 60);
|
|
39
|
+
return `${mins}m${secs % 60}s`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Runs batches of tasks sequentially (one batch per client/account) with
|
|
44
|
+
* parallel execution within each batch. Users are processed in groups of
|
|
45
|
+
* `concurrency` — each group completes all batches before the next starts.
|
|
46
|
+
*
|
|
47
|
+
* @param {Array<{ users: string[], client: string, fn: (user: string) => Promise<any> }>} batches
|
|
48
|
+
* @param {{ concurrency?: number, verb?: string }} options
|
|
49
|
+
* @returns {Promise<Map<string, Array<{ client: string, res: any }>>>} results keyed by user
|
|
50
|
+
*/
|
|
51
|
+
module.exports = async function parallelRunner(
|
|
52
|
+
batches,
|
|
53
|
+
{ concurrency = 5, verb = "Processing" } = {},
|
|
54
|
+
) {
|
|
55
|
+
const allUsers = [...new Set(batches.flatMap((b) => b.users))];
|
|
56
|
+
const totalBatches = batches.length;
|
|
57
|
+
const results = new Map(allUsers.map((u) => [u, []]));
|
|
58
|
+
const startTime = Date.now();
|
|
59
|
+
let frame = 0;
|
|
60
|
+
let throttleCount = 0;
|
|
61
|
+
|
|
62
|
+
// Silence Spinner.prototype.simple — track throttling via slow calls
|
|
63
|
+
const originalSimple = Spinner.prototype.simple;
|
|
64
|
+
Spinner.prototype.simple = async (_message, action) => {
|
|
65
|
+
const t0 = Date.now();
|
|
66
|
+
const res = await action();
|
|
67
|
+
// If a single API call took > 3s it likely hit a retry/backoff
|
|
68
|
+
if (Date.now() - t0 > 3000) {
|
|
69
|
+
throttleCount++;
|
|
70
|
+
}
|
|
71
|
+
return res;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Chunk users into groups of `concurrency`
|
|
75
|
+
const groups = [];
|
|
76
|
+
for (let i = 0; i < allUsers.length; i += concurrency) {
|
|
77
|
+
groups.push(allUsers.slice(i, i + concurrency));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Track state for users (populated as groups start)
|
|
81
|
+
const groupStates = new Map();
|
|
82
|
+
const errors = [];
|
|
83
|
+
|
|
84
|
+
// Render loop — header + one line per user
|
|
85
|
+
const render = setInterval(() => {
|
|
86
|
+
frame = (frame + 1) % SPINNER_FRAMES.length;
|
|
87
|
+
const elapsed = formatElapsed(Date.now() - startTime);
|
|
88
|
+
|
|
89
|
+
// Header line with timing and throttle info
|
|
90
|
+
let header = chalk.dim(` ${elapsed} elapsed`);
|
|
91
|
+
if (throttleCount > 0) {
|
|
92
|
+
header += chalk.yellow(
|
|
93
|
+
` │ ⚠ ${throttleCount} throttled call${throttleCount > 1 ? "s" : ""} (retrying automatically)`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const lines = [header];
|
|
98
|
+
|
|
99
|
+
for (const user of allUsers) {
|
|
100
|
+
const state = groupStates.get(user);
|
|
101
|
+
|
|
102
|
+
if (!state) {
|
|
103
|
+
lines.push(
|
|
104
|
+
chalk.dim(` - ${verb}: ${user} (0/${totalBatches})`),
|
|
105
|
+
);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (state.status === "retrying") {
|
|
110
|
+
const remaining = Math.max(
|
|
111
|
+
0,
|
|
112
|
+
Math.ceil(
|
|
113
|
+
(state.retryDelay - (Date.now() - state.retryStart)) /
|
|
114
|
+
1000,
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
lines.push(
|
|
118
|
+
chalk.yellow(
|
|
119
|
+
` ↻ ${verb}: ${user} - ${state.client} (${state.batchesDone + 1}/${totalBatches}) retry ${state.retryAttempt}/${MAX_RETRIES} ${remaining}s`,
|
|
120
|
+
),
|
|
121
|
+
);
|
|
122
|
+
} else if (state.status === "active") {
|
|
123
|
+
const taskElapsed = Date.now() - state.taskStart;
|
|
124
|
+
let suffix = "";
|
|
125
|
+
if (taskElapsed > 5000) {
|
|
126
|
+
suffix = chalk.yellow(` ${formatElapsed(taskElapsed)}`);
|
|
127
|
+
}
|
|
128
|
+
lines.push(
|
|
129
|
+
chalk.cyan(
|
|
130
|
+
` ${SPINNER_FRAMES[frame]} ${verb}: ${user} - ${state.client} (${state.batchesDone + 1}/${totalBatches})`,
|
|
131
|
+
) + suffix,
|
|
132
|
+
);
|
|
133
|
+
} else if (state.status === "error") {
|
|
134
|
+
lines.push(
|
|
135
|
+
chalk.red(
|
|
136
|
+
` ✖ ${verb}: ${user} - ${state.client} (${state.batchesDone}/${totalBatches}) ${state.errorMsg}`,
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
} else if (state.batchesDone === totalBatches) {
|
|
140
|
+
lines.push(
|
|
141
|
+
chalk.green(
|
|
142
|
+
` ✓ ${verb}: ${user} (${totalBatches}/${totalBatches})`,
|
|
143
|
+
),
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
lines.push(
|
|
147
|
+
chalk.dim(
|
|
148
|
+
` - ${verb}: ${user} (${state.batchesDone}/${totalBatches})`,
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
logUpdate(lines.join("\n"));
|
|
155
|
+
}, 80);
|
|
156
|
+
|
|
157
|
+
// Process each group to full completion before starting the next
|
|
158
|
+
for (const group of groups) {
|
|
159
|
+
for (const u of group) {
|
|
160
|
+
groupStates.set(u, {
|
|
161
|
+
client: "",
|
|
162
|
+
status: "pending",
|
|
163
|
+
batchesDone: 0,
|
|
164
|
+
taskStart: 0,
|
|
165
|
+
hasError: false,
|
|
166
|
+
errorMsg: "",
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
for (const batch of batches) {
|
|
171
|
+
const groupUsers = group.filter((u) => batch.users.includes(u));
|
|
172
|
+
|
|
173
|
+
await Promise.all(
|
|
174
|
+
groupUsers.map(async (user, userIndex) => {
|
|
175
|
+
const state = groupStates.get(user);
|
|
176
|
+
state.client = batch.client;
|
|
177
|
+
state.taskStart = Date.now();
|
|
178
|
+
|
|
179
|
+
for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
|
|
180
|
+
state.status = "active";
|
|
181
|
+
state.taskStart = Date.now();
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
let timeoutHandle;
|
|
185
|
+
const res = await Promise.race([
|
|
186
|
+
batch.fn(user),
|
|
187
|
+
new Promise((_, reject) => {
|
|
188
|
+
timeoutHandle = setTimeout(
|
|
189
|
+
() =>
|
|
190
|
+
reject(
|
|
191
|
+
Object.assign(
|
|
192
|
+
new Error(
|
|
193
|
+
"Request timed out after 2 minutes — will retry",
|
|
194
|
+
),
|
|
195
|
+
{ name: "RequestTimeout" },
|
|
196
|
+
),
|
|
197
|
+
),
|
|
198
|
+
TASK_TIMEOUT,
|
|
199
|
+
);
|
|
200
|
+
}),
|
|
201
|
+
]).finally(() => clearTimeout(timeoutHandle));
|
|
202
|
+
results
|
|
203
|
+
.get(user)
|
|
204
|
+
.push({ client: batch.client, res });
|
|
205
|
+
state.status = "done";
|
|
206
|
+
state.retryAttempt = 0;
|
|
207
|
+
break;
|
|
208
|
+
} catch (err) {
|
|
209
|
+
if (!isRetryable(err) || attempt === MAX_RETRIES) {
|
|
210
|
+
state.status = "error";
|
|
211
|
+
state.hasError = true;
|
|
212
|
+
state.errorMsg = err.message || String(err);
|
|
213
|
+
errors.push({
|
|
214
|
+
user,
|
|
215
|
+
client: batch.client,
|
|
216
|
+
error: err,
|
|
217
|
+
});
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
let delay = Math.min(
|
|
222
|
+
INITIAL_DELAY * Math.pow(2, attempt),
|
|
223
|
+
MAX_DELAY,
|
|
224
|
+
);
|
|
225
|
+
// Stagger retries per user to avoid thundering herd
|
|
226
|
+
delay +=
|
|
227
|
+
Math.floor(Math.random() * delay * 0.3) +
|
|
228
|
+
userIndex * 1000;
|
|
229
|
+
|
|
230
|
+
state.status = "retrying";
|
|
231
|
+
state.retryAttempt = attempt + 1;
|
|
232
|
+
state.retryDelay = delay;
|
|
233
|
+
state.retryStart = Date.now();
|
|
234
|
+
throttleCount++;
|
|
235
|
+
|
|
236
|
+
await new Promise((resolve) =>
|
|
237
|
+
setTimeout(resolve, delay),
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
state.batchesDone++;
|
|
243
|
+
}),
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
clearInterval(render);
|
|
249
|
+
|
|
250
|
+
// Final render
|
|
251
|
+
const elapsed = formatElapsed(Date.now() - startTime);
|
|
252
|
+
let header = chalk.dim(` ${elapsed} elapsed`);
|
|
253
|
+
if (throttleCount > 0) {
|
|
254
|
+
header += chalk.yellow(
|
|
255
|
+
` │ ⚠ ${throttleCount} throttled call${throttleCount > 1 ? "s" : ""}`,
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const lines = [header];
|
|
260
|
+
for (const user of allUsers) {
|
|
261
|
+
const state = groupStates.get(user);
|
|
262
|
+
if (state.hasError) {
|
|
263
|
+
lines.push(
|
|
264
|
+
chalk.red(
|
|
265
|
+
` ✖ ${verb}: ${user} (${state.batchesDone}/${totalBatches}) ${state.errorMsg}`,
|
|
266
|
+
),
|
|
267
|
+
);
|
|
268
|
+
} else {
|
|
269
|
+
lines.push(
|
|
270
|
+
chalk.green(
|
|
271
|
+
` ✓ ${verb}: ${user} (${totalBatches}/${totalBatches})`,
|
|
272
|
+
),
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
logUpdate(lines.join("\n"));
|
|
277
|
+
logUpdate.done();
|
|
278
|
+
|
|
279
|
+
// Restore spinner
|
|
280
|
+
Spinner.prototype.simple = originalSimple;
|
|
281
|
+
|
|
282
|
+
if (errors.length) {
|
|
283
|
+
const summary = errors
|
|
284
|
+
.map(
|
|
285
|
+
(e) => `${e.user} (${e.client}): ${e.error.message || e.error}`,
|
|
286
|
+
)
|
|
287
|
+
.join("\n");
|
|
288
|
+
const err = new Error(
|
|
289
|
+
`${errors.length} task${errors.length > 1 ? "s" : ""} failed:\n${summary}`,
|
|
290
|
+
);
|
|
291
|
+
err.errors = errors;
|
|
292
|
+
throw err;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return results;
|
|
296
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const _ = require("../../../globals.js");
|
|
2
|
+
const inquirer = require("inquirer");
|
|
3
|
+
const os = require("os");
|
|
4
|
+
const { writeFileSync } = require("fs");
|
|
5
|
+
|
|
6
|
+
module.exports = async function resolveOperator() {
|
|
7
|
+
let operators = _.config.users.filter((d) => d.operator);
|
|
8
|
+
|
|
9
|
+
if (operators.length === 1) {
|
|
10
|
+
return operators[0];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
let candidates =
|
|
14
|
+
operators.length > 1
|
|
15
|
+
? operators
|
|
16
|
+
: _.config.users.filter(
|
|
17
|
+
(d) =>
|
|
18
|
+
d.permissions && d.permissions.includes("manage-users"),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
if (!candidates.length) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
"No users with manage-users permission found. A user with IAMFullAccess is required to rotate keys.",
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let message =
|
|
28
|
+
operators.length > 1
|
|
29
|
+
? "Multiple operators found. Which user are you?"
|
|
30
|
+
: "No operator configured. Which user are you?";
|
|
31
|
+
|
|
32
|
+
let answer = await inquirer.prompt([
|
|
33
|
+
{
|
|
34
|
+
type: "list",
|
|
35
|
+
name: "operator",
|
|
36
|
+
message,
|
|
37
|
+
choices: candidates.map((d) => d.username),
|
|
38
|
+
},
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
_.config.users.forEach((d) => {
|
|
42
|
+
delete d.operator;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
let selected = _.config.users.find((d) => d.username === answer.operator);
|
|
46
|
+
selected.operator = true;
|
|
47
|
+
|
|
48
|
+
writeFileSync(
|
|
49
|
+
`${os.homedir()}/.lab-env`,
|
|
50
|
+
JSON.stringify(_.config, null, 4),
|
|
51
|
+
{ encoding: "utf8" },
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
console.log(
|
|
55
|
+
`\nOperator set to "${selected.username}" and saved to ~/.lab-env\n`,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return selected;
|
|
59
|
+
};
|
|
@@ -28,6 +28,7 @@ const colorize = (module.exports.colorize = (str, type) => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
let latestSpinner = null;
|
|
31
|
+
let spinnerQueue = Promise.resolve();
|
|
31
32
|
|
|
32
33
|
module.exports.Spinner = class Spinner {
|
|
33
34
|
constructor(startMessage, simple = false) {
|
|
@@ -67,31 +68,42 @@ module.exports.Spinner = class Spinner {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
simple(message, action) {
|
|
71
|
+
const ready = spinnerQueue;
|
|
72
|
+
let release;
|
|
73
|
+
spinnerQueue = new Promise((r) => {
|
|
74
|
+
release = r;
|
|
75
|
+
});
|
|
76
|
+
|
|
70
77
|
// eslint-disable-next-line no-async-promise-executor
|
|
71
78
|
return new Promise(async (resolve, reject) => {
|
|
79
|
+
await ready;
|
|
80
|
+
|
|
72
81
|
let instance = new this.constructor(message, true);
|
|
73
82
|
let res;
|
|
74
83
|
|
|
75
84
|
try {
|
|
76
|
-
res = await action();
|
|
85
|
+
res = await action(instance);
|
|
77
86
|
|
|
78
87
|
instance.ora.succeed();
|
|
79
88
|
} catch (e) {
|
|
80
89
|
instance.ora.fail();
|
|
90
|
+
release();
|
|
81
91
|
reject(e);
|
|
92
|
+
return;
|
|
82
93
|
}
|
|
83
94
|
|
|
95
|
+
release();
|
|
84
96
|
resolve(res);
|
|
85
97
|
});
|
|
86
98
|
}
|
|
87
99
|
|
|
88
|
-
ping() {
|
|
89
|
-
|
|
90
|
-
|
|
100
|
+
ping(spinner) {
|
|
101
|
+
const target = spinner || latestSpinner;
|
|
102
|
+
target.ora.color = target.ora.color === "cyan" ? "magenta" : "cyan";
|
|
91
103
|
let message = " - check: ";
|
|
92
|
-
let split =
|
|
104
|
+
let split = target.ora.text.split(message);
|
|
93
105
|
let iteration = (split[1] && +split[1].split(":")[0]) || 0;
|
|
94
|
-
|
|
106
|
+
target.ora.text = `${split[0]}${message}${iteration + 1}`;
|
|
95
107
|
}
|
|
96
108
|
};
|
|
97
109
|
|
|
@@ -122,16 +134,22 @@ module.exports.nameSafe = (name, service = "s3") => {
|
|
|
122
134
|
|
|
123
135
|
if (service === "eb") {
|
|
124
136
|
maxLength = 40;
|
|
137
|
+
} else if (service === "os") {
|
|
138
|
+
maxLength = 28;
|
|
139
|
+
} else if (service === "cache") {
|
|
140
|
+
maxLength = 40;
|
|
125
141
|
}
|
|
126
142
|
|
|
127
143
|
safe = safe.substring(0, maxLength - suffix.length - prefix.length);
|
|
128
144
|
safe = safe.replace(/[^a-zA-Z0-9-_. ]/g, ""); // Remove special chars except . _ - as these are all transformed into -
|
|
145
|
+
safe = safe.replace(/-+$/, ""); // Strip trailing hyphens before suffix is appended
|
|
129
146
|
safe = safe.toLowerCase();
|
|
130
147
|
safe = `${prefix}${safe}`;
|
|
131
148
|
safe = `${safe}${suffix}`;
|
|
132
149
|
safe = safe.replace(/\./g, "-");
|
|
133
150
|
// eslint-disable-next-line no-useless-escape
|
|
134
151
|
safe = safe.replace(/\_/g, "-");
|
|
152
|
+
safe = safe.replace(/--+/g, "-"); // Collapse any consecutive hyphens
|
|
135
153
|
|
|
136
154
|
return safe;
|
|
137
155
|
};
|
|
@@ -144,13 +162,13 @@ module.exports.copyToClipboard = (text) => {
|
|
|
144
162
|
}
|
|
145
163
|
};
|
|
146
164
|
|
|
147
|
-
module.exports.poll = async (cb, resolve, reject) => {
|
|
165
|
+
module.exports.poll = async (cb, resolve, reject, spinner) => {
|
|
148
166
|
let res;
|
|
149
167
|
|
|
150
168
|
do {
|
|
151
169
|
await new Promise((resolve) => setTimeout(() => resolve(), 5000));
|
|
152
170
|
|
|
153
|
-
await module.exports.Spinner.prototype.ping();
|
|
171
|
+
await module.exports.Spinner.prototype.ping(spinner);
|
|
154
172
|
|
|
155
173
|
res = await cb();
|
|
156
174
|
|
|
@@ -161,3 +179,52 @@ module.exports.poll = async (cb, resolve, reject) => {
|
|
|
161
179
|
|
|
162
180
|
return res;
|
|
163
181
|
};
|
|
182
|
+
|
|
183
|
+
module.exports.pollAll = async (
|
|
184
|
+
services,
|
|
185
|
+
message = "Waiting for services to provision",
|
|
186
|
+
) => {
|
|
187
|
+
const instance = new module.exports.Spinner(
|
|
188
|
+
`${message} - checking (${services[0].name})`,
|
|
189
|
+
true,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const results = new Array(services.length).fill(null);
|
|
193
|
+
const pending = services.map((s, i) => ({ ...s, index: i, checks: 0 }));
|
|
194
|
+
let cursor = 0;
|
|
195
|
+
|
|
196
|
+
while (pending.length > 0) {
|
|
197
|
+
const service = pending[cursor % pending.length];
|
|
198
|
+
service.checks++;
|
|
199
|
+
|
|
200
|
+
instance.ora.text = `${message} - checking (${service.name}) - check: ${service.checks}`;
|
|
201
|
+
|
|
202
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
203
|
+
|
|
204
|
+
instance.ora.color = instance.ora.color === "cyan" ? "magenta" : "cyan";
|
|
205
|
+
|
|
206
|
+
const res = await service.cb();
|
|
207
|
+
|
|
208
|
+
if (service.reject && service.reject(res)) {
|
|
209
|
+
instance.ora.fail();
|
|
210
|
+
throw new Error(
|
|
211
|
+
`Polling received reject response for ${service.name}`,
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (!service.shouldContinue(res)) {
|
|
216
|
+
results[service.index] = res;
|
|
217
|
+
pending.splice(cursor % pending.length, 1);
|
|
218
|
+
|
|
219
|
+
if (pending.length > 0) {
|
|
220
|
+
cursor = cursor % pending.length;
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
cursor++;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
instance.ora.succeed();
|
|
228
|
+
|
|
229
|
+
return results;
|
|
230
|
+
};
|