@opencrvs/toolkit 2.1.0-rc.d1b9774 → 2.1.0-rc.d235243

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