@opencrvs/toolkit 2.0.0-rc.ac001d6 → 2.0.0-rc.ac3c151

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 (98) hide show
  1. package/README.md +14 -0
  2. package/build.sh +1 -0
  3. package/dist/application-config/index.js +55 -35
  4. package/dist/cli.js +3166 -45
  5. package/dist/commons/api/router.d.ts +94 -17
  6. package/dist/commons/application-config/index.d.ts +1 -0
  7. package/dist/commons/conditionals/conditionals.d.ts +348 -4
  8. package/dist/commons/conditionals/validate.d.ts +51 -2
  9. package/dist/commons/events/ActionConfig.d.ts +28 -2
  10. package/dist/commons/events/ActionDocument.d.ts +6 -0
  11. package/dist/commons/events/ActionInput.d.ts +6 -0
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +342 -0
  13. package/dist/commons/events/CountryConfigQueryInput.d.ts +42 -0
  14. package/dist/commons/events/EventDocument.d.ts +3 -0
  15. package/dist/commons/events/EventIndex.d.ts +14 -0
  16. package/dist/commons/events/FieldConfig.d.ts +378 -50
  17. package/dist/commons/events/FieldType.d.ts +1 -0
  18. package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
  19. package/dist/commons/events/FieldValue.d.ts +6 -0
  20. package/dist/commons/events/WorkqueueConfig.d.ts +39 -0
  21. package/dist/commons/events/field.d.ts +53 -1
  22. package/dist/commons/events/index.d.ts +1 -0
  23. package/dist/commons/events/state/flags.d.ts +1 -0
  24. package/dist/commons/events/state/utils.d.ts +12 -287
  25. package/dist/commons/events/utils.d.ts +12 -1
  26. package/dist/conditionals/index.js +48 -1
  27. package/dist/environment/custom-types.d.ts +33 -0
  28. package/dist/environment/custom-types.d.ts.map +1 -0
  29. package/dist/environment/custom-types.js +12 -0
  30. package/dist/environment/derived-variables.d.ts +134 -0
  31. package/dist/environment/derived-variables.d.ts.map +1 -0
  32. package/dist/environment/derived-variables.js +169 -0
  33. package/dist/environment/editor-questions.d.ts +4 -0
  34. package/dist/environment/editor-questions.d.ts.map +1 -0
  35. package/dist/environment/editor-questions.js +65 -0
  36. package/dist/environment/git.d.ts +5 -0
  37. package/dist/environment/git.d.ts.map +1 -0
  38. package/dist/environment/git.js +38 -0
  39. package/dist/environment/github.d.ts +26 -0
  40. package/dist/environment/github.d.ts.map +1 -0
  41. package/dist/environment/github.js +244 -0
  42. package/dist/environment/index.d.ts +5 -0
  43. package/dist/environment/index.d.ts.map +1 -0
  44. package/dist/environment/index.js +71 -0
  45. package/dist/environment/logger.d.ts +15 -0
  46. package/dist/environment/logger.d.ts.map +1 -0
  47. package/dist/environment/logger.js +25 -0
  48. package/dist/environment/manage-users.d.ts +11 -0
  49. package/dist/environment/manage-users.d.ts.map +1 -0
  50. package/dist/environment/manage-users.js +494 -0
  51. package/dist/environment/questions-helper.d.ts +15 -0
  52. package/dist/environment/questions-helper.d.ts.map +1 -0
  53. package/dist/environment/questions-helper.js +70 -0
  54. package/dist/environment/questions.d.ts +199 -0
  55. package/dist/environment/questions.d.ts.map +1 -0
  56. package/dist/environment/questions.js +412 -0
  57. package/dist/environment/setup-environment.d.ts +2 -0
  58. package/dist/environment/setup-environment.d.ts.map +1 -0
  59. package/dist/environment/setup-environment.js +773 -0
  60. package/dist/environment/ssh-keygen.d.ts +5 -0
  61. package/dist/environment/ssh-keygen.d.ts.map +1 -0
  62. package/dist/environment/ssh-keygen.js +18 -0
  63. package/dist/environment/swarm-to-k8s.d.ts +2 -0
  64. package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
  65. package/dist/environment/swarm-to-k8s.js +172 -0
  66. package/dist/environment/templates.d.ts +27 -0
  67. package/dist/environment/templates.d.ts.map +1 -0
  68. package/dist/environment/templates.js +159 -0
  69. package/dist/environment/update-workflows.d.ts +2 -0
  70. package/dist/environment/update-workflows.d.ts.map +1 -0
  71. package/dist/environment/update-workflows.js +168 -0
  72. package/dist/environment/users.d.ts +2 -0
  73. package/dist/environment/users.d.ts.map +1 -0
  74. package/dist/environment/users.js +110 -0
  75. package/dist/environment/utils.d.ts +18 -0
  76. package/dist/environment/utils.d.ts.map +1 -0
  77. package/dist/environment/utils.js +100 -0
  78. package/dist/events/index.js +384 -148
  79. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  80. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  81. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -1
  82. package/dist/migrations/v2.0/index.js +10 -4
  83. package/dist/notification/index.js +250 -40
  84. package/dist/scopes/index.d.ts +4 -6
  85. package/dist/scopes/index.js +9 -3
  86. package/dist/templates/charts-values/dependencies/values.override.yaml +4 -0
  87. package/dist/templates/charts-values/dependencies/values.yaml +82 -0
  88. package/dist/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  89. package/dist/templates/charts-values/opencrvs-services/values.yaml +79 -0
  90. package/dist/templates/charts-values/traefik/values.override.yaml +4 -0
  91. package/dist/templates/charts-values/traefik/values.yaml +116 -0
  92. package/dist/templates/inventory/inventory.template.yml +100 -0
  93. package/dist/templates/inventory/production.example.yml +77 -0
  94. package/dist/templates/inventory/qa.example.yml +48 -0
  95. package/opencrvs-toolkit-2.0.0-rc.ac3c151.tgz +0 -0
  96. package/package.json +15 -1
  97. package/tsconfig.tsbuildinfo +1 -1
  98. package/opencrvs-toolkit-2.0.0-rc.ac001d6.tgz +0 -0
@@ -0,0 +1,773 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __rest = (this && this.__rest) || function (s, e) {
22
+ var t = {};
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
+ t[p] = s[p];
25
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
+ t[p[i]] = s[p[i]];
29
+ }
30
+ return t;
31
+ };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@octokit/core");
37
+ const dotenv_1 = __importDefault(require("dotenv"));
38
+ const kleur_1 = __importDefault(require("kleur"));
39
+ const prompts_1 = __importDefault(require("prompts"));
40
+ function confirm(options) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const inquirer = yield import('@inquirer/prompts');
43
+ return inquirer.confirm(options);
44
+ });
45
+ }
46
+ function select(options) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const inquirer = yield import('@inquirer/prompts');
49
+ return inquirer.select(options);
50
+ });
51
+ }
52
+ const github_1 = require("./github");
53
+ const derived_variables_1 = require("./derived-variables");
54
+ const utils_1 = require("./utils");
55
+ const logger_1 = require("./logger");
56
+ const templates_1 = require("./templates");
57
+ const ssh_keygen_1 = require("./ssh-keygen");
58
+ const questions_1 = require("./questions");
59
+ const editor_questions_1 = require("./editor-questions");
60
+ const questions_helper_1 = require("./questions-helper");
61
+ const manage_users_1 = require("./manage-users");
62
+ function questionToPrompt(_a) {
63
+ var {
64
+ // eslint-disable-next-line no-unused-vars
65
+ valueType,
66
+ // eslint-disable-next-line no-unused-vars
67
+ valueLabel,
68
+ // eslint-disable-next-line no-unused-vars
69
+ scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "scope"]);
70
+ return promptOptions;
71
+ }
72
+ const ALL_QUESTIONS = [];
73
+ const ALL_ANSWERS = [];
74
+ function getAnswers(existingValues) {
75
+ return ALL_ANSWERS.flatMap((answerObject) => {
76
+ const questionsThatAreSecretsOrVariables = Object.entries(answerObject).filter(([key, value]) => {
77
+ if (value === '') {
78
+ return false;
79
+ }
80
+ const existingQuestion = ALL_QUESTIONS.find((question) => question.name === key);
81
+ const valueType = existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueType;
82
+ return valueType === 'VARIABLE' || valueType === 'SECRET';
83
+ });
84
+ return questionsThatAreSecretsOrVariables.map(([key, value]) => {
85
+ const existingQuestion = ALL_QUESTIONS.find((question) => question.name === key);
86
+ const valueType = existingQuestion.valueType;
87
+ if (valueType === 'SECRET') {
88
+ const existingSecret = (0, utils_1.findExistingValue)(existingQuestion.valueLabel, 'SECRET', existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.scope, existingValues);
89
+ return {
90
+ type: valueType,
91
+ name: existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel,
92
+ value: value.toString(),
93
+ didExist: existingSecret,
94
+ scope: existingQuestion.scope
95
+ };
96
+ }
97
+ const existingVariable = (0, utils_1.findExistingValue)(existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel, valueType, existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.scope, existingValues);
98
+ return {
99
+ type: valueType,
100
+ name: existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel,
101
+ didExist: (0, utils_1.findExistingValue)(existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel, valueType, existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.scope, existingValues),
102
+ value: value.toString() || (existingVariable === null || existingVariable === void 0 ? void 0 : existingVariable.value) || '',
103
+ scope: existingQuestion.scope
104
+ };
105
+ });
106
+ });
107
+ }
108
+ function promptAndStoreAnswer(environment, questions, existingValues) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ (0, logger_1.log)('');
111
+ const processedQuestions = questions.flatMap((question) => {
112
+ const questionWithVariableLabel = Object.assign(Object.assign({}, question), { message: `${kleur_1.default.cyan(question.valueLabel || '')}: ${question.message}` });
113
+ if (!questionWithVariableLabel.valueLabel) {
114
+ return questionWithVariableLabel;
115
+ }
116
+ if (questionWithVariableLabel.valueType === 'VARIABLE') {
117
+ const existingVariable = (0, utils_1.findExistingValue)(questionWithVariableLabel.valueLabel, 'VARIABLE', questionWithVariableLabel.scope, existingValues);
118
+ if (existingVariable) {
119
+ let initial_value = existingVariable.value;
120
+ // Get correct initial value for select questions
121
+ if (questionWithVariableLabel.type === 'select' && Array.isArray(questionWithVariableLabel.choices)) {
122
+ initial_value = (0, questions_helper_1.getIndexFromChoices)(questionWithVariableLabel.choices, existingVariable.value);
123
+ }
124
+ return [
125
+ {
126
+ name: 'overWrite' + questionWithVariableLabel.name,
127
+ type: 'confirm',
128
+ scope: questionWithVariableLabel.scope,
129
+ message: `${kleur_1.default.yellow(`Variable ${kleur_1.default.cyan(existingVariable.name)} already exists in Github. Do you want to update it?`)}`
130
+ },
131
+ Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null), initial: initial_value })
132
+ ];
133
+ }
134
+ }
135
+ if (questionWithVariableLabel.valueType === 'SECRET') {
136
+ const existingSecret = (0, utils_1.findExistingValue)(questionWithVariableLabel.valueLabel, 'SECRET', questionWithVariableLabel.scope, existingValues);
137
+ if (existingSecret) {
138
+ return [
139
+ {
140
+ name: 'overWrite' + questionWithVariableLabel.name,
141
+ type: 'confirm',
142
+ scope: questionWithVariableLabel.scope,
143
+ message: `${kleur_1.default.yellow(`${existingSecret.scope === 'REPOSITORY'
144
+ ? 'Repository secret'
145
+ : 'Secret'} ${kleur_1.default.cyan(existingSecret.name)} already exists in Github. Do you want to update it?`)}`
146
+ },
147
+ Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null) })
148
+ ];
149
+ }
150
+ }
151
+ return questionWithVariableLabel;
152
+ });
153
+ const promptQuestions = processedQuestions.map(questionToPrompt);
154
+ const result = yield (0, prompts_1.default)(promptQuestions, {
155
+ onCancel: () => {
156
+ process.exit(1);
157
+ }
158
+ });
159
+ ALL_ANSWERS.push(result);
160
+ (0, utils_1.storeSecrets)(environment, getAnswers(existingValues));
161
+ const existingValuesForQuestions = questions
162
+ // Only variables can have previous values we can use
163
+ .filter((question) => question.valueType === 'VARIABLE')
164
+ .map((question) => {
165
+ var _a;
166
+ return [
167
+ question.name,
168
+ (_a = (0, utils_1.findExistingValue)(question.valueLabel, 'VARIABLE', question.scope, existingValues)) === null || _a === void 0 ? void 0 : _a.value
169
+ ];
170
+ });
171
+ return Object.assign(Object.assign({}, Object.fromEntries(existingValuesForQuestions)), result);
172
+ });
173
+ }
174
+ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOtherQuestions, ...questions_1.dockerhubQuestions, ...questions_1.diskQuestions, ...questions_1.infrastructureQuestions, ...questions_1.backupQuestions, ...questions_1.countryQuestions, ...questions_1.databaseAndMonitoringQuestions, ...questions_1.emailQuestions, ...questions_1.sentryQuestions, ...derived_variables_1.derivedVariables, ...questions_1.metabaseAdminQuestions);
175
+ (() => __awaiter(void 0, void 0, void 0, function* () {
176
+ var _a, _b, _c;
177
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Github'), '\n');
178
+ const { githubOrganisation, githubRepository } = yield (0, prompts_1.default)(questions_1.githubQuestions.map(questionToPrompt), {
179
+ onCancel: () => {
180
+ process.exit(1);
181
+ }
182
+ });
183
+ const { githubToken } = yield promptAndStoreAnswer('', questions_1.githubTokenQuestion, []);
184
+ const octokit = new core_1.Octokit({
185
+ auth: githubToken
186
+ });
187
+ (0, logger_1.log)(kleur_1.default.green('\nSuccessfully logged in to Github\n'));
188
+ let existingEnvironments = yield (0, github_1.getRepositoryEnvironments)(octokit, githubOrganisation, githubRepository);
189
+ let defaultChoices = [
190
+ { name: 'Development', value: 'development' },
191
+ { name: 'Quality assurance (no PII data)', value: 'qa' },
192
+ {
193
+ name: 'Staging (hosts PII data, no backups)',
194
+ value: 'staging'
195
+ },
196
+ {
197
+ name: 'Production (hosts PII data, requires frequent backups)',
198
+ value: 'production'
199
+ },
200
+ ];
201
+ // Add only environments that are not already present
202
+ const choices = [
203
+ ...defaultChoices,
204
+ ...existingEnvironments
205
+ .filter((env) => !defaultChoices.some((choice) => choice.value === env))
206
+ .map((env) => ({
207
+ name: env,
208
+ value: env
209
+ }))
210
+ ];
211
+ const environment = yield (0, questions_helper_1.selectWithCustom)({
212
+ message: 'Choose a name and purpose for the environment?',
213
+ choices: choices
214
+ });
215
+ let environment_type = 'non-production';
216
+ if (['development', 'qa'].includes(environment)) {
217
+ environment_type = 'non-production';
218
+ }
219
+ else if (['staging', 'production'].includes(environment)) {
220
+ environment_type = 'production';
221
+ }
222
+ else {
223
+ environment_type = yield select({
224
+ message: 'Purpose for the environment?',
225
+ choices: [
226
+ { name: 'Development/Quality assurance/Testing (no PII data)', value: 'non-production' },
227
+ { name: 'Staging/Production (hosts PII data, requires frequent backups)', value: 'production' },
228
+ ],
229
+ });
230
+ }
231
+ const environment_exists = existingEnvironments
232
+ .map((e) => e.trim())
233
+ .includes(environment);
234
+ if (!environment) {
235
+ process.exit(1);
236
+ }
237
+ // Read users .env file based on the environment name they gave above, e.g. .env.production
238
+ dotenv_1.default.config({
239
+ path: `${process.cwd()}/.env.${environment}`
240
+ });
241
+ yield (0, github_1.createEnvironment)(octokit, environment, githubOrganisation, githubRepository);
242
+ const repositoryId = yield (0, github_1.getRepositoryId)(octokit, githubOrganisation, githubRepository);
243
+ const existingRepositorySecrets = yield (0, github_1.listRepositorySecrets)(octokit, githubOrganisation, githubRepository);
244
+ const existingRepositoryVariables = yield (0, github_1.listRepositoryVariables)(octokit, githubOrganisation, githubRepository);
245
+ const existingEnvironmentVariables = yield (0, github_1.listEnvironmentVariables)(octokit, repositoryId, environment);
246
+ const existingEnvironmentSecrets = yield (0, github_1.listEnvironmentSecrets)(octokit, githubOrganisation, repositoryId, environment);
247
+ const existingValues = [
248
+ ...existingEnvironmentVariables,
249
+ ...existingRepositoryVariables,
250
+ ...existingRepositorySecrets,
251
+ ...existingEnvironmentSecrets
252
+ ];
253
+ if (existingEnvironmentVariables.length > 0 ||
254
+ existingEnvironmentSecrets.length > 0) {
255
+ (0, logger_1.log)('\nEnvironment with the name', environment, 'already exists in Github.', '\nFound', existingEnvironmentVariables.length, 'existing variables and', existingEnvironmentSecrets.length, 'secrets');
256
+ }
257
+ if (environment_type === 'production') {
258
+ (0, logger_1.log)('\n', kleur_1.default.yellow().bold('WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n'));
259
+ yield promptAndStoreAnswer(environment, questions_1.githubOtherQuestions, existingValues);
260
+ }
261
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Docker Hub'));
262
+ yield promptAndStoreAnswer(environment, questions_1.dockerhubQuestions, existingValues);
263
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Kubernetes & Runtime'));
264
+ const infrastructure = yield promptAndStoreAnswer(environment, questions_1.infrastructureQuestions, existingValues);
265
+ const kubeWorkerNodes = infrastructure.kubeWorkerNodes
266
+ ? infrastructure.kubeWorkerNodes.split(',').map((ip) => ip.trim()) : [];
267
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('SSH Users'), '\n');
268
+ const users = yield (0, manage_users_1.manageUsers)(`infrastructure/server-setup/inventory/${environment}.yml`);
269
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Traefik SSL Certificate'), '\n');
270
+ const sslCertExists = (0, utils_1.findExistingValue)('SSL_CRT', 'SECRET', 'ENVIRONMENT', existingValues);
271
+ let ssl_answers = [];
272
+ const traefikConfOption = (yield (0, prompts_1.default)([
273
+ {
274
+ name: 'traefikConfOption',
275
+ type: 'select',
276
+ message: 'Choose option to configure Traefik SSL Certificate',
277
+ choices: [
278
+ { title: "Let's Encrypt certificate", value: 'lets_encrypt' },
279
+ { title: "Static SSL certificate", value: 'static_ssl' },
280
+ { title: "Custom configuration", value: 'custom' }
281
+ ],
282
+ initial: sslCertExists ? 1 : 0
283
+ }
284
+ ])).traefikConfOption;
285
+ if (traefikConfOption === "static_ssl") {
286
+ ssl_answers = yield (0, editor_questions_1.askQuestionWithEditor)(questions_1.staticSSLCertQuestions, existingEnvironmentSecrets);
287
+ }
288
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Storage'), '\n');
289
+ let enableEncryption = false;
290
+ const encryption_key_defined = (0, utils_1.findExistingValue)('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', existingValues);
291
+ if (!encryption_key_defined && !environment_exists) {
292
+ const answers_enable_encryption = yield (0, prompts_1.default)([
293
+ {
294
+ name: 'enableEncryption',
295
+ type: 'confirm',
296
+ message: 'Do you want to enable disk encryption?',
297
+ scope: 'ENVIRONMENT',
298
+ initial: Boolean(process.env.ENABLE_ENCRYPTION)
299
+ }
300
+ ].map(questionToPrompt));
301
+ enableEncryption = answers_enable_encryption.enableEncryption;
302
+ }
303
+ if (enableEncryption && !encryption_key_defined && !environment_exists) {
304
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow(' Disk encryption is enabled'));
305
+ yield promptAndStoreAnswer(environment, questions_1.diskQuestions, existingValues);
306
+ }
307
+ else {
308
+ if (!enableEncryption && !encryption_key_defined && environment_exists) {
309
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().grey(`Environment ${environment} is already configured, skipping disk encryption question`));
310
+ }
311
+ const DISK_SPACE = (0, utils_1.findExistingValue)('DISK_SPACE', 'VARIABLE', 'ENVIRONMENT', existingValues);
312
+ if (!DISK_SPACE) {
313
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().grey('All available disk space at /data will be used'));
314
+ }
315
+ else {
316
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Variable DISK_SPACE is read-only, allocated space:'), DISK_SPACE === null || DISK_SPACE === void 0 ? void 0 : DISK_SPACE.value);
317
+ }
318
+ }
319
+ // Backup and restore configuration
320
+ let backupHost = ((_a = (0, utils_1.findExistingValue)('BACKUP_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _a === void 0 ? void 0 : _a.value) || '';
321
+ let backupType = '';
322
+ let restoreEnvironmentName = (_b = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _b === void 0 ? void 0 : _b.value;
323
+ let restoreType = ((_c = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_MODE', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _c === void 0 ? void 0 : _c.value) || process.env.RESTORE_ENVIRONMENT_MODE || 'dump';
324
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Backup'));
325
+ let configureBackup = backupHost ? true : false;
326
+ // Ask question only if backup and restore are not configured
327
+ if (!configureBackup && !restoreEnvironmentName) {
328
+ configureBackup = yield confirm({
329
+ message: 'Do you want to configure backup?',
330
+ default: Boolean(process.env.CONFIGURE_BACKUP)
331
+ });
332
+ }
333
+ let backupHostPrivateKey = '';
334
+ let backupHostPublicKey = '';
335
+ if (configureBackup) {
336
+ const backupAnswers = (yield promptAndStoreAnswer(environment, questions_1.backupQuestions, existingValues));
337
+ let backupHostPrivateKeyExists = (0, utils_1.findExistingValue)('BACKUP_HOST_PRIVATE_KEY', 'SECRET', 'ENVIRONMENT', existingValues);
338
+ backupType = backupAnswers.backupType;
339
+ backupHost = backupAnswers.backupHost || backupHost;
340
+ if (!backupHostPrivateKeyExists) {
341
+ const { publicKey, privateKey } = (0, ssh_keygen_1.generateSSHKeyPair)();
342
+ backupHostPublicKey = publicKey;
343
+ backupHostPrivateKey = privateKey;
344
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`));
345
+ }
346
+ }
347
+ else {
348
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Backup is disabled'));
349
+ }
350
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Restore'));
351
+ let configureRestore = restoreEnvironmentName ? true : false;
352
+ if (!restoreEnvironmentName && !configureBackup) {
353
+ configureRestore = yield confirm({
354
+ message: 'Do you want to configure restore?',
355
+ default: Boolean(process.env.CONFIGURE_RESTORE)
356
+ });
357
+ }
358
+ if (configureRestore) {
359
+ const env_list_filtered = existingEnvironments.filter(env => env !== environment);
360
+ restoreEnvironmentName = yield (0, questions_helper_1.selectWithCustom)({
361
+ message: 'What is the name of your environment to restore?',
362
+ choices: env_list_filtered.map(env => ({
363
+ name: env,
364
+ value: env
365
+ })),
366
+ initial: restoreEnvironmentName
367
+ });
368
+ restoreType = yield select({ message: `Select ${kleur_1.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
369
+ choices: [
370
+ {
371
+ name: 'Full dump (daily full database backup)',
372
+ value: 'dump'
373
+ },
374
+ {
375
+ name: 'Differential (weekly full, daily diff backup)',
376
+ value: 'differential'
377
+ }
378
+ ] });
379
+ }
380
+ else {
381
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Restore is disabled'));
382
+ }
383
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Monitoring'));
384
+ yield promptAndStoreAnswer(environment, questions_1.databaseAndMonitoringQuestions, existingValues);
385
+ const sentryDSNExists = (0, utils_1.findExistingValue)('SENTRY_DSN', 'SECRET', 'ENVIRONMENT', existingValues);
386
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Sentry'));
387
+ if (sentryDSNExists) {
388
+ yield promptAndStoreAnswer(environment, questions_1.sentryQuestions, existingValues);
389
+ }
390
+ else {
391
+ const { useSentry } = yield (0, prompts_1.default)([
392
+ {
393
+ name: 'useSentry',
394
+ type: 'confirm',
395
+ message: 'Do you want to use Sentry?',
396
+ initial: Boolean(process.env.SENTRY_DNS)
397
+ }
398
+ ]);
399
+ if (useSentry) {
400
+ yield promptAndStoreAnswer(environment, questions_1.sentryQuestions, existingValues);
401
+ }
402
+ }
403
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('METABASE ADMIN'));
404
+ yield promptAndStoreAnswer(environment, questions_1.metabaseAdminQuestions, existingValues);
405
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('SMTP'));
406
+ yield promptAndStoreAnswer(environment, questions_1.emailQuestions, existingValues);
407
+ const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
408
+ return Object.assign(Object.assign({}, acc), answer);
409
+ });
410
+ /*
411
+ * Variables the user doesn't need to set manually
412
+ */
413
+ const answerOrExisting = (variable, existingValue,
414
+ // eslint-disable-next-line no-unused-vars
415
+ fn) => fn(variable || (existingValue === null || existingValue === void 0 ? void 0 : existingValue.value)) || '';
416
+ function findExistingOrDefine(name, type, scope, newValue) {
417
+ return (0, utils_1.findExistingValue)(name, type, scope, existingValues)
418
+ ? null
419
+ : process.env[name] || newValue;
420
+ }
421
+ const derivedUpdates = [
422
+ {
423
+ name: 'GH_ENCRYPTION_PASSWORD',
424
+ type: 'SECRET',
425
+ didExist: (0, utils_1.findExistingValue)('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', existingValues),
426
+ value: findExistingOrDefine('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', (0, utils_1.generateLongPassword)()),
427
+ scope: 'REPOSITORY'
428
+ },
429
+ ];
430
+ derivedUpdates.push({
431
+ name: 'NOTIFICATION_TRANSPORT',
432
+ type: 'VARIABLE',
433
+ didExist: (0, utils_1.findExistingValue)('NOTIFICATION_TRANSPORT', 'VARIABLE', 'ENVIRONMENT', existingValues),
434
+ value: findExistingOrDefine('NOTIFICATION_TRANSPORT', 'VARIABLE', 'ENVIRONMENT', 'email'),
435
+ scope: 'ENVIRONMENT'
436
+ });
437
+ derivedUpdates.push(...ssl_answers);
438
+ if (configureBackup) {
439
+ derivedUpdates.push({
440
+ name: 'BACKUP_ENCRYPTION_PASSPHRASE',
441
+ type: 'SECRET',
442
+ didExist: (0, utils_1.findExistingValue)('BACKUP_ENCRYPTION_PASSPHRASE', 'SECRET', 'ENVIRONMENT', existingValues),
443
+ value: findExistingOrDefine('BACKUP_ENCRYPTION_PASSPHRASE', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
444
+ scope: 'ENVIRONMENT'
445
+ });
446
+ }
447
+ const applicationServerUpdates = [
448
+ {
449
+ name: 'ELASTICSEARCH_SUPERUSER_PASSWORD',
450
+ type: 'SECRET',
451
+ didExist: (0, utils_1.findExistingValue)('ELASTICSEARCH_SUPERUSER_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
452
+ value: findExistingOrDefine('ELASTICSEARCH_SUPERUSER_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
453
+ scope: 'ENVIRONMENT'
454
+ },
455
+ {
456
+ name: 'KIBANA_SYSTEM_PASSWORD',
457
+ type: 'SECRET',
458
+ didExist: (0, utils_1.findExistingValue)('KIBANA_SYSTEM_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
459
+ value: findExistingOrDefine('KIBANA_SYSTEM_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
460
+ scope: 'ENVIRONMENT'
461
+ },
462
+ {
463
+ name: 'MINIO_ROOT_USER',
464
+ type: 'SECRET',
465
+ didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', existingValues),
466
+ value: findExistingOrDefine('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
467
+ scope: 'ENVIRONMENT'
468
+ },
469
+ {
470
+ name: 'MINIO_ROOT_PASSWORD',
471
+ type: 'SECRET',
472
+ didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
473
+ value: findExistingOrDefine('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
474
+ scope: 'ENVIRONMENT'
475
+ },
476
+ {
477
+ name: 'MONGODB_ADMIN_USER',
478
+ type: 'SECRET',
479
+ didExist: (0, utils_1.findExistingValue)('MONGODB_ADMIN_USER', 'SECRET', 'ENVIRONMENT', existingValues),
480
+ value: findExistingOrDefine('MONGODB_ADMIN_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
481
+ scope: 'ENVIRONMENT'
482
+ },
483
+ {
484
+ name: 'MONGODB_ADMIN_PASSWORD',
485
+ type: 'SECRET',
486
+ didExist: (0, utils_1.findExistingValue)('MONGODB_ADMIN_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
487
+ value: findExistingOrDefine('MONGODB_ADMIN_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
488
+ scope: 'ENVIRONMENT'
489
+ },
490
+ {
491
+ name: 'POSTGRES_USER',
492
+ type: 'SECRET',
493
+ didExist: (0, utils_1.findExistingValue)('POSTGRES_USER', 'SECRET', 'ENVIRONMENT', existingValues),
494
+ value: findExistingOrDefine('POSTGRES_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
495
+ scope: 'ENVIRONMENT'
496
+ },
497
+ {
498
+ name: 'POSTGRES_PASSWORD',
499
+ type: 'SECRET',
500
+ didExist: (0, utils_1.findExistingValue)('POSTGRES_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
501
+ value: findExistingOrDefine('POSTGRES_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
502
+ scope: 'ENVIRONMENT'
503
+ },
504
+ {
505
+ name: 'SUPER_USER_PASSWORD',
506
+ type: 'SECRET',
507
+ didExist: (0, utils_1.findExistingValue)('SUPER_USER_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
508
+ value: findExistingOrDefine('SUPER_USER_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
509
+ scope: 'ENVIRONMENT'
510
+ },
511
+ {
512
+ type: 'VARIABLE',
513
+ name: 'ACTIVATE_USERS',
514
+ value: 'production' === environment_type ? 'false' : 'true',
515
+ didExist: (0, utils_1.findExistingValue)('ACTIVATE_USERS', 'VARIABLE', 'ENVIRONMENT', existingValues),
516
+ scope: 'ENVIRONMENT'
517
+ },
518
+ {
519
+ type: 'VARIABLE',
520
+ name: 'COUNTRY_CONFIG_HOST',
521
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://countryconfig.${val}`),
522
+ didExist: (0, utils_1.findExistingValue)('COUNTRY_CONFIG_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
523
+ scope: 'ENVIRONMENT'
524
+ },
525
+ {
526
+ type: 'VARIABLE',
527
+ name: 'GATEWAY_HOST',
528
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://gateway.${val}`),
529
+ didExist: (0, utils_1.findExistingValue)('GATEWAY_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
530
+ scope: 'ENVIRONMENT'
531
+ },
532
+ {
533
+ type: 'VARIABLE',
534
+ name: 'CONTENT_SECURITY_POLICY_WILDCARD',
535
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `*.${val}`),
536
+ didExist: (0, utils_1.findExistingValue)('CONTENT_SECURITY_POLICY_WILDCARD', 'VARIABLE', 'ENVIRONMENT', existingValues),
537
+ scope: 'ENVIRONMENT'
538
+ },
539
+ {
540
+ type: 'VARIABLE',
541
+ name: 'CLIENT_APP_URL',
542
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://register.${val}`),
543
+ didExist: (0, utils_1.findExistingValue)('CLIENT_APP_URL', 'VARIABLE', 'ENVIRONMENT', existingValues),
544
+ scope: 'ENVIRONMENT'
545
+ },
546
+ {
547
+ type: 'VARIABLE',
548
+ name: 'LOGIN_URL',
549
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://login.${val}`),
550
+ didExist: (0, utils_1.findExistingValue)('LOGIN_URL', 'VARIABLE', 'ENVIRONMENT', existingValues),
551
+ scope: 'ENVIRONMENT'
552
+ },
553
+ {
554
+ type: 'VARIABLE',
555
+ name: 'RESTORE_ENVIRONMENT_NAME',
556
+ value: answerOrExisting(restoreEnvironmentName, (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => val || ''),
557
+ didExist: (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues),
558
+ scope: 'ENVIRONMENT'
559
+ }
560
+ ];
561
+ if (enableEncryption) {
562
+ applicationServerUpdates.push({
563
+ name: 'ENCRYPTION_KEY',
564
+ type: 'SECRET',
565
+ didExist: (0, utils_1.findExistingValue)('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', existingValues),
566
+ value: findExistingOrDefine('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
567
+ scope: 'ENVIRONMENT'
568
+ });
569
+ }
570
+ if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
571
+ applicationServerUpdates.push({
572
+ name: 'BACKUP_HOST_PRIVATE_KEY',
573
+ type: 'SECRET',
574
+ didExist: undefined,
575
+ value: backupHostPrivateKey,
576
+ scope: 'ENVIRONMENT'
577
+ });
578
+ applicationServerUpdates.push({
579
+ name: 'BACKUP_HOST_PUBLIC_KEY',
580
+ type: 'SECRET',
581
+ didExist: undefined,
582
+ value: backupHostPublicKey,
583
+ scope: 'ENVIRONMENT'
584
+ });
585
+ }
586
+ derivedUpdates.push(...applicationServerUpdates);
587
+ const updates = getAnswers(existingValues)
588
+ .concat(...derivedUpdates.filter((update) => update.value !== null))
589
+ .filter((variable) => {
590
+ var _a;
591
+ return Boolean(variable.value) &&
592
+ // Only update values that changed
593
+ (variable.type !== 'VARIABLE' ||
594
+ variable.value !== ((_a = variable.didExist) === null || _a === void 0 ? void 0 : _a.value));
595
+ });
596
+ (0, utils_1.storeSecrets)(environment, updates);
597
+ /*
598
+ * List out all updates to the variables and confirm with the user
599
+ */
600
+ const newSecrets = updates.filter((update) => update.type === 'SECRET' && !update.didExist);
601
+ const updatedSecrets = updates.filter((update) => update.type === 'SECRET' && Boolean(update.didExist));
602
+ const newVariables = updates.filter((update) => update.type === 'VARIABLE' && !update.didExist);
603
+ const updatedVariables = updates.filter((update) => update.type === 'VARIABLE' && Boolean(update.didExist));
604
+ const unknownVariables = existingValues.filter((value) => {
605
+ return !ALL_QUESTIONS.find((question) => question.valueLabel === value.name &&
606
+ question.valueType === value.type &&
607
+ question.scope === value.scope);
608
+ });
609
+ (0, logger_1.log)('');
610
+ if (newSecrets.length > 0) {
611
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be added to Github for environment ${environment}:`));
612
+ newSecrets
613
+ .filter(({ scope }) => scope === 'ENVIRONMENT')
614
+ .forEach((secret) => {
615
+ (0, logger_1.log)(secret.name, '=', secret.value);
616
+ });
617
+ (0, logger_1.log)('');
618
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be added to Github repository:`));
619
+ newSecrets
620
+ .filter(({ scope }) => scope === 'REPOSITORY')
621
+ .forEach((secret) => {
622
+ (0, logger_1.log)(secret.name, '=', secret.value);
623
+ });
624
+ (0, logger_1.log)('');
625
+ }
626
+ if (updatedSecrets.length > 0) {
627
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be updated in Github for environment ${environment}:`));
628
+ updatedSecrets.forEach((secret) => {
629
+ (0, logger_1.log)(secret.name, '=', secret.value);
630
+ });
631
+ (0, logger_1.log)('');
632
+ }
633
+ if (newVariables.length > 0) {
634
+ (0, logger_1.log)(kleur_1.default.yellow(`The following variables will be added to Github for environment ${environment}:`));
635
+ newVariables.forEach((variable) => {
636
+ (0, logger_1.log)(variable.name, '=', variable.value);
637
+ });
638
+ (0, logger_1.log)('');
639
+ }
640
+ if (updatedVariables.length > 0) {
641
+ (0, logger_1.log)(kleur_1.default.yellow(`The following variables will be updated in Github for environment ${environment}:`));
642
+ updatedVariables.forEach((variable) => {
643
+ var _a;
644
+ (0, logger_1.log)(variable.name, '=', variable.value, `(was ${(_a = variable.didExist) === null || _a === void 0 ? void 0 : _a.value})`);
645
+ });
646
+ (0, logger_1.log)('');
647
+ }
648
+ if (unknownVariables.length > 0) {
649
+ (0, logger_1.log)(kleur_1.default.yellow(`The following unknown variables/secrets were stored in Github are not managed by this script:`));
650
+ (0, logger_1.log)('');
651
+ (0, logger_1.log)(kleur_1.default.blue(`Repository:`));
652
+ unknownVariables
653
+ .filter(({ scope }) => scope === 'REPOSITORY')
654
+ .forEach((variable) => {
655
+ (0, logger_1.log)(kleur_1.default.cyan(variable.type) + ':', variable.name);
656
+ });
657
+ (0, logger_1.log)('');
658
+ (0, logger_1.log)(kleur_1.default.blue(`Environment:`));
659
+ unknownVariables
660
+ .filter(({ scope }) => scope === 'ENVIRONMENT')
661
+ .forEach((variable) => {
662
+ (0, logger_1.log)(kleur_1.default.cyan(variable.type) + ':', variable.name);
663
+ });
664
+ (0, logger_1.log)('');
665
+ (0, logger_1.log)(kleur_1.default.yellow(`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`));
666
+ (0, logger_1.log)('');
667
+ }
668
+ if ([]
669
+ .concat(newSecrets)
670
+ .concat(updatedSecrets)
671
+ .concat(newVariables)
672
+ .concat(updatedVariables).length === 0) {
673
+ process.exit(0);
674
+ }
675
+ const saveChanges = yield confirm({
676
+ message: 'Do you want to continue?',
677
+ default: true
678
+ });
679
+ if (!saveChanges) {
680
+ process.exit(0);
681
+ }
682
+ for (const newSecret of newSecrets) {
683
+ (0, logger_1.log)(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
684
+ if (newSecret.scope === 'ENVIRONMENT') {
685
+ yield (0, github_1.createEnvironmentSecret)(octokit, repositoryId, environment, newSecret.name, newSecret.value, githubOrganisation, githubRepository);
686
+ }
687
+ else {
688
+ yield (0, github_1.createRepositorySecret)(octokit, repositoryId, newSecret.name, newSecret.value, githubOrganisation, githubRepository);
689
+ }
690
+ }
691
+ for (const updatedSecret of updatedSecrets) {
692
+ (0, logger_1.log)(`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`);
693
+ if (updatedSecret.scope === 'ENVIRONMENT') {
694
+ yield (0, github_1.createEnvironmentSecret)(octokit, repositoryId, environment, updatedSecret.name, updatedSecret.value, githubOrganisation, githubRepository);
695
+ }
696
+ else {
697
+ yield (0, github_1.createRepositorySecret)(octokit, repositoryId, updatedSecret.name, updatedSecret.value, githubOrganisation, githubRepository);
698
+ }
699
+ }
700
+ for (const newVariable of newVariables) {
701
+ (0, logger_1.log)(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
702
+ if (newVariable.scope === 'ENVIRONMENT') {
703
+ yield (0, github_1.createEnvironmentVariable)(octokit, repositoryId, environment, newVariable.name, newVariable.value);
704
+ }
705
+ else {
706
+ yield (0, github_1.createRepositoryVariable)(octokit, repositoryId, newVariable.name, newVariable.value);
707
+ }
708
+ }
709
+ for (const updatedVariable of updatedVariables) {
710
+ (0, logger_1.log)(`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`);
711
+ if (updatedVariable.scope === 'ENVIRONMENT') {
712
+ yield (0, github_1.updateEnvironmentVariable)(octokit, repositoryId, environment, updatedVariable.name, updatedVariable.value);
713
+ }
714
+ else {
715
+ yield (0, github_1.updateRepositoryVariable)(octokit, repositoryId, updatedVariable.name, updatedVariable.value);
716
+ }
717
+ }
718
+ (0, logger_1.log)(kleur_1.default.green(`Successfully updated Github secrets and variables for environment ${environment}`));
719
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Running configuration files updates'));
720
+ (0, templates_1.generateInventory)(environment, {
721
+ kube_worker_nodes: kubeWorkerNodes,
722
+ kube_api_host: infrastructure.kubeAPIHost || '',
723
+ backup_host: backupHost || '',
724
+ users: users
725
+ });
726
+ (0, templates_1.copyChartsValues)(environment, {
727
+ env: environment,
728
+ environment_type: environment_type,
729
+ // FIXME: In general that should be environment_type,
730
+ // Hardcode like this blocks us from being generic:
731
+ // https://github.com/opencrvs/opencrvs-core/issues/11171
732
+ two_fa_enabled: environment !== 'production' ? false : true,
733
+ backup_enabled: configureBackup ? true : false,
734
+ restore_enabled: restoreEnvironmentName ? true : false,
735
+ restore_environment_name: restoreEnvironmentName || "",
736
+ restore_type: restoreType,
737
+ traefik_mode: traefikConfOption,
738
+ backup_type: backupType
739
+ });
740
+ let addon_message = kubeWorkerNodes.length > 0 || configureBackup ?
741
+ "--------------------------------------------------------------------------------------------\n" +
742
+ `\n➡️ ${kleur_1.default.bold().yellow('COPY the SSH public key from the master VM to your clipboard')}\n` +
743
+ "--------------------------------------------------------------------------------------------\n" : "";
744
+ addon_message += kubeWorkerNodes.length > 0 ?
745
+ `➡️ ${kleur_1.default.bold().yellow('Run following command on Kubernetes worker VM to create provision user and setup SSH key:')}\n` +
746
+ "\n" +
747
+ "curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\ \n" +
748
+ `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"\n` : "";
749
+ addon_message += configureBackup ?
750
+ `\n➡️ ${kleur_1.default.bold().yellow('Run following command on backup server to create provision user and setup SSH key:')}\n` +
751
+ "curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\ \n" +
752
+ `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"` : "";
753
+ (0, logger_1.log)(`
754
+ ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
755
+ Follow the steps below to complete the setup of your environment:
756
+ ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
757
+ ➡️ ${kleur_1.default.bold().yellow('Run following command on Kubernetes master VM to bootstrap self-hosted runner:')}
758
+
759
+ curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
760
+ bash opencrvs-bootstrap.sh --owner ${githubOrganisation} \\
761
+ --repo ${githubRepository} \\
762
+ --env ${environment} \\
763
+ --token ${githubToken} \\
764
+ --enable-runner
765
+
766
+ ${addon_message}
767
+
768
+ ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
769
+ ${kleur_1.default.yellow('Please KINDLY read hints above')}
770
+ `);
771
+ (0, logger_1.log)('\nAll variables stored in', kleur_1.default.cyan(`.env.${environment}`));
772
+ (0, logger_1.log)(kleur_1.default.bold().yellow('DO NOT COMMIT THIS FILE TO GIT!'));
773
+ }))();