@opencrvs/toolkit 2.1.0-rc.7985421 → 2.1.0-rc.7c723fe

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 (242) 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 +361 -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 +3751 -1232
  11. package/dist/commons/api/router.d.ts +745 -372
  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 +42 -12
  20. package/dist/commons/events/AuditLog.d.ts +39 -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 +104 -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/locations.d.ts +162 -26
  38. package/dist/commons/events/mocks.test.utils.d.ts +30 -0
  39. package/dist/commons/events/scopes.d.ts +21 -1
  40. package/dist/commons/events/test.utils.d.ts +78 -25
  41. package/dist/commons/events/utils.d.ts +39 -4
  42. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  43. package/dist/commons/notification/dispatch.d.ts +10 -0
  44. package/dist/commons/notification/index.d.ts +1 -0
  45. package/dist/conditionals/index.js +348 -65
  46. package/dist/csv.d.ts +25 -0
  47. package/dist/csv.d.ts.map +1 -0
  48. package/dist/csv.js +120 -0
  49. package/dist/environment/index.d.ts +1 -0
  50. package/dist/environment/index.d.ts.map +1 -1
  51. package/dist/environment/index.js +12 -1
  52. package/dist/environment/logger.d.ts +15 -3
  53. package/dist/environment/logger.d.ts.map +1 -1
  54. package/dist/environment/manage-users.js +1 -1
  55. package/dist/environment/paths.d.ts +7 -0
  56. package/dist/environment/paths.d.ts.map +1 -0
  57. package/dist/environment/paths.js +72 -0
  58. package/dist/environment/questions.d.ts.map +1 -1
  59. package/dist/environment/questions.js +20 -14
  60. package/dist/environment/setup-environment.d.ts +1 -1
  61. package/dist/environment/setup-environment.d.ts.map +1 -1
  62. package/dist/environment/setup-environment.js +594 -562
  63. package/dist/environment/swarm-to-k8s.js +3 -4
  64. package/dist/environment/templates.d.ts +0 -1
  65. package/dist/environment/templates.d.ts.map +1 -1
  66. package/dist/environment/templates.js +5 -9
  67. package/dist/environment/update-workflows.d.ts.map +1 -1
  68. package/dist/environment/update-workflows.js +21 -5
  69. package/dist/environment/upgrade.d.ts +2 -0
  70. package/dist/environment/upgrade.d.ts.map +1 -0
  71. package/dist/environment/upgrade.js +82 -0
  72. package/dist/environment/users.js +11 -13
  73. package/dist/environment/utils.d.ts +0 -12
  74. package/dist/environment/utils.d.ts.map +1 -1
  75. package/dist/environment/utils.js +1 -28
  76. package/dist/events/index.js +7286 -6783
  77. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  78. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  79. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  80. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  81. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  82. package/dist/migrations/v2.1/add-translations.js +149 -0
  83. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/enable-telemetry.d.ts} +1 -1
  84. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  85. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  86. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  87. package/dist/migrations/v2.1/index.js +1952 -0
  88. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  89. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  90. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
  91. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  92. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  93. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  94. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  95. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  96. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  97. package/dist/migrations/{v2.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  98. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  99. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  100. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  101. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  102. package/dist/migrations/v2.1/template-files.js +49 -0
  103. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  104. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  105. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  106. package/dist/notification/index.js +1839 -1499
  107. package/dist/scopes/index.d.ts +612 -36
  108. package/dist/scopes/index.js +350 -65
  109. package/dist/telemetry/index.d.ts +45 -0
  110. package/dist/telemetry/index.d.ts.map +1 -0
  111. package/dist/telemetry/index.js +43 -0
  112. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  113. package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
  114. package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
  115. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  116. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  117. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  118. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  119. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  120. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  121. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  122. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  123. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  124. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  125. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  126. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  127. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  128. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  129. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  130. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  131. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  132. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  133. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  134. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  135. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  136. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  137. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  138. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  139. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  140. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  141. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  142. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  143. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  144. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  145. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  146. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  147. package/dist/templates/inventory/inventory.template.yml +1 -3
  148. package/dist/translations/template.d.ts +11 -0
  149. package/dist/translations/template.d.ts.map +1 -0
  150. package/dist/translations/template.js +100 -0
  151. package/dist/verify/endpoints.d.ts +2 -0
  152. package/dist/verify/endpoints.d.ts.map +1 -0
  153. package/dist/verify/endpoints.js +510 -0
  154. package/opencrvs-toolkit-2.1.0-rc.7c723fe.tgz +0 -0
  155. package/package.json +13 -7
  156. package/tsconfig.build.json +11 -0
  157. package/tsconfig.build.tsbuildinfo +1 -0
  158. package/tsconfig.json +3 -0
  159. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  160. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  161. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  162. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  163. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  164. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  165. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  166. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  167. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  168. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  169. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  170. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  171. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  172. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  173. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  174. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  175. package/dist/migrations/v2.0/create-events-index.js +0 -325
  176. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  177. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  178. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  179. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  180. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  181. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  182. package/dist/migrations/v2.0/index.d.ts +0 -13
  183. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  184. package/dist/migrations/v2.0/index.js +0 -103
  185. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  186. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  187. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  188. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  189. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  190. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  191. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  192. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  193. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  194. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  195. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  196. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  197. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  198. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  199. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  200. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  201. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  202. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  203. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  204. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  205. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  206. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  207. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  208. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  209. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  210. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  211. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  212. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  213. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  214. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  215. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  216. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  217. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  218. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  219. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  220. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  221. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  222. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  223. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  224. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  225. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  226. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  227. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  228. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  229. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  230. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  231. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  232. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  233. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  234. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  235. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  236. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  237. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  238. package/dist/migrations/v2.0/update-package-json.js +0 -105
  239. package/dist/templates/inventory/production.example.yml +0 -77
  240. package/dist/templates/inventory/qa.example.yml +0 -48
  241. package/opencrvs-toolkit-2.1.0-rc.7985421.tgz +0 -0
  242. 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,612 @@ 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
+ choices: [
400
+ {
401
+ name: 'Full dump (daily full database backup)',
402
+ value: 'dump'
403
+ },
404
+ {
405
+ name: 'Differential (weekly full, daily diff backup)',
406
+ value: 'differential'
407
+ }
408
+ ]
409
+ });
410
+ restoreHost = yield input({
411
+ message: 'What is the host/IP address of the restore backup server?',
412
+ default: restoreHost
413
+ });
414
+ }
415
+ else {
416
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Restore is disabled'));
417
+ }
418
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Monitoring'));
419
+ yield promptAndStoreAnswer(questions_1.databaseAndMonitoringQuestions, existingValues);
420
+ const sentryDSNExists = (0, utils_1.findExistingValue)('SENTRY_DSN', 'SECRET', 'ENVIRONMENT', existingValues);
421
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Sentry'));
422
+ if (sentryDSNExists) {
423
+ yield promptAndStoreAnswer(questions_1.sentryQuestions, existingValues);
424
+ }
425
+ else {
426
+ const { useSentry } = yield (0, prompts_1.default)([
389
427
  {
390
- name: 'Differential (weekly full, daily diff backup)',
391
- value: 'differential'
428
+ name: 'useSentry',
429
+ type: 'confirm',
430
+ message: 'Do you want to use Sentry?',
431
+ initial: Boolean(process.env.SENTRY_DNS)
392
432
  }
393
- ]
433
+ ]);
434
+ if (useSentry) {
435
+ yield promptAndStoreAnswer(questions_1.sentryQuestions, existingValues);
436
+ }
437
+ }
438
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('METABASE ADMIN'));
439
+ yield promptAndStoreAnswer(questions_1.metabaseAdminQuestions, existingValues);
440
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('SMTP'));
441
+ yield promptAndStoreAnswer(questions_1.emailQuestions, existingValues);
442
+ const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
443
+ return Object.assign(Object.assign({}, acc), answer);
394
444
  });
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)([
445
+ /*
446
+ * Variables the user doesn't need to set manually
447
+ */
448
+ const answerOrExisting = (variable, existingValue, fn) => fn(variable || (existingValue === null || existingValue === void 0 ? void 0 : existingValue.value)) || '';
449
+ function findExistingOrDefine(name, type, scope, newValue) {
450
+ return (0, utils_1.findExistingValue)(name, type, scope, existingValues)
451
+ ? null
452
+ : process.env[name] || newValue;
453
+ }
454
+ const derivedUpdates = [
408
455
  {
409
- name: 'useSentry',
410
- type: 'confirm',
411
- message: 'Do you want to use Sentry?',
412
- initial: Boolean(process.env.SENTRY_DNS)
456
+ name: 'GH_ENCRYPTION_PASSWORD',
457
+ type: 'SECRET',
458
+ didExist: (0, utils_1.findExistingValue)('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', existingValues),
459
+ value: findExistingOrDefine('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', (0, utils_1.generateLongPassword)()),
460
+ scope: 'REPOSITORY'
413
461
  }
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) {
462
+ ];
453
463
  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
- {
464
+ name: 'NOTIFICATION_TRANSPORT',
526
465
  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),
530
- 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)()),
466
+ didExist: (0, utils_1.findExistingValue)('NOTIFICATION_TRANSPORT', 'VARIABLE', 'ENVIRONMENT', existingValues),
467
+ value: findExistingOrDefine('NOTIFICATION_TRANSPORT', 'VARIABLE', 'ENVIRONMENT', 'email'),
567
468
  scope: 'ENVIRONMENT'
568
469
  });
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
- });
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);
470
+ derivedUpdates.push(...ssl_answers);
471
+ if (configureBackup) {
472
+ derivedUpdates.push({
473
+ name: 'BACKUP_ENCRYPTION_PASSPHRASE',
474
+ type: 'SECRET',
475
+ didExist: (0, utils_1.findExistingValue)('BACKUP_ENCRYPTION_PASSPHRASE', 'SECRET', 'ENVIRONMENT', existingValues),
476
+ value: findExistingOrDefine('BACKUP_ENCRYPTION_PASSPHRASE', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
477
+ scope: 'ENVIRONMENT'
478
+ });
479
+ }
480
+ const applicationServerUpdates = [
481
+ {
482
+ name: 'ELASTICSEARCH_SUPERUSER_PASSWORD',
483
+ type: 'SECRET',
484
+ didExist: (0, utils_1.findExistingValue)('ELASTICSEARCH_SUPERUSER_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
485
+ value: findExistingOrDefine('ELASTICSEARCH_SUPERUSER_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
486
+ scope: 'ENVIRONMENT'
487
+ },
488
+ {
489
+ name: 'KIBANA_SYSTEM_PASSWORD',
490
+ type: 'SECRET',
491
+ didExist: (0, utils_1.findExistingValue)('KIBANA_SYSTEM_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
492
+ value: findExistingOrDefine('KIBANA_SYSTEM_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
493
+ scope: 'ENVIRONMENT'
494
+ },
495
+ {
496
+ name: 'MINIO_ROOT_USER',
497
+ type: 'SECRET',
498
+ didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', existingValues),
499
+ value: findExistingOrDefine('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
500
+ scope: 'ENVIRONMENT'
501
+ },
502
+ {
503
+ name: 'MINIO_ROOT_PASSWORD',
504
+ type: 'SECRET',
505
+ didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
506
+ value: findExistingOrDefine('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
507
+ scope: 'ENVIRONMENT'
508
+ },
509
+ {
510
+ name: 'POSTGRES_USER',
511
+ type: 'SECRET',
512
+ didExist: (0, utils_1.findExistingValue)('POSTGRES_USER', 'SECRET', 'ENVIRONMENT', existingValues),
513
+ value: findExistingOrDefine('POSTGRES_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
514
+ scope: 'ENVIRONMENT'
515
+ },
516
+ {
517
+ name: 'POSTGRES_PASSWORD',
518
+ type: 'SECRET',
519
+ didExist: (0, utils_1.findExistingValue)('POSTGRES_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
520
+ value: findExistingOrDefine('POSTGRES_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
521
+ scope: 'ENVIRONMENT'
522
+ },
523
+ {
524
+ name: 'SUPER_USER_PASSWORD',
525
+ type: 'SECRET',
526
+ didExist: (0, utils_1.findExistingValue)('SUPER_USER_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
527
+ value: findExistingOrDefine('SUPER_USER_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
528
+ scope: 'ENVIRONMENT'
529
+ },
530
+ {
531
+ type: 'VARIABLE',
532
+ name: 'ACTIVATE_USERS',
533
+ value: 'production' === environment_type ? 'false' : 'true',
534
+ didExist: (0, utils_1.findExistingValue)('ACTIVATE_USERS', 'VARIABLE', 'ENVIRONMENT', existingValues),
535
+ scope: 'ENVIRONMENT'
536
+ },
537
+ {
538
+ type: 'VARIABLE',
539
+ name: 'COUNTRY_CONFIG_HOST',
540
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://countryconfig.${val}`),
541
+ didExist: (0, utils_1.findExistingValue)('COUNTRY_CONFIG_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
542
+ scope: 'ENVIRONMENT'
543
+ },
544
+ {
545
+ type: 'VARIABLE',
546
+ name: 'GATEWAY_HOST',
547
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://gateway.${val}`),
548
+ didExist: (0, utils_1.findExistingValue)('GATEWAY_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
549
+ scope: 'ENVIRONMENT'
550
+ },
551
+ {
552
+ type: 'VARIABLE',
553
+ name: 'CONTENT_SECURITY_POLICY_WILDCARD',
554
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `*.${val}`),
555
+ didExist: (0, utils_1.findExistingValue)('CONTENT_SECURITY_POLICY_WILDCARD', 'VARIABLE', 'ENVIRONMENT', existingValues),
556
+ scope: 'ENVIRONMENT'
557
+ },
558
+ {
559
+ type: 'VARIABLE',
560
+ name: 'CLIENT_APP_URL',
561
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://register.${val}`),
562
+ didExist: (0, utils_1.findExistingValue)('CLIENT_APP_URL', 'VARIABLE', 'ENVIRONMENT', existingValues),
563
+ scope: 'ENVIRONMENT'
564
+ },
565
+ {
566
+ type: 'VARIABLE',
567
+ name: 'LOGIN_URL',
568
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://login.${val}`),
569
+ didExist: (0, utils_1.findExistingValue)('LOGIN_URL', 'VARIABLE', 'ENVIRONMENT', existingValues),
570
+ scope: 'ENVIRONMENT'
571
+ },
572
+ {
573
+ type: 'VARIABLE',
574
+ name: 'RESTORE_ENVIRONMENT_NAME',
575
+ value: answerOrExisting(restoreEnvironmentName, (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => val || ''),
576
+ didExist: (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues),
577
+ scope: 'ENVIRONMENT'
578
+ },
579
+ {
580
+ type: 'VARIABLE',
581
+ name: 'RESTORE_HOST',
582
+ value: answerOrExisting(restoreHost, (0, utils_1.findExistingValue)('RESTORE_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => val || ''),
583
+ didExist: (0, utils_1.findExistingValue)('RESTORE_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
584
+ scope: 'ENVIRONMENT'
585
+ }
586
+ ];
587
+ if (enableEncryption) {
588
+ applicationServerUpdates.push({
589
+ name: 'ENCRYPTION_KEY',
590
+ type: 'SECRET',
591
+ didExist: (0, utils_1.findExistingValue)('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', existingValues),
592
+ value: findExistingOrDefine('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
593
+ scope: 'ENVIRONMENT'
594
+ });
595
+ }
596
+ if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
597
+ applicationServerUpdates.push({
598
+ name: 'BACKUP_HOST_PRIVATE_KEY',
599
+ type: 'SECRET',
600
+ didExist: undefined,
601
+ value: backupHostPrivateKey,
602
+ scope: 'ENVIRONMENT'
603
+ });
604
+ applicationServerUpdates.push({
605
+ name: 'BACKUP_HOST_PUBLIC_KEY',
606
+ type: 'SECRET',
607
+ didExist: undefined,
608
+ value: backupHostPublicKey,
609
+ scope: 'ENVIRONMENT'
610
+ });
611
+ }
612
+ derivedUpdates.push(...applicationServerUpdates);
613
+ const updates = getAnswers(existingValues)
614
+ .concat(...derivedUpdates.filter((update) => update.value !== null))
615
+ .filter((variable) => { var _a; return Boolean(variable.value) &&
616
+ // Only update values that changed
617
+ (variable.type !== 'VARIABLE' ||
618
+ variable.value !== ((_a = variable.didExist) === null || _a === void 0 ? void 0 : _a.value)); });
619
+ /*
620
+ * List out all updates to the variables and confirm with the user
621
+ */
622
+ const newSecrets = updates.filter((update) => update.type === 'SECRET' && !update.didExist);
623
+ const updatedSecrets = updates.filter((update) => update.type === 'SECRET' && Boolean(update.didExist));
624
+ const newVariables = updates.filter((update) => update.type === 'VARIABLE' && !update.didExist);
625
+ const updatedVariables = updates.filter((update) => update.type === 'VARIABLE' && Boolean(update.didExist));
626
+ const unknownVariables = existingValues.filter((value) => {
627
+ return !ALL_QUESTIONS.find((question) => question.valueLabel === value.name &&
628
+ question.valueType === value.type &&
629
+ question.scope === value.scope);
660
630
  });
661
631
  (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);
632
+ if (newSecrets.length > 0) {
633
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be added to Github for environment ${environment}:`));
634
+ newSecrets
635
+ .filter(({ scope }) => scope === 'ENVIRONMENT')
636
+ .forEach((secret) => {
637
+ (0, logger_1.log)(secret.name, '=', secret.value);
638
+ });
639
+ (0, logger_1.log)('');
640
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be added to Github repository:`));
641
+ newSecrets
642
+ .filter(({ scope }) => scope === 'REPOSITORY')
643
+ .forEach((secret) => {
644
+ (0, logger_1.log)(secret.name, '=', secret.value);
645
+ });
646
+ (0, logger_1.log)('');
683
647
  }
684
- else {
685
- yield (0, github_1.createRepositorySecret)(octokit, repositoryId, newSecret.name, newSecret.value, githubOrganisation, githubRepository);
648
+ if (updatedSecrets.length > 0) {
649
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be updated in Github for environment ${environment}:`));
650
+ updatedSecrets.forEach((secret) => {
651
+ (0, logger_1.log)(secret.name, '=', secret.value);
652
+ });
653
+ (0, logger_1.log)('');
686
654
  }
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);
655
+ if (newVariables.length > 0) {
656
+ (0, logger_1.log)(kleur_1.default.yellow(`The following variables will be added to Github for environment ${environment}:`));
657
+ newVariables.forEach((variable) => {
658
+ (0, logger_1.log)(variable.name, '=', variable.value);
659
+ });
660
+ (0, logger_1.log)('');
692
661
  }
693
- else {
694
- yield (0, github_1.createRepositorySecret)(octokit, repositoryId, updatedSecret.name, updatedSecret.value, githubOrganisation, githubRepository);
662
+ if (updatedVariables.length > 0) {
663
+ (0, logger_1.log)(kleur_1.default.yellow(`The following variables will be updated in Github for environment ${environment}:`));
664
+ updatedVariables.forEach((variable) => {
665
+ var _a;
666
+ (0, logger_1.log)(variable.name, '=', variable.value, `(was ${(_a = variable.didExist) === null || _a === void 0 ? void 0 : _a.value})`);
667
+ });
668
+ (0, logger_1.log)('');
695
669
  }
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);
670
+ if (unknownVariables.length > 0) {
671
+ (0, logger_1.log)(kleur_1.default.yellow(`The following unknown variables/secrets were stored in Github are not managed by this script:`));
672
+ (0, logger_1.log)('');
673
+ (0, logger_1.log)(kleur_1.default.blue(`Repository:`));
674
+ unknownVariables
675
+ .filter(({ scope }) => scope === 'REPOSITORY')
676
+ .forEach((variable) => {
677
+ (0, logger_1.log)(kleur_1.default.cyan(variable.type) + ':', variable.name);
678
+ });
679
+ (0, logger_1.log)('');
680
+ (0, logger_1.log)(kleur_1.default.blue(`Environment:`));
681
+ unknownVariables
682
+ .filter(({ scope }) => scope === 'ENVIRONMENT')
683
+ .forEach((variable) => {
684
+ (0, logger_1.log)(kleur_1.default.cyan(variable.type) + ':', variable.name);
685
+ });
686
+ (0, logger_1.log)('');
687
+ (0, logger_1.log)(kleur_1.default.yellow(`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`));
688
+ (0, logger_1.log)('');
701
689
  }
702
- else {
703
- yield (0, github_1.createRepositoryVariable)(octokit, repositoryId, newVariable.name, newVariable.value);
690
+ if ([]
691
+ .concat(newSecrets)
692
+ .concat(updatedSecrets)
693
+ .concat(newVariables)
694
+ .concat(updatedVariables).length === 0) {
695
+ process.exit(0);
704
696
  }
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);
697
+ (0, logger_1.log)(kleur_1.default
698
+ .bold()
699
+ .red("⚠️ COPY THESE NOW INTO A PASSWORD MANAGER — YOU WON'T SEE THEM AGAIN"));
700
+ (0, logger_1.log)('');
701
+ const saveChanges = yield confirm({
702
+ message: 'Do you want to continue?',
703
+ default: true
704
+ });
705
+ if (!saveChanges) {
706
+ process.exit(0);
710
707
  }
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' +
708
+ for (const newSecret of newSecrets) {
709
+ (0, logger_1.log)(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
710
+ if (newSecret.scope === 'ENVIRONMENT') {
711
+ yield (0, github_1.createEnvironmentSecret)(octokit, repositoryId, environment, newSecret.name, newSecret.value, githubOrganisation, githubRepository);
712
+ }
713
+ else {
714
+ yield (0, github_1.createRepositorySecret)(octokit, repositoryId, newSecret.name, newSecret.value, githubOrganisation, githubRepository);
715
+ }
716
+ }
717
+ for (const updatedSecret of updatedSecrets) {
718
+ (0, logger_1.log)(`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`);
719
+ if (updatedSecret.scope === 'ENVIRONMENT') {
720
+ yield (0, github_1.createEnvironmentSecret)(octokit, repositoryId, environment, updatedSecret.name, updatedSecret.value, githubOrganisation, githubRepository);
721
+ }
722
+ else {
723
+ yield (0, github_1.createRepositorySecret)(octokit, repositoryId, updatedSecret.name, updatedSecret.value, githubOrganisation, githubRepository);
724
+ }
725
+ }
726
+ for (const newVariable of newVariables) {
727
+ (0, logger_1.log)(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
728
+ if (newVariable.scope === 'ENVIRONMENT') {
729
+ yield (0, github_1.createEnvironmentVariable)(octokit, repositoryId, environment, newVariable.name, newVariable.value);
730
+ }
731
+ else {
732
+ yield (0, github_1.createRepositoryVariable)(octokit, repositoryId, newVariable.name, newVariable.value);
733
+ }
734
+ }
735
+ for (const updatedVariable of updatedVariables) {
736
+ (0, logger_1.log)(`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`);
737
+ if (updatedVariable.scope === 'ENVIRONMENT') {
738
+ yield (0, github_1.updateEnvironmentVariable)(octokit, repositoryId, environment, updatedVariable.name, updatedVariable.value);
739
+ }
740
+ else {
741
+ yield (0, github_1.updateRepositoryVariable)(octokit, repositoryId, updatedVariable.name, updatedVariable.value);
742
+ }
743
+ }
744
+ (0, logger_1.log)(kleur_1.default.green(`Successfully updated Github secrets and variables for environment ${environment}`));
745
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Running configuration files updates'));
746
+ (0, templates_1.generateInventory)(environment, {
747
+ kube_worker_nodes: kubeWorkerNodes,
748
+ kube_api_host: infrastructure.kubeApiHost || '',
749
+ backup_host: backupHost || '',
750
+ users: users
751
+ });
752
+ (0, templates_1.copyChartsValues)(environment, {
753
+ env: environment,
754
+ environment_type: environment_type,
755
+ two_fa_enabled,
756
+ traefik_mode: traefikConfOption,
757
+ restore_enabled: restoreEnvironmentName ? true : false,
758
+ restore_environment_name: restoreEnvironmentName || '',
759
+ restore_type: restoreType,
760
+ restore_host: restoreHost || '',
761
+ backup_enabled: configureBackup ? true : false,
762
+ backup_type: backupType,
763
+ backup_host: backupHost || ''
764
+ });
765
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Updating workflow files'));
766
+ yield (0, update_workflows_1.updateWorkflowEnvironments)();
767
+ let addon_message = kubeWorkerNodes.length > 0 || configureBackup
768
+ ? '--------------------------------------------------------------------------------------------\n' +
769
+ `\n➡️ ${kleur_1.default.bold().yellow('COPY the SSH public key from the master VM to your clipboard')}\n` +
770
+ '--------------------------------------------------------------------------------------------\n'
771
+ : '';
772
+ addon_message +=
773
+ kubeWorkerNodes.length > 0
774
+ ? `➡️ ${kleur_1.default.bold().yellow('Run following command on Kubernetes worker VM to create provision user and setup SSH key:')}\n` +
775
+ '\n' +
776
+ 'curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\ \n' +
777
+ `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"\n`
778
+ : '';
779
+ addon_message += configureBackup
780
+ ? `\n➡️ ${kleur_1.default.bold().yellow('Run following command on backup server to create provision user and setup SSH key:')}\n` +
746
781
  '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`
782
+ `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"`
748
783
  : '';
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)(`
784
+ (0, logger_1.log)(`
755
785
  ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
756
786
  Follow the steps below to complete the setup of your environment:
757
787
  ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
@@ -769,6 +799,8 @@ ${addon_message}
769
799
  ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
770
800
  ${kleur_1.default.yellow('Please KINDLY read hints above')}
771
801
  `);
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
- }))();
802
+ (0, logger_1.log)('\nAll secrets and variables were printed above.', kleur_1.default
803
+ .bold()
804
+ .yellow('Store them in a password manager — they are not saved to disk.'));
805
+ });
806
+ }