@opencrvs/toolkit 2.1.0-rc.c498f10 → 2.1.0-rc.c500a81

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