@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.
- package/dist/generators/clan-resources/clan-project/index.js +89 -189
- package/dist/generators/common-resources/bigquery/index.js +172 -267
- package/dist/generators/common-resources/budget/index.js +67 -153
- package/dist/generators/common-resources/cloud-armor/index.js +17 -167
- package/dist/generators/common-resources/cloud-storage/index.js +96 -205
- package/dist/generators/common-resources/cloudsql/index.js +71 -177
- package/dist/generators/common-resources/cloudsql-database/index.js +40 -287
- package/dist/generators/common-resources/confluent-cluster/index.js +23 -132
- package/dist/generators/common-resources/datastore/index.js +48 -194
- package/dist/generators/common-resources/elastic-cloud/index.js +22 -132
- package/dist/generators/common-resources/elastic-index-policy/handle-yaml.js +76 -0
- package/dist/generators/common-resources/elastic-index-policy/index.js +131 -286
- package/dist/generators/common-resources/elastic-template/index.js +52 -162
- package/dist/generators/common-resources/firestore/index.js +93 -233
- package/dist/generators/common-resources/iam/index.js +35 -157
- package/dist/generators/common-resources/iam/valid-prefix.js +8 -0
- package/dist/generators/common-resources/kafka-connect/index.js +35 -144
- package/dist/generators/common-resources/kafka-topics/index.js +20 -129
- package/dist/generators/common-resources/kms/index.js +31 -141
- package/dist/generators/common-resources/memorystore/index.js +42 -328
- package/dist/generators/common-resources/monitoring/handle-yaml.js +49 -0
- package/dist/generators/common-resources/monitoring/index.js +144 -322
- package/dist/generators/common-resources/monitoring/templates/alerts/generic-infra.yaml +37 -2
- package/dist/generators/common-resources/monitoring/validate.js +58 -0
- package/dist/generators/common-resources/pubsub/append.js +130 -0
- package/dist/generators/common-resources/pubsub/get-gcp-projects.js +34 -0
- package/dist/generators/common-resources/pubsub/handle-subscribers.js +68 -0
- package/dist/generators/common-resources/pubsub/index.js +194 -536
- package/dist/generators/common-resources/pubsub/validate.js +53 -0
- package/dist/generators/common-resources/scheduler/append.js +85 -0
- package/dist/generators/common-resources/scheduler/index.js +62 -249
- package/dist/generators/common-resources/spanner/append.js +31 -0
- package/dist/generators/common-resources/spanner/index.js +102 -269
- package/dist/generators/common-resources/spanner/validate.js +38 -0
- package/dist/generators/docs/rca/index.js +25 -135
- package/dist/generators/docs/runbook/index.js +16 -126
- package/dist/generators/docs/srb/index.js +33 -147
- package/dist/generators/docs/srb/run-docker.js +2 -0
- package/dist/generators/init/clan-infra/gcp-projects.js +47 -0
- package/dist/generators/init/clan-infra/index.js +95 -290
- package/dist/generators/init/clan-infra/tribe-clan-repo.js +38 -0
- package/dist/generators/init/clan-infra/validate.js +8 -0
- package/dist/generators/maintenance/manage-states/index.js +142 -219
- package/dist/generators/maintenance/update-modules/index.js +56 -155
- package/dist/generators/organization/clan-project/googlecloud.js +124 -0
- package/dist/generators/organization/clan-project/index.js +81 -303
- package/dist/node_modules/.package-lock.json +88 -31
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/bucket.js +5 -5
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/file.d.ts +1 -0
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/file.js +10 -1
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/storage.js +1 -1
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/transfer-manager.d.ts +4 -4
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/transfer-manager.js +4 -4
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/util.d.ts +1 -1
- package/dist/node_modules/@google-cloud/storage/build/cjs/src/util.js +2 -2
- package/dist/node_modules/@google-cloud/storage/build/esm/src/bucket.js +5 -5
- package/dist/node_modules/@google-cloud/storage/build/esm/src/file.d.ts +1 -0
- package/dist/node_modules/@google-cloud/storage/build/esm/src/file.js +10 -1
- package/dist/node_modules/@google-cloud/storage/build/esm/src/storage.js +1 -1
- package/dist/node_modules/@google-cloud/storage/build/esm/src/transfer-manager.d.ts +4 -4
- package/dist/node_modules/@google-cloud/storage/build/esm/src/transfer-manager.js +4 -4
- package/dist/node_modules/@google-cloud/storage/build/esm/src/util.d.ts +1 -1
- package/dist/node_modules/@google-cloud/storage/build/esm/src/util.js +2 -2
- package/dist/node_modules/@google-cloud/storage/package.json +5 -5
- package/dist/package.json +45 -0
- package/dist/src/BaseGenerator.js +84 -0
- package/dist/src/SecretsGenerator.js +137 -0
- package/dist/src/cli.js +54 -255
- package/dist/src/dependency-check.js +48 -0
- package/dist/src/update-check.js +38 -0
- package/dist/src/validators.js +33 -0
- package/dist/src/yeoman.js +80 -0
- package/package.json +2 -3
- package/dist/node_modules/@google-cloud/storage/CHANGELOG.md +0 -1769
|
@@ -1,236 +1,125 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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/cloud-storage/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:
|
|
125
|
-
name:
|
|
126
|
-
message:
|
|
127
|
-
validate: required
|
|
10
|
+
type: 'input',
|
|
11
|
+
name: 'bucketName',
|
|
12
|
+
message: 'Please provide the Cloud Storage bucket name',
|
|
13
|
+
validate: required,
|
|
128
14
|
},
|
|
129
15
|
{
|
|
130
|
-
type:
|
|
131
|
-
name:
|
|
132
|
-
message:
|
|
133
|
-
default:
|
|
134
|
-
choices: [
|
|
16
|
+
type: 'list',
|
|
17
|
+
name: 'versioning',
|
|
18
|
+
message: 'Do you want to enable versioning for the bucket?',
|
|
19
|
+
default: 'true',
|
|
20
|
+
choices: ['true', 'false'],
|
|
135
21
|
},
|
|
136
22
|
{
|
|
137
|
-
type:
|
|
138
|
-
name:
|
|
139
|
-
message:
|
|
140
|
-
validate: required
|
|
23
|
+
type: 'input',
|
|
24
|
+
name: 'prefix',
|
|
25
|
+
message: 'Please provide the prefix for the bucket name',
|
|
26
|
+
validate: required,
|
|
141
27
|
},
|
|
142
28
|
{
|
|
143
|
-
type:
|
|
144
|
-
name:
|
|
145
|
-
message:
|
|
146
|
-
default:
|
|
147
|
-
choices: [
|
|
29
|
+
type: 'list',
|
|
30
|
+
name: 'lifecycleRules',
|
|
31
|
+
message: 'Do you want to set up lifecycle rules for the bucket?',
|
|
32
|
+
default: 'false',
|
|
33
|
+
choices: ['true', 'false'],
|
|
148
34
|
},
|
|
149
35
|
{
|
|
150
|
-
when:
|
|
151
|
-
type:
|
|
152
|
-
name:
|
|
153
|
-
message:
|
|
154
|
-
default:
|
|
155
|
-
choices: [
|
|
36
|
+
when: (response) => response.lifecycleRules === 'true',
|
|
37
|
+
type: 'list',
|
|
38
|
+
name: 'action',
|
|
39
|
+
message: 'Select the action of this Lifecycle Rule',
|
|
40
|
+
default: 'Delete',
|
|
41
|
+
choices: ['Delete', 'SetStorageClass'],
|
|
156
42
|
},
|
|
157
43
|
{
|
|
158
|
-
when:
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
44
|
+
when: (response) =>
|
|
45
|
+
response.lifecycleRules === 'true' &&
|
|
46
|
+
response.action === 'SetStorageClass',
|
|
47
|
+
type: 'list',
|
|
48
|
+
name: 'storageClass',
|
|
49
|
+
message: 'Select the Storage Class for objects in the bucket',
|
|
50
|
+
default: 'STANDARD',
|
|
164
51
|
choices: [
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
]
|
|
52
|
+
'STANDARD',
|
|
53
|
+
'MULTI_REGIONAL',
|
|
54
|
+
'REGIONAL',
|
|
55
|
+
'NEARLINE',
|
|
56
|
+
'COLDLINE',
|
|
57
|
+
'ARCHIVE',
|
|
58
|
+
],
|
|
172
59
|
},
|
|
173
60
|
{
|
|
174
|
-
when:
|
|
175
|
-
type:
|
|
176
|
-
name:
|
|
177
|
-
message:
|
|
178
|
-
|
|
61
|
+
when: (response) => response.lifecycleRules === 'true',
|
|
62
|
+
type: 'input',
|
|
63
|
+
name: 'age',
|
|
64
|
+
message:
|
|
65
|
+
'Minimum age of an object in days to satisfy the condition. Use null to not set the value',
|
|
66
|
+
validate: required,
|
|
179
67
|
},
|
|
180
68
|
{
|
|
181
|
-
when:
|
|
182
|
-
type:
|
|
183
|
-
name:
|
|
184
|
-
message:
|
|
185
|
-
the specified date in UTC. Use null to not set the value
|
|
186
|
-
validate: required
|
|
69
|
+
when: (response) => response.lifecycleRules === 'true',
|
|
70
|
+
type: 'input',
|
|
71
|
+
name: 'createdBefore',
|
|
72
|
+
message:
|
|
73
|
+
'A date in format YYYY-MM-DD. This condition is satisfied when an object is created before midnight of the specified date in UTC. Use null to not set the value',
|
|
74
|
+
validate: required,
|
|
187
75
|
},
|
|
188
76
|
{
|
|
189
|
-
when:
|
|
190
|
-
type:
|
|
191
|
-
name:
|
|
192
|
-
message:
|
|
193
|
-
the value
|
|
194
|
-
default:
|
|
195
|
-
choices: [
|
|
77
|
+
when: (response) => response.lifecycleRules === 'true',
|
|
78
|
+
type: 'list',
|
|
79
|
+
name: 'withState',
|
|
80
|
+
message:
|
|
81
|
+
'Match to live and/or archived objects. Unversioned buckets have only live objects. Use null to not set the value',
|
|
82
|
+
default: 'LIVE',
|
|
83
|
+
choices: ['LIVE', 'ARCHIVED', 'ANY', 'null'],
|
|
196
84
|
},
|
|
197
85
|
{
|
|
198
|
-
when:
|
|
199
|
-
type:
|
|
200
|
-
name:
|
|
201
|
-
message:
|
|
202
|
-
STANDARD, MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE, DURABLE_REDUCED_AVAILABILITY. Use null to not set the
|
|
203
|
-
|
|
204
|
-
validate: required
|
|
86
|
+
when: (response) => response.lifecycleRules === 'true',
|
|
87
|
+
type: 'input',
|
|
88
|
+
name: 'matchesStorageClass',
|
|
89
|
+
message:
|
|
90
|
+
'Specify comma delimited string of Storage Class of objects to satisfy the condition. Supported values: STANDARD, MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE, DURABLE_REDUCED_AVAILABILITY. Use null to not set the value',
|
|
91
|
+
validate: required,
|
|
205
92
|
},
|
|
206
93
|
{
|
|
207
|
-
when:
|
|
208
|
-
type:
|
|
209
|
-
name:
|
|
210
|
-
message:
|
|
211
|
-
|
|
212
|
-
validate: required
|
|
94
|
+
when: (response) => response.lifecycleRules === 'true',
|
|
95
|
+
type: 'input',
|
|
96
|
+
name: 'numNewerVersions',
|
|
97
|
+
message:
|
|
98
|
+
'Relevant only for versioned objects. The number of newer versions of an object to satisfy the condition. Use null to not set the value',
|
|
99
|
+
validate: required,
|
|
213
100
|
},
|
|
214
101
|
{
|
|
215
|
-
type:
|
|
216
|
-
name:
|
|
217
|
-
message:
|
|
218
|
-
default:
|
|
219
|
-
choices: [
|
|
102
|
+
type: 'list',
|
|
103
|
+
name: 'retentionPolicy',
|
|
104
|
+
message: 'Do you want to set up a retention period for the bucket?',
|
|
105
|
+
default: 'false',
|
|
106
|
+
choices: ['true', 'false'],
|
|
220
107
|
},
|
|
221
108
|
{
|
|
222
|
-
when:
|
|
223
|
-
type:
|
|
224
|
-
name:
|
|
225
|
-
message:
|
|
226
|
-
|
|
227
|
-
validate: required
|
|
228
|
-
}
|
|
109
|
+
when: (response) => response.retentionPolicy === 'true',
|
|
110
|
+
type: 'input',
|
|
111
|
+
name: 'retentionPeriod',
|
|
112
|
+
message:
|
|
113
|
+
'The period of time, in seconds, that objects in the bucket must be retained and cannot be deleted, overwritten, or archived. The value must be less than 2147483647 seconds',
|
|
114
|
+
validate: required,
|
|
115
|
+
},
|
|
229
116
|
];
|
|
117
|
+
|
|
230
118
|
return this.prompt(prompts).then((props) => {
|
|
231
119
|
this.answers = props;
|
|
232
120
|
});
|
|
233
121
|
}
|
|
122
|
+
|
|
234
123
|
writing() {
|
|
235
124
|
const {
|
|
236
125
|
bucketName,
|
|
@@ -245,10 +134,11 @@ rwritten, or archived. The value must be less than 2147483647 seconds",
|
|
|
245
134
|
withState,
|
|
246
135
|
matchesStorageClass,
|
|
247
136
|
numNewerVersions,
|
|
248
|
-
retentionPeriod
|
|
137
|
+
retentionPeriod,
|
|
249
138
|
} = this.answers;
|
|
250
|
-
|
|
251
|
-
|
|
139
|
+
|
|
140
|
+
['prod', 'staging'].forEach((env) => {
|
|
141
|
+
this.copyDir('cloud-storage', path.join('infra', env, 'cloud-storage'), {
|
|
252
142
|
...this.answers,
|
|
253
143
|
env,
|
|
254
144
|
bucketName,
|
|
@@ -263,14 +153,15 @@ rwritten, or archived. The value must be less than 2147483647 seconds",
|
|
|
263
153
|
withState,
|
|
264
154
|
matchesStorageClass,
|
|
265
155
|
numNewerVersions,
|
|
266
|
-
retentionPeriod
|
|
156
|
+
retentionPeriod,
|
|
267
157
|
});
|
|
268
158
|
});
|
|
269
159
|
}
|
|
160
|
+
|
|
270
161
|
end() {
|
|
271
162
|
this.log(`
|
|
272
|
-
${chalk.green(
|
|
273
|
-
${chalk.yellow(
|
|
274
|
-
${chalk.green(
|
|
163
|
+
${chalk.green('Your Cloud Storage resources have now been created.')}
|
|
164
|
+
${chalk.yellow('Note: Bucket names are globally unique, the staging bucket has the suffix -staging')}
|
|
165
|
+
${chalk.green('1.')} Push this change in a feature branch and open a pull request.`);
|
|
275
166
|
}
|
|
276
167
|
};
|
|
@@ -1,232 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
});
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const BaseGenerator = require('../../../src/BaseGenerator');
|
|
42
4
|
|
|
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, 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: required,
|
|
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, required, 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, required, filename), "validate"),
|
|
107
|
-
filter: this.kebabCase
|
|
108
|
-
}
|
|
109
|
-
];
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
// generators/common-resources/cloudsql/index.js
|
|
116
|
-
var path = require("path");
|
|
117
|
-
var chalk = require("chalk");
|
|
118
|
-
var BaseGenerator = require_BaseGenerator();
|
|
119
5
|
module.exports = class extends BaseGenerator {
|
|
120
6
|
prompting() {
|
|
121
7
|
const prompts = [
|
|
122
8
|
{
|
|
123
|
-
type:
|
|
124
|
-
name:
|
|
125
|
-
message:
|
|
9
|
+
type: 'list',
|
|
10
|
+
name: 'instanceType',
|
|
11
|
+
message: 'Select Cloud SQL database instance type',
|
|
126
12
|
store: true,
|
|
127
|
-
default:
|
|
128
|
-
choices: [
|
|
13
|
+
default: 'postgres-clan',
|
|
14
|
+
choices: ['postgres-clan', 'mysql', 'mssql'],
|
|
129
15
|
},
|
|
130
16
|
{
|
|
131
|
-
type:
|
|
132
|
-
name:
|
|
133
|
-
message:
|
|
17
|
+
type: 'list',
|
|
18
|
+
name: 'instanceDatabaseVersion',
|
|
19
|
+
message: 'Select Database Version',
|
|
134
20
|
store: true,
|
|
135
|
-
default:
|
|
21
|
+
default: (response) => {
|
|
136
22
|
const defaultTypes = {
|
|
137
|
-
|
|
138
|
-
mysql:
|
|
139
|
-
mssql:
|
|
23
|
+
'postgres-clan': 'POSTGRES_16',
|
|
24
|
+
mysql: 'MYSQL_5_7',
|
|
25
|
+
mssql: 'SQLSERVER_2017_STANDARD',
|
|
140
26
|
};
|
|
141
27
|
return defaultTypes[response.instanceType];
|
|
142
|
-
},
|
|
143
|
-
choices:
|
|
28
|
+
},
|
|
29
|
+
choices: (response) => {
|
|
144
30
|
const tierTypes = {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
31
|
+
'postgres-clan': [
|
|
32
|
+
'POSTGRES_13',
|
|
33
|
+
'POSTGRES_14',
|
|
34
|
+
'POSTGRES_15',
|
|
35
|
+
'POSTGRES_16',
|
|
150
36
|
],
|
|
151
|
-
mysql: [
|
|
37
|
+
mysql: ['MYSQL_5_6', 'MYSQL_5_7'],
|
|
152
38
|
mssql: [
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
]
|
|
39
|
+
'SQLSERVER_2017_STANDARD',
|
|
40
|
+
'SQLSERVER_2017_ENTERPRISE',
|
|
41
|
+
'SQLSERVER_2017_EXPRESS',
|
|
42
|
+
'SQLSERVER_2017_WEB',
|
|
43
|
+
],
|
|
158
44
|
};
|
|
159
45
|
return tierTypes[response.instanceType];
|
|
160
|
-
},
|
|
46
|
+
},
|
|
161
47
|
},
|
|
162
48
|
{
|
|
163
|
-
type:
|
|
164
|
-
name:
|
|
165
|
-
message:
|
|
49
|
+
type: 'number',
|
|
50
|
+
name: 'diskSize',
|
|
51
|
+
message: 'Enter the disk size for the instance, in GB',
|
|
166
52
|
store: true,
|
|
167
|
-
default: 10
|
|
53
|
+
default: 10,
|
|
168
54
|
},
|
|
169
55
|
{
|
|
170
|
-
type:
|
|
171
|
-
name:
|
|
172
|
-
message:
|
|
173
|
-
default:
|
|
174
|
-
choices: [
|
|
175
|
-
}
|
|
56
|
+
type: 'list',
|
|
57
|
+
name: 'enableBackups',
|
|
58
|
+
message: 'Enable Databases backup?',
|
|
59
|
+
default: 'true',
|
|
60
|
+
choices: ['true', 'false'],
|
|
61
|
+
},
|
|
176
62
|
];
|
|
63
|
+
|
|
177
64
|
return this.prompt(prompts).then((props) => {
|
|
178
65
|
this.answers = props;
|
|
179
66
|
});
|
|
180
67
|
}
|
|
68
|
+
|
|
181
69
|
writing() {
|
|
182
70
|
const { instanceType } = this.answers;
|
|
183
|
-
|
|
71
|
+
|
|
72
|
+
// CloudSQL Instance
|
|
73
|
+
['prod', 'staging'].forEach((env) => {
|
|
184
74
|
this.copyDir(
|
|
185
|
-
path.join(instanceType,
|
|
186
|
-
path.join(
|
|
75
|
+
path.join(instanceType, 'instance'),
|
|
76
|
+
path.join('infra', env, 'cloud-sql', instanceType, 'instance'),
|
|
187
77
|
{
|
|
188
78
|
...this.answers,
|
|
189
|
-
env
|
|
190
|
-
}
|
|
79
|
+
env,
|
|
80
|
+
},
|
|
191
81
|
);
|
|
192
82
|
});
|
|
193
|
-
|
|
83
|
+
|
|
84
|
+
// CloudSQL Instance secrets
|
|
85
|
+
['prod', 'staging'].forEach((env) => {
|
|
194
86
|
this.copyDir(
|
|
195
|
-
path.join(instanceType,
|
|
196
|
-
path.join(
|
|
87
|
+
path.join(instanceType, 'instance-secrets'),
|
|
88
|
+
path.join('infra', env, 'cloud-sql', instanceType, 'secrets'),
|
|
197
89
|
{
|
|
198
90
|
...this.answers,
|
|
199
|
-
env
|
|
200
|
-
}
|
|
91
|
+
env,
|
|
92
|
+
},
|
|
201
93
|
);
|
|
202
94
|
});
|
|
203
95
|
}
|
|
96
|
+
|
|
204
97
|
end() {
|
|
205
98
|
const { instanceType } = this.answers;
|
|
99
|
+
|
|
206
100
|
const specStageFile = path.join(
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
101
|
+
'infra',
|
|
102
|
+
'staging',
|
|
103
|
+
'cloud-sql',
|
|
210
104
|
instanceType,
|
|
211
|
-
|
|
212
|
-
|
|
105
|
+
'instance',
|
|
106
|
+
'spec.hcl',
|
|
213
107
|
);
|
|
214
108
|
const specProdFile = path.join(
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
109
|
+
'infra',
|
|
110
|
+
'prod',
|
|
111
|
+
'cloud-sql',
|
|
218
112
|
instanceType,
|
|
219
|
-
|
|
220
|
-
|
|
113
|
+
'instance',
|
|
114
|
+
'spec.hcl',
|
|
221
115
|
);
|
|
116
|
+
|
|
222
117
|
this.log(`
|
|
223
|
-
${chalk.green(`Your CloudSQL ${chalk.cyan(instanceType)} instance have now been created. To finalize your configuration
|
|
224
|
-
please continue
|
|
118
|
+
${chalk.green(`Your CloudSQL ${chalk.cyan(instanceType)} instance have now been created. To finalize your configuration, please continue
|
|
225
119
|
with manual editing of the generated files.`)}
|
|
226
|
-
${chalk.green(
|
|
120
|
+
${chalk.green('1.')} Review and change specs if needed.
|
|
227
121
|
\u2192 ${chalk.cyan(specStageFile)}
|
|
228
122
|
\u2192 ${chalk.cyan(specProdFile)}
|
|
229
|
-
${chalk.green(
|
|
123
|
+
${chalk.green('2.')} Push this change in a feature branch and open a pull request.
|
|
230
124
|
`);
|
|
231
125
|
}
|
|
232
126
|
};
|