@opencrvs/toolkit 2.1.0-rc.2ec6bd5 → 2.1.0-rc.3028b2e

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