@opencrvs/toolkit 2.1.0-rc.1f688f9 → 2.1.0-rc.268cfbe

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