@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,234 +1,88 @@
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 fs = 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 && fs.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) => fs.readdirSync(parent).filter((f) => !f.startsWith(".")).filter((f) => fs.
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) => fs.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) => !fs.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) => !fs.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/init/clan-infra/tribe-clan-repo.js
116
- var require_tribe_clan_repo = __commonJS({
117
- "generators/init/clan-infra/tribe-clan-repo.js"(exports2, module2) {
118
- var path2 = require("path");
119
- var fs = require("fs");
120
- var getKeyValue = /* @__PURE__ */ __name((content, key) => {
121
- let value = "";
122
- content.split(/\r?\n/).forEach((line) => {
123
- if (line.includes(key)) {
124
- value = line.split("=")[1].replace('"', "").replace('"', "").trim();
125
- }
126
- });
127
- return value;
128
- }, "getKeyValue");
129
- var getTribeAndClanName2 = /* @__PURE__ */ __name(() => {
130
- const repoName = path2.basename(path2.resolve());
131
- const isClanInfraRepo = /^(?:\w+-){2}common(?:$|\W)$/.test(repoName);
132
- let tribe = "";
133
- let clan = "";
134
- if (isClanInfraRepo) {
135
- [tribe, clan] = repoName.split("-");
136
- } else {
137
- const commonHCL = path2.join("infra", "common.hcl");
138
- if (fs.existsSync(commonHCL)) {
139
- const commonHCLContent = fs.readFileSync(commonHCL, "utf8");
140
- tribe = getKeyValue(commonHCLContent, "tribe_name");
141
- clan = getKeyValue(commonHCLContent, "clan_name");
142
- }
143
- }
144
- return {
145
- tribe,
146
- clan
147
- };
148
- }, "getTribeAndClanName");
149
- module2.exports = getTribeAndClanName2;
150
- }
151
- });
1
+ const path = require('path');
2
+ const chalk = require('chalk');
3
+ const BaseGenerator = require('../../../src/BaseGenerator');
4
+ const { required } = require('../../../src/validators');
5
+ const getTribeAndClanName = require('../../init/clan-infra/tribe-clan-repo');
152
6
 
153
- // generators/common-resources/datastore/index.js
154
- var path = require("path");
155
- var chalk = require("chalk");
156
- var BaseGenerator = require_BaseGenerator();
157
- var { required } = require_validators();
158
- var getTribeAndClanName = require_tribe_clan_repo();
159
7
  module.exports = class extends BaseGenerator {
160
8
  prompting() {
161
9
  const prompts = [
162
10
  {
163
- type: "input",
164
- name: "serviceName",
11
+ type: 'input',
12
+ name: 'serviceName',
165
13
  default: getTribeAndClanName().clan,
166
- message: "Enter your service name or press enter to use clan name",
167
- validate: required
14
+ message: 'Enter your service name or press enter to use clan name',
15
+ validate: required,
168
16
  },
169
17
  {
170
- type: "input",
171
- name: "kind",
172
- message: "Please provide the entity kind which the index applies to",
173
- validate: required
18
+ type: 'input',
19
+ name: 'kind',
20
+ message: 'Please provide the entity kind which the index applies to',
21
+ validate: required,
174
22
  },
175
23
  {
176
- type: "list",
177
- name: "ancestor",
178
- message: "Select a policy for including ancestors in the index. Default value is NONE",
179
- default: "NONE",
180
- choices: ["NONE", "ALL_ANCESTORS"]
24
+ type: 'list',
25
+ name: 'ancestor',
26
+ message:
27
+ 'Select a policy for including ancestors in the index. Default value is NONE',
28
+ default: 'NONE',
29
+ choices: ['NONE', 'ALL_ANCESTORS'],
181
30
  },
182
31
  {
183
- type: "list",
184
- name: "createProperties",
185
- message: "Do you want to add an ordered list of properties to index on?",
186
- default: "yes",
187
- choices: ["yes", "no"]
32
+ type: 'list',
33
+ name: 'createProperties',
34
+ message:
35
+ 'Do you want to add an ordered list of properties to index on?',
36
+ default: 'yes',
37
+ choices: ['yes', 'no'],
188
38
  },
189
39
  {
190
- when: /* @__PURE__ */ __name((response) => response.createProperties === "yes", "when"),
191
- type: "input",
192
- name: "propertyName",
193
- message: "Please provide the property name to index",
194
- validate: required
40
+ when: (response) => response.createProperties === 'yes',
41
+ type: 'input',
42
+ name: 'propertyName',
43
+ message: 'Please provide the property name to index',
44
+ validate: required,
195
45
  },
196
46
  {
197
- when: /* @__PURE__ */ __name((response) => response.createProperties === "yes", "when"),
198
- type: "input",
199
- name: "propertyDirection",
200
- message: "Select the direction the index should optimize for sorting",
201
- default: "ASCENDING",
202
- choices: ["ASCENDING", "DESCENDING"]
203
- }
47
+ when: (response) => response.createProperties === 'yes',
48
+ type: 'input',
49
+ name: 'propertyDirection',
50
+ message: 'Select the direction the index should optimize for sorting',
51
+ default: 'ASCENDING',
52
+ choices: ['ASCENDING', 'DESCENDING'],
53
+ },
204
54
  ];
55
+
205
56
  return this.prompt(prompts).then((props) => {
206
57
  this.answers = props;
207
58
  });
208
59
  }
60
+
209
61
  writing() {
210
62
  const { serviceName, kind, ancestor, createProperties } = this.answers;
211
- ["prod", "staging"].forEach((env) => {
63
+
64
+ ['prod', 'staging'].forEach((env) => {
212
65
  this.copyDir(
213
- "datastore",
214
- path.join("infra", env, "datastore", serviceName),
66
+ 'datastore',
67
+ path.join('infra', env, 'datastore', serviceName),
215
68
  {
216
69
  ...this.answers,
217
70
  env,
218
71
  serviceName,
219
72
  kind,
220
73
  ancestor,
221
- createProperties
222
- }
74
+ createProperties,
75
+ },
223
76
  );
224
77
  });
225
78
  }
79
+
226
80
  end() {
227
81
  this.log(`
228
82
  ${chalk.green(`Your Datastore index has now been created. To finalize your configuration, please continue
229
83
  with manual editing of the generated files.`)}
230
- ${chalk.green("1.")} Review and add more indexes if needed.
231
- ${chalk.green("2.")} Push this change in a feature branch and open a pull request.
84
+ ${chalk.green('1.')} Review and add more indexes if needed.
85
+ ${chalk.green('2.')} Push this change in a feature branch and open a pull request.
232
86
  `);
233
87
  }
234
88
  };
@@ -1,156 +1,46 @@
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 fs = 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 && fs.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) => fs.readdirSync(parent).filter((f) => !f.startsWith(".")).filter((f) => fs.
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) => fs.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) => !fs.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) => !fs.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
- });
1
+ const path = require('path');
2
+ const chalk = require('chalk');
3
+ const BaseGenerator = require('../../../src/BaseGenerator');
4
+ const { required } = require('../../../src/validators');
114
5
 
115
- // generators/common-resources/elastic-cloud/index.js
116
- var path = require("path");
117
- var chalk = require("chalk");
118
- var BaseGenerator = require_BaseGenerator();
119
- var { required } = require_validators();
120
6
  module.exports = class extends BaseGenerator {
121
7
  prompting() {
122
8
  const prompts = [
123
9
  {
124
- type: "input",
125
- name: "deploymentName",
126
- message: "Please provide the name of the deployment",
127
- validate: required
128
- }
10
+ type: 'input',
11
+ name: 'deploymentName',
12
+ message: 'Please provide the name of the deployment',
13
+ validate: required,
14
+ },
129
15
  ];
16
+
130
17
  return this.prompt(prompts).then((props) => {
131
18
  this.answers = props;
132
19
  });
133
20
  }
21
+
134
22
  writing() {
135
23
  const { deploymentName } = this.answers;
136
- ["prod", "staging"].forEach((env) => {
137
- this.copyDir("elastic", path.join("infra", env, "elastic"), {
24
+
25
+ ['prod', 'staging'].forEach((env) => {
26
+ this.copyDir('elastic', path.join('infra', env, 'elastic'), {
138
27
  ...this.answers,
139
28
  env,
140
- deploymentName
29
+ deploymentName,
141
30
  });
142
31
  });
143
32
  }
33
+
144
34
  end() {
145
- const specStageFile = path.join("infra", "staging", "elastic");
146
- const specProdFile = path.join("infra", "prod", "elastic");
35
+ const specStageFile = path.join('infra', 'staging', 'elastic');
36
+ const specProdFile = path.join('infra', 'prod', 'elastic');
147
37
  this.log(`
148
38
  ${chalk.green(`Your Elastic Cloud deployments have now been created. To finalize your configuration, please continue
149
39
  with manual editing of the generated files.`)}
150
- ${chalk.green("1.")} Review Elastic configuration
151
- \u2192 ${chalk.cyan(path.join(specStageFile, "spec.hcl"))}
152
- \u2192 ${chalk.cyan(path.join(specProdFile, "spec.hcl"))}
153
- ${chalk.green("2.")} Push this change in a feature branch and open a pull request.
40
+ ${chalk.green('1.')} Review Elastic configuration
41
+ \u2192 ${chalk.cyan(path.join(specStageFile, 'spec.hcl'))}
42
+ \u2192 ${chalk.cyan(path.join(specProdFile, 'spec.hcl'))}
43
+ ${chalk.green('2.')} Push this change in a feature branch and open a pull request.
154
44
  `);
155
45
  }
156
46
  };
@@ -0,0 +1,76 @@
1
+ const fs = require('fs');
2
+ const yaml = require('js-yaml');
3
+
4
+ const handleHotPhase = (answers, phaseData) => {
5
+ if (answers.hotReadonly === 'true') {
6
+ phaseData.readonly = { enabled: true };
7
+ }
8
+
9
+ if (answers.hotPriority) {
10
+ phaseData.set_priority = { priority: answers.hotPriority };
11
+ }
12
+ };
13
+
14
+ const handleColdPhase = (answers, phaseData) => {
15
+ if (answers.coldReadonly === 'true') {
16
+ phaseData.readonly = { enabled: true };
17
+ }
18
+
19
+ if (answers.coldPriority) {
20
+ phaseData.set_priority = { priority: answers.coldPriority };
21
+ }
22
+
23
+ if (answers.coldFreeze === 'true') {
24
+ phaseData.freeze = { enabled: true };
25
+ }
26
+ };
27
+
28
+ const handleWarmPhase = (answers, phaseData) => {
29
+ if (answers.warmReadonly === 'true') {
30
+ phaseData.readonly = { enabled: true };
31
+ }
32
+
33
+ if (answers.warmPriority) {
34
+ phaseData.set_priority = { priority: answers.warmPriority };
35
+ }
36
+
37
+ if (answers.warmMigrate === 'true') {
38
+ phaseData.migrate = { enabled: true };
39
+ }
40
+ };
41
+
42
+ const handlePolicies = async (answers, yamlPath) => {
43
+ const existingData = yaml.load(fs.readFileSync(yamlPath, 'utf8')) || {
44
+ policies: [],
45
+ };
46
+
47
+ const policy = {
48
+ name: answers.policyName,
49
+ };
50
+
51
+ answers.phase.forEach((phase) => {
52
+ const phaseData = {
53
+ min_age: answers[`${phase}MinAge`],
54
+ };
55
+
56
+ if (phase === 'hot') {
57
+ handleHotPhase(answers, phaseData);
58
+ }
59
+
60
+ if (phase === 'cold') {
61
+ handleColdPhase(answers, phaseData);
62
+ }
63
+
64
+ if (phase === 'warm') {
65
+ handleWarmPhase(answers, phaseData);
66
+ }
67
+
68
+ policy[phase] = phaseData;
69
+ });
70
+
71
+ existingData.policies.push(policy);
72
+
73
+ fs.writeFileSync(yamlPath, yaml.dump(existingData));
74
+ };
75
+
76
+ module.exports = handlePolicies;