@opencrvs/toolkit 2.1.0-rc.ffe0b7f → 2.2.0-rc.ab91cce

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