@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.
Files changed (55) 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/validate.js +58 -0
  24. package/dist/generators/common-resources/pubsub/append.js +130 -0
  25. package/dist/generators/common-resources/pubsub/get-gcp-projects.js +34 -0
  26. package/dist/generators/common-resources/pubsub/handle-subscribers.js +68 -0
  27. package/dist/generators/common-resources/pubsub/index.js +194 -536
  28. package/dist/generators/common-resources/pubsub/validate.js +53 -0
  29. package/dist/generators/common-resources/scheduler/append.js +85 -0
  30. package/dist/generators/common-resources/scheduler/index.js +62 -249
  31. package/dist/generators/common-resources/spanner/append.js +31 -0
  32. package/dist/generators/common-resources/spanner/index.js +102 -269
  33. package/dist/generators/common-resources/spanner/validate.js +38 -0
  34. package/dist/generators/docs/rca/index.js +25 -135
  35. package/dist/generators/docs/runbook/index.js +16 -126
  36. package/dist/generators/docs/srb/index.js +33 -147
  37. package/dist/generators/docs/srb/run-docker.js +2 -0
  38. package/dist/generators/init/clan-infra/gcp-projects.js +47 -0
  39. package/dist/generators/init/clan-infra/index.js +95 -290
  40. package/dist/generators/init/clan-infra/tribe-clan-repo.js +38 -0
  41. package/dist/generators/init/clan-infra/validate.js +8 -0
  42. package/dist/generators/maintenance/manage-states/index.js +142 -219
  43. package/dist/generators/maintenance/update-modules/index.js +56 -155
  44. package/dist/generators/organization/clan-project/googlecloud.js +124 -0
  45. package/dist/generators/organization/clan-project/index.js +81 -303
  46. package/dist/node_modules/.package-lock.json +81 -23
  47. package/dist/package.json +45 -0
  48. package/dist/src/BaseGenerator.js +84 -0
  49. package/dist/src/SecretsGenerator.js +137 -0
  50. package/dist/src/cli.js +54 -255
  51. package/dist/src/dependency-check.js +48 -0
  52. package/dist/src/update-check.js +38 -0
  53. package/dist/src/validators.js +33 -0
  54. package/dist/src/yeoman.js +80 -0
  55. package/package.json +1 -2
@@ -0,0 +1,130 @@
1
+ const yaml = require('js-yaml');
2
+ const fs = require('fs');
3
+
4
+ const addDLQ = async (yamlArray, env, dlqTopic) => {
5
+ if (env === 'prod') {
6
+ yamlArray[0].dead_letter_topic = dlqTopic;
7
+ }
8
+ };
9
+
10
+ const appendNotIncludePull = async (inputs, subscriptionFilePath, dlqTopic) => {
11
+ const pullArray = [];
12
+
13
+ pullArray.push({
14
+ name: `${inputs.existingTopic}+${inputs.subscriberName}`,
15
+ ack_deadline_seconds: '60',
16
+ expiration_policy: '',
17
+ });
18
+
19
+ await addDLQ(pullArray, inputs.env, dlqTopic);
20
+ const yamlPullArray = yaml.dump(pullArray);
21
+ fs.appendFileSync(
22
+ subscriptionFilePath,
23
+ `pull_subscriptions:\n${yamlPullArray}`,
24
+ );
25
+ };
26
+
27
+ const appendIncludePull = async (
28
+ fileContent,
29
+ originalContentYaml,
30
+ subscriptionFilePath,
31
+ input,
32
+ dlqTopic,
33
+ ) => {
34
+ if (fileContent.includes('pull_subscriptions')) {
35
+ const pullArray = Object.values(originalContentYaml.pull_subscriptions);
36
+ const yamlPullArray = yaml.dump(pullArray);
37
+ fs.writeFileSync(
38
+ subscriptionFilePath,
39
+ `pull_subscriptions:\n${yamlPullArray}`,
40
+ );
41
+ }
42
+
43
+ const newPullArray = [];
44
+
45
+ newPullArray.push({
46
+ name: `${input.existingTopic}+${input.subscriberName}`,
47
+ ack_deadline_seconds: '60',
48
+ expiration_policy: '',
49
+ });
50
+
51
+ await addDLQ(newPullArray, input.env, dlqTopic);
52
+ const finalYamlPullArray = yaml.dump(newPullArray);
53
+ fs.appendFileSync(subscriptionFilePath, finalYamlPullArray);
54
+
55
+ if (fileContent.includes('push_subscriptions')) {
56
+ const pushArray = Object.values(originalContentYaml.push_subscriptions);
57
+ const yamlPushArray = yaml.dump(pushArray);
58
+ fs.appendFileSync(
59
+ subscriptionFilePath,
60
+ `push_subscriptions:\n${yamlPushArray}`,
61
+ );
62
+ }
63
+ };
64
+
65
+ const appendNotIncludePush = async (inputs, subscriptionFilePath, dlqTopic) => {
66
+ const pushArray = [];
67
+
68
+ pushArray.push({
69
+ name: `${inputs.existingTopic}+${inputs.subscriberName}`,
70
+ push_endpoint: inputs.pushEndpoint,
71
+ oidc_service_account_email: inputs.oidcEmail,
72
+ audience: inputs.audience,
73
+ expiration_policy: '',
74
+ filter: `attributes.Consumer = "${inputs.subscriberName}" OR NOT attributes:Consumer`,
75
+ });
76
+
77
+ await addDLQ(pushArray, inputs.env, dlqTopic);
78
+ const yamlPushArray = yaml.dump(pushArray);
79
+ fs.appendFileSync(
80
+ subscriptionFilePath,
81
+ `push_subscriptions:\n${yamlPushArray}`,
82
+ );
83
+ };
84
+
85
+ const appendIncludePush = async (
86
+ fileContent,
87
+ originalContentYaml,
88
+ subscriptionFilePath,
89
+ input,
90
+ dlqTopic,
91
+ ) => {
92
+ if (fileContent.includes('push_subscriptions')) {
93
+ const pushArray = Object.values(originalContentYaml.push_subscriptions);
94
+ const yamlPushArray = yaml.dump(pushArray);
95
+ fs.writeFileSync(
96
+ subscriptionFilePath,
97
+ `push_subscriptions:\n${yamlPushArray}`,
98
+ );
99
+ }
100
+
101
+ const newPushArray = [];
102
+
103
+ newPushArray.push({
104
+ name: `${input.existingTopic}+${input.subscriberName}`,
105
+ push_endpoint: input.pushEndpoint,
106
+ oidc_service_account_email: input.oidcEmail,
107
+ audience: input.audience,
108
+ expiration_policy: '',
109
+ filter: `attributes.Consumer = "${input.subscriberName}" OR NOT attributes:Consumer`,
110
+ });
111
+ await addDLQ(newPushArray, input.env, dlqTopic);
112
+ const yamlPushArray = yaml.dump(newPushArray);
113
+ fs.appendFileSync(subscriptionFilePath, yamlPushArray);
114
+
115
+ if (fileContent.includes('pull_subscriptions')) {
116
+ const pullArray = Object.values(originalContentYaml.pull_subscriptions);
117
+ const yamlPullArray = yaml.dump(pullArray);
118
+ fs.appendFileSync(
119
+ subscriptionFilePath,
120
+ `pull_subscriptions:\n${yamlPullArray}`,
121
+ );
122
+ }
123
+ };
124
+
125
+ module.exports = {
126
+ appendNotIncludePull,
127
+ appendIncludePull,
128
+ appendNotIncludePush,
129
+ appendIncludePush,
130
+ };
@@ -0,0 +1,34 @@
1
+ const path = require('path');
2
+ const fs = require('fs');
3
+
4
+ const getKeyValue = (content, key) => {
5
+ let value = '';
6
+ content.split(/\r?\n/).forEach((line) => {
7
+ if (line.startsWith(key)) {
8
+ value = line.split('=')[1].replace('"', '').replace('"', '').trim();
9
+ }
10
+ });
11
+ return value;
12
+ };
13
+
14
+ const getProjectId = (env) => {
15
+ let projectId = '';
16
+ const projectHCL = path.join('infra', env, 'project.hcl');
17
+ if (fs.existsSync(projectHCL)) {
18
+ const projectHCLContent = fs.readFileSync(projectHCL, 'utf8');
19
+ projectId = getKeyValue(projectHCLContent, ' project_id');
20
+ }
21
+
22
+ return projectId;
23
+ };
24
+
25
+ const getProdPushEndopint = (pushEndpoint) => {
26
+ let prodPushEndopint = '';
27
+ prodPushEndopint = pushEndpoint.replace('.dev', '.com');
28
+ return prodPushEndopint;
29
+ };
30
+
31
+ module.exports = {
32
+ getProjectId,
33
+ getProdPushEndopint,
34
+ };
@@ -0,0 +1,68 @@
1
+ const fs = require('fs');
2
+ const yaml = require('js-yaml');
3
+ const {
4
+ appendNotIncludePull,
5
+ appendIncludePull,
6
+ appendNotIncludePush,
7
+ appendIncludePush,
8
+ } = require('./append');
9
+
10
+ const handleSubscribers = async (
11
+ env,
12
+ answers,
13
+ oidcEmail,
14
+ pushEndpoint,
15
+ subscriptionFilePath,
16
+ dlqTopic,
17
+ ) => {
18
+ const { subscriberName, existingTopic, pushOrPull, audience } = answers;
19
+
20
+ const subscriptionFileContent = fs.readFileSync(subscriptionFilePath, 'utf8');
21
+
22
+ const inputs = {
23
+ ...this.answers,
24
+ env,
25
+ existingTopic,
26
+ subscriberName,
27
+ audience,
28
+ oidcEmail,
29
+ pushEndpoint,
30
+ dlqTopic,
31
+ };
32
+
33
+ if (pushOrPull === 'pull') {
34
+ if (
35
+ subscriptionFileContent.length === 0 ||
36
+ !subscriptionFileContent.includes('pull_subscriptions')
37
+ ) {
38
+ await appendNotIncludePull(inputs, subscriptionFilePath, dlqTopic);
39
+ } else {
40
+ const originalContentYaml = yaml.load(subscriptionFileContent);
41
+ const fileContent = subscriptionFileContent;
42
+ await appendIncludePull(
43
+ fileContent,
44
+ originalContentYaml,
45
+ subscriptionFilePath,
46
+ inputs,
47
+ dlqTopic,
48
+ );
49
+ }
50
+ } else if (
51
+ subscriptionFileContent.length === 0 ||
52
+ !subscriptionFileContent.includes('push_subscriptions')
53
+ ) {
54
+ await appendNotIncludePush(inputs, subscriptionFilePath, dlqTopic);
55
+ } else {
56
+ const originalContentYaml = yaml.load(subscriptionFileContent);
57
+ const fileContent = subscriptionFileContent;
58
+ await appendIncludePush(
59
+ fileContent,
60
+ originalContentYaml,
61
+ subscriptionFilePath,
62
+ inputs,
63
+ dlqTopic,
64
+ );
65
+ }
66
+ };
67
+
68
+ module.exports = handleSubscribers;