@opencrvs/toolkit 2.1.0-rc.12673aa → 2.1.0-rc.14fb6a5

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