@hiiretail/gcp-infra-generators 1.0.0 → 1.0.1
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/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 +81 -23
- 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 +1 -2
|
@@ -1,533 +1,180 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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/pubsub/validate.js
|
|
116
|
-
var require_validate = __commonJS({
|
|
117
|
-
"generators/common-resources/pubsub/validate.js"(exports2, module2) {
|
|
118
|
-
var fs2 = require("fs");
|
|
119
|
-
var path2 = require("path");
|
|
120
|
-
var validSystemName2 = /* @__PURE__ */ __name((input) => {
|
|
121
|
-
if (input.replace(/\s/g, "").length === 3) {
|
|
122
|
-
return true;
|
|
123
|
-
}
|
|
124
|
-
return "System name must be 3 characters";
|
|
125
|
-
}, "validSystemName");
|
|
126
|
-
var validVersion2 = /* @__PURE__ */ __name((input) => {
|
|
127
|
-
const regex = "^v[0-9]$";
|
|
128
|
-
if (input.match(regex)) {
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
return "Not supported input of version";
|
|
132
|
-
}, "validVersion");
|
|
133
|
-
var validSubscriberName2 = /* @__PURE__ */ __name((input) => {
|
|
134
|
-
const systemName = input.split(".")[0];
|
|
135
|
-
const serviceName = input.split(".")[1];
|
|
136
|
-
const serviceNameRexep = "^[a-zA-Z-_]+$";
|
|
137
|
-
if (systemName.replace(/\s/g, "").length === 3 && serviceName.match(serviceNameRexep)) {
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
return "Not supported input for subscriber name";
|
|
141
|
-
}, "validSubscriberName");
|
|
142
|
-
var checkExistingTopicPath2 = /* @__PURE__ */ __name((input) => {
|
|
143
|
-
const topicDirPath = path2.join(
|
|
144
|
-
process.cwd(),
|
|
145
|
-
"infra",
|
|
146
|
-
"staging",
|
|
147
|
-
"pubsub",
|
|
148
|
-
input
|
|
149
|
-
);
|
|
150
|
-
if (fs2.existsSync(topicDirPath)) {
|
|
151
|
-
return true;
|
|
152
|
-
}
|
|
153
|
-
return "Topic does not exist. Check the spelling";
|
|
154
|
-
}, "checkExistingTopicPath");
|
|
155
|
-
module2.exports = {
|
|
156
|
-
validSystemName: validSystemName2,
|
|
157
|
-
validVersion: validVersion2,
|
|
158
|
-
validSubscriberName: validSubscriberName2,
|
|
159
|
-
checkExistingTopicPath: checkExistingTopicPath2
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// generators/common-resources/pubsub/append.js
|
|
165
|
-
var require_append = __commonJS({
|
|
166
|
-
"generators/common-resources/pubsub/append.js"(exports2, module2) {
|
|
167
|
-
var yaml = require("js-yaml");
|
|
168
|
-
var fs2 = require("fs");
|
|
169
|
-
var addDLQ = /* @__PURE__ */ __name(async (yamlArray, env, dlqTopic) => {
|
|
170
|
-
if (env === "prod") {
|
|
171
|
-
yamlArray[0].dead_letter_topic = dlqTopic;
|
|
172
|
-
}
|
|
173
|
-
}, "addDLQ");
|
|
174
|
-
var appendNotIncludePull = /* @__PURE__ */ __name(async (inputs, subscriptionFilePath, dlqTopic) => {
|
|
175
|
-
const pullArray = [];
|
|
176
|
-
pullArray.push({
|
|
177
|
-
name: `${inputs.existingTopic}+${inputs.subscriberName}`,
|
|
178
|
-
ack_deadline_seconds: "60",
|
|
179
|
-
expiration_policy: ""
|
|
180
|
-
});
|
|
181
|
-
await addDLQ(pullArray, inputs.env, dlqTopic);
|
|
182
|
-
const yamlPullArray = yaml.dump(pullArray);
|
|
183
|
-
fs2.appendFileSync(
|
|
184
|
-
subscriptionFilePath,
|
|
185
|
-
`pull_subscriptions:
|
|
186
|
-
${yamlPullArray}`
|
|
187
|
-
);
|
|
188
|
-
}, "appendNotIncludePull");
|
|
189
|
-
var appendIncludePull = /* @__PURE__ */ __name(async (fileContent, originalContentYaml, subscriptionFilePath, input, dlqTopic) => {
|
|
190
|
-
if (fileContent.includes("pull_subscriptions")) {
|
|
191
|
-
const pullArray = Object.values(originalContentYaml.pull_subscriptions);
|
|
192
|
-
const yamlPullArray = yaml.dump(pullArray);
|
|
193
|
-
fs2.writeFileSync(
|
|
194
|
-
subscriptionFilePath,
|
|
195
|
-
`pull_subscriptions:
|
|
196
|
-
${yamlPullArray}`
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
const newPullArray = [];
|
|
200
|
-
newPullArray.push({
|
|
201
|
-
name: `${input.existingTopic}+${input.subscriberName}`,
|
|
202
|
-
ack_deadline_seconds: "60",
|
|
203
|
-
expiration_policy: ""
|
|
204
|
-
});
|
|
205
|
-
await addDLQ(newPullArray, input.env, dlqTopic);
|
|
206
|
-
const finalYamlPullArray = yaml.dump(newPullArray);
|
|
207
|
-
fs2.appendFileSync(subscriptionFilePath, finalYamlPullArray);
|
|
208
|
-
if (fileContent.includes("push_subscriptions")) {
|
|
209
|
-
const pushArray = Object.values(originalContentYaml.push_subscriptions);
|
|
210
|
-
const yamlPushArray = yaml.dump(pushArray);
|
|
211
|
-
fs2.appendFileSync(
|
|
212
|
-
subscriptionFilePath,
|
|
213
|
-
`push_subscriptions:
|
|
214
|
-
${yamlPushArray}`
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
}, "appendIncludePull");
|
|
218
|
-
var appendNotIncludePush = /* @__PURE__ */ __name(async (inputs, subscriptionFilePath, dlqTopic) => {
|
|
219
|
-
const pushArray = [];
|
|
220
|
-
pushArray.push({
|
|
221
|
-
name: `${inputs.existingTopic}+${inputs.subscriberName}`,
|
|
222
|
-
push_endpoint: inputs.pushEndpoint,
|
|
223
|
-
oidc_service_account_email: inputs.oidcEmail,
|
|
224
|
-
audience: inputs.audience,
|
|
225
|
-
expiration_policy: "",
|
|
226
|
-
filter: `attributes.Consumer = "${inputs.subscriberName}" OR NOT attributes:Consumer`
|
|
227
|
-
});
|
|
228
|
-
await addDLQ(pushArray, inputs.env, dlqTopic);
|
|
229
|
-
const yamlPushArray = yaml.dump(pushArray);
|
|
230
|
-
fs2.appendFileSync(
|
|
231
|
-
subscriptionFilePath,
|
|
232
|
-
`push_subscriptions:
|
|
233
|
-
${yamlPushArray}`
|
|
234
|
-
);
|
|
235
|
-
}, "appendNotIncludePush");
|
|
236
|
-
var appendIncludePush = /* @__PURE__ */ __name(async (fileContent, originalContentYaml, subscriptionFilePath, input, dlqTopic) => {
|
|
237
|
-
if (fileContent.includes("push_subscriptions")) {
|
|
238
|
-
const pushArray = Object.values(originalContentYaml.push_subscriptions);
|
|
239
|
-
const yamlPushArray2 = yaml.dump(pushArray);
|
|
240
|
-
fs2.writeFileSync(
|
|
241
|
-
subscriptionFilePath,
|
|
242
|
-
`push_subscriptions:
|
|
243
|
-
${yamlPushArray2}`
|
|
244
|
-
);
|
|
245
|
-
}
|
|
246
|
-
const newPushArray = [];
|
|
247
|
-
newPushArray.push({
|
|
248
|
-
name: `${input.existingTopic}+${input.subscriberName}`,
|
|
249
|
-
push_endpoint: input.pushEndpoint,
|
|
250
|
-
oidc_service_account_email: input.oidcEmail,
|
|
251
|
-
audience: input.audience,
|
|
252
|
-
expiration_policy: "",
|
|
253
|
-
filter: `attributes.Consumer = "${input.subscriberName}" OR NOT attributes:Consumer`
|
|
254
|
-
});
|
|
255
|
-
await addDLQ(newPushArray, input.env, dlqTopic);
|
|
256
|
-
const yamlPushArray = yaml.dump(newPushArray);
|
|
257
|
-
fs2.appendFileSync(subscriptionFilePath, yamlPushArray);
|
|
258
|
-
if (fileContent.includes("pull_subscriptions")) {
|
|
259
|
-
const pullArray = Object.values(originalContentYaml.pull_subscriptions);
|
|
260
|
-
const yamlPullArray = yaml.dump(pullArray);
|
|
261
|
-
fs2.appendFileSync(
|
|
262
|
-
subscriptionFilePath,
|
|
263
|
-
`pull_subscriptions:
|
|
264
|
-
${yamlPullArray}`
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
}, "appendIncludePush");
|
|
268
|
-
module2.exports = {
|
|
269
|
-
appendNotIncludePull,
|
|
270
|
-
appendIncludePull,
|
|
271
|
-
appendNotIncludePush,
|
|
272
|
-
appendIncludePush
|
|
273
|
-
};
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
// generators/common-resources/pubsub/handle-subscribers.js
|
|
278
|
-
var require_handle_subscribers = __commonJS({
|
|
279
|
-
"generators/common-resources/pubsub/handle-subscribers.js"(exports2, module2) {
|
|
280
|
-
var fs2 = require("fs");
|
|
281
|
-
var yaml = require("js-yaml");
|
|
282
|
-
var {
|
|
283
|
-
appendNotIncludePull,
|
|
284
|
-
appendIncludePull,
|
|
285
|
-
appendNotIncludePush,
|
|
286
|
-
appendIncludePush
|
|
287
|
-
} = require_append();
|
|
288
|
-
var handleSubscribers2 = /* @__PURE__ */ __name(async (env, answers, oidcEmail, pushEndpoint, subscriptionFilePath, dlqTopic) => {
|
|
289
|
-
const { subscriberName, existingTopic, pushOrPull, audience } = answers;
|
|
290
|
-
const subscriptionFileContent = fs2.readFileSync(subscriptionFilePath, "utf8");
|
|
291
|
-
const inputs = {
|
|
292
|
-
...exports2.answers,
|
|
293
|
-
env,
|
|
294
|
-
existingTopic,
|
|
295
|
-
subscriberName,
|
|
296
|
-
audience,
|
|
297
|
-
oidcEmail,
|
|
298
|
-
pushEndpoint,
|
|
299
|
-
dlqTopic
|
|
300
|
-
};
|
|
301
|
-
if (pushOrPull === "pull") {
|
|
302
|
-
if (subscriptionFileContent.length === 0 || !subscriptionFileContent.includes("pull_subscriptions")) {
|
|
303
|
-
await appendNotIncludePull(inputs, subscriptionFilePath, dlqTopic);
|
|
304
|
-
} else {
|
|
305
|
-
const originalContentYaml = yaml.load(subscriptionFileContent);
|
|
306
|
-
const fileContent = subscriptionFileContent;
|
|
307
|
-
await appendIncludePull(
|
|
308
|
-
fileContent,
|
|
309
|
-
originalContentYaml,
|
|
310
|
-
subscriptionFilePath,
|
|
311
|
-
inputs,
|
|
312
|
-
dlqTopic
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
} else if (subscriptionFileContent.length === 0 || !subscriptionFileContent.includes("push_subscriptions")) {
|
|
316
|
-
await appendNotIncludePush(inputs, subscriptionFilePath, dlqTopic);
|
|
317
|
-
} else {
|
|
318
|
-
const originalContentYaml = yaml.load(subscriptionFileContent);
|
|
319
|
-
const fileContent = subscriptionFileContent;
|
|
320
|
-
await appendIncludePush(
|
|
321
|
-
fileContent,
|
|
322
|
-
originalContentYaml,
|
|
323
|
-
subscriptionFilePath,
|
|
324
|
-
inputs,
|
|
325
|
-
dlqTopic
|
|
326
|
-
);
|
|
327
|
-
}
|
|
328
|
-
}, "handleSubscribers");
|
|
329
|
-
module2.exports = handleSubscribers2;
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
// generators/common-resources/pubsub/get-gcp-projects.js
|
|
334
|
-
var require_get_gcp_projects = __commonJS({
|
|
335
|
-
"generators/common-resources/pubsub/get-gcp-projects.js"(exports2, module2) {
|
|
336
|
-
var path2 = require("path");
|
|
337
|
-
var fs2 = require("fs");
|
|
338
|
-
var getKeyValue = /* @__PURE__ */ __name((content, key) => {
|
|
339
|
-
let value = "";
|
|
340
|
-
content.split(/\r?\n/).forEach((line) => {
|
|
341
|
-
if (line.startsWith(key)) {
|
|
342
|
-
value = line.split("=")[1].replace('"', "").replace('"', "").trim();
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
return value;
|
|
346
|
-
}, "getKeyValue");
|
|
347
|
-
var getProjectId2 = /* @__PURE__ */ __name((env) => {
|
|
348
|
-
let projectId = "";
|
|
349
|
-
const projectHCL = path2.join("infra", env, "project.hcl");
|
|
350
|
-
if (fs2.existsSync(projectHCL)) {
|
|
351
|
-
const projectHCLContent = fs2.readFileSync(projectHCL, "utf8");
|
|
352
|
-
projectId = getKeyValue(projectHCLContent, " project_id");
|
|
353
|
-
}
|
|
354
|
-
return projectId;
|
|
355
|
-
}, "getProjectId");
|
|
356
|
-
var getProdPushEndopint2 = /* @__PURE__ */ __name((pushEndpoint) => {
|
|
357
|
-
let prodPushEndopint = "";
|
|
358
|
-
prodPushEndopint = pushEndpoint.replace(".dev", ".com");
|
|
359
|
-
return prodPushEndopint;
|
|
360
|
-
}, "getProdPushEndopint");
|
|
361
|
-
module2.exports = {
|
|
362
|
-
getProjectId: getProjectId2,
|
|
363
|
-
getProdPushEndopint: getProdPushEndopint2
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
// generators/common-resources/pubsub/index.js
|
|
369
|
-
var path = require("path");
|
|
370
|
-
var chalk = require("chalk");
|
|
371
|
-
var fs = require("fs");
|
|
372
|
-
var BaseGenerator = require_BaseGenerator();
|
|
373
|
-
var { required } = require_validators();
|
|
374
|
-
var {
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const fs = require('fs');
|
|
4
|
+
const BaseGenerator = require('../../../src/BaseGenerator');
|
|
5
|
+
const { required } = require('../../../src/validators');
|
|
6
|
+
const {
|
|
375
7
|
validSystemName,
|
|
376
8
|
validVersion,
|
|
377
9
|
validSubscriberName,
|
|
378
|
-
checkExistingTopicPath
|
|
379
|
-
} =
|
|
380
|
-
|
|
381
|
-
|
|
10
|
+
checkExistingTopicPath,
|
|
11
|
+
} = require('./validate');
|
|
12
|
+
const handleSubscribers = require('./handle-subscribers');
|
|
13
|
+
const { getProjectId, getProdPushEndopint } = require('./get-gcp-projects');
|
|
14
|
+
|
|
382
15
|
module.exports = class extends BaseGenerator {
|
|
383
16
|
prompting() {
|
|
384
17
|
const prompts = [
|
|
385
18
|
{
|
|
386
|
-
type:
|
|
387
|
-
name:
|
|
388
|
-
message:
|
|
389
|
-
default:
|
|
390
|
-
choices: [
|
|
19
|
+
type: 'list',
|
|
20
|
+
name: 'createResource',
|
|
21
|
+
message: 'Do you want to create a new topic or a subscription?',
|
|
22
|
+
default: 'subscription',
|
|
23
|
+
choices: ['topic', 'subscription'],
|
|
391
24
|
},
|
|
392
25
|
{
|
|
393
|
-
when:
|
|
394
|
-
type:
|
|
395
|
-
name:
|
|
396
|
-
message:
|
|
397
|
-
validate:
|
|
26
|
+
when: (response) => response.createResource === 'topic',
|
|
27
|
+
type: 'input',
|
|
28
|
+
name: 'systemName',
|
|
29
|
+
message: 'Please provide three-letter system name as defined in Styra',
|
|
30
|
+
validate: (input) => required(input) && validSystemName(input),
|
|
398
31
|
},
|
|
399
32
|
{
|
|
400
|
-
when:
|
|
401
|
-
type:
|
|
402
|
-
name:
|
|
403
|
-
message:
|
|
404
|
-
default:
|
|
405
|
-
choices: [
|
|
33
|
+
when: (response) => response.createResource === 'topic',
|
|
34
|
+
type: 'list',
|
|
35
|
+
name: 'scope',
|
|
36
|
+
message: 'Please select the scope for the topic',
|
|
37
|
+
default: 'private',
|
|
38
|
+
choices: ['private', 'public'],
|
|
406
39
|
},
|
|
407
40
|
{
|
|
408
|
-
when:
|
|
409
|
-
type:
|
|
410
|
-
name:
|
|
411
|
-
message:
|
|
412
|
-
default:
|
|
41
|
+
when: (response) => response.createResource === 'topic',
|
|
42
|
+
type: 'list',
|
|
43
|
+
name: 'intention',
|
|
44
|
+
message: 'Please select the intention of the topic',
|
|
45
|
+
default: 'input',
|
|
413
46
|
choices: [
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
]
|
|
47
|
+
'input',
|
|
48
|
+
'output',
|
|
49
|
+
'event',
|
|
50
|
+
'notification',
|
|
51
|
+
'audit',
|
|
52
|
+
'logging',
|
|
53
|
+
],
|
|
421
54
|
},
|
|
422
55
|
{
|
|
423
|
-
when:
|
|
424
|
-
type:
|
|
425
|
-
name:
|
|
426
|
-
message:
|
|
427
|
-
|
|
56
|
+
when: (response) => response.createResource === 'topic',
|
|
57
|
+
type: 'input',
|
|
58
|
+
name: 'payload',
|
|
59
|
+
message:
|
|
60
|
+
'Please provide the payload (plural for entities, events - verb in the past tense)',
|
|
61
|
+
validate: required,
|
|
428
62
|
},
|
|
429
63
|
{
|
|
430
|
-
when:
|
|
431
|
-
type:
|
|
432
|
-
name:
|
|
433
|
-
message:
|
|
434
|
-
default:
|
|
435
|
-
validate:
|
|
64
|
+
when: (response) => response.createResource === 'topic',
|
|
65
|
+
type: 'input',
|
|
66
|
+
name: 'version',
|
|
67
|
+
message: 'Please provide the version',
|
|
68
|
+
default: 'v1',
|
|
69
|
+
validate: (input) => required(input) && validVersion(input),
|
|
436
70
|
},
|
|
437
71
|
{
|
|
438
|
-
when:
|
|
439
|
-
type:
|
|
440
|
-
name:
|
|
441
|
-
message:
|
|
442
|
-
default:
|
|
443
|
-
choices: [
|
|
444
|
-
validate: required
|
|
72
|
+
when: (response) => response.createResource === 'subscription',
|
|
73
|
+
type: 'list',
|
|
74
|
+
name: 'externalSub',
|
|
75
|
+
message: 'Do you want to create an external subscription?',
|
|
76
|
+
default: 'no',
|
|
77
|
+
choices: ['no', 'yes'],
|
|
78
|
+
validate: required,
|
|
445
79
|
},
|
|
446
80
|
{
|
|
447
|
-
when:
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
81
|
+
when: (response) =>
|
|
82
|
+
response.createResource === 'subscription' &&
|
|
83
|
+
response.externalSub === 'yes',
|
|
84
|
+
type: 'input',
|
|
85
|
+
name: 'clanName',
|
|
86
|
+
message: 'Please provide the name of your clan',
|
|
87
|
+
validate: required,
|
|
453
88
|
},
|
|
454
89
|
{
|
|
455
|
-
when:
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
90
|
+
when: (response) =>
|
|
91
|
+
response.createResource === 'subscription' &&
|
|
92
|
+
response.externalSub === 'yes',
|
|
93
|
+
type: 'input',
|
|
94
|
+
name: 'stagingProjectIdConsumer',
|
|
95
|
+
message: 'Please provide STAGING project_id of your clan',
|
|
96
|
+
validate: required,
|
|
461
97
|
},
|
|
462
98
|
{
|
|
463
|
-
when:
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
99
|
+
when: (response) =>
|
|
100
|
+
response.createResource === 'subscription' &&
|
|
101
|
+
response.externalSub === 'yes',
|
|
102
|
+
type: 'input',
|
|
103
|
+
name: 'prodProjectIdConsumer',
|
|
104
|
+
message: 'Please provide PRODUCTION project_id of your clan',
|
|
105
|
+
validate: required,
|
|
469
106
|
},
|
|
470
107
|
{
|
|
471
|
-
when:
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
108
|
+
when: (response) =>
|
|
109
|
+
response.createResource === 'subscription' &&
|
|
110
|
+
response.externalSub === 'yes',
|
|
111
|
+
type: 'input',
|
|
112
|
+
name: 'costCenter',
|
|
113
|
+
message:
|
|
114
|
+
'Please provide the cost center of your project (specified in your common.hcl file)',
|
|
115
|
+
validate: required,
|
|
477
116
|
},
|
|
478
117
|
{
|
|
479
|
-
when:
|
|
480
|
-
type:
|
|
481
|
-
name:
|
|
482
|
-
message:
|
|
483
|
-
default:
|
|
484
|
-
choices: [
|
|
485
|
-
validate: required
|
|
118
|
+
when: (response) => response.createResource === 'subscription',
|
|
119
|
+
type: 'list',
|
|
120
|
+
name: 'pushOrPull',
|
|
121
|
+
message: 'Please select what type of subscription you want to create',
|
|
122
|
+
default: 'push',
|
|
123
|
+
choices: ['push', 'pull'],
|
|
124
|
+
validate: required,
|
|
486
125
|
},
|
|
487
126
|
{
|
|
488
|
-
when:
|
|
489
|
-
type:
|
|
490
|
-
name:
|
|
491
|
-
message:
|
|
492
|
-
|
|
127
|
+
when: (response) => response.createResource === 'subscription',
|
|
128
|
+
type: 'input',
|
|
129
|
+
name: 'subscriberName',
|
|
130
|
+
message:
|
|
131
|
+
'Please provide the subscriber name in format <system-name>.<service-name>',
|
|
132
|
+
validate: (input) => required(input) && validSubscriberName(input),
|
|
493
133
|
},
|
|
494
134
|
{
|
|
495
|
-
when:
|
|
496
|
-
type:
|
|
497
|
-
name:
|
|
498
|
-
message:
|
|
499
|
-
|
|
135
|
+
when: (response) => response.createResource === 'subscription',
|
|
136
|
+
type: 'input',
|
|
137
|
+
name: 'existingTopic',
|
|
138
|
+
message:
|
|
139
|
+
'Please provide the name of the existing topic you want to subscribe to',
|
|
140
|
+
validate: (input) => required(input) && checkExistingTopicPath(input),
|
|
500
141
|
},
|
|
501
142
|
{
|
|
502
|
-
when:
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
143
|
+
when: (response) =>
|
|
144
|
+
response.createResource === 'subscription' &&
|
|
145
|
+
response.pushOrPull === 'push',
|
|
146
|
+
type: 'input',
|
|
147
|
+
name: 'stagePushEndpoint',
|
|
148
|
+
message: 'Please provide the push endpoint for the STAGING environment',
|
|
149
|
+
validate: required,
|
|
508
150
|
},
|
|
509
151
|
{
|
|
510
|
-
when:
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
152
|
+
when: (response) =>
|
|
153
|
+
response.createResource === 'subscription' &&
|
|
154
|
+
response.pushOrPull === 'push',
|
|
155
|
+
type: 'input',
|
|
156
|
+
name: 'oidcName',
|
|
157
|
+
message:
|
|
158
|
+
'Please provide the service account name for generating the OIDC token (part after @ will be added automatically)',
|
|
159
|
+
validate: required,
|
|
517
160
|
},
|
|
518
161
|
{
|
|
519
|
-
when:
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
162
|
+
when: (response) =>
|
|
163
|
+
response.createResource === 'subscription' &&
|
|
164
|
+
response.pushOrPull === 'push',
|
|
165
|
+
type: 'input',
|
|
166
|
+
name: 'audience',
|
|
167
|
+
message:
|
|
168
|
+
'Please provide the audience that will be used when generating OIDC token',
|
|
169
|
+
validate: required,
|
|
170
|
+
},
|
|
526
171
|
];
|
|
172
|
+
|
|
527
173
|
return this.prompt(prompts).then((props) => {
|
|
528
174
|
this.answers = props;
|
|
529
175
|
});
|
|
530
176
|
}
|
|
177
|
+
|
|
531
178
|
writing() {
|
|
532
179
|
const {
|
|
533
180
|
systemName,
|
|
@@ -547,34 +194,37 @@ matically)",
|
|
|
547
194
|
stagingProjectIdConsumer,
|
|
548
195
|
prodProjectIdConsumer,
|
|
549
196
|
costCenter,
|
|
550
|
-
externalSub
|
|
197
|
+
externalSub,
|
|
551
198
|
} = this.answers;
|
|
552
|
-
|
|
553
|
-
|
|
199
|
+
|
|
200
|
+
const dlqTopicName = `dlq.${getProjectId('prod').split('-prod')[0]}.common`;
|
|
201
|
+
let dlqTopic = `projects/${getProjectId('prod')}/topics/${dlqTopicName}`;
|
|
202
|
+
|
|
554
203
|
const dlqTopicDirPath = path.join(
|
|
555
204
|
process.cwd(),
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
dlqTopicName
|
|
205
|
+
'infra',
|
|
206
|
+
'prod',
|
|
207
|
+
'pubsub',
|
|
208
|
+
dlqTopicName,
|
|
560
209
|
);
|
|
561
210
|
this.fs.copyTpl(
|
|
562
|
-
this.templatePath(
|
|
211
|
+
this.templatePath('pubsub-dlq/terragrunt.hcl'),
|
|
563
212
|
this.destinationPath(`${dlqTopicDirPath}/terragrunt.hcl`),
|
|
564
213
|
{
|
|
565
|
-
...this.answers
|
|
566
|
-
}
|
|
214
|
+
...this.answers,
|
|
215
|
+
},
|
|
567
216
|
);
|
|
568
|
-
|
|
569
|
-
|
|
217
|
+
|
|
218
|
+
['prod', 'staging'].forEach(async (env) => {
|
|
219
|
+
if (createResource === 'topic') {
|
|
570
220
|
const topicDirPath = path.join(
|
|
571
221
|
process.cwd(),
|
|
572
|
-
|
|
222
|
+
'infra',
|
|
573
223
|
env,
|
|
574
|
-
|
|
575
|
-
topicName
|
|
224
|
+
'pubsub',
|
|
225
|
+
topicName,
|
|
576
226
|
);
|
|
577
|
-
[
|
|
227
|
+
['terragrunt.hcl', 'spec.hcl'].forEach(async (file) => {
|
|
578
228
|
this.fs.copyTpl(
|
|
579
229
|
this.templatePath(`pubsub/${file}`),
|
|
580
230
|
this.destinationPath(`${topicDirPath}/${file}`),
|
|
@@ -583,33 +233,35 @@ matically)",
|
|
|
583
233
|
env,
|
|
584
234
|
topicName,
|
|
585
235
|
subscriberName,
|
|
586
|
-
dlqTopic
|
|
587
|
-
}
|
|
236
|
+
dlqTopic,
|
|
237
|
+
},
|
|
588
238
|
);
|
|
589
239
|
});
|
|
590
240
|
}
|
|
241
|
+
|
|
591
242
|
let projectId = getProjectId(env);
|
|
592
243
|
let oidcEmail = `${oidcName}@${projectId}.iam.gserviceaccount.com`;
|
|
593
|
-
let pushEndpoint =
|
|
594
|
-
if (env ===
|
|
244
|
+
let pushEndpoint = '';
|
|
245
|
+
if (env === 'prod' && pushOrPull === 'push') {
|
|
595
246
|
pushEndpoint = getProdPushEndopint(stagePushEndpoint);
|
|
596
247
|
}
|
|
597
|
-
if (env ===
|
|
248
|
+
if (env === 'staging' && pushOrPull === 'push') {
|
|
598
249
|
pushEndpoint = stagePushEndpoint;
|
|
599
250
|
}
|
|
600
|
-
|
|
251
|
+
|
|
252
|
+
if (createResource === 'subscription' && externalSub === 'no') {
|
|
601
253
|
const subscriptionDirPath = path.join(
|
|
602
254
|
process.cwd(),
|
|
603
|
-
|
|
255
|
+
'infra',
|
|
604
256
|
env,
|
|
605
|
-
|
|
606
|
-
existingTopic
|
|
257
|
+
'pubsub',
|
|
258
|
+
existingTopic,
|
|
607
259
|
);
|
|
608
260
|
const fullPath = `${subscriptionDirPath}/subscribers.yaml`;
|
|
609
261
|
if (!fs.existsSync(fullPath)) {
|
|
610
|
-
fs.writeFileSync(fullPath,
|
|
262
|
+
fs.writeFileSync(fullPath, '');
|
|
611
263
|
this.fs.copyTpl(
|
|
612
|
-
this.templatePath(
|
|
264
|
+
this.templatePath('pubsub/subscribers.yaml'),
|
|
613
265
|
this.destinationPath(fullPath),
|
|
614
266
|
{
|
|
615
267
|
...this.answers,
|
|
@@ -619,44 +271,47 @@ matically)",
|
|
|
619
271
|
audience,
|
|
620
272
|
oidcEmail,
|
|
621
273
|
pushEndpoint,
|
|
622
|
-
dlqTopic
|
|
623
|
-
}
|
|
274
|
+
dlqTopic,
|
|
275
|
+
},
|
|
624
276
|
);
|
|
625
277
|
}
|
|
626
|
-
|
|
278
|
+
|
|
279
|
+
['terragrunt.hcl', 'spec.hcl'].forEach(async (file) => {
|
|
627
280
|
this.fs.copyTpl(
|
|
628
281
|
this.templatePath(`pubsub/${file}`),
|
|
629
282
|
this.destinationPath(`${subscriptionDirPath}/${file}`),
|
|
630
283
|
{
|
|
631
284
|
...this.answers,
|
|
632
285
|
env,
|
|
633
|
-
existingTopic
|
|
634
|
-
}
|
|
286
|
+
existingTopic,
|
|
287
|
+
},
|
|
635
288
|
);
|
|
636
289
|
});
|
|
290
|
+
|
|
637
291
|
await handleSubscribers(
|
|
638
292
|
env,
|
|
639
293
|
this.answers,
|
|
640
294
|
oidcEmail,
|
|
641
295
|
pushEndpoint,
|
|
642
296
|
`${subscriptionDirPath}/subscribers.yaml`,
|
|
643
|
-
dlqTopic
|
|
297
|
+
dlqTopic,
|
|
644
298
|
);
|
|
645
299
|
}
|
|
646
|
-
if (createResource ===
|
|
300
|
+
if (createResource === 'subscription' && externalSub === 'yes') {
|
|
647
301
|
const externalDirPath = path.join(
|
|
648
302
|
process.cwd(),
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
303
|
+
'infra',
|
|
304
|
+
'prod',
|
|
305
|
+
'pubsub',
|
|
652
306
|
existingTopic,
|
|
653
|
-
`${clanName}-${env}
|
|
307
|
+
`${clanName}-${env}`,
|
|
654
308
|
);
|
|
655
|
-
projectId = getProjectId(
|
|
309
|
+
projectId = getProjectId('prod');
|
|
656
310
|
if (!fs.existsSync(externalDirPath)) {
|
|
657
311
|
fs.mkdirSync(externalDirPath);
|
|
658
312
|
}
|
|
659
|
-
|
|
313
|
+
|
|
314
|
+
['terragrunt.hcl', 'spec.hcl'].forEach(async (file) => {
|
|
660
315
|
this.fs.copyTpl(
|
|
661
316
|
this.templatePath(`pubsub-external/${file}`),
|
|
662
317
|
this.destinationPath(`${externalDirPath}/${file}`),
|
|
@@ -668,21 +323,22 @@ matically)",
|
|
|
668
323
|
prodProjectIdConsumer,
|
|
669
324
|
costCenter,
|
|
670
325
|
subscriberName,
|
|
671
|
-
projectId
|
|
672
|
-
}
|
|
326
|
+
projectId,
|
|
327
|
+
},
|
|
673
328
|
);
|
|
674
329
|
});
|
|
330
|
+
|
|
675
331
|
const externalSubPath = `${externalDirPath}/subscribers.yaml`;
|
|
676
|
-
if (env ===
|
|
332
|
+
if (env === 'staging') {
|
|
677
333
|
oidcEmail = `${oidcName}@${stagingProjectIdConsumer}.iam.gserviceaccount.com`;
|
|
678
334
|
} else {
|
|
679
335
|
oidcEmail = `${oidcName}@${prodProjectIdConsumer}.iam.gserviceaccount.com`;
|
|
680
|
-
dlqTopic = `projects/${prodProjectIdConsumer}/topics/${prodProjectIdConsumer.split(
|
|
336
|
+
dlqTopic = `projects/${prodProjectIdConsumer}/topics/${prodProjectIdConsumer.split('-')[0]}-common-dlq`;
|
|
681
337
|
}
|
|
682
338
|
if (!fs.existsSync(externalSubPath)) {
|
|
683
|
-
fs.writeFileSync(externalSubPath,
|
|
339
|
+
fs.writeFileSync(externalSubPath, '');
|
|
684
340
|
this.fs.copyTpl(
|
|
685
|
-
this.templatePath(
|
|
341
|
+
this.templatePath('pubsub-external/subscribers.yaml'),
|
|
686
342
|
this.destinationPath(externalSubPath),
|
|
687
343
|
{
|
|
688
344
|
...this.answers,
|
|
@@ -692,27 +348,29 @@ matically)",
|
|
|
692
348
|
audience,
|
|
693
349
|
oidcEmail,
|
|
694
350
|
pushEndpoint,
|
|
695
|
-
dlqTopic
|
|
696
|
-
}
|
|
351
|
+
dlqTopic,
|
|
352
|
+
},
|
|
697
353
|
);
|
|
698
354
|
}
|
|
355
|
+
|
|
699
356
|
await handleSubscribers(
|
|
700
357
|
env,
|
|
701
358
|
this.answers,
|
|
702
359
|
oidcEmail,
|
|
703
360
|
pushEndpoint,
|
|
704
361
|
externalSubPath,
|
|
705
|
-
dlqTopic
|
|
362
|
+
dlqTopic,
|
|
706
363
|
);
|
|
707
364
|
}
|
|
708
365
|
});
|
|
709
366
|
}
|
|
367
|
+
|
|
710
368
|
end() {
|
|
711
369
|
this.log(`
|
|
712
370
|
${chalk.green(`Your PubSub resources have now been created. To finalize your configuration, please continue
|
|
713
371
|
with manual editing of the generated files.`)}
|
|
714
|
-
${chalk.green(
|
|
715
|
-
${chalk.green(
|
|
372
|
+
${chalk.green('1.')} Review created subscribers.
|
|
373
|
+
${chalk.green('2.')} Push this change in a feature branch and open a pull request.
|
|
716
374
|
`);
|
|
717
375
|
}
|
|
718
376
|
};
|