@hiiretail/gcp-infra-generators 1.0.0 → 1.0.2

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 (74) hide show
  1. package/dist/generators/clan-resources/clan-project/index.js +89 -189
  2. package/dist/generators/common-resources/bigquery/index.js +172 -267
  3. package/dist/generators/common-resources/budget/index.js +67 -153
  4. package/dist/generators/common-resources/cloud-armor/index.js +17 -167
  5. package/dist/generators/common-resources/cloud-storage/index.js +96 -205
  6. package/dist/generators/common-resources/cloudsql/index.js +71 -177
  7. package/dist/generators/common-resources/cloudsql-database/index.js +40 -287
  8. package/dist/generators/common-resources/confluent-cluster/index.js +23 -132
  9. package/dist/generators/common-resources/datastore/index.js +48 -194
  10. package/dist/generators/common-resources/elastic-cloud/index.js +22 -132
  11. package/dist/generators/common-resources/elastic-index-policy/handle-yaml.js +76 -0
  12. package/dist/generators/common-resources/elastic-index-policy/index.js +131 -286
  13. package/dist/generators/common-resources/elastic-template/index.js +52 -162
  14. package/dist/generators/common-resources/firestore/index.js +93 -233
  15. package/dist/generators/common-resources/iam/index.js +35 -157
  16. package/dist/generators/common-resources/iam/valid-prefix.js +8 -0
  17. package/dist/generators/common-resources/kafka-connect/index.js +35 -144
  18. package/dist/generators/common-resources/kafka-topics/index.js +20 -129
  19. package/dist/generators/common-resources/kms/index.js +31 -141
  20. package/dist/generators/common-resources/memorystore/index.js +42 -328
  21. package/dist/generators/common-resources/monitoring/handle-yaml.js +49 -0
  22. package/dist/generators/common-resources/monitoring/index.js +144 -322
  23. package/dist/generators/common-resources/monitoring/templates/alerts/generic-infra.yaml +37 -2
  24. package/dist/generators/common-resources/monitoring/validate.js +58 -0
  25. package/dist/generators/common-resources/pubsub/append.js +130 -0
  26. package/dist/generators/common-resources/pubsub/get-gcp-projects.js +34 -0
  27. package/dist/generators/common-resources/pubsub/handle-subscribers.js +68 -0
  28. package/dist/generators/common-resources/pubsub/index.js +194 -536
  29. package/dist/generators/common-resources/pubsub/validate.js +53 -0
  30. package/dist/generators/common-resources/scheduler/append.js +85 -0
  31. package/dist/generators/common-resources/scheduler/index.js +62 -249
  32. package/dist/generators/common-resources/spanner/append.js +31 -0
  33. package/dist/generators/common-resources/spanner/index.js +102 -269
  34. package/dist/generators/common-resources/spanner/validate.js +38 -0
  35. package/dist/generators/docs/rca/index.js +25 -135
  36. package/dist/generators/docs/runbook/index.js +16 -126
  37. package/dist/generators/docs/srb/index.js +33 -147
  38. package/dist/generators/docs/srb/run-docker.js +2 -0
  39. package/dist/generators/init/clan-infra/gcp-projects.js +47 -0
  40. package/dist/generators/init/clan-infra/index.js +95 -290
  41. package/dist/generators/init/clan-infra/tribe-clan-repo.js +38 -0
  42. package/dist/generators/init/clan-infra/validate.js +8 -0
  43. package/dist/generators/maintenance/manage-states/index.js +142 -219
  44. package/dist/generators/maintenance/update-modules/index.js +56 -155
  45. package/dist/generators/organization/clan-project/googlecloud.js +124 -0
  46. package/dist/generators/organization/clan-project/index.js +81 -303
  47. package/dist/node_modules/.package-lock.json +88 -31
  48. package/dist/node_modules/@google-cloud/storage/build/cjs/src/bucket.js +5 -5
  49. package/dist/node_modules/@google-cloud/storage/build/cjs/src/file.d.ts +1 -0
  50. package/dist/node_modules/@google-cloud/storage/build/cjs/src/file.js +10 -1
  51. package/dist/node_modules/@google-cloud/storage/build/cjs/src/storage.js +1 -1
  52. package/dist/node_modules/@google-cloud/storage/build/cjs/src/transfer-manager.d.ts +4 -4
  53. package/dist/node_modules/@google-cloud/storage/build/cjs/src/transfer-manager.js +4 -4
  54. package/dist/node_modules/@google-cloud/storage/build/cjs/src/util.d.ts +1 -1
  55. package/dist/node_modules/@google-cloud/storage/build/cjs/src/util.js +2 -2
  56. package/dist/node_modules/@google-cloud/storage/build/esm/src/bucket.js +5 -5
  57. package/dist/node_modules/@google-cloud/storage/build/esm/src/file.d.ts +1 -0
  58. package/dist/node_modules/@google-cloud/storage/build/esm/src/file.js +10 -1
  59. package/dist/node_modules/@google-cloud/storage/build/esm/src/storage.js +1 -1
  60. package/dist/node_modules/@google-cloud/storage/build/esm/src/transfer-manager.d.ts +4 -4
  61. package/dist/node_modules/@google-cloud/storage/build/esm/src/transfer-manager.js +4 -4
  62. package/dist/node_modules/@google-cloud/storage/build/esm/src/util.d.ts +1 -1
  63. package/dist/node_modules/@google-cloud/storage/build/esm/src/util.js +2 -2
  64. package/dist/node_modules/@google-cloud/storage/package.json +5 -5
  65. package/dist/package.json +45 -0
  66. package/dist/src/BaseGenerator.js +84 -0
  67. package/dist/src/SecretsGenerator.js +137 -0
  68. package/dist/src/cli.js +54 -255
  69. package/dist/src/dependency-check.js +48 -0
  70. package/dist/src/update-check.js +38 -0
  71. package/dist/src/validators.js +33 -0
  72. package/dist/src/yeoman.js +80 -0
  73. package/package.json +2 -3
  74. package/dist/node_modules/@google-cloud/storage/CHANGELOG.md +0 -1769
@@ -1,409 +1,231 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- var __commonJS = (cb, mod) => function __require() {
5
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
6
- };
7
-
8
- // src/validators.js
9
- var require_validators = __commonJS({
10
- "src/validators.js"(exports2, module2) {
11
- var path2 = require("path");
12
- module2.exports = {
13
- chain: /* @__PURE__ */ __name((input, ...validators) => {
14
- let msg = "";
15
- validators.every((validator) => {
16
- msg = validator(input);
17
- return msg === true;
18
- });
19
- return msg === true ? true : msg;
20
- }, "chain"),
21
- filename: /* @__PURE__ */ __name((input) => {
22
- if (!input) {
23
- return true;
24
- }
25
- return path2.basename(input) === input ? true : "Invalid filename";
26
- }, "filename"),
27
- maxLength: /* @__PURE__ */ __name((input, maxLength) => !input || input.length <= maxLength ? true : `Exceeds max \
28
- length: ${maxLength}`, "maxLength"),
29
- required: /* @__PURE__ */ __name((input) => {
30
- const msg = "Required";
31
- if (Array.isArray(input)) {
32
- return input.length > 0 ? true : msg;
33
- }
34
- if (input) {
35
- return input.trim().length > 0 ? true : msg;
36
- }
37
- return msg;
38
- }, "required")
39
- };
40
- }
41
- });
42
-
43
- // src/BaseGenerator.js
44
- var require_BaseGenerator = __commonJS({
45
- "src/BaseGenerator.js"(exports2, module2) {
46
- var Generator = require("yeoman-generator");
47
- var path2 = require("path");
48
- var fs2 = require("fs");
49
- var inquirer = require("inquirer");
50
- var { chain, required: required2, filename } = require_validators();
51
- module2.exports = class extends Generator {
52
- constructor(args, opts) {
53
- super(args, opts);
54
- this.baseDir = path2.resolve(path2.join(__dirname, ".."));
55
- this.destinationRoot(process.cwd());
56
- const [command, generator] = opts.namespace.split(":").slice(-2);
57
- this.generatorId = path2.join(command, generator);
58
- this.sourceRoot(
59
- path2.join(this.baseDir, "generators", this.generatorId, "templates")
60
- );
61
- this.copyDir = (templateDir, targetDir, answers = this.answers, skipIfExists = false) => {
62
- if (skipIfExists && fs2.existsSync(targetDir)) {
63
- return;
64
- }
65
- this.fs.copyTpl(
66
- this.templatePath(`${templateDir}/**/*`),
67
- this.destinationPath(targetDir),
68
- answers
69
- );
70
- };
71
- this.listSubDirectories = (parent) => fs2.readdirSync(parent).filter((f) => !f.startsWith(".")).filter((f) => fs2.
72
- lstatSync(path2.join(parent, f)).isDirectory()).sort((a, b) => a.localeCompare(b));
73
- this.kebabCase = (input) => input.replace(/\s|_/g, "-");
74
- this.chooseOrCreatePrompts = (name, getChoicesDirectory) => [
75
- {
76
- when: /* @__PURE__ */ __name((answers) => fs2.existsSync(getChoicesDirectory(answers)), "when"),
77
- type: "list",
78
- name,
79
- message: `Choose ${name}`,
80
- store: true,
81
- choices: /* @__PURE__ */ __name((answers) => [
82
- ...this.listSubDirectories(getChoicesDirectory(answers)),
83
- new inquirer.Separator(),
84
- `Create new ${name}`
85
- ], "choices"),
86
- validate: required2,
87
- filter: this.kebabCase
88
- },
89
- {
90
- when: /* @__PURE__ */ __name((answers) => !fs2.existsSync(getChoicesDirectory(answers)) || answers[name] ===
91
- `Create-new-${name}`, "when"),
92
- type: "input",
93
- name: `new-${name}`,
94
- message: `New ${name} name`,
95
- store: false,
96
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
97
- filter: this.kebabCase
98
- },
99
- {
100
- when: /* @__PURE__ */ __name((answers) => !fs2.existsSync(getChoicesDirectory(answers)) || answers[name] ===
101
- "Create-new-tribe", "when"),
102
- type: "input",
103
- name: "costCenter",
104
- message: "Please provide the Cost Center of the Tribe",
105
- store: false,
106
- validate: /* @__PURE__ */ __name((input) => chain(input, required2, filename), "validate"),
107
- filter: this.kebabCase
108
- }
109
- ];
110
- }
111
- };
112
- }
113
- });
114
-
115
- // generators/common-resources/monitoring/validate.js
116
- var require_validate = __commonJS({
117
- "generators/common-resources/monitoring/validate.js"(exports2, module2) {
118
- var validate2 = {};
119
- var hasWhitespace = /* @__PURE__ */ __name((str) => /\s/.test(str), "hasWhitespace");
120
- var isUrl = /* @__PURE__ */ __name((str) => {
121
- try {
122
- return Boolean(new URL(str));
123
- } catch {
124
- return false;
125
- }
126
- }, "isUrl");
127
- validate2.clan = (input) => {
128
- if (!hasWhitespace(input)) return true;
129
- return "Clan name must not include spaces";
130
- };
131
- validate2.projectId = (input) => {
132
- if (input.trim() !== "" && !hasWhitespace(input)) return true;
133
- return "Project ID must not be empty or contain spaces";
134
- };
135
- validate2.hostname = (input) => {
136
- if (input.split(".").at(-1) === "com" && !hasWhitespace(input)) return true;
137
- return "Hostname must not include path to the page to run the check against or spaces";
138
- };
139
- validate2.systemName = (input) => {
140
- if (input.length === 3 && !hasWhitespace(input)) return true;
141
- return "System name must be 3 characters";
142
- };
143
- validate2.confluenceUrl = (input) => {
144
- if (input === "" || isUrl(input) && !hasWhitespace(input)) return true;
145
- return "You must enter a valid URL";
146
- };
147
- validate2.instanceID = (input) => {
148
- if (input.split("/").length === 6 && !hasWhitespace(input)) return true;
149
- return "You must enter the full instance path (example: projects/example/locations/europe-west1/instances/instance\
150
- ID)";
151
- };
152
- validate2.databaseId = (input) => {
153
- if (input.split(":").length === 2 && !hasWhitespace(input)) return true;
154
- return "You must enter the full database path (example: my-project:databaseID)";
155
- };
156
- validate2.pubSubSubscription = (input) => {
157
- if (input.split("/").length === 4 && !hasWhitespace(input)) return true;
158
- return "You must enter the full subscription path (example: projects/example/subscriptions/subscriptionId)";
159
- };
160
- validate2.path = (input) => {
161
- if (input.includes("/") && !hasWhitespace(input)) return true;
162
- return "Path must contain a slash and not include spaces";
163
- };
164
- module2.exports = validate2;
165
- }
166
- });
167
-
168
- // generators/common-resources/monitoring/handle-yaml.js
169
- var require_handle_yaml = __commonJS({
170
- "generators/common-resources/monitoring/handle-yaml.js"(exports2, module2) {
171
- var ejs2 = require("ejs");
172
- function cleanAlerts2(alerts) {
173
- const copy = [...alerts];
174
- return copy.map((obj) => {
175
- if ("enabled" in obj && obj.enabled === true) {
176
- delete obj.enabled;
177
- }
178
- return obj;
179
- });
180
- }
181
- __name(cleanAlerts2, "cleanAlerts");
182
- var handleAlert = /* @__PURE__ */ __name((templates, answers) => {
183
- const alerts = [];
184
- Object.entries(templates).forEach(([, template]) => {
185
- const newAlert = JSON.parse(ejs2.render(JSON.stringify(template), answers));
186
- alerts.push(newAlert);
187
- });
188
- const cleanedAlerts = cleanAlerts2(alerts);
189
- return Array.isArray(cleanedAlerts) ? cleanedAlerts : [cleanedAlerts];
190
- }, "handleAlert");
191
- var handleAlerts2 = /* @__PURE__ */ __name((alerts, templates, answers) => {
192
- const newAlertsList = [];
193
- const newAlerts = handleAlert(templates, answers);
194
- newAlertsList.push(...newAlerts);
195
- return newAlertsList;
196
- }, "handleAlerts");
197
- var handleUptimeChecks2 = /* @__PURE__ */ __name((slos, templates, answers) => {
198
- const newUptimeCheck = JSON.parse(
199
- ejs2.render(JSON.stringify(templates), answers)
200
- );
201
- slos.push(newUptimeCheck);
202
- return slos;
203
- }, "handleUptimeChecks");
204
- module2.exports = {
205
- handleAlert,
206
- handleAlerts: handleAlerts2,
207
- handleUptimeChecks: handleUptimeChecks2,
208
- cleanAlerts: cleanAlerts2
209
- };
210
- }
211
- });
212
-
213
- // generators/common-resources/monitoring/index.js
214
- var path = require("path");
215
- var chalk = require("chalk");
216
- var fs = require("fs");
217
- var ejs = require("ejs");
218
- var yaml = require("js-yaml");
219
- var BaseGenerator = require_BaseGenerator();
220
- var { required } = require_validators();
221
- var validate = require_validate();
222
- var {
1
+ const path = require('path');
2
+ const chalk = require('chalk');
3
+ const fs = require('fs');
4
+ const ejs = require('ejs');
5
+ const yaml = require('js-yaml');
6
+ const BaseGenerator = require('../../../src/BaseGenerator');
7
+ const { required } = require('../../../src/validators');
8
+ const validate = require('./validate');
9
+ const {
223
10
  handleAlerts,
224
11
  handleUptimeChecks,
225
- cleanAlerts
226
- } = require_handle_yaml();
227
- var uptimeCheckTemplates = yaml.load(
228
- fs.readFileSync(`${__dirname}/templates/uptime-checks/uptime-checks.yaml`)
12
+ cleanAlerts,
13
+ } = require('./handle-yaml');
14
+
15
+ const uptimeCheckTemplates = yaml.load(
16
+ fs.readFileSync(`${__dirname}/templates/uptime-checks/uptime-checks.yaml`),
229
17
  );
230
- var alertTemplates = yaml.load(
231
- fs.readFileSync(`${__dirname}/templates/alerts/generic-infra.yaml`)
18
+ const alertTemplates = yaml.load(
19
+ fs.readFileSync(`${__dirname}/templates/alerts/generic-infra.yaml`),
232
20
  );
21
+
22
+ /* istanbul ignore next */
233
23
  module.exports = class extends BaseGenerator {
234
24
  async prompting() {
235
25
  this.answers = await this.prompt([
236
26
  {
237
- type: "list",
238
- name: "monitoringResource",
239
- message: "Select the resource you want to create:",
240
- choices: ["alerts", "uptime-checks"]
27
+ type: 'list',
28
+ name: 'monitoringResource',
29
+ message: 'Select the resource you want to create:',
30
+ choices: ['alerts', 'uptime-checks'],
241
31
  },
242
32
  {
243
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "alerts", "when"),
244
- type: "list",
245
- name: "alert",
246
- message: "Select the category of alerts you want to create:",
247
- choices: Object.keys(alertTemplates)
33
+ when: (response) => response.monitoringResource === 'alerts',
34
+ type: 'list',
35
+ name: 'alert',
36
+ message: 'Select the category of alerts you want to create:',
37
+ choices: Object.keys(alertTemplates),
248
38
  },
39
+
249
40
  {
250
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "alerts", "when"),
251
- type: "list",
252
- name: "allOrSpecific",
253
- message: "Do you want to create a specific alert or all recommended alerts?",
254
- choices: /* @__PURE__ */ __name((response) => [
41
+ when: (response) => response.monitoringResource === 'alerts',
42
+ type: 'list',
43
+ name: 'allOrSpecific',
44
+ message:
45
+ 'Do you want to create a specific alert or all recommended alerts?',
46
+ choices: (response) => [
255
47
  `All (${Object.keys(alertTemplates[response.alert] || {}).length})`,
256
- "Specific"
257
- ], "choices")
48
+ 'Specific',
49
+ ],
258
50
  },
259
51
  {
260
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "alerts" && response.allOrSpecific ===
261
- "Specific", "when"),
262
- type: "list",
263
- name: "specificAlert",
264
- message: /* @__PURE__ */ __name((response) => `Select the specific alert you want to create for ${response.alert}\
265
- :`, "message"),
266
- choices: /* @__PURE__ */ __name((response) => Object.keys(alertTemplates[response.alert]), "choices")
52
+ when: (response) =>
53
+ response.monitoringResource === 'alerts' &&
54
+ response.allOrSpecific === 'Specific',
55
+ type: 'list',
56
+ name: 'specificAlert',
57
+ message: (response) =>
58
+ `Select the specific alert you want to create for ${response.alert}:`,
59
+ choices: (response) => Object.keys(alertTemplates[response.alert]),
267
60
  },
268
61
  {
269
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "alerts", "when"),
270
- type: "input",
271
- name: "clan",
272
- message: "Please provide the clan name (ex: SRE, PNP, IAM...):",
273
- default: /* @__PURE__ */ __name(() => {
274
- const gitPath = path.resolve(process.cwd(), ".git");
62
+ when: (response) => response.monitoringResource === 'alerts',
63
+ type: 'input',
64
+ name: 'clan',
65
+ message: 'Please provide the clan name (ex: SRE, PNP, IAM...):',
66
+ default: () => {
67
+ const gitPath = path.resolve(process.cwd(), '.git');
275
68
  if (fs.existsSync(gitPath)) {
276
69
  const repoName = path.basename(process.cwd());
277
70
  const regex = /-([a-z]{3})-/i;
278
71
  const match = regex.exec(repoName);
279
- return match ? match[1].toUpperCase() : "";
72
+ return match ? match[1].toUpperCase() : '';
280
73
  }
281
- return "";
282
- }, "default"),
283
- validate: required && validate.clan
74
+ return '';
75
+ },
76
+ validate: required && validate.clan,
284
77
  },
285
78
  {
286
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "alerts", "when"),
287
- type: "input",
288
- name: "projectId",
289
- message: "Please provide the project ID:",
290
- validate: required && validate.projectId
79
+ when: (response) => response.monitoringResource === 'alerts',
80
+ type: 'input',
81
+ name: 'projectId',
82
+ message: 'Please provide the project ID:',
83
+ validate: required && validate.projectId,
291
84
  },
292
85
  {
293
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "uptime-checks", "when"),
294
- type: "input",
295
- name: "serviceName",
296
- message: "Please provide the namespace where the service resides:",
297
- default: /* @__PURE__ */ __name((response) => `${response.clan}-service`, "default"),
298
- validate: required && validate.serviceName
86
+ when: (response) => response.monitoringResource === 'uptime-checks',
87
+ type: 'input',
88
+ name: 'serviceName',
89
+ message: 'Please provide the namespace where the service resides:',
90
+ default: (response) => `${response.clan}-service`,
91
+ validate: required && validate.serviceName,
299
92
  },
300
93
  {
301
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "uptime-checks", "when"),
302
- type: "input",
303
- name: "hostname",
304
- message: "Please provide the base hostname of the service (ex: my-service.retailsvc.com):",
305
- validate: required && validate.hostname
94
+ when: (response) => response.monitoringResource === 'uptime-checks',
95
+ type: 'input',
96
+ name: 'hostname',
97
+ message:
98
+ 'Please provide the base hostname of the service (ex: my-service.retailsvc.com):',
99
+ validate: required && validate.hostname,
306
100
  },
307
101
  {
308
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "uptime-checks", "when"),
309
- type: "input",
310
- name: "runbookLink",
311
- message: "Please provide the full URL to your runbook in confluence (Leave empty if none):",
312
- validate: required && validate.runbookLink
102
+ when: (response) => response.monitoringResource === 'uptime-checks',
103
+ type: 'input',
104
+ name: 'runbookLink',
105
+ message:
106
+ 'Please provide the full URL to your runbook in confluence (Leave empty if none):',
107
+ validate: required && validate.runbookLink,
313
108
  },
314
109
  {
315
- when: /* @__PURE__ */ __name((response) => response.monitoringResource === "uptime-checks", "when"),
316
- type: "input",
317
- name: "path",
318
- message: "Please provide the path/endpoint to run the check against (ex: /health):",
319
- validate: required && validate.path
320
- }
110
+ when: (response) => response.monitoringResource === 'uptime-checks',
111
+ type: 'input',
112
+ name: 'path',
113
+ message:
114
+ 'Please provide the path/endpoint to run the check against (ex: /health):',
115
+ validate: required && validate.path,
116
+ },
321
117
  ]);
322
118
  }
119
+
323
120
  async writing() {
324
121
  const { monitoringResource } = this.answers;
325
122
  const resourceDir = path.join(
326
123
  process.cwd(),
327
- "infra",
328
- "prod",
329
- "monitoring",
330
- monitoringResource
124
+ 'infra',
125
+ 'prod',
126
+ 'monitoring',
127
+ monitoringResource,
331
128
  );
332
- const copyTemplate = /* @__PURE__ */ __name((resource, resourcePath, yamlPath) => {
129
+
130
+ const copyTemplate = (resource, resourcePath, yamlPath) => {
333
131
  if (!fs.existsSync(resourcePath))
334
132
  fs.mkdirSync(resourcePath, { recursive: true });
335
- if (!fs.existsSync(yamlPath)) fs.appendFileSync(yamlPath, "");
133
+ if (!fs.existsSync(yamlPath)) fs.appendFileSync(yamlPath, '');
336
134
  if (!fs.existsSync(`${resourcePath}/terragrunt.hcl`)) {
337
135
  this.fs.copyTpl(
338
136
  this.templatePath(`${resource}/terragrunt.hcl`),
339
137
  this.destinationPath(`${resourcePath}/terragrunt.hcl`),
340
- this.answers
138
+ this.answers,
341
139
  );
342
140
  }
343
- }, "copyTemplate");
344
- if (monitoringResource === "alerts" && this.answers.allOrSpecific === "Specific") {
141
+ };
142
+
143
+ /* istanbul ignore next */
144
+ if (
145
+ monitoringResource === 'alerts' &&
146
+ this.answers.allOrSpecific === 'Specific'
147
+ ) {
345
148
  const yamlPath = `${resourceDir}/base-specific.yaml`;
346
- copyTemplate("alerts", resourceDir, yamlPath);
347
- const oldYaml = yaml.load(fs.readFileSync(yamlPath, "utf8")) || [];
348
- const template = alertTemplates[this.answers.alert][this.answers.specificAlert];
149
+
150
+ copyTemplate('alerts', resourceDir, yamlPath);
151
+
152
+ const oldYaml = yaml.load(fs.readFileSync(yamlPath, 'utf8')) || [];
153
+ const template =
154
+ alertTemplates[this.answers.alert][this.answers.specificAlert];
349
155
  const newAlert = JSON.parse(
350
- ejs.render(JSON.stringify(template), this.answers)
156
+ ejs.render(JSON.stringify(template), this.answers),
351
157
  );
158
+
352
159
  oldYaml.push(newAlert);
353
160
  const cleanedAlerts = cleanAlerts(oldYaml);
161
+
354
162
  fs.writeFileSync(
355
163
  yamlPath,
356
164
  yaml.dump(cleanedAlerts, {
357
165
  lineWidth: 250,
358
- noArrayIndent: false
359
- })
166
+ noArrayIndent: false,
167
+ }),
360
168
  );
361
169
  }
362
- if (monitoringResource === "alerts" && this.answers.allOrSpecific === `All (${Object.keys(alertTemplates[this.answers.
363
- alert] || {}).length})`) {
170
+
171
+ /* istanbul ignore next */
172
+ if (
173
+ monitoringResource === 'alerts' &&
174
+ this.answers.allOrSpecific ===
175
+ `All (${Object.keys(alertTemplates[this.answers.alert] || {}).length})`
176
+ ) {
364
177
  const yamlPath = `${resourceDir}/base.yaml`;
365
- copyTemplate("alerts", resourceDir, yamlPath);
366
- const oldYaml = yaml.load(fs.readFileSync(yamlPath, "utf8")) || [];
178
+
179
+ copyTemplate('alerts', resourceDir, yamlPath);
180
+
181
+ const oldYaml = yaml.load(fs.readFileSync(yamlPath, 'utf8')) || [];
367
182
  const newAlerts = handleAlerts(
368
183
  oldYaml,
369
184
  alertTemplates[this.answers.alert],
370
- this.answers
185
+ this.answers,
371
186
  );
372
- const currentContent = fs.readFileSync(yamlPath, "utf8");
373
- if (currentContent !== "") {
374
- fs.appendFileSync(yamlPath, "\n");
187
+ const currentContent = fs.readFileSync(yamlPath, 'utf8');
188
+
189
+ if (currentContent !== '') {
190
+ fs.appendFileSync(yamlPath, '\n');
375
191
  }
192
+
376
193
  newAlerts.forEach((alert, index) => {
377
194
  fs.appendFileSync(
378
195
  yamlPath,
379
- yaml.dump([alert], { lineWidth: 250, noArrayIndent: false })
196
+ yaml.dump([alert], { lineWidth: 250, noArrayIndent: false }),
380
197
  );
381
198
  if (index !== newAlerts.length - 1) {
382
- fs.appendFileSync(yamlPath, "\n");
199
+ fs.appendFileSync(yamlPath, '\n');
383
200
  }
384
201
  });
385
202
  }
386
- if (monitoringResource === "uptime-checks") {
203
+
204
+ if (monitoringResource === 'uptime-checks') {
387
205
  const yamlPath = `${resourceDir}/uptime-checks.yaml`;
388
- copyTemplate("uptime-checks", resourceDir, yamlPath);
389
- const oldYaml = yaml.load(fs.readFileSync(yamlPath, "utf8")) || [];
206
+
207
+ copyTemplate('uptime-checks', resourceDir, yamlPath);
208
+
209
+ const oldYaml = yaml.load(fs.readFileSync(yamlPath, 'utf8')) || [];
390
210
  const newYaml = await handleUptimeChecks(
391
211
  oldYaml,
392
212
  uptimeCheckTemplates,
393
- this.answers
213
+ this.answers,
394
214
  );
215
+
395
216
  fs.writeFileSync(
396
217
  yamlPath,
397
- yaml.dump(newYaml, { lineWidth: 250, noArrayIndent: true })
218
+ yaml.dump(newYaml, { lineWidth: 250, noArrayIndent: true }),
398
219
  );
399
220
  }
400
221
  }
222
+
401
223
  end() {
402
224
  this.log(`
403
- ${chalk.yellow("Your monitoring resources have now been created.")}
404
- ${chalk.green("1.")} Please note that these are just example configurations and might need further adjustments.
405
- ${chalk.green("2.")} To finalize your configuration, please continue with manual editing of the generated files.
406
- ${chalk.green("3.")} Push the changes in a feature branch and open a pull request.
225
+ ${chalk.yellow('Your monitoring resources have now been created.')}
226
+ ${chalk.green('1.')} Please note that these are just example configurations and might need further adjustments.
227
+ ${chalk.green('2.')} To finalize your configuration, please continue with manual editing of the generated files.
228
+ ${chalk.green('3.')} Push the changes in a feature branch and open a pull request.
407
229
  `);
408
230
  }
409
231
  };