@opencrvs/toolkit 2.1.0-rc.30bcbde → 2.1.0-rc.312fbd1

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