@opencrvs/toolkit 2.1.0-rc.d13869e → 2.1.0-rc.d235243
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -12
- package/build.sh +23 -5
- package/create-countryconfig/index.js +441 -59
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +362 -284
- package/dist/authentication/index.d.ts +66 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +765 -0
- package/dist/cli.js +2119 -1321
- package/dist/commons/api/router.d.ts +940 -363
- package/dist/commons/application-config/index.d.ts +0 -2
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +34 -8
- package/dist/commons/events/ActionConfig.d.ts +5 -14
- package/dist/commons/events/ActionDocument.d.ts +35 -15
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/ActionStatus.d.ts +14 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +48 -12
- package/dist/commons/events/AuditLog.d.ts +148 -0
- package/dist/commons/events/Draft.d.ts +1 -21
- package/dist/commons/events/EventConfig.d.ts +3 -0
- package/dist/commons/events/EventDocument.d.ts +472 -4
- package/dist/commons/events/EventIndex.d.ts +3 -26
- package/dist/commons/events/EventMetadata.d.ts +1 -11
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +109 -63
- package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
- package/dist/commons/events/FieldValue.d.ts +3 -2
- package/dist/commons/events/Flag.d.ts +42 -0
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/PlainDate.d.ts +8 -0
- package/dist/commons/events/SummaryConfig.d.ts +249 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
- package/dist/commons/events/event.d.ts +12 -0
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locationPayloads.d.ts +95 -0
- package/dist/commons/events/locations.d.ts +169 -26
- package/dist/commons/events/mocks.test.utils.d.ts +30 -0
- package/dist/commons/events/scopes.d.ts +21 -1
- package/dist/commons/events/test.utils.d.ts +78 -25
- package/dist/commons/events/utils.d.ts +39 -4
- package/dist/commons/notification/UserNotifications.d.ts +28 -13
- package/dist/commons/notification/dispatch.d.ts +10 -0
- package/dist/commons/notification/index.d.ts +1 -0
- package/dist/conditionals/index.js +349 -65
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/derived-variables.d.ts +18 -0
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +21 -0
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +12 -1
- package/dist/environment/logger.d.ts +15 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +1 -1
- package/dist/environment/paths.d.ts +7 -0
- package/dist/environment/paths.d.ts.map +1 -0
- package/dist/environment/paths.js +72 -0
- package/dist/environment/questions.d.ts +16 -0
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +46 -15
- package/dist/environment/setup-environment.d.ts +1 -1
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +634 -560
- package/dist/environment/swarm-to-k8s.js +3 -4
- package/dist/environment/templates.d.ts +0 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +5 -9
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +23 -6
- package/dist/environment/upgrade.d.ts +2 -0
- package/dist/environment/upgrade.d.ts.map +1 -0
- package/dist/environment/upgrade.js +82 -0
- package/dist/environment/users.js +11 -13
- package/dist/environment/utils.d.ts +0 -12
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +1 -28
- package/dist/events/index.js +7689 -7063
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
- package/dist/migrations/v2.1/add-translations.d.ts +9 -0
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-translations.js +149 -0
- package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/enable-telemetry.d.ts} +1 -1
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
- package/dist/migrations/v2.1/enable-telemetry.js +455 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +47 -215
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
- package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-sentry.js +354 -0
- package/dist/migrations/{v2.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
- package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
- package/dist/migrations/v2.1/template-files.d.ts +8 -0
- package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
- package/dist/migrations/v2.1/template-files.js +49 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
- package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
- package/dist/migrations/v2.2/add-e2e-tests.d.ts +19 -0
- package/dist/migrations/v2.2/add-e2e-tests.d.ts.map +1 -0
- package/dist/migrations/v2.2/add-e2e-tests.js +143 -0
- package/dist/migrations/v2.2/index.d.ts +6 -0
- package/dist/migrations/v2.2/index.d.ts.map +1 -0
- package/dist/migrations/v2.2/index.js +279 -0
- package/dist/migrations/v2.2/template-files.d.ts +8 -0
- package/dist/migrations/v2.2/template-files.d.ts.map +1 -0
- package/dist/migrations/v2.2/template-files.js +49 -0
- package/dist/migrations/v2.2/upgrade-tilt.d.ts +8 -0
- package/dist/migrations/v2.2/upgrade-tilt.d.ts.map +1 -0
- package/dist/migrations/v2.2/upgrade-tilt.js +139 -0
- package/dist/notification/index.js +1887 -1438
- package/dist/scopes/index.d.ts +614 -36
- package/dist/scopes/index.js +351 -65
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +43 -0
- package/dist/templates/charts-values/dependencies/values.yaml +8 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
- package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
- package/dist/templates/charts-values/traefik/values.yaml +25 -12
- package/dist/templates/countryconfig-template/.tiltignore +1 -0
- package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
- package/dist/templates/countryconfig-template/Tiltfile +112 -0
- package/dist/templates/countryconfig-template/assets/README.md +1 -0
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
- package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
- package/dist/templates/countryconfig-template/e2e/README.md +36 -0
- package/dist/templates/countryconfig-template/e2e/constants.ts +28 -0
- package/dist/templates/countryconfig-template/e2e/login.e2e.ts +59 -0
- package/dist/templates/countryconfig-template/package.json +153 -0
- package/dist/templates/countryconfig-template/playwright.config.ts +42 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
- package/dist/templates/countryconfig-template/tilt/common.tilt +159 -0
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
- package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/dist/translations/template.d.ts +11 -0
- package/dist/translations/template.d.ts.map +1 -0
- package/dist/translations/template.js +100 -0
- package/dist/verify/endpoints.d.ts +2 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +510 -0
- package/opencrvs-toolkit-2.1.0-rc.d235243.tgz +0 -0
- package/package.json +13 -7
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
- package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
- package/dist/migrations/v2.0/create-events-index.js +0 -325
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
- package/dist/migrations/v2.0/index.d.ts +0 -13
- package/dist/migrations/v2.0/index.d.ts.map +0 -1
- package/dist/migrations/v2.0/index.js +0 -103
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-scopes.js +0 -305
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
- package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
- package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
- package/dist/migrations/v2.0/update-package-json.js +0 -105
- package/dist/templates/inventory/production.example.yml +0 -77
- package/dist/templates/inventory/qa.example.yml +0 -48
- package/opencrvs-toolkit-2.1.0-rc.d13869e.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
package/dist/cli.js
CHANGED
|
@@ -30,6 +30,42 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
+
// src/environment/paths.ts
|
|
34
|
+
function getEnvironmentInventoryPath(environment) {
|
|
35
|
+
return (0, import_path4.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
|
+
}
|
|
37
|
+
function findOldInventoryFiles() {
|
|
38
|
+
return glob.sync((0, import_path4.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
|
+
}
|
|
40
|
+
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
+
return (0, import_path4.basename)(filePath, ".yml");
|
|
42
|
+
}
|
|
43
|
+
function assertNoOldInventoryLayout() {
|
|
44
|
+
if (findOldInventoryFiles().length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(
|
|
48
|
+
[
|
|
49
|
+
`Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
|
|
50
|
+
"Please run `yarn environment:upgrade` before running `yarn environment:init`."
|
|
51
|
+
].join(" ")
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
var import_path4, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
|
|
55
|
+
var init_paths = __esm({
|
|
56
|
+
"src/environment/paths.ts"() {
|
|
57
|
+
"use strict";
|
|
58
|
+
import_path4 = require("path");
|
|
59
|
+
glob = __toESM(require("glob"));
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path4.join)(
|
|
61
|
+
"infrastructure",
|
|
62
|
+
"server-setup",
|
|
63
|
+
"inventory"
|
|
64
|
+
);
|
|
65
|
+
INVENTORY_FILE_NAME = "inventory.yml";
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
33
69
|
// src/environment/logger.ts
|
|
34
70
|
var import_kleur, log, warn, success, info, error;
|
|
35
71
|
var init_logger = __esm({
|
|
@@ -443,12 +479,33 @@ var init_derived_variables = __esm({
|
|
|
443
479
|
type: "disabled",
|
|
444
480
|
scope: "ENVIRONMENT"
|
|
445
481
|
},
|
|
482
|
+
{
|
|
483
|
+
name: "RESTORE_ENVIRONMENT_MODE",
|
|
484
|
+
valueLabel: "RESTORE_ENVIRONMENT_MODE",
|
|
485
|
+
valueType: "VARIABLE",
|
|
486
|
+
type: "disabled",
|
|
487
|
+
scope: "ENVIRONMENT"
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
name: "RESTORE_HOST",
|
|
491
|
+
valueLabel: "RESTORE_HOST",
|
|
492
|
+
valueType: "VARIABLE",
|
|
493
|
+
type: "disabled",
|
|
494
|
+
scope: "ENVIRONMENT"
|
|
495
|
+
},
|
|
446
496
|
{
|
|
447
497
|
name: "NOTIFICATION_TRANSPORT",
|
|
448
498
|
valueLabel: "NOTIFICATION_TRANSPORT",
|
|
449
499
|
valueType: "VARIABLE",
|
|
450
500
|
type: "disabled",
|
|
451
501
|
scope: "ENVIRONMENT"
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
name: "E2E_ENABLED",
|
|
505
|
+
valueLabel: "E2E_ENABLED",
|
|
506
|
+
valueType: "VARIABLE",
|
|
507
|
+
type: "disabled",
|
|
508
|
+
scope: "ENVIRONMENT"
|
|
452
509
|
}
|
|
453
510
|
];
|
|
454
511
|
}
|
|
@@ -467,24 +524,8 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
467
524
|
(value) => value.name === name && value.type === type && value.scope === scope
|
|
468
525
|
);
|
|
469
526
|
}
|
|
470
|
-
function storeSecrets(environment, answers) {
|
|
471
|
-
let envConfig = {};
|
|
472
|
-
try {
|
|
473
|
-
envConfig = import_dotenv.default.parse(
|
|
474
|
-
(0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
475
|
-
);
|
|
476
|
-
} catch (error4) {
|
|
477
|
-
envConfig = {};
|
|
478
|
-
}
|
|
479
|
-
const linesFromAnswers = answers.map(
|
|
480
|
-
(update) => `${update.name}="${update.value}"`
|
|
481
|
-
);
|
|
482
|
-
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
483
|
-
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
484
|
-
(0, import_fs.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
485
|
-
}
|
|
486
527
|
function readYamlFile(filePath) {
|
|
487
|
-
const fileContent =
|
|
528
|
+
const fileContent = import_fs4.default.readFileSync(filePath, "utf8");
|
|
488
529
|
return yaml.load(fileContent);
|
|
489
530
|
}
|
|
490
531
|
function writeYamlFile(filePath, data) {
|
|
@@ -497,33 +538,29 @@ function writeYamlFile(filePath, data) {
|
|
|
497
538
|
noRefs: true,
|
|
498
539
|
sortKeys: false
|
|
499
540
|
});
|
|
500
|
-
|
|
501
|
-
} catch (
|
|
502
|
-
throw new Error(`Failed to write inventory file: ${
|
|
541
|
+
import_fs4.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
542
|
+
} catch (error3) {
|
|
543
|
+
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
503
544
|
}
|
|
504
545
|
}
|
|
505
|
-
var
|
|
546
|
+
var import_fs4, yaml;
|
|
506
547
|
var init_utils = __esm({
|
|
507
548
|
"src/environment/utils.ts"() {
|
|
508
549
|
"use strict";
|
|
509
|
-
|
|
550
|
+
import_fs4 = __toESM(require("fs"));
|
|
510
551
|
yaml = __toESM(require("js-yaml"));
|
|
511
|
-
import_dotenv = __toESM(require("dotenv"));
|
|
512
552
|
}
|
|
513
553
|
});
|
|
514
554
|
|
|
515
555
|
// src/environment/templates.ts
|
|
516
|
-
function getUsers(data) {
|
|
517
|
-
if (!data?.all?.vars?.users) {
|
|
518
|
-
return { users: [] };
|
|
519
|
-
}
|
|
520
|
-
return data.all.vars.users;
|
|
521
|
-
}
|
|
522
556
|
function extractAndModifyUsers(data) {
|
|
523
557
|
if (!data?.all?.vars?.users) {
|
|
524
558
|
return { users: [] };
|
|
525
559
|
}
|
|
526
560
|
const users = data.all.vars.users.map((user) => {
|
|
561
|
+
if (user.role) {
|
|
562
|
+
return user;
|
|
563
|
+
}
|
|
527
564
|
const { sudoer, ...rest } = user;
|
|
528
565
|
return {
|
|
529
566
|
...rest,
|
|
@@ -559,29 +596,29 @@ function extractWorkerNodes(data) {
|
|
|
559
596
|
return worker_hosts;
|
|
560
597
|
}
|
|
561
598
|
function copyChartsValues(env, values) {
|
|
562
|
-
const srcDir =
|
|
563
|
-
const destDir =
|
|
564
|
-
|
|
599
|
+
const srcDir = import_path5.default.resolve(__dirname, "templates", "charts-values");
|
|
600
|
+
const destDir = import_path5.default.resolve(process.cwd(), "environments", env);
|
|
601
|
+
import_fs5.default.mkdirSync(destDir, { recursive: true });
|
|
565
602
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
566
603
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
567
604
|
values["opencrvs_environment"] = env;
|
|
568
605
|
function copyRecursive(src, dest) {
|
|
569
|
-
const stat =
|
|
606
|
+
const stat = import_fs5.default.statSync(src);
|
|
570
607
|
if (stat.isDirectory()) {
|
|
571
|
-
|
|
572
|
-
for (const item of
|
|
573
|
-
copyRecursive(
|
|
608
|
+
import_fs5.default.mkdirSync(dest, { recursive: true });
|
|
609
|
+
for (const item of import_fs5.default.readdirSync(src)) {
|
|
610
|
+
copyRecursive(import_path5.default.join(src, item), import_path5.default.join(dest, item));
|
|
574
611
|
}
|
|
575
612
|
} else {
|
|
576
|
-
const content =
|
|
613
|
+
const content = import_fs5.default.readFileSync(src, "utf8");
|
|
577
614
|
const template = import_handlebars.default.compile(content);
|
|
578
615
|
const updated = template(values);
|
|
579
616
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
580
|
-
if (isOverridesFile &&
|
|
617
|
+
if (isOverridesFile && import_fs5.default.existsSync(dest)) {
|
|
581
618
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
582
619
|
return;
|
|
583
620
|
}
|
|
584
|
-
|
|
621
|
+
import_fs5.default.writeFileSync(dest, updated, "utf8");
|
|
585
622
|
log(` \u2713 Created: ${dest}`);
|
|
586
623
|
}
|
|
587
624
|
}
|
|
@@ -592,36 +629,31 @@ function copyChartsValues(env, values) {
|
|
|
592
629
|
`);
|
|
593
630
|
}
|
|
594
631
|
function generateInventory(env, values) {
|
|
595
|
-
const templatePath =
|
|
632
|
+
const templatePath = import_path5.default.join(
|
|
596
633
|
__dirname,
|
|
597
634
|
"templates",
|
|
598
635
|
"inventory",
|
|
599
636
|
"inventory.template.yml"
|
|
600
637
|
);
|
|
601
|
-
const outputPath =
|
|
602
|
-
|
|
603
|
-
"infrastructure",
|
|
604
|
-
"server-setup",
|
|
605
|
-
"inventory",
|
|
606
|
-
`${env}.yml`
|
|
607
|
-
);
|
|
608
|
-
const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
|
|
638
|
+
const outputPath = import_path5.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
639
|
+
const templateFile = import_fs5.default.readFileSync(templatePath, "utf-8");
|
|
609
640
|
const template = import_handlebars.default.compile(templateFile);
|
|
610
641
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
611
642
|
const updated = template(values);
|
|
612
|
-
|
|
613
|
-
|
|
643
|
+
import_fs5.default.mkdirSync(import_path5.default.dirname(outputPath), { recursive: true });
|
|
644
|
+
import_fs5.default.writeFileSync(outputPath, updated);
|
|
614
645
|
log(`
|
|
615
646
|
\u2705 Generated inventory file at ${outputPath}
|
|
616
647
|
`);
|
|
617
648
|
}
|
|
618
|
-
var
|
|
649
|
+
var import_fs5, import_path5, import_handlebars;
|
|
619
650
|
var init_templates = __esm({
|
|
620
651
|
"src/environment/templates.ts"() {
|
|
621
652
|
"use strict";
|
|
622
|
-
|
|
623
|
-
|
|
653
|
+
import_fs5 = __toESM(require("fs"));
|
|
654
|
+
import_path5 = __toESM(require("path"));
|
|
624
655
|
init_logger();
|
|
656
|
+
init_paths();
|
|
625
657
|
import_handlebars = __toESM(require("handlebars"));
|
|
626
658
|
import_handlebars.default.registerHelper("data_label_idx", function(value) {
|
|
627
659
|
return parseInt(value) + 2;
|
|
@@ -645,6 +677,142 @@ var init_ssh_keygen = __esm({
|
|
|
645
677
|
}
|
|
646
678
|
});
|
|
647
679
|
|
|
680
|
+
// src/environment/update-workflows.ts
|
|
681
|
+
var update_workflows_exports = {};
|
|
682
|
+
__export(update_workflows_exports, {
|
|
683
|
+
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
684
|
+
});
|
|
685
|
+
function isDirectory(path8) {
|
|
686
|
+
try {
|
|
687
|
+
return (0, import_fs6.statSync)(path8).isDirectory();
|
|
688
|
+
} catch {
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
async function extractInfrastructureNames() {
|
|
693
|
+
const files = glob2.sync((0, import_path6.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
694
|
+
const infraEnvironments = files.map((file) => (0, import_path6.basename)((0, import_path6.dirname)(file)));
|
|
695
|
+
if (infraEnvironments.length === 0) {
|
|
696
|
+
console.log(
|
|
697
|
+
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
698
|
+
);
|
|
699
|
+
return [];
|
|
700
|
+
}
|
|
701
|
+
log("\u{1F50D} Found infrastructure configurations:", infraEnvironments.join(", "));
|
|
702
|
+
return infraEnvironments;
|
|
703
|
+
}
|
|
704
|
+
async function extractEnvironmentNames() {
|
|
705
|
+
const entries = await (0, import_promises.readdir)("environments");
|
|
706
|
+
const environments = entries.filter((entry) => {
|
|
707
|
+
const environmentPath = (0, import_path6.join)("environments", entry);
|
|
708
|
+
const opencrvsServicesPath = (0, import_path6.join)(environmentPath, "opencrvs-services");
|
|
709
|
+
return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
710
|
+
});
|
|
711
|
+
if (environments.length === 0) {
|
|
712
|
+
console.log(
|
|
713
|
+
"\u26A0\uFE0F Warning: No environment directories found in environments/"
|
|
714
|
+
);
|
|
715
|
+
return [];
|
|
716
|
+
}
|
|
717
|
+
log("\u{1F50D} Found OpenCRVS configurations:", environments.join(", "));
|
|
718
|
+
return environments;
|
|
719
|
+
}
|
|
720
|
+
function updateOptionsInYaml(content, envList) {
|
|
721
|
+
const optionsRegex = /([ ]*options:[ ]*\n)((?:[ ]*-[^\n]*\n)+)/;
|
|
722
|
+
const match = content.match(optionsRegex);
|
|
723
|
+
if (!match) {
|
|
724
|
+
throw new Error("Could not find options array in workflow file");
|
|
725
|
+
}
|
|
726
|
+
const firstItemMatch = match[2].match(/^([ ]*)-/);
|
|
727
|
+
const itemIndent = firstItemMatch ? firstItemMatch[1] : " ";
|
|
728
|
+
const newOptions = match[1] + envList.map((env) => `${itemIndent}- ${env}`).join("\n") + "\n";
|
|
729
|
+
return content.replace(optionsRegex, newOptions);
|
|
730
|
+
}
|
|
731
|
+
async function updateWorkflows(envList, config) {
|
|
732
|
+
const { workflows } = config;
|
|
733
|
+
for (const workflowPath of workflows) {
|
|
734
|
+
if (!(0, import_fs6.existsSync)(workflowPath)) {
|
|
735
|
+
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
736
|
+
continue;
|
|
737
|
+
}
|
|
738
|
+
try {
|
|
739
|
+
const fileContents = (0, import_fs6.readFileSync)(workflowPath, "utf8");
|
|
740
|
+
const workflowData = yaml2.load(fileContents);
|
|
741
|
+
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
742
|
+
throw new Error(
|
|
743
|
+
"Workflow does not have the expected structure: on.workflow_dispatch.inputs.environment.options"
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
747
|
+
(0, import_fs6.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
748
|
+
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
749
|
+
} catch (error3) {
|
|
750
|
+
console.error(
|
|
751
|
+
`
|
|
752
|
+
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
753
|
+
);
|
|
754
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
|
|
755
|
+
throw error3;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
async function updateWorkflowEnvironments() {
|
|
760
|
+
try {
|
|
761
|
+
let didUpdateWorkflows = false;
|
|
762
|
+
const infraEnvironments = await extractInfrastructureNames();
|
|
763
|
+
if (infraEnvironments.length > 0) {
|
|
764
|
+
console.log("\u{1F504} Updating infrastructure workflows:");
|
|
765
|
+
await updateWorkflows(infraEnvironments, {
|
|
766
|
+
workflows: [
|
|
767
|
+
".github/workflows/provision.yml",
|
|
768
|
+
".github/workflows/reset-2fa.yml"
|
|
769
|
+
],
|
|
770
|
+
path: "on.workflow_dispatch.inputs.environment.options"
|
|
771
|
+
});
|
|
772
|
+
didUpdateWorkflows = true;
|
|
773
|
+
}
|
|
774
|
+
const environments = await extractEnvironmentNames();
|
|
775
|
+
if (environments.length > 0) {
|
|
776
|
+
const workflows = [
|
|
777
|
+
".github/workflows/deploy-dependencies.yml",
|
|
778
|
+
".github/workflows/deploy-opencrvs.yml",
|
|
779
|
+
".github/workflows/clear-all-data.yml",
|
|
780
|
+
".github/workflows/seed-data.yml",
|
|
781
|
+
".github/workflows/reindex.yml",
|
|
782
|
+
".github/workflows/github-to-k8s-sync-env.yml",
|
|
783
|
+
".github/workflows/e2e.yml"
|
|
784
|
+
];
|
|
785
|
+
log("\u{1F4CB} Updating OpenCRVS application workflows:");
|
|
786
|
+
await updateWorkflows(environments, {
|
|
787
|
+
workflows,
|
|
788
|
+
path: "on.workflow_dispatch.inputs.environment.options"
|
|
789
|
+
});
|
|
790
|
+
didUpdateWorkflows = true;
|
|
791
|
+
}
|
|
792
|
+
if (didUpdateWorkflows) {
|
|
793
|
+
success("\u2705 Workflow updates completed successfully!");
|
|
794
|
+
} else {
|
|
795
|
+
log("\u2139\uFE0F No workflows were updated.");
|
|
796
|
+
}
|
|
797
|
+
} catch (error3) {
|
|
798
|
+
console.error("\n\u274C Error updating workflows:", error3);
|
|
799
|
+
process.exit(1);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
var import_promises, import_fs6, import_path6, glob2, yaml2;
|
|
803
|
+
var init_update_workflows = __esm({
|
|
804
|
+
"src/environment/update-workflows.ts"() {
|
|
805
|
+
"use strict";
|
|
806
|
+
import_promises = require("fs/promises");
|
|
807
|
+
import_fs6 = require("fs");
|
|
808
|
+
import_path6 = require("path");
|
|
809
|
+
glob2 = __toESM(require("glob"));
|
|
810
|
+
yaml2 = __toESM(require("js-yaml"));
|
|
811
|
+
init_logger();
|
|
812
|
+
init_paths();
|
|
813
|
+
}
|
|
814
|
+
});
|
|
815
|
+
|
|
648
816
|
// src/environment/git.ts
|
|
649
817
|
function getRepoInfo() {
|
|
650
818
|
try {
|
|
@@ -675,18 +843,18 @@ var init_git = __esm({
|
|
|
675
843
|
});
|
|
676
844
|
|
|
677
845
|
// src/environment/questions.ts
|
|
678
|
-
function validateCIDR(
|
|
679
|
-
if (!
|
|
846
|
+
function validateCIDR(input4) {
|
|
847
|
+
if (!input4.trim()) {
|
|
680
848
|
return true;
|
|
681
849
|
}
|
|
682
850
|
const cidrRegex = /^((25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\/([0-9]|[12][0-9]|3[0-2])$/;
|
|
683
|
-
return cidrRegex.test(
|
|
851
|
+
return cidrRegex.test(input4.trim()) ? true : "Please enter a valid CIDR (e.g. 10.0.0.0/24)";
|
|
684
852
|
}
|
|
685
|
-
function validateCIDRs(
|
|
686
|
-
if (!
|
|
853
|
+
function validateCIDRs(input4) {
|
|
854
|
+
if (!input4.trim()) {
|
|
687
855
|
return true;
|
|
688
856
|
}
|
|
689
|
-
const cidrs =
|
|
857
|
+
const cidrs = input4.split(",").map((v) => v.trim());
|
|
690
858
|
for (const cidr of cidrs) {
|
|
691
859
|
const result = validateCIDR(cidr);
|
|
692
860
|
if (result !== true) {
|
|
@@ -695,7 +863,11 @@ function validateCIDRs(input3) {
|
|
|
695
863
|
}
|
|
696
864
|
return true;
|
|
697
865
|
}
|
|
698
|
-
|
|
866
|
+
function toGithubRepositorySlug(input4) {
|
|
867
|
+
const match = input4.trim().match(GITHUB_REPOSITORY_PATTERN);
|
|
868
|
+
return match ? `${match[1]}/${match[2]}` : void 0;
|
|
869
|
+
}
|
|
870
|
+
var import_kleur2, notEmpty, dockerhubQuestions, githubQuestions, githubOtherQuestions, githubTokenQuestion, GITHUB_REPOSITORY_PATTERN, e2eQuestions, countryQuestions, infrastructureQuestions, staticSSLCertQuestions, backupQuestions, diskQuestions, databaseAndMonitoringQuestions, emailQuestions, sentryQuestions, metabaseAdminQuestions;
|
|
699
871
|
var init_questions = __esm({
|
|
700
872
|
"src/environment/questions.ts"() {
|
|
701
873
|
"use strict";
|
|
@@ -806,6 +978,20 @@ var init_questions = __esm({
|
|
|
806
978
|
valueLabel: "GH_TOKEN"
|
|
807
979
|
}
|
|
808
980
|
];
|
|
981
|
+
GITHUB_REPOSITORY_PATTERN = /^(?:(?:https:\/\/|git@)github\.com[/:])?([\w.-]+)\/([\w.-]+?)(?:\.git)?\/?$/;
|
|
982
|
+
e2eQuestions = [
|
|
983
|
+
{
|
|
984
|
+
name: "countryconfigRepository",
|
|
985
|
+
type: "text",
|
|
986
|
+
message: "What is your country configuration repository? (e.g. https://github.com/opencrvs/opencrvs-farajaland)",
|
|
987
|
+
valueType: "VARIABLE",
|
|
988
|
+
valueLabel: "COUNTRYCONFIG_REPOSITORY",
|
|
989
|
+
validate: (value) => toGithubRepositorySlug(value) ? true : "Please enter a GitHub repository URL or owner/repository",
|
|
990
|
+
format: (value) => toGithubRepositorySlug(value) ?? value,
|
|
991
|
+
initial: process.env.COUNTRYCONFIG_REPOSITORY,
|
|
992
|
+
scope: "REPOSITORY"
|
|
993
|
+
}
|
|
994
|
+
];
|
|
809
995
|
countryQuestions = [
|
|
810
996
|
{
|
|
811
997
|
name: "country",
|
|
@@ -829,11 +1015,28 @@ var init_questions = __esm({
|
|
|
829
1015
|
scope: "ENVIRONMENT"
|
|
830
1016
|
},
|
|
831
1017
|
{
|
|
832
|
-
name: "
|
|
1018
|
+
name: "kubeMasterNode",
|
|
1019
|
+
type: "text",
|
|
1020
|
+
message: `Kubernetes master node hostnames or IP (default: auto-detect)`,
|
|
1021
|
+
valueType: "VARIABLE",
|
|
1022
|
+
valueLabel: "KUBE_MASTER_NODE",
|
|
1023
|
+
initial: process.env.KUBE_MASTER_NODE,
|
|
1024
|
+
scope: "ENVIRONMENT"
|
|
1025
|
+
},
|
|
1026
|
+
{
|
|
1027
|
+
name: "kubeWorkerNodes",
|
|
1028
|
+
type: "text",
|
|
1029
|
+
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
1030
|
+
valueType: "VARIABLE",
|
|
1031
|
+
valueLabel: "KUBE_WORKER_NODES",
|
|
1032
|
+
initial: process.env.KUBE_WORKER_NODES || "",
|
|
1033
|
+
scope: "ENVIRONMENT"
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
name: "kubeApiHost",
|
|
833
1037
|
type: "text",
|
|
834
|
-
message: `Kubernetes API endpoint (default:
|
|
1038
|
+
message: `Kubernetes API endpoint IP (default: KUBE_MASTER_NODE)`,
|
|
835
1039
|
valueType: "VARIABLE",
|
|
836
|
-
// validate: notEmpty,
|
|
837
1040
|
valueLabel: "KUBE_API_HOST",
|
|
838
1041
|
initial: process.env.KUBE_API_HOST,
|
|
839
1042
|
scope: "ENVIRONMENT"
|
|
@@ -847,16 +1050,6 @@ var init_questions = __esm({
|
|
|
847
1050
|
valueLabel: "KUBE_API_ALLOWED_CIDRS",
|
|
848
1051
|
initial: process.env.KUBE_API_ALLOWED_CIDRS || "",
|
|
849
1052
|
scope: "ENVIRONMENT"
|
|
850
|
-
},
|
|
851
|
-
{
|
|
852
|
-
name: "kubeWorkerNodes",
|
|
853
|
-
type: "text",
|
|
854
|
-
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
855
|
-
valueType: "VARIABLE",
|
|
856
|
-
// validate: notEmpty,
|
|
857
|
-
valueLabel: "KUBE_WORKER_NODES",
|
|
858
|
-
initial: process.env.KUBE_WORKER_NODES || "",
|
|
859
|
-
scope: "ENVIRONMENT"
|
|
860
1053
|
}
|
|
861
1054
|
];
|
|
862
1055
|
staticSSLCertQuestions = [
|
|
@@ -887,7 +1080,6 @@ var init_questions = __esm({
|
|
|
887
1080
|
type: "text",
|
|
888
1081
|
message: `Please enter backup server host/IP address, (default: no backup):`,
|
|
889
1082
|
valueType: "VARIABLE",
|
|
890
|
-
// validate: notEmpty,
|
|
891
1083
|
valueLabel: "BACKUP_HOST",
|
|
892
1084
|
initial: process.env.BACKUP_HOST || "",
|
|
893
1085
|
scope: "ENVIRONMENT"
|
|
@@ -1210,7 +1402,7 @@ function updateInventoryFile(filePath, users) {
|
|
|
1210
1402
|
function parseInventoryFile(filePath) {
|
|
1211
1403
|
try {
|
|
1212
1404
|
const data = readYamlFile(filePath);
|
|
1213
|
-
return
|
|
1405
|
+
return extractAndModifyUsers(data);
|
|
1214
1406
|
} catch {
|
|
1215
1407
|
return [];
|
|
1216
1408
|
}
|
|
@@ -1220,7 +1412,7 @@ function getCurrentUsername() {
|
|
|
1220
1412
|
}
|
|
1221
1413
|
function getCurrentUserSSHKeys() {
|
|
1222
1414
|
const homeDir = os.homedir();
|
|
1223
|
-
const sshDir =
|
|
1415
|
+
const sshDir = path5.join(homeDir, ".ssh");
|
|
1224
1416
|
const keys = [];
|
|
1225
1417
|
const keyFiles = [
|
|
1226
1418
|
"id_rsa.pub",
|
|
@@ -1229,7 +1421,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1229
1421
|
"id_dsa.pub"
|
|
1230
1422
|
];
|
|
1231
1423
|
for (const keyFile of keyFiles) {
|
|
1232
|
-
const keyPath =
|
|
1424
|
+
const keyPath = path5.join(sshDir, keyFile);
|
|
1233
1425
|
try {
|
|
1234
1426
|
if (fs3.existsSync(keyPath)) {
|
|
1235
1427
|
const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
|
|
@@ -1237,7 +1429,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1237
1429
|
keys.push(keyContent);
|
|
1238
1430
|
}
|
|
1239
1431
|
}
|
|
1240
|
-
} catch (
|
|
1432
|
+
} catch (error3) {
|
|
1241
1433
|
continue;
|
|
1242
1434
|
}
|
|
1243
1435
|
}
|
|
@@ -1570,13 +1762,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1570
1762
|
}
|
|
1571
1763
|
return users;
|
|
1572
1764
|
}
|
|
1573
|
-
var os, fs3,
|
|
1765
|
+
var os, fs3, path5, input2, select2, confirm, editor, checkbox;
|
|
1574
1766
|
var init_manage_users = __esm({
|
|
1575
1767
|
"src/environment/manage-users.ts"() {
|
|
1576
1768
|
"use strict";
|
|
1577
1769
|
os = __toESM(require("os"));
|
|
1578
1770
|
fs3 = __toESM(require("fs"));
|
|
1579
|
-
|
|
1771
|
+
path5 = __toESM(require("path"));
|
|
1580
1772
|
init_logger();
|
|
1581
1773
|
init_utils();
|
|
1582
1774
|
init_templates();
|
|
@@ -1590,6 +1782,9 @@ var init_manage_users = __esm({
|
|
|
1590
1782
|
|
|
1591
1783
|
// src/environment/setup-environment.ts
|
|
1592
1784
|
var setup_environment_exports = {};
|
|
1785
|
+
__export(setup_environment_exports, {
|
|
1786
|
+
runSetupEnvironment: () => runSetupEnvironment
|
|
1787
|
+
});
|
|
1593
1788
|
async function confirm2(options) {
|
|
1594
1789
|
const inquirer = await import("@inquirer/prompts");
|
|
1595
1790
|
return inquirer.confirm(options);
|
|
@@ -1598,6 +1793,10 @@ async function select3(options) {
|
|
|
1598
1793
|
const inquirer = await import("@inquirer/prompts");
|
|
1599
1794
|
return inquirer.select(options);
|
|
1600
1795
|
}
|
|
1796
|
+
async function input3(options) {
|
|
1797
|
+
const inquirer = await import("@inquirer/prompts");
|
|
1798
|
+
return inquirer.input(options);
|
|
1799
|
+
}
|
|
1601
1800
|
function questionToPrompt({
|
|
1602
1801
|
valueType,
|
|
1603
1802
|
valueLabel,
|
|
@@ -1664,7 +1863,7 @@ function getAnswers(existingValues) {
|
|
|
1664
1863
|
});
|
|
1665
1864
|
});
|
|
1666
1865
|
}
|
|
1667
|
-
async function promptAndStoreAnswer(
|
|
1866
|
+
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1668
1867
|
log("");
|
|
1669
1868
|
const processedQuestions = questions.flatMap((question) => {
|
|
1670
1869
|
const questionWithVariableLabel = {
|
|
@@ -1743,7 +1942,6 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1743
1942
|
}
|
|
1744
1943
|
});
|
|
1745
1944
|
ALL_ANSWERS.push(result);
|
|
1746
|
-
storeSecrets(environment, getAnswers(existingValues));
|
|
1747
1945
|
const existingValuesForQuestions = questions.filter((question) => question.valueType === "VARIABLE").map((question) => [
|
|
1748
1946
|
question.name,
|
|
1749
1947
|
findExistingValue(
|
|
@@ -1755,974 +1953,1020 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1755
1953
|
]);
|
|
1756
1954
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1757
1955
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
(
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
log(import_kleur4.default.green("\nSuccessfully logged in to Github\n"));
|
|
1811
|
-
const existingEnvironments = await getRepositoryEnvironments(
|
|
1812
|
-
octokit,
|
|
1813
|
-
githubOrganisation,
|
|
1814
|
-
githubRepository
|
|
1815
|
-
);
|
|
1816
|
-
const defaultChoices = [
|
|
1817
|
-
{ name: "Development", value: "development" },
|
|
1818
|
-
{ name: "Quality assurance (no PII data)", value: "qa" },
|
|
1956
|
+
async function runSetupEnvironment() {
|
|
1957
|
+
log("\n", import_kleur4.default.bold().underline("Github"), "\n");
|
|
1958
|
+
const { githubOrganisation, githubRepository } = await (0, import_prompts2.default)(
|
|
1959
|
+
githubQuestions.map(questionToPrompt),
|
|
1960
|
+
{
|
|
1961
|
+
onCancel: () => {
|
|
1962
|
+
process.exit(1);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
);
|
|
1966
|
+
const { githubToken } = await promptAndStoreAnswer(githubTokenQuestion, []);
|
|
1967
|
+
const octokit = new import_core.Octokit({
|
|
1968
|
+
auth: githubToken
|
|
1969
|
+
});
|
|
1970
|
+
log(import_kleur4.default.green("\nSuccessfully logged in to Github\n"));
|
|
1971
|
+
const existingEnvironments = await getRepositoryEnvironments(
|
|
1972
|
+
octokit,
|
|
1973
|
+
githubOrganisation,
|
|
1974
|
+
githubRepository
|
|
1975
|
+
);
|
|
1976
|
+
const defaultChoices = [
|
|
1977
|
+
{ name: "Development", value: "development" },
|
|
1978
|
+
{ name: "Quality assurance (no PII data)", value: "qa" },
|
|
1979
|
+
{
|
|
1980
|
+
name: "Staging (hosts PII data, no backups)",
|
|
1981
|
+
value: "staging"
|
|
1982
|
+
},
|
|
1983
|
+
{
|
|
1984
|
+
name: "Production (hosts PII data, requires frequent backups)",
|
|
1985
|
+
value: "production"
|
|
1986
|
+
}
|
|
1987
|
+
];
|
|
1988
|
+
const choices = [
|
|
1989
|
+
...defaultChoices,
|
|
1990
|
+
...existingEnvironments.filter((env) => !defaultChoices.some((choice) => choice.value === env)).map((env) => ({
|
|
1991
|
+
name: env,
|
|
1992
|
+
value: env
|
|
1993
|
+
}))
|
|
1994
|
+
];
|
|
1995
|
+
const environment = await selectWithCustom({
|
|
1996
|
+
message: "Choose a name and purpose for the environment?",
|
|
1997
|
+
choices
|
|
1998
|
+
});
|
|
1999
|
+
let environment_type = "non-production";
|
|
2000
|
+
if (["development", "qa"].includes(environment)) {
|
|
2001
|
+
environment_type = "non-production";
|
|
2002
|
+
} else if (["staging", "production"].includes(environment)) {
|
|
2003
|
+
environment_type = "production";
|
|
2004
|
+
} else {
|
|
2005
|
+
environment_type = await select3({
|
|
2006
|
+
message: "Purpose for the environment?",
|
|
2007
|
+
choices: [
|
|
1819
2008
|
{
|
|
1820
|
-
name: "
|
|
1821
|
-
value: "
|
|
2009
|
+
name: "Development/Quality assurance/Testing (no PII data)",
|
|
2010
|
+
value: "non-production"
|
|
1822
2011
|
},
|
|
1823
2012
|
{
|
|
1824
|
-
name: "Production (hosts PII data, requires frequent backups)",
|
|
2013
|
+
name: "Staging/Production (hosts PII data, requires frequent backups)",
|
|
1825
2014
|
value: "production"
|
|
1826
2015
|
}
|
|
1827
|
-
]
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
2016
|
+
]
|
|
2017
|
+
});
|
|
2018
|
+
}
|
|
2019
|
+
log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
|
|
2020
|
+
const two_fa_enabled = await confirm2({
|
|
2021
|
+
message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
|
|
2022
|
+
default: process.env.TWO_FA_ENABLED ? process.env.TWO_FA_ENABLED === "true" : environment_type === "production"
|
|
2023
|
+
});
|
|
2024
|
+
if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
|
|
2025
|
+
warn(
|
|
2026
|
+
"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."
|
|
2027
|
+
);
|
|
2028
|
+
}
|
|
2029
|
+
const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
|
|
2030
|
+
if (!environment) {
|
|
2031
|
+
process.exit(1);
|
|
2032
|
+
}
|
|
2033
|
+
await createEnvironment(
|
|
2034
|
+
octokit,
|
|
2035
|
+
environment,
|
|
2036
|
+
githubOrganisation,
|
|
2037
|
+
githubRepository
|
|
2038
|
+
);
|
|
2039
|
+
const repositoryId = await getRepositoryId(
|
|
2040
|
+
octokit,
|
|
2041
|
+
githubOrganisation,
|
|
2042
|
+
githubRepository
|
|
2043
|
+
);
|
|
2044
|
+
const existingRepositorySecrets = await listRepositorySecrets(
|
|
2045
|
+
octokit,
|
|
2046
|
+
githubOrganisation,
|
|
2047
|
+
githubRepository
|
|
2048
|
+
);
|
|
2049
|
+
const existingRepositoryVariables = await listRepositoryVariables(
|
|
2050
|
+
octokit,
|
|
2051
|
+
githubOrganisation,
|
|
2052
|
+
githubRepository
|
|
2053
|
+
);
|
|
2054
|
+
const existingEnvironmentVariables = await listEnvironmentVariables(
|
|
2055
|
+
octokit,
|
|
2056
|
+
repositoryId,
|
|
2057
|
+
environment
|
|
2058
|
+
);
|
|
2059
|
+
const existingEnvironmentSecrets = await listEnvironmentSecrets(
|
|
2060
|
+
octokit,
|
|
2061
|
+
githubOrganisation,
|
|
2062
|
+
repositoryId,
|
|
2063
|
+
environment
|
|
2064
|
+
);
|
|
2065
|
+
const existingValues = [
|
|
2066
|
+
...existingEnvironmentVariables,
|
|
2067
|
+
...existingRepositoryVariables,
|
|
2068
|
+
...existingRepositorySecrets,
|
|
2069
|
+
...existingEnvironmentSecrets
|
|
2070
|
+
];
|
|
2071
|
+
log("\n", import_kleur4.default.bold().underline("End-to-end (E2E) tests"));
|
|
2072
|
+
const existingE2EEnabled = findExistingValue(
|
|
2073
|
+
"E2E_ENABLED",
|
|
2074
|
+
"VARIABLE",
|
|
2075
|
+
"ENVIRONMENT",
|
|
2076
|
+
existingValues
|
|
2077
|
+
);
|
|
2078
|
+
const e2e_enabled = await confirm2({
|
|
2079
|
+
message: "Would you like to configure e2e tests for this environment? Tests run after every deployment and create test records.",
|
|
2080
|
+
default: process.env.E2E_ENABLED ? process.env.E2E_ENABLED === "true" : existingE2EEnabled?.value === "true"
|
|
2081
|
+
});
|
|
2082
|
+
if (e2e_enabled) {
|
|
2083
|
+
if (environment_type === "production") {
|
|
2084
|
+
warn(
|
|
2085
|
+
"E2E tests are enabled on a production-like environment. Tests will create records alongside real citizen data. Only do this if you know what you are doing."
|
|
1871
2086
|
);
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
2087
|
+
}
|
|
2088
|
+
if (two_fa_enabled) {
|
|
2089
|
+
warn(
|
|
2090
|
+
"E2E tests usually sign in with the fixed 2FA code 000000, which is only accepted when 2FA is disabled."
|
|
1876
2091
|
);
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
2092
|
+
}
|
|
2093
|
+
const countryconfigRepository = findExistingValue(
|
|
2094
|
+
"COUNTRYCONFIG_REPOSITORY",
|
|
2095
|
+
"VARIABLE",
|
|
2096
|
+
"REPOSITORY",
|
|
2097
|
+
existingValues
|
|
2098
|
+
);
|
|
2099
|
+
if (countryconfigRepository) {
|
|
2100
|
+
log(
|
|
2101
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2102
|
+
import_kleur4.default.bold().grey(
|
|
2103
|
+
`E2E tests will run from repository ${countryconfigRepository.value} (COUNTRYCONFIG_REPOSITORY)`
|
|
2104
|
+
)
|
|
1881
2105
|
);
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
2106
|
+
} else {
|
|
2107
|
+
await promptAndStoreAnswer(e2eQuestions, existingValues);
|
|
2108
|
+
}
|
|
2109
|
+
}
|
|
2110
|
+
if (existingEnvironmentVariables.length > 0 || existingEnvironmentSecrets.length > 0) {
|
|
2111
|
+
log(
|
|
2112
|
+
"\nEnvironment with the name",
|
|
2113
|
+
environment,
|
|
2114
|
+
"already exists in Github.",
|
|
2115
|
+
"\nFound",
|
|
2116
|
+
existingEnvironmentVariables.length,
|
|
2117
|
+
"existing variables and",
|
|
2118
|
+
existingEnvironmentSecrets.length,
|
|
2119
|
+
"secrets"
|
|
2120
|
+
);
|
|
2121
|
+
}
|
|
2122
|
+
if (environment_type === "production") {
|
|
2123
|
+
log(
|
|
2124
|
+
"\n",
|
|
2125
|
+
import_kleur4.default.yellow().bold(
|
|
2126
|
+
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
2127
|
+
)
|
|
2128
|
+
);
|
|
2129
|
+
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
2130
|
+
}
|
|
2131
|
+
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
2132
|
+
await promptAndStoreAnswer(dockerhubQuestions, existingValues);
|
|
2133
|
+
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
2134
|
+
const infrastructure = await promptAndStoreAnswer(
|
|
2135
|
+
infrastructureQuestions,
|
|
2136
|
+
existingValues
|
|
2137
|
+
);
|
|
2138
|
+
const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
|
|
2139
|
+
log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
|
|
2140
|
+
const users = await manageUsers(getEnvironmentInventoryPath(environment));
|
|
2141
|
+
log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
|
|
2142
|
+
const sslCertExists = findExistingValue(
|
|
2143
|
+
"SSL_CRT",
|
|
2144
|
+
"SECRET",
|
|
2145
|
+
"ENVIRONMENT",
|
|
2146
|
+
existingValues
|
|
2147
|
+
);
|
|
2148
|
+
let ssl_answers = [];
|
|
2149
|
+
const traefikConfOption = (await (0, import_prompts2.default)([
|
|
2150
|
+
{
|
|
2151
|
+
name: "traefikConfOption",
|
|
2152
|
+
type: "select",
|
|
2153
|
+
message: "Choose option to configure Traefik SSL Certificate",
|
|
2154
|
+
choices: [
|
|
2155
|
+
{ title: "Let's Encrypt certificate", value: "lets_encrypt" },
|
|
2156
|
+
{ title: "Static SSL certificate", value: "static_ssl" },
|
|
2157
|
+
{ title: "Custom configuration", value: "custom" }
|
|
2158
|
+
],
|
|
2159
|
+
initial: sslCertExists ? 1 : 0
|
|
2160
|
+
}
|
|
2161
|
+
])).traefikConfOption;
|
|
2162
|
+
if (traefikConfOption === "static_ssl") {
|
|
2163
|
+
ssl_answers = await askQuestionWithEditor(
|
|
2164
|
+
staticSSLCertQuestions,
|
|
2165
|
+
existingEnvironmentSecrets
|
|
2166
|
+
);
|
|
2167
|
+
}
|
|
2168
|
+
log("\n", import_kleur4.default.bold().underline("Storage"), "\n");
|
|
2169
|
+
let enableEncryption = false;
|
|
2170
|
+
const encryption_key_defined = findExistingValue(
|
|
2171
|
+
"ENCRYPTION_KEY",
|
|
2172
|
+
"SECRET",
|
|
2173
|
+
"ENVIRONMENT",
|
|
2174
|
+
existingValues
|
|
2175
|
+
);
|
|
2176
|
+
if (!encryption_key_defined && !environment_exists) {
|
|
2177
|
+
const answers_enable_encryption = await (0, import_prompts2.default)(
|
|
2178
|
+
[
|
|
2179
|
+
{
|
|
2180
|
+
name: "enableEncryption",
|
|
2181
|
+
type: "confirm",
|
|
2182
|
+
message: "Do you want to enable disk encryption?",
|
|
2183
|
+
scope: "ENVIRONMENT",
|
|
2184
|
+
initial: Boolean(process.env.ENABLE_ENCRYPTION)
|
|
2185
|
+
}
|
|
2186
|
+
].map(questionToPrompt)
|
|
2187
|
+
);
|
|
2188
|
+
enableEncryption = answers_enable_encryption.enableEncryption;
|
|
2189
|
+
}
|
|
2190
|
+
if (enableEncryption && !encryption_key_defined && !environment_exists) {
|
|
2191
|
+
log(
|
|
2192
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2193
|
+
import_kleur4.default.bold().yellow(" Disk encryption is enabled")
|
|
2194
|
+
);
|
|
2195
|
+
await promptAndStoreAnswer(diskQuestions, existingValues);
|
|
2196
|
+
} else {
|
|
2197
|
+
if (!enableEncryption && !encryption_key_defined && environment_exists) {
|
|
2198
|
+
log(
|
|
2199
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2200
|
+
import_kleur4.default.bold().grey(
|
|
2201
|
+
`Environment ${environment} is already configured, skipping disk encryption question`
|
|
2202
|
+
)
|
|
1886
2203
|
);
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
2204
|
+
}
|
|
2205
|
+
const DISK_SPACE = findExistingValue(
|
|
2206
|
+
"DISK_SPACE",
|
|
2207
|
+
"VARIABLE",
|
|
2208
|
+
"ENVIRONMENT",
|
|
2209
|
+
existingValues
|
|
2210
|
+
);
|
|
2211
|
+
if (!DISK_SPACE) {
|
|
2212
|
+
log(
|
|
2213
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2214
|
+
import_kleur4.default.bold().grey("All available disk space at /data will be used")
|
|
1891
2215
|
);
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
2216
|
+
} else {
|
|
2217
|
+
log(
|
|
2218
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2219
|
+
import_kleur4.default.bold().yellow("Variable DISK_SPACE is read-only, allocated space:"),
|
|
2220
|
+
DISK_SPACE?.value
|
|
1897
2221
|
);
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
let backupHost = findExistingValue("BACKUP_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2225
|
+
let backupType = "";
|
|
2226
|
+
let restoreEnvironmentName = findExistingValue(
|
|
2227
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2228
|
+
"VARIABLE",
|
|
2229
|
+
"ENVIRONMENT",
|
|
2230
|
+
existingValues
|
|
2231
|
+
)?.value;
|
|
2232
|
+
let restoreHost = findExistingValue("RESTORE_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2233
|
+
let restoreType = findExistingValue(
|
|
2234
|
+
"RESTORE_ENVIRONMENT_MODE",
|
|
2235
|
+
"VARIABLE",
|
|
2236
|
+
"ENVIRONMENT",
|
|
2237
|
+
existingValues
|
|
2238
|
+
)?.value || process.env.RESTORE_ENVIRONMENT_MODE || "dump";
|
|
2239
|
+
log("\n", import_kleur4.default.bold().underline("Backup"));
|
|
2240
|
+
let configureBackup = backupHost ? true : false;
|
|
2241
|
+
if (!configureBackup && !restoreEnvironmentName) {
|
|
2242
|
+
configureBackup = await confirm2({
|
|
2243
|
+
message: "Do you want to configure backup?",
|
|
2244
|
+
default: Boolean(process.env.CONFIGURE_BACKUP)
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
let backupHostPrivateKey = "";
|
|
2248
|
+
let backupHostPublicKey = "";
|
|
2249
|
+
if (configureBackup) {
|
|
2250
|
+
const backupAnswers = await promptAndStoreAnswer(
|
|
2251
|
+
backupQuestions,
|
|
2252
|
+
existingValues
|
|
2253
|
+
);
|
|
2254
|
+
const backupHostPrivateKeyExists = findExistingValue(
|
|
2255
|
+
"BACKUP_HOST_PRIVATE_KEY",
|
|
2256
|
+
"SECRET",
|
|
2257
|
+
"ENVIRONMENT",
|
|
2258
|
+
existingValues
|
|
2259
|
+
);
|
|
2260
|
+
backupType = backupAnswers.backupType;
|
|
2261
|
+
backupHost = backupAnswers.backupHost || backupHost;
|
|
2262
|
+
if (!backupHostPrivateKeyExists) {
|
|
2263
|
+
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2264
|
+
backupHostPublicKey = publicKey;
|
|
2265
|
+
backupHostPrivateKey = privateKey;
|
|
2266
|
+
log(
|
|
2267
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2268
|
+
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
2269
|
+
);
|
|
2270
|
+
}
|
|
2271
|
+
} else {
|
|
2272
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
2273
|
+
}
|
|
2274
|
+
log("\n", import_kleur4.default.bold().underline("Restore"));
|
|
2275
|
+
let configureRestore = restoreEnvironmentName ? true : false;
|
|
2276
|
+
if (!restoreEnvironmentName && !configureBackup) {
|
|
2277
|
+
configureRestore = await confirm2({
|
|
2278
|
+
message: "Do you want to configure restore?",
|
|
2279
|
+
default: Boolean(process.env.CONFIGURE_RESTORE)
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
if (configureRestore) {
|
|
2283
|
+
const env_list_filtered = existingEnvironments.filter(
|
|
2284
|
+
(env) => env !== environment
|
|
2285
|
+
);
|
|
2286
|
+
restoreEnvironmentName = await selectWithCustom({
|
|
2287
|
+
message: "What is the name of your environment to restore?",
|
|
2288
|
+
choices: env_list_filtered.map((env) => ({
|
|
2289
|
+
name: env,
|
|
2290
|
+
value: env
|
|
2291
|
+
})),
|
|
2292
|
+
initial: restoreEnvironmentName
|
|
2293
|
+
});
|
|
2294
|
+
restoreType = await select3({
|
|
2295
|
+
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2296
|
+
default: restoreType,
|
|
2297
|
+
choices: [
|
|
2298
|
+
{
|
|
2299
|
+
name: "Full dump (daily full database backup)",
|
|
2300
|
+
value: "dump"
|
|
2301
|
+
},
|
|
2302
|
+
{
|
|
2303
|
+
name: "Differential (weekly full, daily diff backup)",
|
|
2304
|
+
value: "differential"
|
|
2305
|
+
}
|
|
2306
|
+
]
|
|
2307
|
+
});
|
|
2308
|
+
restoreHost = await input3({
|
|
2309
|
+
message: "What is the host/IP address of the restore backup server?",
|
|
2310
|
+
default: restoreHost
|
|
2311
|
+
});
|
|
2312
|
+
} else {
|
|
2313
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2314
|
+
}
|
|
2315
|
+
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2316
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2317
|
+
const sentryDSNExists = findExistingValue(
|
|
2318
|
+
"SENTRY_DSN",
|
|
2319
|
+
"SECRET",
|
|
2320
|
+
"ENVIRONMENT",
|
|
2321
|
+
existingValues
|
|
2322
|
+
);
|
|
2323
|
+
log("\n", import_kleur4.default.bold().underline("Sentry"));
|
|
2324
|
+
if (sentryDSNExists) {
|
|
2325
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2326
|
+
} else {
|
|
2327
|
+
const { useSentry } = await (0, import_prompts2.default)([
|
|
2328
|
+
{
|
|
2329
|
+
name: "useSentry",
|
|
2330
|
+
type: "confirm",
|
|
2331
|
+
message: "Do you want to use Sentry?",
|
|
2332
|
+
initial: Boolean(process.env.SENTRY_DNS)
|
|
1928
2333
|
}
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
2334
|
+
]);
|
|
2335
|
+
if (useSentry) {
|
|
2336
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2340
|
+
await promptAndStoreAnswer(metabaseAdminQuestions, existingValues);
|
|
2341
|
+
log("\n", import_kleur4.default.bold().underline("SMTP"));
|
|
2342
|
+
await promptAndStoreAnswer(emailQuestions, existingValues);
|
|
2343
|
+
const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
|
|
2344
|
+
return { ...acc, ...answer };
|
|
2345
|
+
});
|
|
2346
|
+
const answerOrExisting = (variable, existingValue, fn) => fn(variable || existingValue?.value) || "";
|
|
2347
|
+
function findExistingOrDefine(name, type, scope, newValue) {
|
|
2348
|
+
return findExistingValue(name, type, scope, existingValues) ? null : process.env[name] || newValue;
|
|
2349
|
+
}
|
|
2350
|
+
const derivedUpdates = [
|
|
2351
|
+
{
|
|
2352
|
+
name: "GH_ENCRYPTION_PASSWORD",
|
|
2353
|
+
type: "SECRET",
|
|
2354
|
+
didExist: findExistingValue(
|
|
2355
|
+
"GH_ENCRYPTION_PASSWORD",
|
|
2356
|
+
"SECRET",
|
|
2357
|
+
"REPOSITORY",
|
|
1935
2358
|
existingValues
|
|
1936
|
-
)
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
2359
|
+
),
|
|
2360
|
+
value: findExistingOrDefine(
|
|
2361
|
+
"GH_ENCRYPTION_PASSWORD",
|
|
2362
|
+
"SECRET",
|
|
2363
|
+
"REPOSITORY",
|
|
2364
|
+
generateLongPassword()
|
|
2365
|
+
),
|
|
2366
|
+
scope: "REPOSITORY"
|
|
2367
|
+
}
|
|
2368
|
+
];
|
|
2369
|
+
derivedUpdates.push({
|
|
2370
|
+
name: "NOTIFICATION_TRANSPORT",
|
|
2371
|
+
type: "VARIABLE",
|
|
2372
|
+
didExist: findExistingValue(
|
|
2373
|
+
"NOTIFICATION_TRANSPORT",
|
|
2374
|
+
"VARIABLE",
|
|
2375
|
+
"ENVIRONMENT",
|
|
2376
|
+
existingValues
|
|
2377
|
+
),
|
|
2378
|
+
value: findExistingOrDefine(
|
|
2379
|
+
"NOTIFICATION_TRANSPORT",
|
|
2380
|
+
"VARIABLE",
|
|
2381
|
+
"ENVIRONMENT",
|
|
2382
|
+
"email"
|
|
2383
|
+
),
|
|
2384
|
+
scope: "ENVIRONMENT"
|
|
2385
|
+
});
|
|
2386
|
+
derivedUpdates.push({
|
|
2387
|
+
name: "E2E_ENABLED",
|
|
2388
|
+
type: "VARIABLE",
|
|
2389
|
+
didExist: existingE2EEnabled,
|
|
2390
|
+
// Only store 'false' to switch off an environment that previously had e2e enabled
|
|
2391
|
+
value: e2e_enabled ? "true" : existingE2EEnabled ? "false" : null,
|
|
2392
|
+
scope: "ENVIRONMENT"
|
|
2393
|
+
});
|
|
2394
|
+
derivedUpdates.push(...ssl_answers);
|
|
2395
|
+
if (configureBackup) {
|
|
2396
|
+
derivedUpdates.push({
|
|
2397
|
+
name: "BACKUP_ENCRYPTION_PASSPHRASE",
|
|
2398
|
+
type: "SECRET",
|
|
2399
|
+
didExist: findExistingValue(
|
|
2400
|
+
"BACKUP_ENCRYPTION_PASSPHRASE",
|
|
1945
2401
|
"SECRET",
|
|
1946
2402
|
"ENVIRONMENT",
|
|
1947
2403
|
existingValues
|
|
1948
|
-
)
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
ssl_answers = await askQuestionWithEditor(
|
|
1965
|
-
staticSSLCertQuestions,
|
|
1966
|
-
existingEnvironmentSecrets
|
|
1967
|
-
);
|
|
1968
|
-
}
|
|
1969
|
-
log("\n", import_kleur4.default.bold().underline("Storage"), "\n");
|
|
1970
|
-
let enableEncryption = false;
|
|
1971
|
-
const encryption_key_defined = findExistingValue(
|
|
1972
|
-
"ENCRYPTION_KEY",
|
|
2404
|
+
),
|
|
2405
|
+
value: findExistingOrDefine(
|
|
2406
|
+
"BACKUP_ENCRYPTION_PASSPHRASE",
|
|
2407
|
+
"SECRET",
|
|
2408
|
+
"ENVIRONMENT",
|
|
2409
|
+
generateLongPassword()
|
|
2410
|
+
),
|
|
2411
|
+
scope: "ENVIRONMENT"
|
|
2412
|
+
});
|
|
2413
|
+
}
|
|
2414
|
+
const applicationServerUpdates = [
|
|
2415
|
+
{
|
|
2416
|
+
name: "ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2417
|
+
type: "SECRET",
|
|
2418
|
+
didExist: findExistingValue(
|
|
2419
|
+
"ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
1973
2420
|
"SECRET",
|
|
1974
2421
|
"ENVIRONMENT",
|
|
1975
2422
|
existingValues
|
|
1976
|
-
)
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2423
|
+
),
|
|
2424
|
+
value: findExistingOrDefine(
|
|
2425
|
+
"ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2426
|
+
"SECRET",
|
|
2427
|
+
"ENVIRONMENT",
|
|
2428
|
+
generateLongPassword()
|
|
2429
|
+
),
|
|
2430
|
+
scope: "ENVIRONMENT"
|
|
2431
|
+
},
|
|
2432
|
+
{
|
|
2433
|
+
name: "KIBANA_SYSTEM_PASSWORD",
|
|
2434
|
+
type: "SECRET",
|
|
2435
|
+
didExist: findExistingValue(
|
|
2436
|
+
"KIBANA_SYSTEM_PASSWORD",
|
|
2437
|
+
"SECRET",
|
|
2438
|
+
"ENVIRONMENT",
|
|
2439
|
+
existingValues
|
|
2440
|
+
),
|
|
2441
|
+
value: findExistingOrDefine(
|
|
2442
|
+
"KIBANA_SYSTEM_PASSWORD",
|
|
2443
|
+
"SECRET",
|
|
2444
|
+
"ENVIRONMENT",
|
|
2445
|
+
generateLongPassword()
|
|
2446
|
+
),
|
|
2447
|
+
scope: "ENVIRONMENT"
|
|
2448
|
+
},
|
|
2449
|
+
{
|
|
2450
|
+
name: "MINIO_ROOT_USER",
|
|
2451
|
+
type: "SECRET",
|
|
2452
|
+
didExist: findExistingValue(
|
|
2453
|
+
"MINIO_ROOT_USER",
|
|
2454
|
+
"SECRET",
|
|
2455
|
+
"ENVIRONMENT",
|
|
2456
|
+
existingValues
|
|
2457
|
+
),
|
|
2458
|
+
value: findExistingOrDefine(
|
|
2459
|
+
"MINIO_ROOT_USER",
|
|
2460
|
+
"SECRET",
|
|
2461
|
+
"ENVIRONMENT",
|
|
2462
|
+
generateLongPassword()
|
|
2463
|
+
),
|
|
2464
|
+
scope: "ENVIRONMENT"
|
|
2465
|
+
},
|
|
2466
|
+
{
|
|
2467
|
+
name: "MINIO_ROOT_PASSWORD",
|
|
2468
|
+
type: "SECRET",
|
|
2469
|
+
didExist: findExistingValue(
|
|
2470
|
+
"MINIO_ROOT_PASSWORD",
|
|
2471
|
+
"SECRET",
|
|
2472
|
+
"ENVIRONMENT",
|
|
2473
|
+
existingValues
|
|
2474
|
+
),
|
|
2475
|
+
value: findExistingOrDefine(
|
|
2476
|
+
"MINIO_ROOT_PASSWORD",
|
|
2477
|
+
"SECRET",
|
|
2478
|
+
"ENVIRONMENT",
|
|
2479
|
+
generateLongPassword()
|
|
2480
|
+
),
|
|
2481
|
+
scope: "ENVIRONMENT"
|
|
2482
|
+
},
|
|
2483
|
+
{
|
|
2484
|
+
name: "POSTGRES_USER",
|
|
2485
|
+
type: "SECRET",
|
|
2486
|
+
didExist: findExistingValue(
|
|
2487
|
+
"POSTGRES_USER",
|
|
2488
|
+
"SECRET",
|
|
2489
|
+
"ENVIRONMENT",
|
|
2490
|
+
existingValues
|
|
2491
|
+
),
|
|
2492
|
+
value: findExistingOrDefine(
|
|
2493
|
+
"POSTGRES_USER",
|
|
2494
|
+
"SECRET",
|
|
2495
|
+
"ENVIRONMENT",
|
|
2496
|
+
generateLongPassword()
|
|
2497
|
+
),
|
|
2498
|
+
scope: "ENVIRONMENT"
|
|
2499
|
+
},
|
|
2500
|
+
{
|
|
2501
|
+
name: "POSTGRES_PASSWORD",
|
|
2502
|
+
type: "SECRET",
|
|
2503
|
+
didExist: findExistingValue(
|
|
2504
|
+
"POSTGRES_PASSWORD",
|
|
2505
|
+
"SECRET",
|
|
2506
|
+
"ENVIRONMENT",
|
|
2507
|
+
existingValues
|
|
2508
|
+
),
|
|
2509
|
+
value: findExistingOrDefine(
|
|
2510
|
+
"POSTGRES_PASSWORD",
|
|
2511
|
+
"SECRET",
|
|
2512
|
+
"ENVIRONMENT",
|
|
2513
|
+
generateLongPassword()
|
|
2514
|
+
),
|
|
2515
|
+
scope: "ENVIRONMENT"
|
|
2516
|
+
},
|
|
2517
|
+
{
|
|
2518
|
+
name: "SUPER_USER_PASSWORD",
|
|
2519
|
+
type: "SECRET",
|
|
2520
|
+
didExist: findExistingValue(
|
|
2521
|
+
"SUPER_USER_PASSWORD",
|
|
2522
|
+
"SECRET",
|
|
2523
|
+
"ENVIRONMENT",
|
|
2524
|
+
existingValues
|
|
2525
|
+
),
|
|
2526
|
+
value: findExistingOrDefine(
|
|
2527
|
+
"SUPER_USER_PASSWORD",
|
|
2528
|
+
"SECRET",
|
|
2529
|
+
"ENVIRONMENT",
|
|
2530
|
+
generateLongPassword()
|
|
2531
|
+
),
|
|
2532
|
+
scope: "ENVIRONMENT"
|
|
2533
|
+
},
|
|
2534
|
+
{
|
|
2535
|
+
type: "VARIABLE",
|
|
2536
|
+
name: "ACTIVATE_USERS",
|
|
2537
|
+
value: "production" === environment_type ? "false" : "true",
|
|
2538
|
+
didExist: findExistingValue(
|
|
2539
|
+
"ACTIVATE_USERS",
|
|
2029
2540
|
"VARIABLE",
|
|
2030
2541
|
"ENVIRONMENT",
|
|
2031
2542
|
existingValues
|
|
2032
|
-
)
|
|
2033
|
-
|
|
2034
|
-
|
|
2543
|
+
),
|
|
2544
|
+
scope: "ENVIRONMENT"
|
|
2545
|
+
},
|
|
2546
|
+
{
|
|
2547
|
+
type: "VARIABLE",
|
|
2548
|
+
name: "COUNTRY_CONFIG_HOST",
|
|
2549
|
+
value: answerOrExisting(
|
|
2550
|
+
allAnswers.domain,
|
|
2551
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2552
|
+
(val) => `https://countryconfig.${val}`
|
|
2553
|
+
),
|
|
2554
|
+
didExist: findExistingValue(
|
|
2555
|
+
"COUNTRY_CONFIG_HOST",
|
|
2035
2556
|
"VARIABLE",
|
|
2036
2557
|
"ENVIRONMENT",
|
|
2037
2558
|
existingValues
|
|
2038
|
-
)
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
existingValues
|
|
2054
|
-
);
|
|
2055
|
-
const backupHostPrivateKeyExists = findExistingValue(
|
|
2056
|
-
"BACKUP_HOST_PRIVATE_KEY",
|
|
2057
|
-
"SECRET",
|
|
2058
|
-
"ENVIRONMENT",
|
|
2059
|
-
existingValues
|
|
2060
|
-
);
|
|
2061
|
-
backupType = backupAnswers.backupType;
|
|
2062
|
-
backupHost = backupAnswers.backupHost || backupHost;
|
|
2063
|
-
if (!backupHostPrivateKeyExists) {
|
|
2064
|
-
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2065
|
-
backupHostPublicKey = publicKey;
|
|
2066
|
-
backupHostPrivateKey = privateKey;
|
|
2067
|
-
log(
|
|
2068
|
-
import_kleur4.default.bold().green("\u2714"),
|
|
2069
|
-
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
2070
|
-
);
|
|
2071
|
-
}
|
|
2072
|
-
} else {
|
|
2073
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
2074
|
-
}
|
|
2075
|
-
log("\n", import_kleur4.default.bold().underline("Restore"));
|
|
2076
|
-
let configureRestore = restoreEnvironmentName ? true : false;
|
|
2077
|
-
if (!restoreEnvironmentName && !configureBackup) {
|
|
2078
|
-
configureRestore = await confirm2({
|
|
2079
|
-
message: "Do you want to configure restore?",
|
|
2080
|
-
default: Boolean(process.env.CONFIGURE_RESTORE)
|
|
2081
|
-
});
|
|
2082
|
-
}
|
|
2083
|
-
if (configureRestore) {
|
|
2084
|
-
const env_list_filtered = existingEnvironments.filter(
|
|
2085
|
-
(env) => env !== environment
|
|
2086
|
-
);
|
|
2087
|
-
restoreEnvironmentName = await selectWithCustom({
|
|
2088
|
-
message: "What is the name of your environment to restore?",
|
|
2089
|
-
choices: env_list_filtered.map((env) => ({
|
|
2090
|
-
name: env,
|
|
2091
|
-
value: env
|
|
2092
|
-
})),
|
|
2093
|
-
initial: restoreEnvironmentName
|
|
2094
|
-
});
|
|
2095
|
-
restoreType = await select3({
|
|
2096
|
-
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2097
|
-
choices: [
|
|
2098
|
-
{
|
|
2099
|
-
name: "Full dump (daily full database backup)",
|
|
2100
|
-
value: "dump"
|
|
2101
|
-
},
|
|
2102
|
-
{
|
|
2103
|
-
name: "Differential (weekly full, daily diff backup)",
|
|
2104
|
-
value: "differential"
|
|
2105
|
-
}
|
|
2106
|
-
]
|
|
2107
|
-
});
|
|
2108
|
-
} else {
|
|
2109
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2110
|
-
}
|
|
2111
|
-
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2112
|
-
await promptAndStoreAnswer(
|
|
2113
|
-
environment,
|
|
2114
|
-
databaseAndMonitoringQuestions,
|
|
2559
|
+
),
|
|
2560
|
+
scope: "ENVIRONMENT"
|
|
2561
|
+
},
|
|
2562
|
+
{
|
|
2563
|
+
type: "VARIABLE",
|
|
2564
|
+
name: "GATEWAY_HOST",
|
|
2565
|
+
value: answerOrExisting(
|
|
2566
|
+
allAnswers.domain,
|
|
2567
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2568
|
+
(val) => `https://gateway.${val}`
|
|
2569
|
+
),
|
|
2570
|
+
didExist: findExistingValue(
|
|
2571
|
+
"GATEWAY_HOST",
|
|
2572
|
+
"VARIABLE",
|
|
2573
|
+
"ENVIRONMENT",
|
|
2115
2574
|
existingValues
|
|
2116
|
-
)
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2575
|
+
),
|
|
2576
|
+
scope: "ENVIRONMENT"
|
|
2577
|
+
},
|
|
2578
|
+
{
|
|
2579
|
+
type: "VARIABLE",
|
|
2580
|
+
name: "CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2581
|
+
value: answerOrExisting(
|
|
2582
|
+
allAnswers.domain,
|
|
2583
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2584
|
+
(val) => `*.${val}`
|
|
2585
|
+
),
|
|
2586
|
+
didExist: findExistingValue(
|
|
2587
|
+
"CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2588
|
+
"VARIABLE",
|
|
2120
2589
|
"ENVIRONMENT",
|
|
2121
2590
|
existingValues
|
|
2122
|
-
)
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2140
|
-
await promptAndStoreAnswer(
|
|
2141
|
-
environment,
|
|
2142
|
-
metabaseAdminQuestions,
|
|
2591
|
+
),
|
|
2592
|
+
scope: "ENVIRONMENT"
|
|
2593
|
+
},
|
|
2594
|
+
{
|
|
2595
|
+
type: "VARIABLE",
|
|
2596
|
+
name: "CLIENT_APP_URL",
|
|
2597
|
+
value: answerOrExisting(
|
|
2598
|
+
allAnswers.domain,
|
|
2599
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2600
|
+
(val) => `https://register.${val}`
|
|
2601
|
+
),
|
|
2602
|
+
didExist: findExistingValue(
|
|
2603
|
+
"CLIENT_APP_URL",
|
|
2604
|
+
"VARIABLE",
|
|
2605
|
+
"ENVIRONMENT",
|
|
2143
2606
|
existingValues
|
|
2144
|
-
)
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
scope: "REPOSITORY"
|
|
2171
|
-
}
|
|
2172
|
-
];
|
|
2173
|
-
derivedUpdates.push({
|
|
2174
|
-
name: "NOTIFICATION_TRANSPORT",
|
|
2175
|
-
type: "VARIABLE",
|
|
2176
|
-
didExist: findExistingValue(
|
|
2177
|
-
"NOTIFICATION_TRANSPORT",
|
|
2607
|
+
),
|
|
2608
|
+
scope: "ENVIRONMENT"
|
|
2609
|
+
},
|
|
2610
|
+
{
|
|
2611
|
+
type: "VARIABLE",
|
|
2612
|
+
name: "LOGIN_URL",
|
|
2613
|
+
value: answerOrExisting(
|
|
2614
|
+
allAnswers.domain,
|
|
2615
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2616
|
+
(val) => `https://login.${val}`
|
|
2617
|
+
),
|
|
2618
|
+
didExist: findExistingValue(
|
|
2619
|
+
"LOGIN_URL",
|
|
2620
|
+
"VARIABLE",
|
|
2621
|
+
"ENVIRONMENT",
|
|
2622
|
+
existingValues
|
|
2623
|
+
),
|
|
2624
|
+
scope: "ENVIRONMENT"
|
|
2625
|
+
},
|
|
2626
|
+
{
|
|
2627
|
+
type: "VARIABLE",
|
|
2628
|
+
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2629
|
+
value: answerOrExisting(
|
|
2630
|
+
restoreEnvironmentName,
|
|
2631
|
+
findExistingValue(
|
|
2632
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2178
2633
|
"VARIABLE",
|
|
2179
2634
|
"ENVIRONMENT",
|
|
2180
2635
|
existingValues
|
|
2181
2636
|
),
|
|
2182
|
-
|
|
2183
|
-
|
|
2637
|
+
(val) => val || ""
|
|
2638
|
+
),
|
|
2639
|
+
didExist: findExistingValue(
|
|
2640
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2641
|
+
"VARIABLE",
|
|
2642
|
+
"ENVIRONMENT",
|
|
2643
|
+
existingValues
|
|
2644
|
+
),
|
|
2645
|
+
scope: "ENVIRONMENT"
|
|
2646
|
+
},
|
|
2647
|
+
{
|
|
2648
|
+
type: "VARIABLE",
|
|
2649
|
+
name: "RESTORE_HOST",
|
|
2650
|
+
value: answerOrExisting(
|
|
2651
|
+
restoreHost,
|
|
2652
|
+
findExistingValue(
|
|
2653
|
+
"RESTORE_HOST",
|
|
2184
2654
|
"VARIABLE",
|
|
2185
2655
|
"ENVIRONMENT",
|
|
2186
|
-
|
|
2656
|
+
existingValues
|
|
2187
2657
|
),
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
}
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
),
|
|
2382
|
-
didExist: findExistingValue(
|
|
2383
|
-
"CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2384
|
-
"VARIABLE",
|
|
2385
|
-
"ENVIRONMENT",
|
|
2386
|
-
existingValues
|
|
2387
|
-
),
|
|
2388
|
-
scope: "ENVIRONMENT"
|
|
2389
|
-
},
|
|
2390
|
-
{
|
|
2391
|
-
type: "VARIABLE",
|
|
2392
|
-
name: "CLIENT_APP_URL",
|
|
2393
|
-
value: answerOrExisting(
|
|
2394
|
-
allAnswers.domain,
|
|
2395
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2396
|
-
(val) => `https://register.${val}`
|
|
2397
|
-
),
|
|
2398
|
-
didExist: findExistingValue(
|
|
2399
|
-
"CLIENT_APP_URL",
|
|
2400
|
-
"VARIABLE",
|
|
2401
|
-
"ENVIRONMENT",
|
|
2402
|
-
existingValues
|
|
2403
|
-
),
|
|
2404
|
-
scope: "ENVIRONMENT"
|
|
2405
|
-
},
|
|
2406
|
-
{
|
|
2407
|
-
type: "VARIABLE",
|
|
2408
|
-
name: "LOGIN_URL",
|
|
2409
|
-
value: answerOrExisting(
|
|
2410
|
-
allAnswers.domain,
|
|
2411
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2412
|
-
(val) => `https://login.${val}`
|
|
2413
|
-
),
|
|
2414
|
-
didExist: findExistingValue(
|
|
2415
|
-
"LOGIN_URL",
|
|
2416
|
-
"VARIABLE",
|
|
2417
|
-
"ENVIRONMENT",
|
|
2418
|
-
existingValues
|
|
2419
|
-
),
|
|
2420
|
-
scope: "ENVIRONMENT"
|
|
2421
|
-
},
|
|
2422
|
-
{
|
|
2423
|
-
type: "VARIABLE",
|
|
2424
|
-
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2425
|
-
value: answerOrExisting(
|
|
2426
|
-
restoreEnvironmentName,
|
|
2427
|
-
findExistingValue(
|
|
2428
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2429
|
-
"VARIABLE",
|
|
2430
|
-
"ENVIRONMENT",
|
|
2431
|
-
existingValues
|
|
2432
|
-
),
|
|
2433
|
-
(val) => val || ""
|
|
2434
|
-
),
|
|
2435
|
-
didExist: findExistingValue(
|
|
2436
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2437
|
-
"VARIABLE",
|
|
2438
|
-
"ENVIRONMENT",
|
|
2439
|
-
existingValues
|
|
2440
|
-
),
|
|
2441
|
-
scope: "ENVIRONMENT"
|
|
2442
|
-
}
|
|
2443
|
-
];
|
|
2444
|
-
if (enableEncryption) {
|
|
2445
|
-
applicationServerUpdates.push({
|
|
2446
|
-
name: "ENCRYPTION_KEY",
|
|
2447
|
-
type: "SECRET",
|
|
2448
|
-
didExist: findExistingValue(
|
|
2449
|
-
"ENCRYPTION_KEY",
|
|
2450
|
-
"SECRET",
|
|
2451
|
-
"ENVIRONMENT",
|
|
2452
|
-
existingValues
|
|
2453
|
-
),
|
|
2454
|
-
value: findExistingOrDefine(
|
|
2455
|
-
"ENCRYPTION_KEY",
|
|
2456
|
-
"SECRET",
|
|
2457
|
-
"ENVIRONMENT",
|
|
2458
|
-
generateLongPassword()
|
|
2459
|
-
),
|
|
2460
|
-
scope: "ENVIRONMENT"
|
|
2461
|
-
});
|
|
2462
|
-
}
|
|
2463
|
-
if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
|
|
2464
|
-
applicationServerUpdates.push({
|
|
2465
|
-
name: "BACKUP_HOST_PRIVATE_KEY",
|
|
2466
|
-
type: "SECRET",
|
|
2467
|
-
didExist: void 0,
|
|
2468
|
-
value: backupHostPrivateKey,
|
|
2469
|
-
scope: "ENVIRONMENT"
|
|
2470
|
-
});
|
|
2471
|
-
applicationServerUpdates.push({
|
|
2472
|
-
name: "BACKUP_HOST_PUBLIC_KEY",
|
|
2473
|
-
type: "SECRET",
|
|
2474
|
-
didExist: void 0,
|
|
2475
|
-
value: backupHostPublicKey,
|
|
2476
|
-
scope: "ENVIRONMENT"
|
|
2477
|
-
});
|
|
2478
|
-
}
|
|
2479
|
-
derivedUpdates.push(...applicationServerUpdates);
|
|
2480
|
-
const updates = getAnswers(existingValues).concat(
|
|
2481
|
-
...derivedUpdates.filter(
|
|
2482
|
-
(update) => update.value !== null
|
|
2483
|
-
)
|
|
2484
|
-
).filter(
|
|
2485
|
-
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2486
|
-
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2658
|
+
(val) => val || ""
|
|
2659
|
+
),
|
|
2660
|
+
didExist: findExistingValue(
|
|
2661
|
+
"RESTORE_HOST",
|
|
2662
|
+
"VARIABLE",
|
|
2663
|
+
"ENVIRONMENT",
|
|
2664
|
+
existingValues
|
|
2665
|
+
),
|
|
2666
|
+
scope: "ENVIRONMENT"
|
|
2667
|
+
},
|
|
2668
|
+
{
|
|
2669
|
+
type: "VARIABLE",
|
|
2670
|
+
name: "RESTORE_ENVIRONMENT_MODE",
|
|
2671
|
+
// Only persist the mode when restore is configured
|
|
2672
|
+
value: restoreEnvironmentName ? restoreType : "",
|
|
2673
|
+
didExist: findExistingValue(
|
|
2674
|
+
"RESTORE_ENVIRONMENT_MODE",
|
|
2675
|
+
"VARIABLE",
|
|
2676
|
+
"ENVIRONMENT",
|
|
2677
|
+
existingValues
|
|
2678
|
+
),
|
|
2679
|
+
scope: "ENVIRONMENT"
|
|
2680
|
+
}
|
|
2681
|
+
];
|
|
2682
|
+
if (enableEncryption) {
|
|
2683
|
+
applicationServerUpdates.push({
|
|
2684
|
+
name: "ENCRYPTION_KEY",
|
|
2685
|
+
type: "SECRET",
|
|
2686
|
+
didExist: findExistingValue(
|
|
2687
|
+
"ENCRYPTION_KEY",
|
|
2688
|
+
"SECRET",
|
|
2689
|
+
"ENVIRONMENT",
|
|
2690
|
+
existingValues
|
|
2691
|
+
),
|
|
2692
|
+
value: findExistingOrDefine(
|
|
2693
|
+
"ENCRYPTION_KEY",
|
|
2694
|
+
"SECRET",
|
|
2695
|
+
"ENVIRONMENT",
|
|
2696
|
+
generateLongPassword()
|
|
2697
|
+
),
|
|
2698
|
+
scope: "ENVIRONMENT"
|
|
2699
|
+
});
|
|
2700
|
+
}
|
|
2701
|
+
if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
|
|
2702
|
+
applicationServerUpdates.push({
|
|
2703
|
+
name: "BACKUP_HOST_PRIVATE_KEY",
|
|
2704
|
+
type: "SECRET",
|
|
2705
|
+
didExist: void 0,
|
|
2706
|
+
value: backupHostPrivateKey,
|
|
2707
|
+
scope: "ENVIRONMENT"
|
|
2708
|
+
});
|
|
2709
|
+
applicationServerUpdates.push({
|
|
2710
|
+
name: "BACKUP_HOST_PUBLIC_KEY",
|
|
2711
|
+
type: "SECRET",
|
|
2712
|
+
didExist: void 0,
|
|
2713
|
+
value: backupHostPublicKey,
|
|
2714
|
+
scope: "ENVIRONMENT"
|
|
2715
|
+
});
|
|
2716
|
+
}
|
|
2717
|
+
derivedUpdates.push(...applicationServerUpdates);
|
|
2718
|
+
const updates = getAnswers(existingValues).concat(
|
|
2719
|
+
...derivedUpdates.filter(
|
|
2720
|
+
(update) => update.value !== null
|
|
2721
|
+
)
|
|
2722
|
+
).filter(
|
|
2723
|
+
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2724
|
+
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2725
|
+
);
|
|
2726
|
+
const newSecrets = updates.filter(
|
|
2727
|
+
(update) => update.type === "SECRET" && !update.didExist
|
|
2728
|
+
);
|
|
2729
|
+
const updatedSecrets = updates.filter(
|
|
2730
|
+
(update) => update.type === "SECRET" && Boolean(update.didExist)
|
|
2731
|
+
);
|
|
2732
|
+
const newVariables = updates.filter(
|
|
2733
|
+
(update) => update.type === "VARIABLE" && !update.didExist
|
|
2734
|
+
);
|
|
2735
|
+
const updatedVariables = updates.filter(
|
|
2736
|
+
(update) => update.type === "VARIABLE" && Boolean(update.didExist)
|
|
2737
|
+
);
|
|
2738
|
+
const unknownVariables = existingValues.filter((value) => {
|
|
2739
|
+
return !ALL_QUESTIONS.find(
|
|
2740
|
+
(question) => question.valueLabel === value.name && question.valueType === value.type && question.scope === value.scope
|
|
2741
|
+
);
|
|
2742
|
+
});
|
|
2743
|
+
log("");
|
|
2744
|
+
if (newSecrets.length > 0) {
|
|
2745
|
+
log(
|
|
2746
|
+
import_kleur4.default.yellow(
|
|
2747
|
+
`The following secrets will be added to Github for environment ${environment}:`
|
|
2748
|
+
)
|
|
2749
|
+
);
|
|
2750
|
+
newSecrets.filter(({ scope }) => scope === "ENVIRONMENT").forEach((secret) => {
|
|
2751
|
+
log(secret.name, "=", secret.value);
|
|
2752
|
+
});
|
|
2753
|
+
log("");
|
|
2754
|
+
log(
|
|
2755
|
+
import_kleur4.default.yellow(`The following secrets will be added to Github repository:`)
|
|
2756
|
+
);
|
|
2757
|
+
newSecrets.filter(({ scope }) => scope === "REPOSITORY").forEach((secret) => {
|
|
2758
|
+
log(secret.name, "=", secret.value);
|
|
2759
|
+
});
|
|
2760
|
+
log("");
|
|
2761
|
+
}
|
|
2762
|
+
if (updatedSecrets.length > 0) {
|
|
2763
|
+
log(
|
|
2764
|
+
import_kleur4.default.yellow(
|
|
2765
|
+
`The following secrets will be updated in Github for environment ${environment}:`
|
|
2766
|
+
)
|
|
2767
|
+
);
|
|
2768
|
+
updatedSecrets.forEach((secret) => {
|
|
2769
|
+
log(secret.name, "=", secret.value);
|
|
2770
|
+
});
|
|
2771
|
+
log("");
|
|
2772
|
+
}
|
|
2773
|
+
if (newVariables.length > 0) {
|
|
2774
|
+
log(
|
|
2775
|
+
import_kleur4.default.yellow(
|
|
2776
|
+
`The following variables will be added to Github for environment ${environment}:`
|
|
2777
|
+
)
|
|
2778
|
+
);
|
|
2779
|
+
newVariables.forEach((variable) => {
|
|
2780
|
+
log(variable.name, "=", variable.value);
|
|
2781
|
+
});
|
|
2782
|
+
log("");
|
|
2783
|
+
}
|
|
2784
|
+
if (updatedVariables.length > 0) {
|
|
2785
|
+
log(
|
|
2786
|
+
import_kleur4.default.yellow(
|
|
2787
|
+
`The following variables will be updated in Github for environment ${environment}:`
|
|
2788
|
+
)
|
|
2789
|
+
);
|
|
2790
|
+
updatedVariables.forEach((variable) => {
|
|
2791
|
+
log(
|
|
2792
|
+
variable.name,
|
|
2793
|
+
"=",
|
|
2794
|
+
variable.value,
|
|
2795
|
+
`(was ${variable.didExist?.value})`
|
|
2796
|
+
);
|
|
2797
|
+
});
|
|
2798
|
+
log("");
|
|
2799
|
+
}
|
|
2800
|
+
if (unknownVariables.length > 0) {
|
|
2801
|
+
log(
|
|
2802
|
+
import_kleur4.default.yellow(
|
|
2803
|
+
`The following unknown variables/secrets were stored in Github are not managed by this script:`
|
|
2804
|
+
)
|
|
2805
|
+
);
|
|
2806
|
+
log("");
|
|
2807
|
+
log(import_kleur4.default.blue(`Repository:`));
|
|
2808
|
+
unknownVariables.filter(({ scope }) => scope === "REPOSITORY").forEach((variable) => {
|
|
2809
|
+
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2810
|
+
});
|
|
2811
|
+
log("");
|
|
2812
|
+
log(import_kleur4.default.blue(`Environment:`));
|
|
2813
|
+
unknownVariables.filter(({ scope }) => scope === "ENVIRONMENT").forEach((variable) => {
|
|
2814
|
+
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2815
|
+
});
|
|
2816
|
+
log("");
|
|
2817
|
+
log(
|
|
2818
|
+
import_kleur4.default.yellow(
|
|
2819
|
+
`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`
|
|
2820
|
+
)
|
|
2821
|
+
);
|
|
2822
|
+
log("");
|
|
2823
|
+
}
|
|
2824
|
+
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2825
|
+
process.exit(0);
|
|
2826
|
+
}
|
|
2827
|
+
log(
|
|
2828
|
+
import_kleur4.default.bold().red(
|
|
2829
|
+
"\u26A0\uFE0F COPY THESE NOW INTO A PASSWORD MANAGER \u2014 YOU WON'T SEE THEM AGAIN"
|
|
2830
|
+
)
|
|
2831
|
+
);
|
|
2832
|
+
log("");
|
|
2833
|
+
const saveChanges = await confirm2({
|
|
2834
|
+
message: "Do you want to continue?",
|
|
2835
|
+
default: true
|
|
2836
|
+
});
|
|
2837
|
+
if (!saveChanges) {
|
|
2838
|
+
process.exit(0);
|
|
2839
|
+
}
|
|
2840
|
+
for (const newSecret of newSecrets) {
|
|
2841
|
+
log(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
|
|
2842
|
+
if (newSecret.scope === "ENVIRONMENT") {
|
|
2843
|
+
await createEnvironmentSecret(
|
|
2844
|
+
octokit,
|
|
2845
|
+
repositoryId,
|
|
2846
|
+
environment,
|
|
2847
|
+
newSecret.name,
|
|
2848
|
+
newSecret.value,
|
|
2849
|
+
githubOrganisation,
|
|
2850
|
+
githubRepository
|
|
2487
2851
|
);
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2852
|
+
} else {
|
|
2853
|
+
await createRepositorySecret(
|
|
2854
|
+
octokit,
|
|
2855
|
+
repositoryId,
|
|
2856
|
+
newSecret.name,
|
|
2857
|
+
newSecret.value,
|
|
2858
|
+
githubOrganisation,
|
|
2859
|
+
githubRepository
|
|
2491
2860
|
);
|
|
2492
|
-
|
|
2493
|
-
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
for (const updatedSecret of updatedSecrets) {
|
|
2864
|
+
log(
|
|
2865
|
+
`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`
|
|
2866
|
+
);
|
|
2867
|
+
if (updatedSecret.scope === "ENVIRONMENT") {
|
|
2868
|
+
await createEnvironmentSecret(
|
|
2869
|
+
octokit,
|
|
2870
|
+
repositoryId,
|
|
2871
|
+
environment,
|
|
2872
|
+
updatedSecret.name,
|
|
2873
|
+
updatedSecret.value,
|
|
2874
|
+
githubOrganisation,
|
|
2875
|
+
githubRepository
|
|
2494
2876
|
);
|
|
2495
|
-
|
|
2496
|
-
|
|
2877
|
+
} else {
|
|
2878
|
+
await createRepositorySecret(
|
|
2879
|
+
octokit,
|
|
2880
|
+
repositoryId,
|
|
2881
|
+
updatedSecret.name,
|
|
2882
|
+
updatedSecret.value,
|
|
2883
|
+
githubOrganisation,
|
|
2884
|
+
githubRepository
|
|
2497
2885
|
);
|
|
2498
|
-
|
|
2499
|
-
|
|
2886
|
+
}
|
|
2887
|
+
}
|
|
2888
|
+
for (const newVariable of newVariables) {
|
|
2889
|
+
log(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
|
|
2890
|
+
if (newVariable.scope === "ENVIRONMENT") {
|
|
2891
|
+
await createEnvironmentVariable(
|
|
2892
|
+
octokit,
|
|
2893
|
+
repositoryId,
|
|
2894
|
+
environment,
|
|
2895
|
+
newVariable.name,
|
|
2896
|
+
newVariable.value
|
|
2500
2897
|
);
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
if (newSecrets.length > 0) {
|
|
2508
|
-
log(
|
|
2509
|
-
import_kleur4.default.yellow(
|
|
2510
|
-
`The following secrets will be added to Github for environment ${environment}:`
|
|
2511
|
-
)
|
|
2512
|
-
);
|
|
2513
|
-
newSecrets.filter(({ scope }) => scope === "ENVIRONMENT").forEach((secret) => {
|
|
2514
|
-
log(secret.name, "=", secret.value);
|
|
2515
|
-
});
|
|
2516
|
-
log("");
|
|
2517
|
-
log(
|
|
2518
|
-
import_kleur4.default.yellow(`The following secrets will be added to Github repository:`)
|
|
2519
|
-
);
|
|
2520
|
-
newSecrets.filter(({ scope }) => scope === "REPOSITORY").forEach((secret) => {
|
|
2521
|
-
log(secret.name, "=", secret.value);
|
|
2522
|
-
});
|
|
2523
|
-
log("");
|
|
2524
|
-
}
|
|
2525
|
-
if (updatedSecrets.length > 0) {
|
|
2526
|
-
log(
|
|
2527
|
-
import_kleur4.default.yellow(
|
|
2528
|
-
`The following secrets will be updated in Github for environment ${environment}:`
|
|
2529
|
-
)
|
|
2530
|
-
);
|
|
2531
|
-
updatedSecrets.forEach((secret) => {
|
|
2532
|
-
log(secret.name, "=", secret.value);
|
|
2533
|
-
});
|
|
2534
|
-
log("");
|
|
2535
|
-
}
|
|
2536
|
-
if (newVariables.length > 0) {
|
|
2537
|
-
log(
|
|
2538
|
-
import_kleur4.default.yellow(
|
|
2539
|
-
`The following variables will be added to Github for environment ${environment}:`
|
|
2540
|
-
)
|
|
2541
|
-
);
|
|
2542
|
-
newVariables.forEach((variable) => {
|
|
2543
|
-
log(variable.name, "=", variable.value);
|
|
2544
|
-
});
|
|
2545
|
-
log("");
|
|
2546
|
-
}
|
|
2547
|
-
if (updatedVariables.length > 0) {
|
|
2548
|
-
log(
|
|
2549
|
-
import_kleur4.default.yellow(
|
|
2550
|
-
`The following variables will be updated in Github for environment ${environment}:`
|
|
2551
|
-
)
|
|
2552
|
-
);
|
|
2553
|
-
updatedVariables.forEach((variable) => {
|
|
2554
|
-
log(
|
|
2555
|
-
variable.name,
|
|
2556
|
-
"=",
|
|
2557
|
-
variable.value,
|
|
2558
|
-
`(was ${variable.didExist?.value})`
|
|
2559
|
-
);
|
|
2560
|
-
});
|
|
2561
|
-
log("");
|
|
2562
|
-
}
|
|
2563
|
-
if (unknownVariables.length > 0) {
|
|
2564
|
-
log(
|
|
2565
|
-
import_kleur4.default.yellow(
|
|
2566
|
-
`The following unknown variables/secrets were stored in Github are not managed by this script:`
|
|
2567
|
-
)
|
|
2568
|
-
);
|
|
2569
|
-
log("");
|
|
2570
|
-
log(import_kleur4.default.blue(`Repository:`));
|
|
2571
|
-
unknownVariables.filter(({ scope }) => scope === "REPOSITORY").forEach((variable) => {
|
|
2572
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2573
|
-
});
|
|
2574
|
-
log("");
|
|
2575
|
-
log(import_kleur4.default.blue(`Environment:`));
|
|
2576
|
-
unknownVariables.filter(({ scope }) => scope === "ENVIRONMENT").forEach((variable) => {
|
|
2577
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2578
|
-
});
|
|
2579
|
-
log("");
|
|
2580
|
-
log(
|
|
2581
|
-
import_kleur4.default.yellow(
|
|
2582
|
-
`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`
|
|
2583
|
-
)
|
|
2584
|
-
);
|
|
2585
|
-
log("");
|
|
2586
|
-
}
|
|
2587
|
-
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2588
|
-
process.exit(0);
|
|
2589
|
-
}
|
|
2590
|
-
const saveChanges = await confirm2({
|
|
2591
|
-
message: "Do you want to continue?",
|
|
2592
|
-
default: true
|
|
2593
|
-
});
|
|
2594
|
-
if (!saveChanges) {
|
|
2595
|
-
process.exit(0);
|
|
2596
|
-
}
|
|
2597
|
-
for (const newSecret of newSecrets) {
|
|
2598
|
-
log(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
|
|
2599
|
-
if (newSecret.scope === "ENVIRONMENT") {
|
|
2600
|
-
await createEnvironmentSecret(
|
|
2601
|
-
octokit,
|
|
2602
|
-
repositoryId,
|
|
2603
|
-
environment,
|
|
2604
|
-
newSecret.name,
|
|
2605
|
-
newSecret.value,
|
|
2606
|
-
githubOrganisation,
|
|
2607
|
-
githubRepository
|
|
2608
|
-
);
|
|
2609
|
-
} else {
|
|
2610
|
-
await createRepositorySecret(
|
|
2611
|
-
octokit,
|
|
2612
|
-
repositoryId,
|
|
2613
|
-
newSecret.name,
|
|
2614
|
-
newSecret.value,
|
|
2615
|
-
githubOrganisation,
|
|
2616
|
-
githubRepository
|
|
2617
|
-
);
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
for (const updatedSecret of updatedSecrets) {
|
|
2621
|
-
log(
|
|
2622
|
-
`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`
|
|
2623
|
-
);
|
|
2624
|
-
if (updatedSecret.scope === "ENVIRONMENT") {
|
|
2625
|
-
await createEnvironmentSecret(
|
|
2626
|
-
octokit,
|
|
2627
|
-
repositoryId,
|
|
2628
|
-
environment,
|
|
2629
|
-
updatedSecret.name,
|
|
2630
|
-
updatedSecret.value,
|
|
2631
|
-
githubOrganisation,
|
|
2632
|
-
githubRepository
|
|
2633
|
-
);
|
|
2634
|
-
} else {
|
|
2635
|
-
await createRepositorySecret(
|
|
2636
|
-
octokit,
|
|
2637
|
-
repositoryId,
|
|
2638
|
-
updatedSecret.name,
|
|
2639
|
-
updatedSecret.value,
|
|
2640
|
-
githubOrganisation,
|
|
2641
|
-
githubRepository
|
|
2642
|
-
);
|
|
2643
|
-
}
|
|
2644
|
-
}
|
|
2645
|
-
for (const newVariable of newVariables) {
|
|
2646
|
-
log(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
|
|
2647
|
-
if (newVariable.scope === "ENVIRONMENT") {
|
|
2648
|
-
await createEnvironmentVariable(
|
|
2649
|
-
octokit,
|
|
2650
|
-
repositoryId,
|
|
2651
|
-
environment,
|
|
2652
|
-
newVariable.name,
|
|
2653
|
-
newVariable.value
|
|
2654
|
-
);
|
|
2655
|
-
} else {
|
|
2656
|
-
await createRepositoryVariable(
|
|
2657
|
-
octokit,
|
|
2658
|
-
repositoryId,
|
|
2659
|
-
newVariable.name,
|
|
2660
|
-
newVariable.value
|
|
2661
|
-
);
|
|
2662
|
-
}
|
|
2663
|
-
}
|
|
2664
|
-
for (const updatedVariable of updatedVariables) {
|
|
2665
|
-
log(
|
|
2666
|
-
`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`
|
|
2667
|
-
);
|
|
2668
|
-
if (updatedVariable.scope === "ENVIRONMENT") {
|
|
2669
|
-
await updateEnvironmentVariable(
|
|
2670
|
-
octokit,
|
|
2671
|
-
repositoryId,
|
|
2672
|
-
environment,
|
|
2673
|
-
updatedVariable.name,
|
|
2674
|
-
updatedVariable.value
|
|
2675
|
-
);
|
|
2676
|
-
} else {
|
|
2677
|
-
await updateRepositoryVariable(
|
|
2678
|
-
octokit,
|
|
2679
|
-
repositoryId,
|
|
2680
|
-
updatedVariable.name,
|
|
2681
|
-
updatedVariable.value
|
|
2682
|
-
);
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
log(
|
|
2686
|
-
import_kleur4.default.green(
|
|
2687
|
-
`Successfully updated Github secrets and variables for environment ${environment}`
|
|
2688
|
-
)
|
|
2898
|
+
} else {
|
|
2899
|
+
await createRepositoryVariable(
|
|
2900
|
+
octokit,
|
|
2901
|
+
repositoryId,
|
|
2902
|
+
newVariable.name,
|
|
2903
|
+
newVariable.value
|
|
2689
2904
|
);
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
for (const updatedVariable of updatedVariables) {
|
|
2908
|
+
log(
|
|
2909
|
+
`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`
|
|
2910
|
+
);
|
|
2911
|
+
if (updatedVariable.scope === "ENVIRONMENT") {
|
|
2912
|
+
await updateEnvironmentVariable(
|
|
2913
|
+
octokit,
|
|
2914
|
+
repositoryId,
|
|
2915
|
+
environment,
|
|
2916
|
+
updatedVariable.name,
|
|
2917
|
+
updatedVariable.value
|
|
2918
|
+
);
|
|
2919
|
+
} else {
|
|
2920
|
+
await updateRepositoryVariable(
|
|
2921
|
+
octokit,
|
|
2922
|
+
repositoryId,
|
|
2923
|
+
updatedVariable.name,
|
|
2924
|
+
updatedVariable.value
|
|
2925
|
+
);
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
log(
|
|
2929
|
+
import_kleur4.default.green(
|
|
2930
|
+
`Successfully updated Github secrets and variables for environment ${environment}`
|
|
2931
|
+
)
|
|
2932
|
+
);
|
|
2933
|
+
log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
|
|
2934
|
+
generateInventory(environment, {
|
|
2935
|
+
kube_worker_nodes: kubeWorkerNodes,
|
|
2936
|
+
kube_api_host: infrastructure.kubeApiHost || "",
|
|
2937
|
+
backup_host: backupHost || "",
|
|
2938
|
+
users
|
|
2939
|
+
});
|
|
2940
|
+
copyChartsValues(environment, {
|
|
2941
|
+
env: environment,
|
|
2942
|
+
environment_type,
|
|
2943
|
+
two_fa_enabled,
|
|
2944
|
+
traefik_mode: traefikConfOption,
|
|
2945
|
+
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2946
|
+
restore_environment_name: restoreEnvironmentName || "",
|
|
2947
|
+
restore_type: restoreType,
|
|
2948
|
+
restore_host: restoreHost || "",
|
|
2949
|
+
backup_enabled: configureBackup ? true : false,
|
|
2950
|
+
backup_type: backupType,
|
|
2951
|
+
backup_host: backupHost || ""
|
|
2952
|
+
});
|
|
2953
|
+
log("\n", import_kleur4.default.bold().underline("Updating workflow files"));
|
|
2954
|
+
await updateWorkflowEnvironments();
|
|
2955
|
+
let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
|
|
2712
2956
|
|
|
2713
2957
|
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("COPY the SSH public key from the master VM to your clipboard")}
|
|
2714
2958
|
--------------------------------------------------------------------------------------------
|
|
2715
2959
|
` : "";
|
|
2716
|
-
|
|
2960
|
+
addon_message += kubeWorkerNodes.length > 0 ? `\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on Kubernetes worker VM to create provision user and setup SSH key:")}
|
|
2717
2961
|
|
|
2718
2962
|
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2719
2963
|
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"
|
|
2720
2964
|
` : "";
|
|
2721
|
-
|
|
2965
|
+
addon_message += configureBackup ? `
|
|
2722
2966
|
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on backup server to create provision user and setup SSH key:")}
|
|
2723
2967
|
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2724
2968
|
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"` : "";
|
|
2725
|
-
|
|
2969
|
+
log(`
|
|
2726
2970
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
2727
2971
|
Follow the steps below to complete the setup of your environment:
|
|
2728
2972
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
@@ -2740,131 +2984,115 @@ ${addon_message}
|
|
|
2740
2984
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
2741
2985
|
${import_kleur4.default.yellow("Please KINDLY read hints above")}
|
|
2742
2986
|
`);
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2987
|
+
log(
|
|
2988
|
+
"\nAll secrets and variables were printed above.",
|
|
2989
|
+
import_kleur4.default.bold().yellow("Store them in a password manager \u2014 they are not saved to disk.")
|
|
2990
|
+
);
|
|
2991
|
+
}
|
|
2992
|
+
var import_core, import_kleur4, import_prompts2, ALL_QUESTIONS, ALL_ANSWERS;
|
|
2993
|
+
var init_setup_environment = __esm({
|
|
2994
|
+
"src/environment/setup-environment.ts"() {
|
|
2995
|
+
"use strict";
|
|
2996
|
+
import_core = require("@octokit/core");
|
|
2997
|
+
import_kleur4 = __toESM(require("kleur"));
|
|
2998
|
+
import_prompts2 = __toESM(require("prompts"));
|
|
2999
|
+
init_github();
|
|
3000
|
+
init_derived_variables();
|
|
3001
|
+
init_utils();
|
|
3002
|
+
init_logger();
|
|
3003
|
+
init_templates();
|
|
3004
|
+
init_ssh_keygen();
|
|
3005
|
+
init_update_workflows();
|
|
3006
|
+
init_questions();
|
|
3007
|
+
init_editor_questions();
|
|
3008
|
+
init_questions_helper();
|
|
3009
|
+
init_manage_users();
|
|
3010
|
+
init_paths();
|
|
3011
|
+
ALL_QUESTIONS = [];
|
|
3012
|
+
ALL_ANSWERS = [];
|
|
3013
|
+
ALL_QUESTIONS.push(
|
|
3014
|
+
...githubTokenQuestion,
|
|
3015
|
+
...githubOtherQuestions,
|
|
3016
|
+
...dockerhubQuestions,
|
|
3017
|
+
...diskQuestions,
|
|
3018
|
+
...infrastructureQuestions,
|
|
3019
|
+
...backupQuestions,
|
|
3020
|
+
...countryQuestions,
|
|
3021
|
+
...databaseAndMonitoringQuestions,
|
|
3022
|
+
...emailQuestions,
|
|
3023
|
+
...sentryQuestions,
|
|
3024
|
+
...derivedVariables,
|
|
3025
|
+
...metabaseAdminQuestions,
|
|
3026
|
+
...e2eQuestions
|
|
3027
|
+
);
|
|
2746
3028
|
}
|
|
2747
3029
|
});
|
|
2748
3030
|
|
|
2749
|
-
// src/environment/
|
|
2750
|
-
var
|
|
2751
|
-
__export(
|
|
2752
|
-
|
|
3031
|
+
// src/environment/upgrade.ts
|
|
3032
|
+
var upgrade_exports = {};
|
|
3033
|
+
__export(upgrade_exports, {
|
|
3034
|
+
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2753
3035
|
});
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
if (infraEnvironments.length === 0) {
|
|
2758
|
-
console.log(
|
|
2759
|
-
"\u26A0\uFE0F Warning: No environment directories found in infrastructure/server-setup/inventory/"
|
|
2760
|
-
);
|
|
2761
|
-
return [];
|
|
3036
|
+
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
3037
|
+
if (!(0, import_fs7.existsSync)(sourcePath)) {
|
|
3038
|
+
return false;
|
|
2762
3039
|
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
}
|
|
2766
|
-
async function extractEnvironmentNames() {
|
|
2767
|
-
const entries = await (0, import_promises.readdir)("environments");
|
|
2768
|
-
const environments = entries.filter((entry) => {
|
|
2769
|
-
const fullPath = (0, import_path3.join)("environments", entry);
|
|
2770
|
-
return (0, import_fs3.statSync)(fullPath).isDirectory();
|
|
2771
|
-
});
|
|
2772
|
-
if (environments.length === 0) {
|
|
2773
|
-
console.log(
|
|
2774
|
-
"\u26A0\uFE0F Warning: No environment directories found in environments/"
|
|
3040
|
+
if ((0, import_fs7.existsSync)(destinationPath)) {
|
|
3041
|
+
warn(
|
|
3042
|
+
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2775
3043
|
);
|
|
2776
|
-
return
|
|
2777
|
-
}
|
|
2778
|
-
log("\u{1F50D} Found OpenCRVS configurations:", environments.join(", "));
|
|
2779
|
-
return environments;
|
|
2780
|
-
}
|
|
2781
|
-
function updateOptionsInYaml(content, envList) {
|
|
2782
|
-
const optionsRegex = /([ ]*options:[ ]*\n)((?:[ ]*-[^\n]*\n)+)/;
|
|
2783
|
-
const match = content.match(optionsRegex);
|
|
2784
|
-
if (!match) {
|
|
2785
|
-
throw new Error("Could not find options array in workflow file");
|
|
2786
|
-
}
|
|
2787
|
-
const firstItemMatch = match[2].match(/^([ ]*)-/);
|
|
2788
|
-
const itemIndent = firstItemMatch ? firstItemMatch[1] : " ";
|
|
2789
|
-
const newOptions = match[1] + envList.map((env) => `${itemIndent}- ${env}`).join("\n") + "\n";
|
|
2790
|
-
return content.replace(optionsRegex, newOptions);
|
|
2791
|
-
}
|
|
2792
|
-
async function updateWorkflows(envList, config) {
|
|
2793
|
-
const { workflows } = config;
|
|
2794
|
-
for (const workflowPath of workflows) {
|
|
2795
|
-
try {
|
|
2796
|
-
const fileContents = (0, import_fs3.readFileSync)(workflowPath, "utf8");
|
|
2797
|
-
const workflowData = yaml2.load(fileContents);
|
|
2798
|
-
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2799
|
-
throw new Error(
|
|
2800
|
-
"Workflow does not have the expected structure: on.workflow_dispatch.inputs.environment.options"
|
|
2801
|
-
);
|
|
2802
|
-
}
|
|
2803
|
-
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2804
|
-
(0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2805
|
-
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2806
|
-
} catch (error4) {
|
|
2807
|
-
console.error(
|
|
2808
|
-
`
|
|
2809
|
-
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2810
|
-
);
|
|
2811
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
|
|
2812
|
-
throw error4;
|
|
2813
|
-
}
|
|
3044
|
+
return false;
|
|
2814
3045
|
}
|
|
3046
|
+
(0, import_fs7.mkdirSync)((0, import_path7.dirname)(destinationPath), { recursive: true });
|
|
3047
|
+
(0, import_fs7.renameSync)(sourcePath, destinationPath);
|
|
3048
|
+
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
3049
|
+
return true;
|
|
2815
3050
|
}
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
if (
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
".github/workflows/deploy-opencrvs.yml",
|
|
2836
|
-
".github/workflows/clear-all-data.yml",
|
|
2837
|
-
".github/workflows/seed-data.yml",
|
|
2838
|
-
".github/workflows/reindex.yml",
|
|
2839
|
-
".github/workflows/github-to-k8s-sync-env.yml"
|
|
2840
|
-
];
|
|
2841
|
-
log("\u{1F4CB} Updating OpenCRVS application workflows:");
|
|
2842
|
-
await updateWorkflows(environments, {
|
|
2843
|
-
workflows,
|
|
2844
|
-
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2845
|
-
});
|
|
2846
|
-
didUpdateWorkflows = true;
|
|
2847
|
-
}
|
|
2848
|
-
if (didUpdateWorkflows) {
|
|
2849
|
-
success("\u2705 Workflow updates completed successfully!");
|
|
2850
|
-
} else {
|
|
2851
|
-
log("\u2139\uFE0F No workflows were updated.");
|
|
3051
|
+
function migrateInventoryFiles() {
|
|
3052
|
+
const oldInventoryFiles = findOldInventoryFiles();
|
|
3053
|
+
if (oldInventoryFiles.length === 0) {
|
|
3054
|
+
log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
|
|
3055
|
+
return false;
|
|
3056
|
+
}
|
|
3057
|
+
log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
|
|
3058
|
+
let didMoveInventory = false;
|
|
3059
|
+
for (const oldInventoryFile of oldInventoryFiles) {
|
|
3060
|
+
const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
|
|
3061
|
+
didMoveInventory = moveFileIfDestinationMissing(
|
|
3062
|
+
oldInventoryFile,
|
|
3063
|
+
getEnvironmentInventoryPath(environment)
|
|
3064
|
+
) || didMoveInventory;
|
|
3065
|
+
}
|
|
3066
|
+
try {
|
|
3067
|
+
if ((0, import_fs7.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs7.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
3068
|
+
(0, import_fs7.rmdirSync)(OLD_INVENTORY_DIR);
|
|
3069
|
+
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2852
3070
|
}
|
|
2853
|
-
} catch
|
|
2854
|
-
|
|
2855
|
-
process.exit(1);
|
|
3071
|
+
} catch {
|
|
3072
|
+
warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
|
|
2856
3073
|
}
|
|
3074
|
+
return didMoveInventory;
|
|
2857
3075
|
}
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
3076
|
+
async function upgradeEnvironmentLayout() {
|
|
3077
|
+
const didMoveInventory = migrateInventoryFiles();
|
|
3078
|
+
await updateWorkflowEnvironments();
|
|
3079
|
+
if (didMoveInventory) {
|
|
3080
|
+
success("\n\u2705 Environment layout upgrade completed successfully.");
|
|
3081
|
+
} else {
|
|
3082
|
+
success("\n\u2705 Environment layout already uses the current structure.");
|
|
3083
|
+
}
|
|
3084
|
+
log("\nCommit changes into git after upgrade");
|
|
3085
|
+
}
|
|
3086
|
+
var import_fs7, import_path7, import_kleur5;
|
|
3087
|
+
var init_upgrade = __esm({
|
|
3088
|
+
"src/environment/upgrade.ts"() {
|
|
2861
3089
|
"use strict";
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
glob = __toESM(require("glob"));
|
|
2866
|
-
yaml2 = __toESM(require("js-yaml"));
|
|
3090
|
+
import_fs7 = require("fs");
|
|
3091
|
+
import_path7 = require("path");
|
|
3092
|
+
import_kleur5 = __toESM(require("kleur"));
|
|
2867
3093
|
init_logger();
|
|
3094
|
+
init_paths();
|
|
3095
|
+
init_update_workflows();
|
|
2868
3096
|
}
|
|
2869
3097
|
});
|
|
2870
3098
|
|
|
@@ -2877,7 +3105,7 @@ async function select4(options) {
|
|
|
2877
3105
|
const inquirer = await import("@inquirer/prompts");
|
|
2878
3106
|
return inquirer.select(options);
|
|
2879
3107
|
}
|
|
2880
|
-
async function selectInventoryFile(dirPath = "./
|
|
3108
|
+
async function selectInventoryFile(dirPath = "./environments") {
|
|
2881
3109
|
if (!fs4.existsSync(dirPath)) {
|
|
2882
3110
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
2883
3111
|
warn(
|
|
@@ -2885,22 +3113,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2885
3113
|
);
|
|
2886
3114
|
return null;
|
|
2887
3115
|
}
|
|
2888
|
-
const
|
|
2889
|
-
const filePath =
|
|
2890
|
-
|
|
2891
|
-
const ext = path4.extname(file).slice(1).toLowerCase();
|
|
2892
|
-
return isFile && (ext === "yml" || ext === "yaml");
|
|
3116
|
+
const environments = fs4.readdirSync(dirPath).filter((entry) => {
|
|
3117
|
+
const filePath = path6.join(dirPath, entry);
|
|
3118
|
+
return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
|
|
2893
3119
|
}).sort();
|
|
2894
|
-
if (
|
|
3120
|
+
if (environments.length === 0) {
|
|
2895
3121
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
2896
3122
|
warn(
|
|
2897
3123
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
2898
3124
|
);
|
|
2899
3125
|
return null;
|
|
2900
3126
|
}
|
|
2901
|
-
const choices =
|
|
2902
|
-
name:
|
|
2903
|
-
value:
|
|
3127
|
+
const choices = environments.map((environment) => ({
|
|
3128
|
+
name: environment,
|
|
3129
|
+
value: getEnvironmentInventoryPath(environment)
|
|
2904
3130
|
}));
|
|
2905
3131
|
const selectedFile = await select4({
|
|
2906
3132
|
message: "Select environment (inventory file) to load users:",
|
|
@@ -2909,33 +3135,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2909
3135
|
return selectedFile;
|
|
2910
3136
|
}
|
|
2911
3137
|
async function manageEnvironmentUsers() {
|
|
2912
|
-
console.log("\n",
|
|
3138
|
+
console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
|
|
2913
3139
|
const inventory_file = await selectInventoryFile();
|
|
2914
3140
|
if (!inventory_file) {
|
|
2915
3141
|
return;
|
|
2916
3142
|
}
|
|
2917
3143
|
await manageUsers(inventory_file);
|
|
2918
3144
|
}
|
|
2919
|
-
var fs4,
|
|
3145
|
+
var fs4, path6, import_kleur6;
|
|
2920
3146
|
var init_users = __esm({
|
|
2921
3147
|
"src/environment/users.ts"() {
|
|
2922
3148
|
"use strict";
|
|
2923
3149
|
fs4 = __toESM(require("fs"));
|
|
2924
|
-
|
|
2925
|
-
|
|
3150
|
+
path6 = __toESM(require("path"));
|
|
3151
|
+
import_kleur6 = __toESM(require("kleur"));
|
|
2926
3152
|
init_manage_users();
|
|
2927
3153
|
init_logger();
|
|
3154
|
+
init_paths();
|
|
2928
3155
|
}
|
|
2929
3156
|
});
|
|
2930
3157
|
|
|
2931
3158
|
// src/environment/swarm-to-k8s.ts
|
|
2932
3159
|
var swarm_to_k8s_exports = {};
|
|
2933
|
-
var
|
|
3160
|
+
var path7, import_kleur7, import_core2;
|
|
2934
3161
|
var init_swarm_to_k8s = __esm({
|
|
2935
3162
|
"src/environment/swarm-to-k8s.ts"() {
|
|
2936
3163
|
"use strict";
|
|
2937
|
-
|
|
2938
|
-
|
|
3164
|
+
path7 = __toESM(require("path"));
|
|
3165
|
+
import_kleur7 = __toESM(require("kleur"));
|
|
2939
3166
|
init_logger();
|
|
2940
3167
|
init_utils();
|
|
2941
3168
|
init_templates();
|
|
@@ -2944,7 +3171,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2944
3171
|
init_github();
|
|
2945
3172
|
(async () => {
|
|
2946
3173
|
log(
|
|
2947
|
-
|
|
3174
|
+
import_kleur7.default.bold(
|
|
2948
3175
|
"------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
|
|
2949
3176
|
)
|
|
2950
3177
|
);
|
|
@@ -2975,7 +3202,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2975
3202
|
);
|
|
2976
3203
|
process.exit(0);
|
|
2977
3204
|
}
|
|
2978
|
-
log(
|
|
3205
|
+
log(import_kleur7.default.bold().underline("Migration properties:"));
|
|
2979
3206
|
log(` \u2713 Environment: ${environment}`);
|
|
2980
3207
|
const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
|
|
2981
3208
|
if (!old_inventory_path) {
|
|
@@ -2986,7 +3213,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2986
3213
|
);
|
|
2987
3214
|
process.exit(1);
|
|
2988
3215
|
}
|
|
2989
|
-
const ansible_inventory =
|
|
3216
|
+
const ansible_inventory = path7.join(old_inventory_path, environment + ".yml");
|
|
2990
3217
|
const data = readYamlFile(ansible_inventory);
|
|
2991
3218
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
2992
3219
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3005,10 +3232,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3005
3232
|
copyChartsValues(environment, {
|
|
3006
3233
|
env: environment,
|
|
3007
3234
|
environment_type,
|
|
3008
|
-
|
|
3009
|
-
// Hardcode like this blocks us from being generic:
|
|
3010
|
-
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
3011
|
-
two_fa_enabled: environment !== "production" ? false : true,
|
|
3235
|
+
two_fa_enabled: process.env.TWO_FA_ENABLED ? process.env.TWO_FA_ENABLED === "true" : environment_type === "production",
|
|
3012
3236
|
backup_enabled: environment === "production" ? "true" : "false",
|
|
3013
3237
|
restore_enabled: environment === "staging" ? "true" : "false",
|
|
3014
3238
|
restore_environment_name: environment === "staging" ? "production" : "",
|
|
@@ -3110,191 +3334,249 @@ var init_swarm_to_k8s = __esm({
|
|
|
3110
3334
|
}
|
|
3111
3335
|
});
|
|
3112
3336
|
|
|
3113
|
-
// src/migrations/v2.
|
|
3114
|
-
var
|
|
3337
|
+
// src/migrations/v2.2/add-e2e-tests.ts
|
|
3338
|
+
var import_fs3 = require("fs");
|
|
3339
|
+
var import_path3 = __toESM(require("path"));
|
|
3340
|
+
|
|
3341
|
+
// src/migrations/v2.2/template-files.ts
|
|
3342
|
+
var import_fs = require("fs");
|
|
3115
3343
|
var import_path = __toESM(require("path"));
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
var CONDITIONALS_PROPERTY_NAME = "conditionals";
|
|
3121
|
-
var ACTION_TYPE_ENUM_NAME = "ActionType";
|
|
3122
|
-
var REQUEST_CORRECTION_TYPE = "REQUEST_CORRECTION";
|
|
3123
|
-
var CORRECTION_ACTIONS_TO_ADD = [
|
|
3124
|
-
{
|
|
3125
|
-
actionType: "APPROVE_CORRECTION",
|
|
3126
|
-
labelId: "v2.events.correction.approve.label",
|
|
3127
|
-
defaultMessage: "Approve correction",
|
|
3128
|
-
description: "Label for the approve correction action"
|
|
3129
|
-
},
|
|
3130
|
-
{
|
|
3131
|
-
actionType: "REJECT_CORRECTION",
|
|
3132
|
-
labelId: "v2.events.correction.reject.label",
|
|
3133
|
-
defaultMessage: "Reject correction",
|
|
3134
|
-
description: "Label for the reject correction action"
|
|
3135
|
-
}
|
|
3136
|
-
];
|
|
3137
|
-
function isActionOfType(obj, typeName) {
|
|
3138
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
3139
|
-
if (!typeProperty || !import_ts_morph.Node.isPropertyAssignment(typeProperty)) return false;
|
|
3140
|
-
const typeInit = typeProperty.getInitializer();
|
|
3141
|
-
if (!typeInit) return false;
|
|
3142
|
-
if (import_ts_morph.Node.isPropertyAccessExpression(typeInit)) {
|
|
3143
|
-
return typeInit.getExpression().getText() === ACTION_TYPE_ENUM_NAME && typeInit.getName() === typeName;
|
|
3144
|
-
}
|
|
3145
|
-
if (import_ts_morph.Node.isStringLiteral(typeInit)) {
|
|
3146
|
-
return typeInit.getLiteralValue() === typeName;
|
|
3147
|
-
}
|
|
3148
|
-
return false;
|
|
3149
|
-
}
|
|
3150
|
-
function getTypeInitializerStyle(obj) {
|
|
3151
|
-
const typeProperty = obj.getProperty(TYPE_PROPERTY_NAME);
|
|
3152
|
-
if (typeProperty && import_ts_morph.Node.isPropertyAssignment(typeProperty)) {
|
|
3153
|
-
const typeInit = typeProperty.getInitializer();
|
|
3154
|
-
if (typeInit && import_ts_morph.Node.isPropertyAccessExpression(typeInit)) return "enum";
|
|
3155
|
-
}
|
|
3156
|
-
return "string";
|
|
3157
|
-
}
|
|
3158
|
-
function getNonEmptyArrayPropertyText(obj, propName) {
|
|
3159
|
-
const prop = obj.getProperty(propName);
|
|
3160
|
-
if (!prop || !import_ts_morph.Node.isPropertyAssignment(prop)) return void 0;
|
|
3161
|
-
const init = prop.getInitializer();
|
|
3162
|
-
if (!init || !import_ts_morph.Node.isArrayLiteralExpression(init)) return void 0;
|
|
3163
|
-
if (init.getElements().length === 0) return void 0;
|
|
3164
|
-
return init.getText();
|
|
3165
|
-
}
|
|
3166
|
-
function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText) {
|
|
3167
|
-
const typeText = typeStyle === "enum" ? `${ACTION_TYPE_ENUM_NAME}.${spec.actionType}` : `'${spec.actionType}'`;
|
|
3168
|
-
const lines = [
|
|
3169
|
-
`type: ${typeText}`,
|
|
3170
|
-
`label: {
|
|
3171
|
-
id: '${spec.labelId}',
|
|
3172
|
-
defaultMessage: '${spec.defaultMessage}',
|
|
3173
|
-
description: '${spec.description}'
|
|
3174
|
-
}`
|
|
3344
|
+
function findTemplateDir() {
|
|
3345
|
+
const candidates = [
|
|
3346
|
+
import_path.default.resolve(__dirname, "templates", "countryconfig-template"),
|
|
3347
|
+
import_path.default.resolve(__dirname, "../../../../countryconfig-template")
|
|
3175
3348
|
];
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
if (
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
}
|
|
3186
|
-
function
|
|
3187
|
-
const
|
|
3188
|
-
if (!
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3349
|
+
const templateDir = candidates.find(
|
|
3350
|
+
(candidate) => (0, import_fs.existsSync)(import_path.default.join(candidate, "Tiltfile"))
|
|
3351
|
+
);
|
|
3352
|
+
if (!templateDir) {
|
|
3353
|
+
throw new Error(
|
|
3354
|
+
`Country config template files not found in any of: ${candidates.join(", ")}`
|
|
3355
|
+
);
|
|
3356
|
+
}
|
|
3357
|
+
return templateDir;
|
|
3358
|
+
}
|
|
3359
|
+
function listFiles(root, dir) {
|
|
3360
|
+
const absolute = import_path.default.join(root, dir);
|
|
3361
|
+
if (!(0, import_fs.existsSync)(absolute)) {
|
|
3362
|
+
return [];
|
|
3363
|
+
}
|
|
3364
|
+
return (0, import_fs.readdirSync)(absolute, { withFileTypes: true }).flatMap((entry) => {
|
|
3365
|
+
const relative = import_path.default.posix.join(dir, entry.name);
|
|
3366
|
+
return entry.isDirectory() ? listFiles(root, relative) : [relative];
|
|
3367
|
+
});
|
|
3368
|
+
}
|
|
3369
|
+
|
|
3370
|
+
// src/migrations/v2.2/upgrade-tilt.ts
|
|
3371
|
+
var import_fs2 = require("fs");
|
|
3372
|
+
var import_path2 = __toESM(require("path"));
|
|
3373
|
+
var COUNTRY_OWNED_DIR = "tilt/helm/";
|
|
3374
|
+
var CHARTS_CHECKOUT_DIR = ".opencrvs-core-charts";
|
|
3375
|
+
var IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
|
|
3376
|
+
function writeIfChanged(cwd, relativePath, contents, mode) {
|
|
3377
|
+
const target = import_path2.default.join(cwd, relativePath);
|
|
3378
|
+
const existed = (0, import_fs2.existsSync)(target);
|
|
3379
|
+
if (existed && (0, import_fs2.readFileSync)(target, "utf8") === contents) {
|
|
3380
|
+
return "unchanged";
|
|
3381
|
+
}
|
|
3382
|
+
(0, import_fs2.mkdirSync)(import_path2.default.dirname(target), { recursive: true });
|
|
3383
|
+
(0, import_fs2.writeFileSync)(target, contents);
|
|
3384
|
+
if (mode !== void 0) {
|
|
3385
|
+
(0, import_fs2.chmodSync)(target, mode & 511);
|
|
3386
|
+
}
|
|
3387
|
+
return existed ? "updated" : "created";
|
|
3388
|
+
}
|
|
3389
|
+
function report(relativePath, change) {
|
|
3390
|
+
if (change !== "unchanged") {
|
|
3391
|
+
console.log(` \u2713 ${change} ${relativePath}`);
|
|
3392
|
+
}
|
|
3393
|
+
}
|
|
3394
|
+
function renderTiltfile(template, existing) {
|
|
3395
|
+
const imageName = existing?.match(IMAGE_NAME_PATTERN)?.[2];
|
|
3396
|
+
if (!imageName) {
|
|
3397
|
+
return template;
|
|
3398
|
+
}
|
|
3399
|
+
return template.replace(
|
|
3400
|
+
IMAGE_NAME_PATTERN,
|
|
3401
|
+
(_line, quote) => `countryconfig_image_name=${quote}${imageName}${quote}`
|
|
3193
3402
|
);
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3403
|
+
}
|
|
3404
|
+
function withIgnoreEntry(contents, line2) {
|
|
3405
|
+
const normalise = (entry) => entry.trim().replace(/^\//, "").replace(/\/$/, "");
|
|
3406
|
+
const alreadyIgnored = contents.split(/\r?\n/).some((entry) => normalise(entry) === normalise(line2));
|
|
3407
|
+
if (alreadyIgnored) {
|
|
3408
|
+
return contents;
|
|
3409
|
+
}
|
|
3410
|
+
const separator = contents === "" || contents.endsWith("\n") ? "" : "\n";
|
|
3411
|
+
return `${contents}${separator}${line2}
|
|
3412
|
+
`;
|
|
3413
|
+
}
|
|
3414
|
+
function ensureIgnored(cwd, file, line2) {
|
|
3415
|
+
const target = import_path2.default.join(cwd, file);
|
|
3416
|
+
const contents = (0, import_fs2.existsSync)(target) ? (0, import_fs2.readFileSync)(target, "utf8") : "";
|
|
3417
|
+
report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line2)));
|
|
3418
|
+
}
|
|
3419
|
+
function upgradeTilt(cwd, templateDir) {
|
|
3420
|
+
const tiltfilePath = import_path2.default.join(cwd, "Tiltfile");
|
|
3421
|
+
const existingTiltfile = (0, import_fs2.existsSync)(tiltfilePath) ? (0, import_fs2.readFileSync)(tiltfilePath, "utf8") : void 0;
|
|
3422
|
+
report(
|
|
3423
|
+
"Tiltfile",
|
|
3424
|
+
writeIfChanged(
|
|
3425
|
+
cwd,
|
|
3426
|
+
"Tiltfile",
|
|
3427
|
+
renderTiltfile(
|
|
3428
|
+
(0, import_fs2.readFileSync)(import_path2.default.join(templateDir, "Tiltfile"), "utf8"),
|
|
3429
|
+
existingTiltfile
|
|
3430
|
+
)
|
|
3431
|
+
)
|
|
3432
|
+
);
|
|
3433
|
+
const templateFiles = listFiles(templateDir, "tilt");
|
|
3434
|
+
for (const file of templateFiles) {
|
|
3435
|
+
const source = import_path2.default.join(templateDir, file);
|
|
3436
|
+
const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
|
|
3437
|
+
if (countryOwned && (0, import_fs2.existsSync)(import_path2.default.join(cwd, file))) {
|
|
3197
3438
|
continue;
|
|
3198
3439
|
}
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
|
|
3208
|
-
continue;
|
|
3209
|
-
const elements = actionsInitializer.getElements();
|
|
3210
|
-
const requestCorrectionIndex = elements.findIndex(
|
|
3211
|
-
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, REQUEST_CORRECTION_TYPE)
|
|
3440
|
+
report(
|
|
3441
|
+
file,
|
|
3442
|
+
writeIfChanged(
|
|
3443
|
+
cwd,
|
|
3444
|
+
file,
|
|
3445
|
+
(0, import_fs2.readFileSync)(source, "utf8"),
|
|
3446
|
+
(0, import_fs2.statSync)(source).mode
|
|
3447
|
+
)
|
|
3212
3448
|
);
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3449
|
+
}
|
|
3450
|
+
const unknownFiles = listFiles(cwd, "tilt").filter(
|
|
3451
|
+
(file) => !file.startsWith(COUNTRY_OWNED_DIR) && !templateFiles.includes(file)
|
|
3452
|
+
);
|
|
3453
|
+
for (const file of unknownFiles) {
|
|
3454
|
+
console.warn(
|
|
3455
|
+
` \u26A0\uFE0F ${file} is not part of the template and was left in place.`
|
|
3218
3456
|
);
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3457
|
+
}
|
|
3458
|
+
ensureIgnored(cwd, ".tiltignore", `${CHARTS_CHECKOUT_DIR}/`);
|
|
3459
|
+
ensureIgnored(cwd, ".gitignore", CHARTS_CHECKOUT_DIR);
|
|
3460
|
+
if (existingTiltfile?.includes("opencrvs-helm-charts")) {
|
|
3461
|
+
console.log(
|
|
3462
|
+
` \u2139\uFE0F The Tiltfile no longer uses ../opencrvs-helm-charts; charts are cloned into ${CHARTS_CHECKOUT_DIR}/ instead. The old checkout can be deleted.`
|
|
3222
3463
|
);
|
|
3223
|
-
if (!flagsText && !conditionalsText) continue;
|
|
3224
|
-
const typeStyle = getTypeInitializerStyle(requestCorrection);
|
|
3225
|
-
let insertAt = requestCorrectionIndex + 1;
|
|
3226
|
-
for (const spec of CORRECTION_ACTIONS_TO_ADD) {
|
|
3227
|
-
const alreadyPresent = actionsInitializer.getElements().some(
|
|
3228
|
-
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, spec.actionType)
|
|
3229
|
-
);
|
|
3230
|
-
if (alreadyPresent) continue;
|
|
3231
|
-
const text = buildCorrectionActionText(
|
|
3232
|
-
spec,
|
|
3233
|
-
typeStyle,
|
|
3234
|
-
flagsText,
|
|
3235
|
-
conditionalsText
|
|
3236
|
-
);
|
|
3237
|
-
actionsInitializer.insertElement(insertAt, text);
|
|
3238
|
-
insertAt++;
|
|
3239
|
-
changes++;
|
|
3240
|
-
console.log(
|
|
3241
|
-
` [${relPath}] Added ${spec.actionType} action carrying over REQUEST_CORRECTION's flags/conditionals`
|
|
3242
|
-
);
|
|
3243
|
-
}
|
|
3244
3464
|
}
|
|
3245
|
-
return changes;
|
|
3246
3465
|
}
|
|
3247
3466
|
async function main() {
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3467
|
+
console.log("Upgrading the local Tilt setup...\n");
|
|
3468
|
+
upgradeTilt(process.cwd(), findTemplateDir());
|
|
3469
|
+
console.log(
|
|
3470
|
+
"\n Review local customisations with: git diff -- Tiltfile tilt/ .tiltignore .gitignore\n"
|
|
3471
|
+
);
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
// src/migrations/v2.2/add-e2e-tests.ts
|
|
3475
|
+
var E2E_DIR = "e2e";
|
|
3476
|
+
var PLAYWRIGHT_CONFIG = "playwright.config.ts";
|
|
3477
|
+
var PLAYWRIGHT_PACKAGE = "@playwright/test";
|
|
3478
|
+
var E2E_SCRIPTS = ["e2e", "e2e:ui", "e2e:dev"];
|
|
3479
|
+
var IGNORED_PATHS = ["playwright-report", "test-results"];
|
|
3480
|
+
var TEST_DIR_PATTERN = /testDir\s*:\s*(["'`])(.*?)\1/;
|
|
3481
|
+
function copyFile(templateDir, cwd, file) {
|
|
3482
|
+
const target = import_path3.default.join(cwd, file);
|
|
3483
|
+
(0, import_fs3.mkdirSync)(import_path3.default.dirname(target), { recursive: true });
|
|
3484
|
+
(0, import_fs3.writeFileSync)(target, (0, import_fs3.readFileSync)(import_path3.default.join(templateDir, file), "utf8"));
|
|
3485
|
+
}
|
|
3486
|
+
function pointsIntoE2EDir(config) {
|
|
3487
|
+
const testDir = config.match(TEST_DIR_PATTERN)?.[2];
|
|
3488
|
+
if (testDir === void 0) {
|
|
3489
|
+
return false;
|
|
3490
|
+
}
|
|
3491
|
+
return import_path3.default.posix.normalize(testDir).split("/")[0] === E2E_DIR;
|
|
3492
|
+
}
|
|
3493
|
+
function withE2EPackageEntries(packageJson, templatePackageJson) {
|
|
3494
|
+
const scripts = { ...packageJson.scripts };
|
|
3495
|
+
for (const script of E2E_SCRIPTS) {
|
|
3496
|
+
const templateScript = templatePackageJson.scripts?.[script];
|
|
3497
|
+
if (templateScript && !scripts[script]) {
|
|
3498
|
+
scripts[script] = templateScript;
|
|
3269
3499
|
}
|
|
3270
3500
|
}
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3501
|
+
const hasPlaywright = !!packageJson.dependencies?.[PLAYWRIGHT_PACKAGE] || !!packageJson.devDependencies?.[PLAYWRIGHT_PACKAGE];
|
|
3502
|
+
const playwrightVersion = templatePackageJson.devDependencies?.[PLAYWRIGHT_PACKAGE];
|
|
3503
|
+
return {
|
|
3504
|
+
...packageJson,
|
|
3505
|
+
scripts,
|
|
3506
|
+
...hasPlaywright || !playwrightVersion ? {} : {
|
|
3507
|
+
devDependencies: {
|
|
3508
|
+
...packageJson.devDependencies,
|
|
3509
|
+
[PLAYWRIGHT_PACKAGE]: playwrightVersion
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
function addE2ETests(cwd, templateDir) {
|
|
3515
|
+
if ((0, import_fs3.existsSync)(import_path3.default.join(cwd, E2E_DIR))) {
|
|
3516
|
+
console.log(` \u21B7 ${E2E_DIR}/ already exists, leaving it as is`);
|
|
3517
|
+
return false;
|
|
3518
|
+
}
|
|
3519
|
+
for (const file of listFiles(templateDir, E2E_DIR)) {
|
|
3520
|
+
copyFile(templateDir, cwd, file);
|
|
3521
|
+
console.log(` \u2713 created ${file}`);
|
|
3522
|
+
}
|
|
3523
|
+
const configPath = import_path3.default.join(cwd, PLAYWRIGHT_CONFIG);
|
|
3524
|
+
if (!(0, import_fs3.existsSync)(configPath)) {
|
|
3525
|
+
copyFile(templateDir, cwd, PLAYWRIGHT_CONFIG);
|
|
3526
|
+
console.log(` \u2713 created ${PLAYWRIGHT_CONFIG}`);
|
|
3527
|
+
} else if (pointsIntoE2EDir((0, import_fs3.readFileSync)(configPath, "utf8"))) {
|
|
3528
|
+
copyFile(templateDir, cwd, PLAYWRIGHT_CONFIG);
|
|
3529
|
+
console.log(` \u2713 updated ${PLAYWRIGHT_CONFIG}`);
|
|
3530
|
+
} else {
|
|
3531
|
+
console.warn(
|
|
3532
|
+
` \u26A0\uFE0F ${PLAYWRIGHT_CONFIG} does not run tests from ${E2E_DIR}/ and was left in place. Point its testDir to './${E2E_DIR}' and testMatch to '**/*.e2e.ts' to run the sample tests.`
|
|
3274
3533
|
);
|
|
3275
|
-
return;
|
|
3276
3534
|
}
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
const
|
|
3281
|
-
|
|
3282
|
-
|
|
3535
|
+
const packageJsonPath = import_path3.default.join(cwd, "package.json");
|
|
3536
|
+
if ((0, import_fs3.existsSync)(packageJsonPath)) {
|
|
3537
|
+
const contents = (0, import_fs3.readFileSync)(packageJsonPath, "utf8");
|
|
3538
|
+
const updated = withE2EPackageEntries(
|
|
3539
|
+
JSON.parse(contents),
|
|
3540
|
+
JSON.parse((0, import_fs3.readFileSync)(import_path3.default.join(templateDir, "package.json"), "utf8"))
|
|
3541
|
+
);
|
|
3542
|
+
const trailingNewline = contents.endsWith("\n") ? "\n" : "";
|
|
3543
|
+
const serialised = `${JSON.stringify(updated, null, 2)}${trailingNewline}`;
|
|
3544
|
+
if (serialised !== contents) {
|
|
3545
|
+
(0, import_fs3.writeFileSync)(packageJsonPath, serialised);
|
|
3546
|
+
console.log(" \u2713 updated package.json");
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
const gitignorePath = import_path3.default.join(cwd, ".gitignore");
|
|
3550
|
+
const gitignore = (0, import_fs3.existsSync)(gitignorePath) ? (0, import_fs3.readFileSync)(gitignorePath, "utf8") : "";
|
|
3551
|
+
const updatedGitignore = IGNORED_PATHS.reduce(withIgnoreEntry, gitignore);
|
|
3552
|
+
if (updatedGitignore !== gitignore) {
|
|
3553
|
+
(0, import_fs3.writeFileSync)(gitignorePath, updatedGitignore);
|
|
3554
|
+
console.log(" \u2713 updated .gitignore");
|
|
3555
|
+
}
|
|
3556
|
+
return true;
|
|
3557
|
+
}
|
|
3558
|
+
async function main2() {
|
|
3559
|
+
console.log("Adding sample e2e tests...\n");
|
|
3560
|
+
const added = addE2ETests(process.cwd(), findTemplateDir());
|
|
3561
|
+
if (added) {
|
|
3562
|
+
console.log(
|
|
3563
|
+
`
|
|
3564
|
+
Install dependencies to add ${PLAYWRIGHT_PACKAGE} to your lockfile, then run the tests with: npx playwright test
|
|
3565
|
+
`
|
|
3566
|
+
);
|
|
3283
3567
|
}
|
|
3284
|
-
console.log(
|
|
3285
|
-
`
|
|
3286
|
-
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
3287
|
-
);
|
|
3288
3568
|
}
|
|
3289
3569
|
|
|
3290
|
-
// src/migrations/v2.
|
|
3291
|
-
async function runUpgrade(
|
|
3570
|
+
// src/migrations/v2.2/index.ts
|
|
3571
|
+
async function runUpgrade() {
|
|
3292
3572
|
await main();
|
|
3573
|
+
await main2();
|
|
3293
3574
|
}
|
|
3294
3575
|
|
|
3295
3576
|
// src/environment/index.ts
|
|
3296
|
-
var
|
|
3297
|
-
var
|
|
3577
|
+
var import_fs8 = require("fs");
|
|
3578
|
+
var import_path8 = require("path");
|
|
3579
|
+
init_paths();
|
|
3298
3580
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
3299
3581
|
".github/workflows",
|
|
3300
3582
|
"environments",
|
|
@@ -3304,7 +3586,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3304
3586
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
3305
3587
|
(directory) => {
|
|
3306
3588
|
try {
|
|
3307
|
-
return !(0,
|
|
3589
|
+
return !(0, import_fs8.statSync)((0, import_path8.resolve)(repositoryRoot, directory)).isDirectory();
|
|
3308
3590
|
} catch {
|
|
3309
3591
|
return true;
|
|
3310
3592
|
}
|
|
@@ -3318,7 +3600,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3318
3600
|
}
|
|
3319
3601
|
async function runEnvironmentInit() {
|
|
3320
3602
|
validateRepositoryStructure();
|
|
3321
|
-
|
|
3603
|
+
assertNoOldInventoryLayout();
|
|
3604
|
+
const { runSetupEnvironment: runSetupEnvironment2 } = await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
3605
|
+
await runSetupEnvironment2();
|
|
3606
|
+
}
|
|
3607
|
+
async function runEnvironmentUpgrade() {
|
|
3608
|
+
validateRepositoryStructure();
|
|
3609
|
+
const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
3610
|
+
await upgradeEnvironmentLayout2();
|
|
3322
3611
|
}
|
|
3323
3612
|
async function runEnvironmentUpdateWorkflows() {
|
|
3324
3613
|
validateRepositoryStructure();
|
|
@@ -3335,6 +3624,473 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
3335
3624
|
await Promise.resolve().then(() => (init_swarm_to_k8s(), swarm_to_k8s_exports));
|
|
3336
3625
|
}
|
|
3337
3626
|
|
|
3627
|
+
// src/verify/endpoints.ts
|
|
3628
|
+
var import_colors = require("kleur/colors");
|
|
3629
|
+
var z = __toESM(require("zod/v4"));
|
|
3630
|
+
|
|
3631
|
+
// src/csv.ts
|
|
3632
|
+
function parseCsvLine(line2) {
|
|
3633
|
+
const values = [];
|
|
3634
|
+
let value = "";
|
|
3635
|
+
let quoted = false;
|
|
3636
|
+
for (let index = 0; index < line2.length; index++) {
|
|
3637
|
+
const character = line2[index];
|
|
3638
|
+
if (quoted) {
|
|
3639
|
+
if (character !== '"') {
|
|
3640
|
+
value += character;
|
|
3641
|
+
} else if (line2[index + 1] === '"') {
|
|
3642
|
+
value += '"';
|
|
3643
|
+
index++;
|
|
3644
|
+
} else {
|
|
3645
|
+
quoted = false;
|
|
3646
|
+
}
|
|
3647
|
+
continue;
|
|
3648
|
+
}
|
|
3649
|
+
if (character === '"') {
|
|
3650
|
+
quoted = true;
|
|
3651
|
+
} else if (character === ",") {
|
|
3652
|
+
values.push(value);
|
|
3653
|
+
value = "";
|
|
3654
|
+
} else {
|
|
3655
|
+
value += character;
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
values.push(value);
|
|
3659
|
+
return values;
|
|
3660
|
+
}
|
|
3661
|
+
function idOf(line2) {
|
|
3662
|
+
const comma = line2.indexOf(",");
|
|
3663
|
+
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3664
|
+
}
|
|
3665
|
+
|
|
3666
|
+
// src/translations/template.ts
|
|
3667
|
+
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3668
|
+
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3669
|
+
async function matchingRefs(namespace, prefix) {
|
|
3670
|
+
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3671
|
+
const response = await fetch(url, {
|
|
3672
|
+
headers: { accept: "application/vnd.github+json" }
|
|
3673
|
+
});
|
|
3674
|
+
if (!response.ok) {
|
|
3675
|
+
throw new Error(
|
|
3676
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3677
|
+
);
|
|
3678
|
+
}
|
|
3679
|
+
const refs = await response.json();
|
|
3680
|
+
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3681
|
+
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3682
|
+
}
|
|
3683
|
+
async function candidateRefs(version) {
|
|
3684
|
+
return [
|
|
3685
|
+
...await matchingRefs("heads", `release/${version}.`),
|
|
3686
|
+
...await matchingRefs("tags", `v${version}.`),
|
|
3687
|
+
"develop"
|
|
3688
|
+
];
|
|
3689
|
+
}
|
|
3690
|
+
async function fetchTemplate(refs, application) {
|
|
3691
|
+
for (const ref of refs) {
|
|
3692
|
+
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
3693
|
+
const response = await fetch(url);
|
|
3694
|
+
if (response.ok) {
|
|
3695
|
+
return { ref, contents: await response.text() };
|
|
3696
|
+
}
|
|
3697
|
+
if (response.status !== 404) {
|
|
3698
|
+
throw new Error(
|
|
3699
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3700
|
+
);
|
|
3701
|
+
}
|
|
3702
|
+
}
|
|
3703
|
+
return void 0;
|
|
3704
|
+
}
|
|
3705
|
+
|
|
3706
|
+
// src/verify/endpoints.ts
|
|
3707
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
3708
|
+
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
3709
|
+
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
3710
|
+
{ method: "GET", path: "/client-config.js" },
|
|
3711
|
+
{ method: "GET", path: "/login-config.js" },
|
|
3712
|
+
{ method: "GET", path: "/handlebars.js" },
|
|
3713
|
+
{ method: "GET", path: "/content/client" },
|
|
3714
|
+
{ method: "GET", path: "/content/login" },
|
|
3715
|
+
{ method: "GET", path: "/content/map.geojson" },
|
|
3716
|
+
{ method: "GET", path: "/content/country-logo" },
|
|
3717
|
+
{ method: "GET", path: "/config/application" },
|
|
3718
|
+
{ method: "GET", path: "/config/workqueues" },
|
|
3719
|
+
{ method: "GET", path: "/config/locations" },
|
|
3720
|
+
{ method: "GET", path: "/config/roles" },
|
|
3721
|
+
{ method: "GET", path: "/config/events" }
|
|
3722
|
+
];
|
|
3723
|
+
var PROBE_SEGMENT = "verify-endpoints-probe";
|
|
3724
|
+
var SECURED_TRIGGER_USER_EVENTS = [
|
|
3725
|
+
"user-created",
|
|
3726
|
+
"user-updated",
|
|
3727
|
+
"username-reminder",
|
|
3728
|
+
"reset-password",
|
|
3729
|
+
"reset-password-by-admin",
|
|
3730
|
+
"password-reset-link",
|
|
3731
|
+
"username-reminder-link",
|
|
3732
|
+
"resend-invite",
|
|
3733
|
+
"2fa",
|
|
3734
|
+
"all-user-notification",
|
|
3735
|
+
"change-phone-number",
|
|
3736
|
+
"change-email-address"
|
|
3737
|
+
];
|
|
3738
|
+
var SECURED_ENDPOINTS = [
|
|
3739
|
+
...SECURED_TRIGGER_USER_EVENTS.map(
|
|
3740
|
+
(event) => ({
|
|
3741
|
+
method: "POST",
|
|
3742
|
+
path: `/trigger/user/${event}`
|
|
3743
|
+
})
|
|
3744
|
+
),
|
|
3745
|
+
{ method: "POST", path: "/trigger/telemetry" },
|
|
3746
|
+
{ method: "GET", path: "/trigger/system/ready" },
|
|
3747
|
+
{
|
|
3748
|
+
method: "GET",
|
|
3749
|
+
path: `/certificates/${PROBE_SEGMENT}`,
|
|
3750
|
+
label: "/certificates/{id}"
|
|
3751
|
+
},
|
|
3752
|
+
{ method: "GET", path: "/certificates" },
|
|
3753
|
+
{ method: "GET", path: "/config/users" }
|
|
3754
|
+
];
|
|
3755
|
+
var FALLBACK_EVENT_TRIGGERS = [
|
|
3756
|
+
{
|
|
3757
|
+
method: "POST",
|
|
3758
|
+
path: `/trigger/events/${PROBE_SEGMENT}/actions/${PROBE_SEGMENT}`,
|
|
3759
|
+
label: "/trigger/events/{event}/actions/{action}"
|
|
3760
|
+
},
|
|
3761
|
+
{
|
|
3762
|
+
method: "POST",
|
|
3763
|
+
path: `/trigger/events/birth/actions/${PROBE_SEGMENT}`,
|
|
3764
|
+
label: "/trigger/events/birth/actions/{action}"
|
|
3765
|
+
},
|
|
3766
|
+
{
|
|
3767
|
+
method: "POST",
|
|
3768
|
+
path: `/trigger/events/death/actions/${PROBE_SEGMENT}`,
|
|
3769
|
+
label: "/trigger/events/death/actions/{action}"
|
|
3770
|
+
}
|
|
3771
|
+
];
|
|
3772
|
+
var isSuccess = (status) => status !== "error" && status >= 200 && status < 300;
|
|
3773
|
+
var requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
|
|
3774
|
+
async function requestStatus(url, method) {
|
|
3775
|
+
try {
|
|
3776
|
+
const response = await fetch(url, {
|
|
3777
|
+
method,
|
|
3778
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
3779
|
+
// Sent without an Authorization header on purpose. A secured route
|
|
3780
|
+
// rejects with 401/403 before ever reading the body.
|
|
3781
|
+
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
3782
|
+
body: method === "POST" ? "{}" : void 0
|
|
3783
|
+
});
|
|
3784
|
+
return response.status;
|
|
3785
|
+
} catch {
|
|
3786
|
+
return "error";
|
|
3787
|
+
}
|
|
3788
|
+
}
|
|
3789
|
+
function toEventTriggerConfig(value) {
|
|
3790
|
+
if (typeof value !== "object" || value === null) {
|
|
3791
|
+
return null;
|
|
3792
|
+
}
|
|
3793
|
+
const record2 = value;
|
|
3794
|
+
if (typeof record2.id !== "string") {
|
|
3795
|
+
return null;
|
|
3796
|
+
}
|
|
3797
|
+
const actions = Array.isArray(record2.actions) ? Array.from(
|
|
3798
|
+
new Set(
|
|
3799
|
+
record2.actions.map((action) => {
|
|
3800
|
+
if (typeof action !== "object" || action === null) {
|
|
3801
|
+
return null;
|
|
3802
|
+
}
|
|
3803
|
+
const type = action.type;
|
|
3804
|
+
return typeof type === "string" ? type : null;
|
|
3805
|
+
}).filter((type) => type !== null)
|
|
3806
|
+
)
|
|
3807
|
+
) : [];
|
|
3808
|
+
return { id: record2.id, actions };
|
|
3809
|
+
}
|
|
3810
|
+
async function fetchEventConfigs(baseUrl) {
|
|
3811
|
+
try {
|
|
3812
|
+
const response = await fetch(`${baseUrl}/config/events`, {
|
|
3813
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
3814
|
+
});
|
|
3815
|
+
if (!response.ok) {
|
|
3816
|
+
return null;
|
|
3817
|
+
}
|
|
3818
|
+
const body = await response.json();
|
|
3819
|
+
if (!Array.isArray(body)) {
|
|
3820
|
+
return null;
|
|
3821
|
+
}
|
|
3822
|
+
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
3823
|
+
} catch {
|
|
3824
|
+
return null;
|
|
3825
|
+
}
|
|
3826
|
+
}
|
|
3827
|
+
function resolveBaseUrl(input4) {
|
|
3828
|
+
const withProtocol = /^https?:\/\//i.test(input4) ? input4 : `https://${input4}`;
|
|
3829
|
+
return withProtocol.replace(/\/+$/, "");
|
|
3830
|
+
}
|
|
3831
|
+
function describeStatus(status) {
|
|
3832
|
+
return status === "error" ? "no response" : `HTTP ${status}`;
|
|
3833
|
+
}
|
|
3834
|
+
function endpointLabel(check) {
|
|
3835
|
+
const shown = check.label ?? check.path;
|
|
3836
|
+
const suffix = check.label ? (0, import_colors.dim)(` \u2192 ${check.path}`) : "";
|
|
3837
|
+
return `${check.method} ${shown}${suffix}`;
|
|
3838
|
+
}
|
|
3839
|
+
function line(ok, label, detail) {
|
|
3840
|
+
const mark = ok ? (0, import_colors.green)("\u2713") : (0, import_colors.red)("\u2717");
|
|
3841
|
+
return ` ${mark} ${label} ${(0, import_colors.dim)(`(${detail})`)}`;
|
|
3842
|
+
}
|
|
3843
|
+
function securedDetail(status) {
|
|
3844
|
+
if (status === 401 || status === 403) {
|
|
3845
|
+
return `${describeStatus(status)} \u2014 auth required`;
|
|
3846
|
+
}
|
|
3847
|
+
if (status === 404) {
|
|
3848
|
+
return `${describeStatus(status)} \u2014 not implemented`;
|
|
3849
|
+
}
|
|
3850
|
+
if (status === "error") {
|
|
3851
|
+
return `${describeStatus(status)} \u2014 request failed`;
|
|
3852
|
+
}
|
|
3853
|
+
return `${describeStatus(status)} \u2014 INSECURE: ensure this endpoint requires authentication!`;
|
|
3854
|
+
}
|
|
3855
|
+
var TEMPLATE_VERSION = "2.1";
|
|
3856
|
+
var TRANSLATED_APPLICATIONS = ["client", "login"];
|
|
3857
|
+
function readTemplateTranslations(contents) {
|
|
3858
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3859
|
+
return {
|
|
3860
|
+
ids: lines.slice(1).filter((line2) => line2 !== "").map(idOf),
|
|
3861
|
+
languages: parseCsvLine(lines[0]).filter(
|
|
3862
|
+
(column) => column !== "id" && column !== "description"
|
|
3863
|
+
)
|
|
3864
|
+
};
|
|
3865
|
+
}
|
|
3866
|
+
var ServedTranslations = z.object({
|
|
3867
|
+
languages: z.array(
|
|
3868
|
+
z.object({
|
|
3869
|
+
lang: z.string(),
|
|
3870
|
+
messages: z.record(z.string(), z.string())
|
|
3871
|
+
})
|
|
3872
|
+
)
|
|
3873
|
+
});
|
|
3874
|
+
async function fetchServedTranslations(baseUrl, application) {
|
|
3875
|
+
try {
|
|
3876
|
+
const response = await fetch(`${baseUrl}/content/${application}`, {
|
|
3877
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
3878
|
+
});
|
|
3879
|
+
if (!response.ok) {
|
|
3880
|
+
return null;
|
|
3881
|
+
}
|
|
3882
|
+
const parsed = ServedTranslations.safeParse(await response.json());
|
|
3883
|
+
return parsed.success ? parsed.data.languages : null;
|
|
3884
|
+
} catch {
|
|
3885
|
+
return null;
|
|
3886
|
+
}
|
|
3887
|
+
}
|
|
3888
|
+
var MISSING_IDS_SHOWN = 10;
|
|
3889
|
+
async function verifyTranslations(baseUrl) {
|
|
3890
|
+
let refs;
|
|
3891
|
+
try {
|
|
3892
|
+
refs = await candidateRefs(TEMPLATE_VERSION);
|
|
3893
|
+
} catch (error3) {
|
|
3894
|
+
console.log(
|
|
3895
|
+
" " + (0, import_colors.yellow)(
|
|
3896
|
+
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${error3.message}); translations not checked.`
|
|
3897
|
+
)
|
|
3898
|
+
);
|
|
3899
|
+
return 0;
|
|
3900
|
+
}
|
|
3901
|
+
let failures = 0;
|
|
3902
|
+
for (const application of TRANSLATED_APPLICATIONS) {
|
|
3903
|
+
const endpoint = `GET /content/${application}`;
|
|
3904
|
+
let fetched;
|
|
3905
|
+
try {
|
|
3906
|
+
fetched = await fetchTemplate(refs, application);
|
|
3907
|
+
} catch (error3) {
|
|
3908
|
+
console.log(
|
|
3909
|
+
" " + (0, import_colors.yellow)(
|
|
3910
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${endpoint} not checked.`
|
|
3911
|
+
)
|
|
3912
|
+
);
|
|
3913
|
+
continue;
|
|
3914
|
+
}
|
|
3915
|
+
if (!fetched) {
|
|
3916
|
+
console.log(
|
|
3917
|
+
" " + (0, import_colors.yellow)(
|
|
3918
|
+
`No ${application}.csv in the ${TEMPLATE_VERSION} country config template on GitHub; ${endpoint} not checked.`
|
|
3919
|
+
)
|
|
3920
|
+
);
|
|
3921
|
+
continue;
|
|
3922
|
+
}
|
|
3923
|
+
const template = readTemplateTranslations(fetched.contents);
|
|
3924
|
+
const served = await fetchServedTranslations(baseUrl, application);
|
|
3925
|
+
if (!served) {
|
|
3926
|
+
console.log(
|
|
3927
|
+
" " + (0, import_colors.yellow)(`Could not read ${endpoint}; translations not checked.`)
|
|
3928
|
+
);
|
|
3929
|
+
continue;
|
|
3930
|
+
}
|
|
3931
|
+
const servedIds = new Set(
|
|
3932
|
+
served.flatMap(({ messages }) => Object.keys(messages))
|
|
3933
|
+
);
|
|
3934
|
+
const missing = template.ids.filter((id) => !servedIds.has(id));
|
|
3935
|
+
const servedLanguages = new Set(served.map(({ lang }) => lang));
|
|
3936
|
+
const absentLanguages = template.languages.filter(
|
|
3937
|
+
(lang) => !servedLanguages.has(lang)
|
|
3938
|
+
);
|
|
3939
|
+
if (missing.length === 0) {
|
|
3940
|
+
console.log(
|
|
3941
|
+
line(
|
|
3942
|
+
true,
|
|
3943
|
+
endpoint,
|
|
3944
|
+
`all ${template.ids.length} id(s) from the ${fetched.ref} template served`
|
|
3945
|
+
)
|
|
3946
|
+
);
|
|
3947
|
+
} else {
|
|
3948
|
+
failures++;
|
|
3949
|
+
console.log(
|
|
3950
|
+
line(
|
|
3951
|
+
false,
|
|
3952
|
+
endpoint,
|
|
3953
|
+
`${missing.length} of ${template.ids.length} id(s) from the ${fetched.ref} template not served`
|
|
3954
|
+
)
|
|
3955
|
+
);
|
|
3956
|
+
for (const id of missing.slice(0, MISSING_IDS_SHOWN)) {
|
|
3957
|
+
console.log(` ${(0, import_colors.dim)(id)}`);
|
|
3958
|
+
}
|
|
3959
|
+
if (missing.length > MISSING_IDS_SHOWN) {
|
|
3960
|
+
console.log(
|
|
3961
|
+
` ${(0, import_colors.dim)(`\u2026 and ${missing.length - MISSING_IDS_SHOWN} more`)}`
|
|
3962
|
+
);
|
|
3963
|
+
}
|
|
3964
|
+
}
|
|
3965
|
+
if (absentLanguages.length > 0) {
|
|
3966
|
+
console.log(
|
|
3967
|
+
" " + (0, import_colors.yellow)(
|
|
3968
|
+
`${application}: the template carries ${absentLanguages.join(
|
|
3969
|
+
", "
|
|
3970
|
+
)}, which this country config does not serve.`
|
|
3971
|
+
)
|
|
3972
|
+
);
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
return failures;
|
|
3976
|
+
}
|
|
3977
|
+
async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
3978
|
+
const baseUrl = resolveBaseUrl(target);
|
|
3979
|
+
console.log((0, import_colors.bold)(`Verifying country config endpoints at ${baseUrl}
|
|
3980
|
+
`));
|
|
3981
|
+
let failures = 0;
|
|
3982
|
+
console.log((0, import_colors.bold)("Required public endpoints (must respond 2xx):"));
|
|
3983
|
+
for (const check of REQUIRED_PUBLIC_ENDPOINTS) {
|
|
3984
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
3985
|
+
const ok = isSuccess(status);
|
|
3986
|
+
if (!ok) {
|
|
3987
|
+
failures++;
|
|
3988
|
+
}
|
|
3989
|
+
const detail = status === 404 ? `${describeStatus(status)} \u2014 missing` : ok ? describeStatus(status) : `${describeStatus(status)} \u2014 unexpected`;
|
|
3990
|
+
console.log(line(ok, endpointLabel(check), detail));
|
|
3991
|
+
}
|
|
3992
|
+
{
|
|
3993
|
+
const path8 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
3994
|
+
const status = await requestStatus(`${baseUrl}${path8}`, "GET");
|
|
3995
|
+
const ok = status === 200 || status === 404;
|
|
3996
|
+
if (!ok) {
|
|
3997
|
+
failures++;
|
|
3998
|
+
}
|
|
3999
|
+
let detail;
|
|
4000
|
+
if (status === 404) {
|
|
4001
|
+
detail = `${describeStatus(status)} \u2014 reachable (made-up filename)`;
|
|
4002
|
+
} else if (status === 200) {
|
|
4003
|
+
detail = describeStatus(status);
|
|
4004
|
+
} else if (status === 401 || status === 403) {
|
|
4005
|
+
detail = `${describeStatus(status)} \u2014 must be public`;
|
|
4006
|
+
} else {
|
|
4007
|
+
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
4008
|
+
}
|
|
4009
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path8}`)}`, detail));
|
|
4010
|
+
}
|
|
4011
|
+
console.log();
|
|
4012
|
+
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
4013
|
+
for (const check of SECURED_ENDPOINTS) {
|
|
4014
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
4015
|
+
const ok = requiresAuthOrAbsent(status);
|
|
4016
|
+
if (!ok) {
|
|
4017
|
+
failures++;
|
|
4018
|
+
}
|
|
4019
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
4020
|
+
}
|
|
4021
|
+
console.log();
|
|
4022
|
+
console.log((0, import_colors.bold)("Event action triggers (must be absent or require auth):"));
|
|
4023
|
+
const events = await fetchEventConfigs(baseUrl);
|
|
4024
|
+
if (!events) {
|
|
4025
|
+
console.log(
|
|
4026
|
+
" " + (0, import_colors.yellow)(
|
|
4027
|
+
"Could not read /config/events; falling back to route-pattern checks."
|
|
4028
|
+
)
|
|
4029
|
+
);
|
|
4030
|
+
for (const check of FALLBACK_EVENT_TRIGGERS) {
|
|
4031
|
+
const status = await requestStatus(
|
|
4032
|
+
`${baseUrl}${check.path}`,
|
|
4033
|
+
check.method
|
|
4034
|
+
);
|
|
4035
|
+
const ok = requiresAuthOrAbsent(status);
|
|
4036
|
+
if (!ok) {
|
|
4037
|
+
failures++;
|
|
4038
|
+
}
|
|
4039
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
4040
|
+
}
|
|
4041
|
+
} else if (events.length === 0) {
|
|
4042
|
+
console.log(" " + (0, import_colors.yellow)("No events configured."));
|
|
4043
|
+
} else {
|
|
4044
|
+
for (const event of events) {
|
|
4045
|
+
const actions = event.actions.length ? event.actions : [PROBE_SEGMENT];
|
|
4046
|
+
const failed = [];
|
|
4047
|
+
for (const action of actions) {
|
|
4048
|
+
const status = await requestStatus(
|
|
4049
|
+
`${baseUrl}/trigger/events/${event.id}/actions/${action}`,
|
|
4050
|
+
"POST"
|
|
4051
|
+
);
|
|
4052
|
+
if (!requiresAuthOrAbsent(status)) {
|
|
4053
|
+
failed.push({ action, status });
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
const pattern = `POST /trigger/events/${event.id}/actions/{action}`;
|
|
4057
|
+
if (failed.length === 0) {
|
|
4058
|
+
console.log(
|
|
4059
|
+
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
4060
|
+
);
|
|
4061
|
+
} else {
|
|
4062
|
+
for (const failure of failed) {
|
|
4063
|
+
failures++;
|
|
4064
|
+
console.log(
|
|
4065
|
+
line(
|
|
4066
|
+
false,
|
|
4067
|
+
`POST /trigger/events/${event.id}/actions/${failure.action}`,
|
|
4068
|
+
securedDetail(failure.status)
|
|
4069
|
+
)
|
|
4070
|
+
);
|
|
4071
|
+
}
|
|
4072
|
+
const okCount = actions.length - failed.length;
|
|
4073
|
+
if (okCount > 0) {
|
|
4074
|
+
console.log(
|
|
4075
|
+
line(true, pattern, `${okCount} other action(s) require auth`)
|
|
4076
|
+
);
|
|
4077
|
+
}
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
}
|
|
4081
|
+
console.log();
|
|
4082
|
+
console.log((0, import_colors.bold)("Translations served (must cover the copy core requires):"));
|
|
4083
|
+
failures += await verifyTranslations(baseUrl);
|
|
4084
|
+
console.log();
|
|
4085
|
+
if (failures > 0) {
|
|
4086
|
+
console.log(
|
|
4087
|
+
(0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
|
|
4088
|
+
);
|
|
4089
|
+
process.exit(1);
|
|
4090
|
+
}
|
|
4091
|
+
console.log((0, import_colors.green)((0, import_colors.bold)("\u2713 All endpoint checks passed.")));
|
|
4092
|
+
}
|
|
4093
|
+
|
|
3338
4094
|
// src/cli.ts
|
|
3339
4095
|
var args = process.argv.slice(2);
|
|
3340
4096
|
var USAGE = `
|
|
@@ -3343,10 +4099,37 @@ Usage: opencrvs <command>
|
|
|
3343
4099
|
Commands:
|
|
3344
4100
|
environment Manage deployment environments
|
|
3345
4101
|
upgrade Upgrade an existing environment
|
|
3346
|
-
|
|
4102
|
+
verify-endpoints Verify the locally-running country config exposes the
|
|
4103
|
+
expected endpoints, keeps secured ones locked down and
|
|
4104
|
+
serves the translations core requires
|
|
3347
4105
|
|
|
3348
4106
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3349
4107
|
`.trim();
|
|
4108
|
+
var VERIFY_ENDPOINTS_USAGE = `
|
|
4109
|
+
Usage: opencrvs verify-endpoints [country-config-url]
|
|
4110
|
+
|
|
4111
|
+
Run this after 'opencrvs upgrade', with the upgraded country config running
|
|
4112
|
+
locally, to confirm it still behaves correctly. It checks over HTTP that:
|
|
4113
|
+
- required public endpoints exist (respond 2xx),
|
|
4114
|
+
- user-notification trigger endpoints are either absent or reject
|
|
4115
|
+
unauthenticated requests (never processed without a token), and
|
|
4116
|
+
- '/content/client' and '/content/login' serve every message id the country
|
|
4117
|
+
config template of this version carries.
|
|
4118
|
+
|
|
4119
|
+
Checking the translations reads the template off GitHub. When GitHub cannot be
|
|
4120
|
+
reached the other checks still run and that one is skipped with a warning.
|
|
4121
|
+
|
|
4122
|
+
Arguments:
|
|
4123
|
+
[country-config-url] Optional. Domain or URL of the country config
|
|
4124
|
+
service. Defaults to 'http://localhost:3040', the
|
|
4125
|
+
port country config listens on locally. A bare
|
|
4126
|
+
domain is assumed to use https.
|
|
4127
|
+
|
|
4128
|
+
Options:
|
|
4129
|
+
-h, --help Show this message.
|
|
4130
|
+
|
|
4131
|
+
Exits with a non-zero status if any check fails.
|
|
4132
|
+
`.trim();
|
|
3350
4133
|
var UPGRADE_USAGE = `
|
|
3351
4134
|
Usage: opencrvs upgrade [options]
|
|
3352
4135
|
|
|
@@ -3354,13 +4137,9 @@ Upgrade the country config in the current working directory to the next
|
|
|
3354
4137
|
major version of OpenCRVS.
|
|
3355
4138
|
|
|
3356
4139
|
Options:
|
|
3357
|
-
--docker-swarm Keep and merge the 'infrastructure/' directory with
|
|
3358
|
-
upstream changes. Use this if your country deploys
|
|
3359
|
-
OpenCRVS via Docker Swarm. When omitted, the
|
|
3360
|
-
'infrastructure/' directory is deleted (default).
|
|
3361
4140
|
-h, --help Show this message.
|
|
3362
4141
|
`.trim();
|
|
3363
|
-
function
|
|
4142
|
+
function main3() {
|
|
3364
4143
|
const command = args[0];
|
|
3365
4144
|
if (!command || command === "--help" || command === "-h") {
|
|
3366
4145
|
console.log(USAGE);
|
|
@@ -3371,8 +4150,8 @@ function main2() {
|
|
|
3371
4150
|
return handleEnvironment();
|
|
3372
4151
|
case "upgrade":
|
|
3373
4152
|
return handleUpgrade();
|
|
3374
|
-
case "
|
|
3375
|
-
return
|
|
4153
|
+
case "verify-endpoints":
|
|
4154
|
+
return handleVerifyEndpoints();
|
|
3376
4155
|
default:
|
|
3377
4156
|
console.error(`Unknown command: ${command}
|
|
3378
4157
|
`);
|
|
@@ -3389,6 +4168,7 @@ Usage: opencrvs environment <subcommand>
|
|
|
3389
4168
|
|
|
3390
4169
|
Subcommands:
|
|
3391
4170
|
init Initialise a new environment
|
|
4171
|
+
upgrade Upgrade existing environment configuration
|
|
3392
4172
|
update-workflows Update workflow environment options
|
|
3393
4173
|
users Manage environment users
|
|
3394
4174
|
swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
|
|
@@ -3399,6 +4179,8 @@ Subcommands:
|
|
|
3399
4179
|
switch (subcommand) {
|
|
3400
4180
|
case "init":
|
|
3401
4181
|
return runEnvironmentCommand("initialisation", runEnvironmentInit);
|
|
4182
|
+
case "upgrade":
|
|
4183
|
+
return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
|
|
3402
4184
|
case "update-workflows":
|
|
3403
4185
|
return runEnvironmentCommand(
|
|
3404
4186
|
"workflow update",
|
|
@@ -3419,10 +4201,10 @@ Subcommands:
|
|
|
3419
4201
|
async function runEnvironmentCommand(operation, command) {
|
|
3420
4202
|
try {
|
|
3421
4203
|
await command();
|
|
3422
|
-
} catch (
|
|
4204
|
+
} catch (error3) {
|
|
3423
4205
|
console.error(
|
|
3424
4206
|
`Environment ${operation} failed:`,
|
|
3425
|
-
|
|
4207
|
+
error3 instanceof Error ? error3.message : error3
|
|
3426
4208
|
);
|
|
3427
4209
|
process.exit(1);
|
|
3428
4210
|
}
|
|
@@ -3433,29 +4215,45 @@ async function handleUpgrade() {
|
|
|
3433
4215
|
console.log(UPGRADE_USAGE);
|
|
3434
4216
|
process.exit(0);
|
|
3435
4217
|
}
|
|
3436
|
-
const
|
|
3437
|
-
const unknownFlags = upgradeArgs.filter(
|
|
3438
|
-
(arg) => arg.startsWith("-") && !KNOWN_FLAGS.has(arg)
|
|
3439
|
-
);
|
|
4218
|
+
const unknownFlags = upgradeArgs.filter((arg) => arg.startsWith("-"));
|
|
3440
4219
|
if (unknownFlags.length > 0) {
|
|
3441
4220
|
console.error(`Unknown option(s): ${unknownFlags.join(", ")}
|
|
3442
4221
|
`);
|
|
3443
4222
|
console.log(UPGRADE_USAGE);
|
|
3444
4223
|
process.exit(1);
|
|
3445
4224
|
}
|
|
3446
|
-
const dockerSwarm = upgradeArgs.includes("--docker-swarm");
|
|
3447
4225
|
console.log("Initiating upgrade...");
|
|
3448
4226
|
try {
|
|
3449
|
-
await runUpgrade(
|
|
4227
|
+
await runUpgrade();
|
|
3450
4228
|
console.log("Upgrade completed successfully!");
|
|
3451
|
-
} catch (
|
|
3452
|
-
console.error("Upgrade failed:",
|
|
4229
|
+
} catch (error3) {
|
|
4230
|
+
console.error("Upgrade failed:", error3);
|
|
3453
4231
|
process.exit(1);
|
|
3454
4232
|
}
|
|
3455
4233
|
}
|
|
3456
|
-
function
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
4234
|
+
async function handleVerifyEndpoints() {
|
|
4235
|
+
const verifyArgs = args.slice(1);
|
|
4236
|
+
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
4237
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
4238
|
+
process.exit(0);
|
|
4239
|
+
}
|
|
4240
|
+
const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
|
|
4241
|
+
if (positional.length > 1) {
|
|
4242
|
+
console.error(
|
|
4243
|
+
`Unexpected extra argument(s): ${positional.slice(1).join(", ")}
|
|
4244
|
+
`
|
|
4245
|
+
);
|
|
4246
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
4247
|
+
process.exit(1);
|
|
4248
|
+
}
|
|
4249
|
+
try {
|
|
4250
|
+
await runVerifyEndpoints(positional[0]);
|
|
4251
|
+
} catch (error3) {
|
|
4252
|
+
console.error(
|
|
4253
|
+
"Endpoint verification failed:",
|
|
4254
|
+
error3 instanceof Error ? error3.message : error3
|
|
4255
|
+
);
|
|
4256
|
+
process.exit(1);
|
|
4257
|
+
}
|
|
3460
4258
|
}
|
|
3461
|
-
|
|
4259
|
+
main3();
|