@opencrvs/toolkit 2.1.0-rc.1f688f9 → 2.1.0-rc.268cfbe
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -12
- package/build.sh +20 -5
- package/create-countryconfig/index.js +164 -4
- package/dist/application-config/index.js +36 -25
- 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 +2829 -1294
- package/dist/commons/api/router.d.ts +252 -290
- 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 +19 -4
- package/dist/commons/events/ActionConfig.d.ts +5 -14
- package/dist/commons/events/ActionDocument.d.ts +30 -4
- package/dist/commons/events/AdvancedSearchConfig.d.ts +24 -12
- package/dist/commons/events/AuditLog.d.ts +1 -0
- package/dist/commons/events/Draft.d.ts +1 -21
- package/dist/commons/events/EventDocument.d.ts +4 -4
- package/dist/commons/events/FieldConfig.d.ts +26 -15
- package/dist/commons/events/FieldTypeMapping.d.ts +10 -10
- package/dist/commons/events/FieldValue.d.ts +1 -0
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/locations.d.ts +4 -0
- package/dist/commons/events/scopes.d.ts +21 -1
- package/dist/commons/events/test.utils.d.ts +71 -22
- package/dist/commons/events/utils.d.ts +37 -2
- package/dist/commons/notification/dispatch.d.ts +1 -6
- package/dist/conditionals/index.js +21 -7
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +2 -1
- package/dist/environment/logger.d.ts +3 -0
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +1 -1
- 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 +593 -562
- 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 +3 -8
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +4 -0
- 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 +2115 -1884
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +13 -32
- 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.1/enable-telemetry.d.ts.map +1 -1
- package/dist/migrations/v2.1/enable-telemetry.js +32 -15
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1160 -70
- 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 +345 -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/rename-api-paths.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/notification/index.js +249 -207
- package/dist/scopes/index.d.ts +288 -5
- package/dist/scopes/index.js +22 -7
- package/dist/telemetry/index.js +5 -1
- package/dist/templates/charts-values/dependencies/values.yaml +8 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +6 -0
- package/dist/templates/charts-values/opentelemetry/values.yaml +7 -0
- 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/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 +145 -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/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.268cfbe.tgz +0 -0
- package/package.json +9 -4
- 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 +0 -3
- 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/opencrvs-toolkit-2.1.0-rc.1f688f9.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
package/dist/cli.js
CHANGED
|
@@ -32,13 +32,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
32
|
|
|
33
33
|
// src/environment/paths.ts
|
|
34
34
|
function getEnvironmentInventoryPath(environment) {
|
|
35
|
-
return (0,
|
|
35
|
+
return (0, import_path11.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
36
|
}
|
|
37
37
|
function findOldInventoryFiles() {
|
|
38
|
-
return glob.sync((0,
|
|
38
|
+
return glob.sync((0, import_path11.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
39
|
}
|
|
40
40
|
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
-
return (0,
|
|
41
|
+
return (0, import_path11.basename)(filePath, ".yml");
|
|
42
42
|
}
|
|
43
43
|
function assertNoOldInventoryLayout() {
|
|
44
44
|
if (findOldInventoryFiles().length === 0) {
|
|
@@ -51,13 +51,13 @@ function assertNoOldInventoryLayout() {
|
|
|
51
51
|
].join(" ")
|
|
52
52
|
);
|
|
53
53
|
}
|
|
54
|
-
var
|
|
54
|
+
var import_path11, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
|
|
55
55
|
var init_paths = __esm({
|
|
56
56
|
"src/environment/paths.ts"() {
|
|
57
57
|
"use strict";
|
|
58
|
-
|
|
58
|
+
import_path11 = require("path");
|
|
59
59
|
glob = __toESM(require("glob"));
|
|
60
|
-
OLD_INVENTORY_DIR = (0,
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path11.join)(
|
|
61
61
|
"infrastructure",
|
|
62
62
|
"server-setup",
|
|
63
63
|
"inventory"
|
|
@@ -503,24 +503,8 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
503
503
|
(value) => value.name === name && value.type === type && value.scope === scope
|
|
504
504
|
);
|
|
505
505
|
}
|
|
506
|
-
function storeSecrets(environment, answers) {
|
|
507
|
-
let envConfig = {};
|
|
508
|
-
try {
|
|
509
|
-
envConfig = import_dotenv.default.parse(
|
|
510
|
-
(0, import_fs3.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
511
|
-
);
|
|
512
|
-
} catch (error3) {
|
|
513
|
-
envConfig = {};
|
|
514
|
-
}
|
|
515
|
-
const linesFromAnswers = answers.map(
|
|
516
|
-
(update) => `${update.name}="${update.value}"`
|
|
517
|
-
);
|
|
518
|
-
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
519
|
-
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
520
|
-
(0, import_fs3.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
521
|
-
}
|
|
522
506
|
function readYamlFile(filePath) {
|
|
523
|
-
const fileContent =
|
|
507
|
+
const fileContent = import_fs9.default.readFileSync(filePath, "utf8");
|
|
524
508
|
return yaml.load(fileContent);
|
|
525
509
|
}
|
|
526
510
|
function writeYamlFile(filePath, data) {
|
|
@@ -533,33 +517,29 @@ function writeYamlFile(filePath, data) {
|
|
|
533
517
|
noRefs: true,
|
|
534
518
|
sortKeys: false
|
|
535
519
|
});
|
|
536
|
-
|
|
520
|
+
import_fs9.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
537
521
|
} catch (error3) {
|
|
538
522
|
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
539
523
|
}
|
|
540
524
|
}
|
|
541
|
-
var
|
|
525
|
+
var import_fs9, yaml;
|
|
542
526
|
var init_utils = __esm({
|
|
543
527
|
"src/environment/utils.ts"() {
|
|
544
528
|
"use strict";
|
|
545
|
-
|
|
529
|
+
import_fs9 = __toESM(require("fs"));
|
|
546
530
|
yaml = __toESM(require("js-yaml"));
|
|
547
|
-
import_dotenv = __toESM(require("dotenv"));
|
|
548
531
|
}
|
|
549
532
|
});
|
|
550
533
|
|
|
551
534
|
// src/environment/templates.ts
|
|
552
|
-
function getUsers(data) {
|
|
553
|
-
if (!data?.all?.vars?.users) {
|
|
554
|
-
return { users: [] };
|
|
555
|
-
}
|
|
556
|
-
return data.all.vars.users;
|
|
557
|
-
}
|
|
558
535
|
function extractAndModifyUsers(data) {
|
|
559
536
|
if (!data?.all?.vars?.users) {
|
|
560
537
|
return { users: [] };
|
|
561
538
|
}
|
|
562
539
|
const users = data.all.vars.users.map((user) => {
|
|
540
|
+
if (user.role) {
|
|
541
|
+
return user;
|
|
542
|
+
}
|
|
563
543
|
const { sudoer, ...rest } = user;
|
|
564
544
|
return {
|
|
565
545
|
...rest,
|
|
@@ -595,29 +575,29 @@ function extractWorkerNodes(data) {
|
|
|
595
575
|
return worker_hosts;
|
|
596
576
|
}
|
|
597
577
|
function copyChartsValues(env, values) {
|
|
598
|
-
const srcDir =
|
|
599
|
-
const destDir =
|
|
600
|
-
|
|
578
|
+
const srcDir = import_path12.default.resolve(__dirname, "templates", "charts-values");
|
|
579
|
+
const destDir = import_path12.default.resolve(process.cwd(), "environments", env);
|
|
580
|
+
import_fs10.default.mkdirSync(destDir, { recursive: true });
|
|
601
581
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
602
582
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
603
583
|
values["opencrvs_environment"] = env;
|
|
604
584
|
function copyRecursive(src, dest) {
|
|
605
|
-
const stat =
|
|
585
|
+
const stat = import_fs10.default.statSync(src);
|
|
606
586
|
if (stat.isDirectory()) {
|
|
607
|
-
|
|
608
|
-
for (const item of
|
|
609
|
-
copyRecursive(
|
|
587
|
+
import_fs10.default.mkdirSync(dest, { recursive: true });
|
|
588
|
+
for (const item of import_fs10.default.readdirSync(src)) {
|
|
589
|
+
copyRecursive(import_path12.default.join(src, item), import_path12.default.join(dest, item));
|
|
610
590
|
}
|
|
611
591
|
} else {
|
|
612
|
-
const content =
|
|
592
|
+
const content = import_fs10.default.readFileSync(src, "utf8");
|
|
613
593
|
const template = import_handlebars.default.compile(content);
|
|
614
594
|
const updated = template(values);
|
|
615
595
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
616
|
-
if (isOverridesFile &&
|
|
596
|
+
if (isOverridesFile && import_fs10.default.existsSync(dest)) {
|
|
617
597
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
618
598
|
return;
|
|
619
599
|
}
|
|
620
|
-
|
|
600
|
+
import_fs10.default.writeFileSync(dest, updated, "utf8");
|
|
621
601
|
log(` \u2713 Created: ${dest}`);
|
|
622
602
|
}
|
|
623
603
|
}
|
|
@@ -628,29 +608,29 @@ function copyChartsValues(env, values) {
|
|
|
628
608
|
`);
|
|
629
609
|
}
|
|
630
610
|
function generateInventory(env, values) {
|
|
631
|
-
const templatePath =
|
|
611
|
+
const templatePath = import_path12.default.join(
|
|
632
612
|
__dirname,
|
|
633
613
|
"templates",
|
|
634
614
|
"inventory",
|
|
635
615
|
"inventory.template.yml"
|
|
636
616
|
);
|
|
637
|
-
const outputPath =
|
|
638
|
-
const templateFile =
|
|
617
|
+
const outputPath = import_path12.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
618
|
+
const templateFile = import_fs10.default.readFileSync(templatePath, "utf-8");
|
|
639
619
|
const template = import_handlebars.default.compile(templateFile);
|
|
640
620
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
641
621
|
const updated = template(values);
|
|
642
|
-
|
|
643
|
-
|
|
622
|
+
import_fs10.default.mkdirSync(import_path12.default.dirname(outputPath), { recursive: true });
|
|
623
|
+
import_fs10.default.writeFileSync(outputPath, updated);
|
|
644
624
|
log(`
|
|
645
625
|
\u2705 Generated inventory file at ${outputPath}
|
|
646
626
|
`);
|
|
647
627
|
}
|
|
648
|
-
var
|
|
628
|
+
var import_fs10, import_path12, import_handlebars;
|
|
649
629
|
var init_templates = __esm({
|
|
650
630
|
"src/environment/templates.ts"() {
|
|
651
631
|
"use strict";
|
|
652
|
-
|
|
653
|
-
|
|
632
|
+
import_fs10 = __toESM(require("fs"));
|
|
633
|
+
import_path12 = __toESM(require("path"));
|
|
654
634
|
init_logger();
|
|
655
635
|
init_paths();
|
|
656
636
|
import_handlebars = __toESM(require("handlebars"));
|
|
@@ -676,10 +656,145 @@ var init_ssh_keygen = __esm({
|
|
|
676
656
|
}
|
|
677
657
|
});
|
|
678
658
|
|
|
659
|
+
// src/environment/update-workflows.ts
|
|
660
|
+
var update_workflows_exports = {};
|
|
661
|
+
__export(update_workflows_exports, {
|
|
662
|
+
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
663
|
+
});
|
|
664
|
+
function isDirectory(path14) {
|
|
665
|
+
try {
|
|
666
|
+
return (0, import_fs11.statSync)(path14).isDirectory();
|
|
667
|
+
} catch {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
async function extractInfrastructureNames() {
|
|
672
|
+
const files = glob2.sync((0, import_path13.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
673
|
+
const infraEnvironments = files.map((file) => (0, import_path13.basename)((0, import_path13.dirname)(file)));
|
|
674
|
+
if (infraEnvironments.length === 0) {
|
|
675
|
+
console.log(
|
|
676
|
+
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
677
|
+
);
|
|
678
|
+
return [];
|
|
679
|
+
}
|
|
680
|
+
log("\u{1F50D} Found infrastructure configurations:", infraEnvironments.join(", "));
|
|
681
|
+
return infraEnvironments;
|
|
682
|
+
}
|
|
683
|
+
async function extractEnvironmentNames() {
|
|
684
|
+
const entries = await (0, import_promises.readdir)("environments");
|
|
685
|
+
const environments = entries.filter((entry) => {
|
|
686
|
+
const environmentPath = (0, import_path13.join)("environments", entry);
|
|
687
|
+
const opencrvsServicesPath = (0, import_path13.join)(environmentPath, "opencrvs-services");
|
|
688
|
+
return isDirectory(environmentPath) && (0, import_fs11.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
689
|
+
});
|
|
690
|
+
if (environments.length === 0) {
|
|
691
|
+
console.log(
|
|
692
|
+
"\u26A0\uFE0F Warning: No environment directories found in environments/"
|
|
693
|
+
);
|
|
694
|
+
return [];
|
|
695
|
+
}
|
|
696
|
+
log("\u{1F50D} Found OpenCRVS configurations:", environments.join(", "));
|
|
697
|
+
return environments;
|
|
698
|
+
}
|
|
699
|
+
function updateOptionsInYaml(content, envList) {
|
|
700
|
+
const optionsRegex = /([ ]*options:[ ]*\n)((?:[ ]*-[^\n]*\n)+)/;
|
|
701
|
+
const match = content.match(optionsRegex);
|
|
702
|
+
if (!match) {
|
|
703
|
+
throw new Error("Could not find options array in workflow file");
|
|
704
|
+
}
|
|
705
|
+
const firstItemMatch = match[2].match(/^([ ]*)-/);
|
|
706
|
+
const itemIndent = firstItemMatch ? firstItemMatch[1] : " ";
|
|
707
|
+
const newOptions = match[1] + envList.map((env) => `${itemIndent}- ${env}`).join("\n") + "\n";
|
|
708
|
+
return content.replace(optionsRegex, newOptions);
|
|
709
|
+
}
|
|
710
|
+
async function updateWorkflows(envList, config) {
|
|
711
|
+
const { workflows } = config;
|
|
712
|
+
for (const workflowPath of workflows) {
|
|
713
|
+
if (!(0, import_fs11.existsSync)(workflowPath)) {
|
|
714
|
+
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
try {
|
|
718
|
+
const fileContents = (0, import_fs11.readFileSync)(workflowPath, "utf8");
|
|
719
|
+
const workflowData = yaml2.load(fileContents);
|
|
720
|
+
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
721
|
+
throw new Error(
|
|
722
|
+
"Workflow does not have the expected structure: on.workflow_dispatch.inputs.environment.options"
|
|
723
|
+
);
|
|
724
|
+
}
|
|
725
|
+
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
726
|
+
(0, import_fs11.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
727
|
+
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
728
|
+
} catch (error3) {
|
|
729
|
+
console.error(
|
|
730
|
+
`
|
|
731
|
+
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
732
|
+
);
|
|
733
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
|
|
734
|
+
throw error3;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
async function updateWorkflowEnvironments() {
|
|
739
|
+
try {
|
|
740
|
+
let didUpdateWorkflows = false;
|
|
741
|
+
const infraEnvironments = await extractInfrastructureNames();
|
|
742
|
+
if (infraEnvironments.length > 0) {
|
|
743
|
+
console.log("\u{1F504} Updating infrastructure workflows:");
|
|
744
|
+
await updateWorkflows(infraEnvironments, {
|
|
745
|
+
workflows: [
|
|
746
|
+
".github/workflows/provision.yml",
|
|
747
|
+
".github/workflows/reset-2fa.yml"
|
|
748
|
+
],
|
|
749
|
+
path: "on.workflow_dispatch.inputs.environment.options"
|
|
750
|
+
});
|
|
751
|
+
didUpdateWorkflows = true;
|
|
752
|
+
}
|
|
753
|
+
const environments = await extractEnvironmentNames();
|
|
754
|
+
if (environments.length > 0) {
|
|
755
|
+
const workflows = [
|
|
756
|
+
".github/workflows/deploy-dependencies.yml",
|
|
757
|
+
".github/workflows/deploy-opencrvs.yml",
|
|
758
|
+
".github/workflows/clear-all-data.yml",
|
|
759
|
+
".github/workflows/seed-data.yml",
|
|
760
|
+
".github/workflows/reindex.yml",
|
|
761
|
+
".github/workflows/github-to-k8s-sync-env.yml"
|
|
762
|
+
];
|
|
763
|
+
log("\u{1F4CB} Updating OpenCRVS application workflows:");
|
|
764
|
+
await updateWorkflows(environments, {
|
|
765
|
+
workflows,
|
|
766
|
+
path: "on.workflow_dispatch.inputs.environment.options"
|
|
767
|
+
});
|
|
768
|
+
didUpdateWorkflows = true;
|
|
769
|
+
}
|
|
770
|
+
if (didUpdateWorkflows) {
|
|
771
|
+
success("\u2705 Workflow updates completed successfully!");
|
|
772
|
+
} else {
|
|
773
|
+
log("\u2139\uFE0F No workflows were updated.");
|
|
774
|
+
}
|
|
775
|
+
} catch (error3) {
|
|
776
|
+
console.error("\n\u274C Error updating workflows:", error3);
|
|
777
|
+
process.exit(1);
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
var import_promises, import_fs11, import_path13, glob2, yaml2;
|
|
781
|
+
var init_update_workflows = __esm({
|
|
782
|
+
"src/environment/update-workflows.ts"() {
|
|
783
|
+
"use strict";
|
|
784
|
+
import_promises = require("fs/promises");
|
|
785
|
+
import_fs11 = require("fs");
|
|
786
|
+
import_path13 = require("path");
|
|
787
|
+
glob2 = __toESM(require("glob"));
|
|
788
|
+
yaml2 = __toESM(require("js-yaml"));
|
|
789
|
+
init_logger();
|
|
790
|
+
init_paths();
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
|
|
679
794
|
// src/environment/git.ts
|
|
680
795
|
function getRepoInfo() {
|
|
681
796
|
try {
|
|
682
|
-
const remoteUrl = (0,
|
|
797
|
+
const remoteUrl = (0, import_child_process2.execSync)("git config --get remote.origin.url", {
|
|
683
798
|
stdio: ["ignore", "pipe", "ignore"]
|
|
684
799
|
}).toString().trim();
|
|
685
800
|
const match = remoteUrl.match(/github\.com[:/](.+?)\/(.+?)(\.git)?$/);
|
|
@@ -697,27 +812,27 @@ function getRepoInfo() {
|
|
|
697
812
|
};
|
|
698
813
|
}
|
|
699
814
|
}
|
|
700
|
-
var
|
|
815
|
+
var import_child_process2;
|
|
701
816
|
var init_git = __esm({
|
|
702
817
|
"src/environment/git.ts"() {
|
|
703
818
|
"use strict";
|
|
704
|
-
|
|
819
|
+
import_child_process2 = require("child_process");
|
|
705
820
|
}
|
|
706
821
|
});
|
|
707
822
|
|
|
708
823
|
// src/environment/questions.ts
|
|
709
|
-
function validateCIDR(
|
|
710
|
-
if (!
|
|
824
|
+
function validateCIDR(input4) {
|
|
825
|
+
if (!input4.trim()) {
|
|
711
826
|
return true;
|
|
712
827
|
}
|
|
713
828
|
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])$/;
|
|
714
|
-
return cidrRegex.test(
|
|
829
|
+
return cidrRegex.test(input4.trim()) ? true : "Please enter a valid CIDR (e.g. 10.0.0.0/24)";
|
|
715
830
|
}
|
|
716
|
-
function validateCIDRs(
|
|
717
|
-
if (!
|
|
831
|
+
function validateCIDRs(input4) {
|
|
832
|
+
if (!input4.trim()) {
|
|
718
833
|
return true;
|
|
719
834
|
}
|
|
720
|
-
const cidrs =
|
|
835
|
+
const cidrs = input4.split(",").map((v) => v.trim());
|
|
721
836
|
for (const cidr of cidrs) {
|
|
722
837
|
const result = validateCIDR(cidr);
|
|
723
838
|
if (result !== true) {
|
|
@@ -1247,7 +1362,7 @@ function updateInventoryFile(filePath, users) {
|
|
|
1247
1362
|
function parseInventoryFile(filePath) {
|
|
1248
1363
|
try {
|
|
1249
1364
|
const data = readYamlFile(filePath);
|
|
1250
|
-
return
|
|
1365
|
+
return extractAndModifyUsers(data);
|
|
1251
1366
|
} catch {
|
|
1252
1367
|
return [];
|
|
1253
1368
|
}
|
|
@@ -1257,7 +1372,7 @@ function getCurrentUsername() {
|
|
|
1257
1372
|
}
|
|
1258
1373
|
function getCurrentUserSSHKeys() {
|
|
1259
1374
|
const homeDir = os.homedir();
|
|
1260
|
-
const sshDir =
|
|
1375
|
+
const sshDir = path11.join(homeDir, ".ssh");
|
|
1261
1376
|
const keys = [];
|
|
1262
1377
|
const keyFiles = [
|
|
1263
1378
|
"id_rsa.pub",
|
|
@@ -1266,7 +1381,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1266
1381
|
"id_dsa.pub"
|
|
1267
1382
|
];
|
|
1268
1383
|
for (const keyFile of keyFiles) {
|
|
1269
|
-
const keyPath =
|
|
1384
|
+
const keyPath = path11.join(sshDir, keyFile);
|
|
1270
1385
|
try {
|
|
1271
1386
|
if (fs3.existsSync(keyPath)) {
|
|
1272
1387
|
const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
|
|
@@ -1607,13 +1722,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1607
1722
|
}
|
|
1608
1723
|
return users;
|
|
1609
1724
|
}
|
|
1610
|
-
var os, fs3,
|
|
1725
|
+
var os, fs3, path11, input2, select2, confirm, editor, checkbox;
|
|
1611
1726
|
var init_manage_users = __esm({
|
|
1612
1727
|
"src/environment/manage-users.ts"() {
|
|
1613
1728
|
"use strict";
|
|
1614
1729
|
os = __toESM(require("os"));
|
|
1615
1730
|
fs3 = __toESM(require("fs"));
|
|
1616
|
-
|
|
1731
|
+
path11 = __toESM(require("path"));
|
|
1617
1732
|
init_logger();
|
|
1618
1733
|
init_utils();
|
|
1619
1734
|
init_templates();
|
|
@@ -1627,6 +1742,9 @@ var init_manage_users = __esm({
|
|
|
1627
1742
|
|
|
1628
1743
|
// src/environment/setup-environment.ts
|
|
1629
1744
|
var setup_environment_exports = {};
|
|
1745
|
+
__export(setup_environment_exports, {
|
|
1746
|
+
runSetupEnvironment: () => runSetupEnvironment
|
|
1747
|
+
});
|
|
1630
1748
|
async function confirm2(options) {
|
|
1631
1749
|
const inquirer = await import("@inquirer/prompts");
|
|
1632
1750
|
return inquirer.confirm(options);
|
|
@@ -1635,6 +1753,10 @@ async function select3(options) {
|
|
|
1635
1753
|
const inquirer = await import("@inquirer/prompts");
|
|
1636
1754
|
return inquirer.select(options);
|
|
1637
1755
|
}
|
|
1756
|
+
async function input3(options) {
|
|
1757
|
+
const inquirer = await import("@inquirer/prompts");
|
|
1758
|
+
return inquirer.input(options);
|
|
1759
|
+
}
|
|
1638
1760
|
function questionToPrompt({
|
|
1639
1761
|
valueType,
|
|
1640
1762
|
valueLabel,
|
|
@@ -1701,7 +1823,7 @@ function getAnswers(existingValues) {
|
|
|
1701
1823
|
});
|
|
1702
1824
|
});
|
|
1703
1825
|
}
|
|
1704
|
-
async function promptAndStoreAnswer(
|
|
1826
|
+
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1705
1827
|
log("");
|
|
1706
1828
|
const processedQuestions = questions.flatMap((question) => {
|
|
1707
1829
|
const questionWithVariableLabel = {
|
|
@@ -1780,7 +1902,6 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1780
1902
|
}
|
|
1781
1903
|
});
|
|
1782
1904
|
ALL_ANSWERS.push(result);
|
|
1783
|
-
storeSecrets(environment, getAnswers(existingValues));
|
|
1784
1905
|
const existingValuesForQuestions = questions.filter((question) => question.valueType === "VARIABLE").map((question) => [
|
|
1785
1906
|
question.name,
|
|
1786
1907
|
findExistingValue(
|
|
@@ -1792,1124 +1913,1016 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1792
1913
|
]);
|
|
1793
1914
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1794
1915
|
}
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1916
|
+
async function runSetupEnvironment() {
|
|
1917
|
+
log("\n", import_kleur4.default.bold().underline("Github"), "\n");
|
|
1918
|
+
const { githubOrganisation, githubRepository } = await (0, import_prompts2.default)(
|
|
1919
|
+
githubQuestions.map(questionToPrompt),
|
|
1920
|
+
{
|
|
1921
|
+
onCancel: () => {
|
|
1922
|
+
process.exit(1);
|
|
1923
|
+
}
|
|
1924
|
+
}
|
|
1925
|
+
);
|
|
1926
|
+
const { githubToken } = await promptAndStoreAnswer(githubTokenQuestion, []);
|
|
1927
|
+
const octokit = new import_core.Octokit({
|
|
1928
|
+
auth: githubToken
|
|
1929
|
+
});
|
|
1930
|
+
log(import_kleur4.default.green("\nSuccessfully logged in to Github\n"));
|
|
1931
|
+
const existingEnvironments = await getRepositoryEnvironments(
|
|
1932
|
+
octokit,
|
|
1933
|
+
githubOrganisation,
|
|
1934
|
+
githubRepository
|
|
1935
|
+
);
|
|
1936
|
+
const defaultChoices = [
|
|
1937
|
+
{ name: "Development", value: "development" },
|
|
1938
|
+
{ name: "Quality assurance (no PII data)", value: "qa" },
|
|
1939
|
+
{
|
|
1940
|
+
name: "Staging (hosts PII data, no backups)",
|
|
1941
|
+
value: "staging"
|
|
1942
|
+
},
|
|
1943
|
+
{
|
|
1944
|
+
name: "Production (hosts PII data, requires frequent backups)",
|
|
1945
|
+
value: "production"
|
|
1946
|
+
}
|
|
1947
|
+
];
|
|
1948
|
+
const choices = [
|
|
1949
|
+
...defaultChoices,
|
|
1950
|
+
...existingEnvironments.filter((env) => !defaultChoices.some((choice) => choice.value === env)).map((env) => ({
|
|
1951
|
+
name: env,
|
|
1952
|
+
value: env
|
|
1953
|
+
}))
|
|
1954
|
+
];
|
|
1955
|
+
const environment = await selectWithCustom({
|
|
1956
|
+
message: "Choose a name and purpose for the environment?",
|
|
1957
|
+
choices
|
|
1958
|
+
});
|
|
1959
|
+
let environment_type = "non-production";
|
|
1960
|
+
if (["development", "qa"].includes(environment)) {
|
|
1961
|
+
environment_type = "non-production";
|
|
1962
|
+
} else if (["staging", "production"].includes(environment)) {
|
|
1963
|
+
environment_type = "production";
|
|
1964
|
+
} else {
|
|
1965
|
+
environment_type = await select3({
|
|
1966
|
+
message: "Purpose for the environment?",
|
|
1967
|
+
choices: [
|
|
1968
|
+
{
|
|
1969
|
+
name: "Development/Quality assurance/Testing (no PII data)",
|
|
1970
|
+
value: "non-production"
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
name: "Staging/Production (hosts PII data, requires frequent backups)",
|
|
1974
|
+
value: "production"
|
|
1975
|
+
}
|
|
1976
|
+
]
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
log("\n", import_kleur4.default.bold().underline("Two-factor authentication (2FA)"));
|
|
1980
|
+
const two_fa_enabled = await confirm2({
|
|
1981
|
+
message: "Enable two-factor authentication (2FA)? This should be enabled for any environment that hosts PII data.",
|
|
1982
|
+
default: process.env.TWO_FA_ENABLED ? process.env.TWO_FA_ENABLED === "true" : environment_type === "production"
|
|
1983
|
+
});
|
|
1984
|
+
if (!two_fa_enabled && ["production", "staging"].includes(environment_type)) {
|
|
1985
|
+
warn(
|
|
1986
|
+
"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."
|
|
1829
1987
|
);
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1988
|
+
}
|
|
1989
|
+
const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
|
|
1990
|
+
if (!environment) {
|
|
1991
|
+
process.exit(1);
|
|
1992
|
+
}
|
|
1993
|
+
await createEnvironment(
|
|
1994
|
+
octokit,
|
|
1995
|
+
environment,
|
|
1996
|
+
githubOrganisation,
|
|
1997
|
+
githubRepository
|
|
1998
|
+
);
|
|
1999
|
+
const repositoryId = await getRepositoryId(
|
|
2000
|
+
octokit,
|
|
2001
|
+
githubOrganisation,
|
|
2002
|
+
githubRepository
|
|
2003
|
+
);
|
|
2004
|
+
const existingRepositorySecrets = await listRepositorySecrets(
|
|
2005
|
+
octokit,
|
|
2006
|
+
githubOrganisation,
|
|
2007
|
+
githubRepository
|
|
2008
|
+
);
|
|
2009
|
+
const existingRepositoryVariables = await listRepositoryVariables(
|
|
2010
|
+
octokit,
|
|
2011
|
+
githubOrganisation,
|
|
2012
|
+
githubRepository
|
|
2013
|
+
);
|
|
2014
|
+
const existingEnvironmentVariables = await listEnvironmentVariables(
|
|
2015
|
+
octokit,
|
|
2016
|
+
repositoryId,
|
|
2017
|
+
environment
|
|
2018
|
+
);
|
|
2019
|
+
const existingEnvironmentSecrets = await listEnvironmentSecrets(
|
|
2020
|
+
octokit,
|
|
2021
|
+
githubOrganisation,
|
|
2022
|
+
repositoryId,
|
|
2023
|
+
environment
|
|
2024
|
+
);
|
|
2025
|
+
const existingValues = [
|
|
2026
|
+
...existingEnvironmentVariables,
|
|
2027
|
+
...existingRepositoryVariables,
|
|
2028
|
+
...existingRepositorySecrets,
|
|
2029
|
+
...existingEnvironmentSecrets
|
|
2030
|
+
];
|
|
2031
|
+
if (existingEnvironmentVariables.length > 0 || existingEnvironmentSecrets.length > 0) {
|
|
2032
|
+
log(
|
|
2033
|
+
"\nEnvironment with the name",
|
|
2034
|
+
environment,
|
|
2035
|
+
"already exists in Github.",
|
|
2036
|
+
"\nFound",
|
|
2037
|
+
existingEnvironmentVariables.length,
|
|
2038
|
+
"existing variables and",
|
|
2039
|
+
existingEnvironmentSecrets.length,
|
|
2040
|
+
"secrets"
|
|
2041
|
+
);
|
|
2042
|
+
}
|
|
2043
|
+
if (environment_type === "production") {
|
|
2044
|
+
log(
|
|
2045
|
+
"\n",
|
|
2046
|
+
import_kleur4.default.yellow().bold(
|
|
2047
|
+
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
2048
|
+
)
|
|
2049
|
+
);
|
|
2050
|
+
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
2051
|
+
}
|
|
2052
|
+
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
2053
|
+
await promptAndStoreAnswer(dockerhubQuestions, existingValues);
|
|
2054
|
+
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
2055
|
+
const infrastructure = await promptAndStoreAnswer(
|
|
2056
|
+
infrastructureQuestions,
|
|
2057
|
+
existingValues
|
|
2058
|
+
);
|
|
2059
|
+
const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
|
|
2060
|
+
log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
|
|
2061
|
+
const users = await manageUsers(getEnvironmentInventoryPath(environment));
|
|
2062
|
+
log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
|
|
2063
|
+
const sslCertExists = findExistingValue(
|
|
2064
|
+
"SSL_CRT",
|
|
2065
|
+
"SECRET",
|
|
2066
|
+
"ENVIRONMENT",
|
|
2067
|
+
existingValues
|
|
2068
|
+
);
|
|
2069
|
+
let ssl_answers = [];
|
|
2070
|
+
const traefikConfOption = (await (0, import_prompts2.default)([
|
|
2071
|
+
{
|
|
2072
|
+
name: "traefikConfOption",
|
|
2073
|
+
type: "select",
|
|
2074
|
+
message: "Choose option to configure Traefik SSL Certificate",
|
|
2075
|
+
choices: [
|
|
2076
|
+
{ title: "Let's Encrypt certificate", value: "lets_encrypt" },
|
|
2077
|
+
{ title: "Static SSL certificate", value: "static_ssl" },
|
|
2078
|
+
{ title: "Custom configuration", value: "custom" }
|
|
2079
|
+
],
|
|
2080
|
+
initial: sslCertExists ? 1 : 0
|
|
2081
|
+
}
|
|
2082
|
+
])).traefikConfOption;
|
|
2083
|
+
if (traefikConfOption === "static_ssl") {
|
|
2084
|
+
ssl_answers = await askQuestionWithEditor(
|
|
2085
|
+
staticSSLCertQuestions,
|
|
2086
|
+
existingEnvironmentSecrets
|
|
2087
|
+
);
|
|
2088
|
+
}
|
|
2089
|
+
log("\n", import_kleur4.default.bold().underline("Storage"), "\n");
|
|
2090
|
+
let enableEncryption = false;
|
|
2091
|
+
const encryption_key_defined = findExistingValue(
|
|
2092
|
+
"ENCRYPTION_KEY",
|
|
2093
|
+
"SECRET",
|
|
2094
|
+
"ENVIRONMENT",
|
|
2095
|
+
existingValues
|
|
2096
|
+
);
|
|
2097
|
+
if (!encryption_key_defined && !environment_exists) {
|
|
2098
|
+
const answers_enable_encryption = await (0, import_prompts2.default)(
|
|
2099
|
+
[
|
|
1834
2100
|
{
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
2101
|
+
name: "enableEncryption",
|
|
2102
|
+
type: "confirm",
|
|
2103
|
+
message: "Do you want to enable disk encryption?",
|
|
2104
|
+
scope: "ENVIRONMENT",
|
|
2105
|
+
initial: Boolean(process.env.ENABLE_ENCRYPTION)
|
|
1838
2106
|
}
|
|
2107
|
+
].map(questionToPrompt)
|
|
2108
|
+
);
|
|
2109
|
+
enableEncryption = answers_enable_encryption.enableEncryption;
|
|
2110
|
+
}
|
|
2111
|
+
if (enableEncryption && !encryption_key_defined && !environment_exists) {
|
|
2112
|
+
log(
|
|
2113
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2114
|
+
import_kleur4.default.bold().yellow(" Disk encryption is enabled")
|
|
2115
|
+
);
|
|
2116
|
+
await promptAndStoreAnswer(diskQuestions, existingValues);
|
|
2117
|
+
} else {
|
|
2118
|
+
if (!enableEncryption && !encryption_key_defined && environment_exists) {
|
|
2119
|
+
log(
|
|
2120
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2121
|
+
import_kleur4.default.bold().grey(
|
|
2122
|
+
`Environment ${environment} is already configured, skipping disk encryption question`
|
|
2123
|
+
)
|
|
1839
2124
|
);
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
2125
|
+
}
|
|
2126
|
+
const DISK_SPACE = findExistingValue(
|
|
2127
|
+
"DISK_SPACE",
|
|
2128
|
+
"VARIABLE",
|
|
2129
|
+
"ENVIRONMENT",
|
|
2130
|
+
existingValues
|
|
2131
|
+
);
|
|
2132
|
+
if (!DISK_SPACE) {
|
|
2133
|
+
log(
|
|
2134
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2135
|
+
import_kleur4.default.bold().grey("All available disk space at /data will be used")
|
|
1844
2136
|
);
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
octokit,
|
|
1851
|
-
githubOrganisation,
|
|
1852
|
-
githubRepository
|
|
2137
|
+
} else {
|
|
2138
|
+
log(
|
|
2139
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2140
|
+
import_kleur4.default.bold().yellow("Variable DISK_SPACE is read-only, allocated space:"),
|
|
2141
|
+
DISK_SPACE?.value
|
|
1853
2142
|
);
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
import_dotenv2.default.config({
|
|
1902
|
-
path: `${process.cwd()}/.env.${environment}`
|
|
1903
|
-
});
|
|
1904
|
-
await createEnvironment(
|
|
1905
|
-
octokit,
|
|
1906
|
-
environment,
|
|
1907
|
-
githubOrganisation,
|
|
1908
|
-
githubRepository
|
|
1909
|
-
);
|
|
1910
|
-
const repositoryId = await getRepositoryId(
|
|
1911
|
-
octokit,
|
|
1912
|
-
githubOrganisation,
|
|
1913
|
-
githubRepository
|
|
1914
|
-
);
|
|
1915
|
-
const existingRepositorySecrets = await listRepositorySecrets(
|
|
1916
|
-
octokit,
|
|
1917
|
-
githubOrganisation,
|
|
1918
|
-
githubRepository
|
|
1919
|
-
);
|
|
1920
|
-
const existingRepositoryVariables = await listRepositoryVariables(
|
|
1921
|
-
octokit,
|
|
1922
|
-
githubOrganisation,
|
|
1923
|
-
githubRepository
|
|
1924
|
-
);
|
|
1925
|
-
const existingEnvironmentVariables = await listEnvironmentVariables(
|
|
1926
|
-
octokit,
|
|
1927
|
-
repositoryId,
|
|
1928
|
-
environment
|
|
1929
|
-
);
|
|
1930
|
-
const existingEnvironmentSecrets = await listEnvironmentSecrets(
|
|
1931
|
-
octokit,
|
|
1932
|
-
githubOrganisation,
|
|
1933
|
-
repositoryId,
|
|
1934
|
-
environment
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
let backupHost = findExistingValue("BACKUP_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2146
|
+
let backupType = "";
|
|
2147
|
+
let restoreEnvironmentName = findExistingValue(
|
|
2148
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2149
|
+
"VARIABLE",
|
|
2150
|
+
"ENVIRONMENT",
|
|
2151
|
+
existingValues
|
|
2152
|
+
)?.value;
|
|
2153
|
+
let restoreHost = findExistingValue("RESTORE_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2154
|
+
let restoreType = findExistingValue(
|
|
2155
|
+
"RESTORE_ENVIRONMENT_MODE",
|
|
2156
|
+
"VARIABLE",
|
|
2157
|
+
"ENVIRONMENT",
|
|
2158
|
+
existingValues
|
|
2159
|
+
)?.value || process.env.RESTORE_ENVIRONMENT_MODE || "dump";
|
|
2160
|
+
log("\n", import_kleur4.default.bold().underline("Backup"));
|
|
2161
|
+
let configureBackup = backupHost ? true : false;
|
|
2162
|
+
if (!configureBackup && !restoreEnvironmentName) {
|
|
2163
|
+
configureBackup = await confirm2({
|
|
2164
|
+
message: "Do you want to configure backup?",
|
|
2165
|
+
default: Boolean(process.env.CONFIGURE_BACKUP)
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
let backupHostPrivateKey = "";
|
|
2169
|
+
let backupHostPublicKey = "";
|
|
2170
|
+
if (configureBackup) {
|
|
2171
|
+
const backupAnswers = await promptAndStoreAnswer(
|
|
2172
|
+
backupQuestions,
|
|
2173
|
+
existingValues
|
|
2174
|
+
);
|
|
2175
|
+
const backupHostPrivateKeyExists = findExistingValue(
|
|
2176
|
+
"BACKUP_HOST_PRIVATE_KEY",
|
|
2177
|
+
"SECRET",
|
|
2178
|
+
"ENVIRONMENT",
|
|
2179
|
+
existingValues
|
|
2180
|
+
);
|
|
2181
|
+
backupType = backupAnswers.backupType;
|
|
2182
|
+
backupHost = backupAnswers.backupHost || backupHost;
|
|
2183
|
+
if (!backupHostPrivateKeyExists) {
|
|
2184
|
+
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2185
|
+
backupHostPublicKey = publicKey;
|
|
2186
|
+
backupHostPrivateKey = privateKey;
|
|
2187
|
+
log(
|
|
2188
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2189
|
+
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
1935
2190
|
);
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
2191
|
+
}
|
|
2192
|
+
} else {
|
|
2193
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
2194
|
+
}
|
|
2195
|
+
log("\n", import_kleur4.default.bold().underline("Restore"));
|
|
2196
|
+
let configureRestore = restoreEnvironmentName ? true : false;
|
|
2197
|
+
if (!restoreEnvironmentName && !configureBackup) {
|
|
2198
|
+
configureRestore = await confirm2({
|
|
2199
|
+
message: "Do you want to configure restore?",
|
|
2200
|
+
default: Boolean(process.env.CONFIGURE_RESTORE)
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
if (configureRestore) {
|
|
2204
|
+
const env_list_filtered = existingEnvironments.filter(
|
|
2205
|
+
(env) => env !== environment
|
|
2206
|
+
);
|
|
2207
|
+
restoreEnvironmentName = await selectWithCustom({
|
|
2208
|
+
message: "What is the name of your environment to restore?",
|
|
2209
|
+
choices: env_list_filtered.map((env) => ({
|
|
2210
|
+
name: env,
|
|
2211
|
+
value: env
|
|
2212
|
+
})),
|
|
2213
|
+
initial: restoreEnvironmentName
|
|
2214
|
+
});
|
|
2215
|
+
restoreType = await select3({
|
|
2216
|
+
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2217
|
+
choices: [
|
|
2218
|
+
{
|
|
2219
|
+
name: "Full dump (daily full database backup)",
|
|
2220
|
+
value: "dump"
|
|
2221
|
+
},
|
|
2222
|
+
{
|
|
2223
|
+
name: "Differential (weekly full, daily diff backup)",
|
|
2224
|
+
value: "differential"
|
|
2225
|
+
}
|
|
2226
|
+
]
|
|
2227
|
+
});
|
|
2228
|
+
restoreHost = await input3({
|
|
2229
|
+
message: "What is the host/IP address of the restore backup server?",
|
|
2230
|
+
default: restoreHost
|
|
2231
|
+
});
|
|
2232
|
+
} else {
|
|
2233
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2234
|
+
}
|
|
2235
|
+
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2236
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2237
|
+
const sentryDSNExists = findExistingValue(
|
|
2238
|
+
"SENTRY_DSN",
|
|
2239
|
+
"SECRET",
|
|
2240
|
+
"ENVIRONMENT",
|
|
2241
|
+
existingValues
|
|
2242
|
+
);
|
|
2243
|
+
log("\n", import_kleur4.default.bold().underline("Sentry"));
|
|
2244
|
+
if (sentryDSNExists) {
|
|
2245
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2246
|
+
} else {
|
|
2247
|
+
const { useSentry } = await (0, import_prompts2.default)([
|
|
2248
|
+
{
|
|
2249
|
+
name: "useSentry",
|
|
2250
|
+
type: "confirm",
|
|
2251
|
+
message: "Do you want to use Sentry?",
|
|
2252
|
+
initial: Boolean(process.env.SENTRY_DNS)
|
|
1966
2253
|
}
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
2254
|
+
]);
|
|
2255
|
+
if (useSentry) {
|
|
2256
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2260
|
+
await promptAndStoreAnswer(metabaseAdminQuestions, existingValues);
|
|
2261
|
+
log("\n", import_kleur4.default.bold().underline("SMTP"));
|
|
2262
|
+
await promptAndStoreAnswer(emailQuestions, existingValues);
|
|
2263
|
+
const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
|
|
2264
|
+
return { ...acc, ...answer };
|
|
2265
|
+
});
|
|
2266
|
+
const answerOrExisting = (variable, existingValue, fn) => fn(variable || existingValue?.value) || "";
|
|
2267
|
+
function findExistingOrDefine(name, type, scope, newValue) {
|
|
2268
|
+
return findExistingValue(name, type, scope, existingValues) ? null : process.env[name] || newValue;
|
|
2269
|
+
}
|
|
2270
|
+
const derivedUpdates = [
|
|
2271
|
+
{
|
|
2272
|
+
name: "GH_ENCRYPTION_PASSWORD",
|
|
2273
|
+
type: "SECRET",
|
|
2274
|
+
didExist: findExistingValue(
|
|
2275
|
+
"GH_ENCRYPTION_PASSWORD",
|
|
2276
|
+
"SECRET",
|
|
2277
|
+
"REPOSITORY",
|
|
1973
2278
|
existingValues
|
|
1974
|
-
)
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2279
|
+
),
|
|
2280
|
+
value: findExistingOrDefine(
|
|
2281
|
+
"GH_ENCRYPTION_PASSWORD",
|
|
2282
|
+
"SECRET",
|
|
2283
|
+
"REPOSITORY",
|
|
2284
|
+
generateLongPassword()
|
|
2285
|
+
),
|
|
2286
|
+
scope: "REPOSITORY"
|
|
2287
|
+
}
|
|
2288
|
+
];
|
|
2289
|
+
derivedUpdates.push({
|
|
2290
|
+
name: "NOTIFICATION_TRANSPORT",
|
|
2291
|
+
type: "VARIABLE",
|
|
2292
|
+
didExist: findExistingValue(
|
|
2293
|
+
"NOTIFICATION_TRANSPORT",
|
|
2294
|
+
"VARIABLE",
|
|
2295
|
+
"ENVIRONMENT",
|
|
2296
|
+
existingValues
|
|
2297
|
+
),
|
|
2298
|
+
value: findExistingOrDefine(
|
|
2299
|
+
"NOTIFICATION_TRANSPORT",
|
|
2300
|
+
"VARIABLE",
|
|
2301
|
+
"ENVIRONMENT",
|
|
2302
|
+
"email"
|
|
2303
|
+
),
|
|
2304
|
+
scope: "ENVIRONMENT"
|
|
2305
|
+
});
|
|
2306
|
+
derivedUpdates.push(...ssl_answers);
|
|
2307
|
+
if (configureBackup) {
|
|
2308
|
+
derivedUpdates.push({
|
|
2309
|
+
name: "BACKUP_ENCRYPTION_PASSPHRASE",
|
|
2310
|
+
type: "SECRET",
|
|
2311
|
+
didExist: findExistingValue(
|
|
2312
|
+
"BACKUP_ENCRYPTION_PASSPHRASE",
|
|
1981
2313
|
"SECRET",
|
|
1982
2314
|
"ENVIRONMENT",
|
|
1983
2315
|
existingValues
|
|
1984
|
-
)
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
ssl_answers = await askQuestionWithEditor(
|
|
2001
|
-
staticSSLCertQuestions,
|
|
2002
|
-
existingEnvironmentSecrets
|
|
2003
|
-
);
|
|
2004
|
-
}
|
|
2005
|
-
log("\n", import_kleur4.default.bold().underline("Storage"), "\n");
|
|
2006
|
-
let enableEncryption = false;
|
|
2007
|
-
const encryption_key_defined = findExistingValue(
|
|
2008
|
-
"ENCRYPTION_KEY",
|
|
2316
|
+
),
|
|
2317
|
+
value: findExistingOrDefine(
|
|
2318
|
+
"BACKUP_ENCRYPTION_PASSPHRASE",
|
|
2319
|
+
"SECRET",
|
|
2320
|
+
"ENVIRONMENT",
|
|
2321
|
+
generateLongPassword()
|
|
2322
|
+
),
|
|
2323
|
+
scope: "ENVIRONMENT"
|
|
2324
|
+
});
|
|
2325
|
+
}
|
|
2326
|
+
const applicationServerUpdates = [
|
|
2327
|
+
{
|
|
2328
|
+
name: "ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2329
|
+
type: "SECRET",
|
|
2330
|
+
didExist: findExistingValue(
|
|
2331
|
+
"ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2009
2332
|
"SECRET",
|
|
2010
2333
|
"ENVIRONMENT",
|
|
2011
2334
|
existingValues
|
|
2012
|
-
)
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2335
|
+
),
|
|
2336
|
+
value: findExistingOrDefine(
|
|
2337
|
+
"ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2338
|
+
"SECRET",
|
|
2339
|
+
"ENVIRONMENT",
|
|
2340
|
+
generateLongPassword()
|
|
2341
|
+
),
|
|
2342
|
+
scope: "ENVIRONMENT"
|
|
2343
|
+
},
|
|
2344
|
+
{
|
|
2345
|
+
name: "KIBANA_SYSTEM_PASSWORD",
|
|
2346
|
+
type: "SECRET",
|
|
2347
|
+
didExist: findExistingValue(
|
|
2348
|
+
"KIBANA_SYSTEM_PASSWORD",
|
|
2349
|
+
"SECRET",
|
|
2350
|
+
"ENVIRONMENT",
|
|
2351
|
+
existingValues
|
|
2352
|
+
),
|
|
2353
|
+
value: findExistingOrDefine(
|
|
2354
|
+
"KIBANA_SYSTEM_PASSWORD",
|
|
2355
|
+
"SECRET",
|
|
2356
|
+
"ENVIRONMENT",
|
|
2357
|
+
generateLongPassword()
|
|
2358
|
+
),
|
|
2359
|
+
scope: "ENVIRONMENT"
|
|
2360
|
+
},
|
|
2361
|
+
{
|
|
2362
|
+
name: "MINIO_ROOT_USER",
|
|
2363
|
+
type: "SECRET",
|
|
2364
|
+
didExist: findExistingValue(
|
|
2365
|
+
"MINIO_ROOT_USER",
|
|
2366
|
+
"SECRET",
|
|
2367
|
+
"ENVIRONMENT",
|
|
2368
|
+
existingValues
|
|
2369
|
+
),
|
|
2370
|
+
value: findExistingOrDefine(
|
|
2371
|
+
"MINIO_ROOT_USER",
|
|
2372
|
+
"SECRET",
|
|
2373
|
+
"ENVIRONMENT",
|
|
2374
|
+
generateLongPassword()
|
|
2375
|
+
),
|
|
2376
|
+
scope: "ENVIRONMENT"
|
|
2377
|
+
},
|
|
2378
|
+
{
|
|
2379
|
+
name: "MINIO_ROOT_PASSWORD",
|
|
2380
|
+
type: "SECRET",
|
|
2381
|
+
didExist: findExistingValue(
|
|
2382
|
+
"MINIO_ROOT_PASSWORD",
|
|
2383
|
+
"SECRET",
|
|
2384
|
+
"ENVIRONMENT",
|
|
2385
|
+
existingValues
|
|
2386
|
+
),
|
|
2387
|
+
value: findExistingOrDefine(
|
|
2388
|
+
"MINIO_ROOT_PASSWORD",
|
|
2389
|
+
"SECRET",
|
|
2390
|
+
"ENVIRONMENT",
|
|
2391
|
+
generateLongPassword()
|
|
2392
|
+
),
|
|
2393
|
+
scope: "ENVIRONMENT"
|
|
2394
|
+
},
|
|
2395
|
+
{
|
|
2396
|
+
name: "POSTGRES_USER",
|
|
2397
|
+
type: "SECRET",
|
|
2398
|
+
didExist: findExistingValue(
|
|
2399
|
+
"POSTGRES_USER",
|
|
2400
|
+
"SECRET",
|
|
2401
|
+
"ENVIRONMENT",
|
|
2402
|
+
existingValues
|
|
2403
|
+
),
|
|
2404
|
+
value: findExistingOrDefine(
|
|
2405
|
+
"POSTGRES_USER",
|
|
2406
|
+
"SECRET",
|
|
2407
|
+
"ENVIRONMENT",
|
|
2408
|
+
generateLongPassword()
|
|
2409
|
+
),
|
|
2410
|
+
scope: "ENVIRONMENT"
|
|
2411
|
+
},
|
|
2412
|
+
{
|
|
2413
|
+
name: "POSTGRES_PASSWORD",
|
|
2414
|
+
type: "SECRET",
|
|
2415
|
+
didExist: findExistingValue(
|
|
2416
|
+
"POSTGRES_PASSWORD",
|
|
2417
|
+
"SECRET",
|
|
2418
|
+
"ENVIRONMENT",
|
|
2419
|
+
existingValues
|
|
2420
|
+
),
|
|
2421
|
+
value: findExistingOrDefine(
|
|
2422
|
+
"POSTGRES_PASSWORD",
|
|
2423
|
+
"SECRET",
|
|
2424
|
+
"ENVIRONMENT",
|
|
2425
|
+
generateLongPassword()
|
|
2426
|
+
),
|
|
2427
|
+
scope: "ENVIRONMENT"
|
|
2428
|
+
},
|
|
2429
|
+
{
|
|
2430
|
+
name: "SUPER_USER_PASSWORD",
|
|
2431
|
+
type: "SECRET",
|
|
2432
|
+
didExist: findExistingValue(
|
|
2433
|
+
"SUPER_USER_PASSWORD",
|
|
2434
|
+
"SECRET",
|
|
2435
|
+
"ENVIRONMENT",
|
|
2436
|
+
existingValues
|
|
2437
|
+
),
|
|
2438
|
+
value: findExistingOrDefine(
|
|
2439
|
+
"SUPER_USER_PASSWORD",
|
|
2440
|
+
"SECRET",
|
|
2441
|
+
"ENVIRONMENT",
|
|
2442
|
+
generateLongPassword()
|
|
2443
|
+
),
|
|
2444
|
+
scope: "ENVIRONMENT"
|
|
2445
|
+
},
|
|
2446
|
+
{
|
|
2447
|
+
type: "VARIABLE",
|
|
2448
|
+
name: "ACTIVATE_USERS",
|
|
2449
|
+
value: "production" === environment_type ? "false" : "true",
|
|
2450
|
+
didExist: findExistingValue(
|
|
2451
|
+
"ACTIVATE_USERS",
|
|
2065
2452
|
"VARIABLE",
|
|
2066
2453
|
"ENVIRONMENT",
|
|
2067
2454
|
existingValues
|
|
2068
|
-
)
|
|
2069
|
-
|
|
2070
|
-
|
|
2455
|
+
),
|
|
2456
|
+
scope: "ENVIRONMENT"
|
|
2457
|
+
},
|
|
2458
|
+
{
|
|
2459
|
+
type: "VARIABLE",
|
|
2460
|
+
name: "COUNTRY_CONFIG_HOST",
|
|
2461
|
+
value: answerOrExisting(
|
|
2462
|
+
allAnswers.domain,
|
|
2463
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2464
|
+
(val) => `https://countryconfig.${val}`
|
|
2465
|
+
),
|
|
2466
|
+
didExist: findExistingValue(
|
|
2467
|
+
"COUNTRY_CONFIG_HOST",
|
|
2071
2468
|
"VARIABLE",
|
|
2072
2469
|
"ENVIRONMENT",
|
|
2073
2470
|
existingValues
|
|
2074
|
-
)
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
existingValues
|
|
2090
|
-
);
|
|
2091
|
-
const backupHostPrivateKeyExists = findExistingValue(
|
|
2092
|
-
"BACKUP_HOST_PRIVATE_KEY",
|
|
2093
|
-
"SECRET",
|
|
2094
|
-
"ENVIRONMENT",
|
|
2095
|
-
existingValues
|
|
2096
|
-
);
|
|
2097
|
-
backupType = backupAnswers.backupType;
|
|
2098
|
-
backupHost = backupAnswers.backupHost || backupHost;
|
|
2099
|
-
if (!backupHostPrivateKeyExists) {
|
|
2100
|
-
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2101
|
-
backupHostPublicKey = publicKey;
|
|
2102
|
-
backupHostPrivateKey = privateKey;
|
|
2103
|
-
log(
|
|
2104
|
-
import_kleur4.default.bold().green("\u2714"),
|
|
2105
|
-
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
2106
|
-
);
|
|
2107
|
-
}
|
|
2108
|
-
} else {
|
|
2109
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
2110
|
-
}
|
|
2111
|
-
log("\n", import_kleur4.default.bold().underline("Restore"));
|
|
2112
|
-
let configureRestore = restoreEnvironmentName ? true : false;
|
|
2113
|
-
if (!restoreEnvironmentName && !configureBackup) {
|
|
2114
|
-
configureRestore = await confirm2({
|
|
2115
|
-
message: "Do you want to configure restore?",
|
|
2116
|
-
default: Boolean(process.env.CONFIGURE_RESTORE)
|
|
2117
|
-
});
|
|
2118
|
-
}
|
|
2119
|
-
if (configureRestore) {
|
|
2120
|
-
const env_list_filtered = existingEnvironments.filter(
|
|
2121
|
-
(env) => env !== environment
|
|
2122
|
-
);
|
|
2123
|
-
restoreEnvironmentName = await selectWithCustom({
|
|
2124
|
-
message: "What is the name of your environment to restore?",
|
|
2125
|
-
choices: env_list_filtered.map((env) => ({
|
|
2126
|
-
name: env,
|
|
2127
|
-
value: env
|
|
2128
|
-
})),
|
|
2129
|
-
initial: restoreEnvironmentName
|
|
2130
|
-
});
|
|
2131
|
-
restoreType = await select3({
|
|
2132
|
-
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2133
|
-
choices: [
|
|
2134
|
-
{
|
|
2135
|
-
name: "Full dump (daily full database backup)",
|
|
2136
|
-
value: "dump"
|
|
2137
|
-
},
|
|
2138
|
-
{
|
|
2139
|
-
name: "Differential (weekly full, daily diff backup)",
|
|
2140
|
-
value: "differential"
|
|
2141
|
-
}
|
|
2142
|
-
]
|
|
2143
|
-
});
|
|
2144
|
-
} else {
|
|
2145
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2146
|
-
}
|
|
2147
|
-
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2148
|
-
await promptAndStoreAnswer(
|
|
2149
|
-
environment,
|
|
2150
|
-
databaseAndMonitoringQuestions,
|
|
2471
|
+
),
|
|
2472
|
+
scope: "ENVIRONMENT"
|
|
2473
|
+
},
|
|
2474
|
+
{
|
|
2475
|
+
type: "VARIABLE",
|
|
2476
|
+
name: "GATEWAY_HOST",
|
|
2477
|
+
value: answerOrExisting(
|
|
2478
|
+
allAnswers.domain,
|
|
2479
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2480
|
+
(val) => `https://gateway.${val}`
|
|
2481
|
+
),
|
|
2482
|
+
didExist: findExistingValue(
|
|
2483
|
+
"GATEWAY_HOST",
|
|
2484
|
+
"VARIABLE",
|
|
2485
|
+
"ENVIRONMENT",
|
|
2151
2486
|
existingValues
|
|
2152
|
-
)
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2487
|
+
),
|
|
2488
|
+
scope: "ENVIRONMENT"
|
|
2489
|
+
},
|
|
2490
|
+
{
|
|
2491
|
+
type: "VARIABLE",
|
|
2492
|
+
name: "CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2493
|
+
value: answerOrExisting(
|
|
2494
|
+
allAnswers.domain,
|
|
2495
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2496
|
+
(val) => `*.${val}`
|
|
2497
|
+
),
|
|
2498
|
+
didExist: findExistingValue(
|
|
2499
|
+
"CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2500
|
+
"VARIABLE",
|
|
2156
2501
|
"ENVIRONMENT",
|
|
2157
2502
|
existingValues
|
|
2158
|
-
)
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
}
|
|
2174
|
-
}
|
|
2175
|
-
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2176
|
-
await promptAndStoreAnswer(
|
|
2177
|
-
environment,
|
|
2178
|
-
metabaseAdminQuestions,
|
|
2503
|
+
),
|
|
2504
|
+
scope: "ENVIRONMENT"
|
|
2505
|
+
},
|
|
2506
|
+
{
|
|
2507
|
+
type: "VARIABLE",
|
|
2508
|
+
name: "CLIENT_APP_URL",
|
|
2509
|
+
value: answerOrExisting(
|
|
2510
|
+
allAnswers.domain,
|
|
2511
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2512
|
+
(val) => `https://register.${val}`
|
|
2513
|
+
),
|
|
2514
|
+
didExist: findExistingValue(
|
|
2515
|
+
"CLIENT_APP_URL",
|
|
2516
|
+
"VARIABLE",
|
|
2517
|
+
"ENVIRONMENT",
|
|
2179
2518
|
existingValues
|
|
2180
|
-
)
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
scope: "REPOSITORY"
|
|
2207
|
-
}
|
|
2208
|
-
];
|
|
2209
|
-
derivedUpdates.push({
|
|
2210
|
-
name: "NOTIFICATION_TRANSPORT",
|
|
2211
|
-
type: "VARIABLE",
|
|
2212
|
-
didExist: findExistingValue(
|
|
2213
|
-
"NOTIFICATION_TRANSPORT",
|
|
2519
|
+
),
|
|
2520
|
+
scope: "ENVIRONMENT"
|
|
2521
|
+
},
|
|
2522
|
+
{
|
|
2523
|
+
type: "VARIABLE",
|
|
2524
|
+
name: "LOGIN_URL",
|
|
2525
|
+
value: answerOrExisting(
|
|
2526
|
+
allAnswers.domain,
|
|
2527
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2528
|
+
(val) => `https://login.${val}`
|
|
2529
|
+
),
|
|
2530
|
+
didExist: findExistingValue(
|
|
2531
|
+
"LOGIN_URL",
|
|
2532
|
+
"VARIABLE",
|
|
2533
|
+
"ENVIRONMENT",
|
|
2534
|
+
existingValues
|
|
2535
|
+
),
|
|
2536
|
+
scope: "ENVIRONMENT"
|
|
2537
|
+
},
|
|
2538
|
+
{
|
|
2539
|
+
type: "VARIABLE",
|
|
2540
|
+
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2541
|
+
value: answerOrExisting(
|
|
2542
|
+
restoreEnvironmentName,
|
|
2543
|
+
findExistingValue(
|
|
2544
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2214
2545
|
"VARIABLE",
|
|
2215
2546
|
"ENVIRONMENT",
|
|
2216
2547
|
existingValues
|
|
2217
2548
|
),
|
|
2218
|
-
|
|
2219
|
-
|
|
2549
|
+
(val) => val || ""
|
|
2550
|
+
),
|
|
2551
|
+
didExist: findExistingValue(
|
|
2552
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2553
|
+
"VARIABLE",
|
|
2554
|
+
"ENVIRONMENT",
|
|
2555
|
+
existingValues
|
|
2556
|
+
),
|
|
2557
|
+
scope: "ENVIRONMENT"
|
|
2558
|
+
},
|
|
2559
|
+
{
|
|
2560
|
+
type: "VARIABLE",
|
|
2561
|
+
name: "RESTORE_HOST",
|
|
2562
|
+
value: answerOrExisting(
|
|
2563
|
+
restoreHost,
|
|
2564
|
+
findExistingValue(
|
|
2565
|
+
"RESTORE_HOST",
|
|
2220
2566
|
"VARIABLE",
|
|
2221
2567
|
"ENVIRONMENT",
|
|
2222
|
-
|
|
2568
|
+
existingValues
|
|
2223
2569
|
),
|
|
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
|
-
"ENVIRONMENT",
|
|
2345
|
-
generateLongPassword()
|
|
2346
|
-
),
|
|
2347
|
-
scope: "ENVIRONMENT"
|
|
2348
|
-
},
|
|
2349
|
-
{
|
|
2350
|
-
name: "SUPER_USER_PASSWORD",
|
|
2351
|
-
type: "SECRET",
|
|
2352
|
-
didExist: findExistingValue(
|
|
2353
|
-
"SUPER_USER_PASSWORD",
|
|
2354
|
-
"SECRET",
|
|
2355
|
-
"ENVIRONMENT",
|
|
2356
|
-
existingValues
|
|
2357
|
-
),
|
|
2358
|
-
value: findExistingOrDefine(
|
|
2359
|
-
"SUPER_USER_PASSWORD",
|
|
2360
|
-
"SECRET",
|
|
2361
|
-
"ENVIRONMENT",
|
|
2362
|
-
generateLongPassword()
|
|
2363
|
-
),
|
|
2364
|
-
scope: "ENVIRONMENT"
|
|
2365
|
-
},
|
|
2366
|
-
{
|
|
2367
|
-
type: "VARIABLE",
|
|
2368
|
-
name: "ACTIVATE_USERS",
|
|
2369
|
-
value: "production" === environment_type ? "false" : "true",
|
|
2370
|
-
didExist: findExistingValue(
|
|
2371
|
-
"ACTIVATE_USERS",
|
|
2372
|
-
"VARIABLE",
|
|
2373
|
-
"ENVIRONMENT",
|
|
2374
|
-
existingValues
|
|
2375
|
-
),
|
|
2376
|
-
scope: "ENVIRONMENT"
|
|
2377
|
-
},
|
|
2378
|
-
{
|
|
2379
|
-
type: "VARIABLE",
|
|
2380
|
-
name: "COUNTRY_CONFIG_HOST",
|
|
2381
|
-
value: answerOrExisting(
|
|
2382
|
-
allAnswers.domain,
|
|
2383
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2384
|
-
(val) => `https://countryconfig.${val}`
|
|
2385
|
-
),
|
|
2386
|
-
didExist: findExistingValue(
|
|
2387
|
-
"COUNTRY_CONFIG_HOST",
|
|
2388
|
-
"VARIABLE",
|
|
2389
|
-
"ENVIRONMENT",
|
|
2390
|
-
existingValues
|
|
2391
|
-
),
|
|
2392
|
-
scope: "ENVIRONMENT"
|
|
2393
|
-
},
|
|
2394
|
-
{
|
|
2395
|
-
type: "VARIABLE",
|
|
2396
|
-
name: "GATEWAY_HOST",
|
|
2397
|
-
value: answerOrExisting(
|
|
2398
|
-
allAnswers.domain,
|
|
2399
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2400
|
-
(val) => `https://gateway.${val}`
|
|
2401
|
-
),
|
|
2402
|
-
didExist: findExistingValue(
|
|
2403
|
-
"GATEWAY_HOST",
|
|
2404
|
-
"VARIABLE",
|
|
2405
|
-
"ENVIRONMENT",
|
|
2406
|
-
existingValues
|
|
2407
|
-
),
|
|
2408
|
-
scope: "ENVIRONMENT"
|
|
2409
|
-
},
|
|
2410
|
-
{
|
|
2411
|
-
type: "VARIABLE",
|
|
2412
|
-
name: "CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2413
|
-
value: answerOrExisting(
|
|
2414
|
-
allAnswers.domain,
|
|
2415
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2416
|
-
(val) => `*.${val}`
|
|
2417
|
-
),
|
|
2418
|
-
didExist: findExistingValue(
|
|
2419
|
-
"CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2420
|
-
"VARIABLE",
|
|
2421
|
-
"ENVIRONMENT",
|
|
2422
|
-
existingValues
|
|
2423
|
-
),
|
|
2424
|
-
scope: "ENVIRONMENT"
|
|
2425
|
-
},
|
|
2426
|
-
{
|
|
2427
|
-
type: "VARIABLE",
|
|
2428
|
-
name: "CLIENT_APP_URL",
|
|
2429
|
-
value: answerOrExisting(
|
|
2430
|
-
allAnswers.domain,
|
|
2431
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2432
|
-
(val) => `https://register.${val}`
|
|
2433
|
-
),
|
|
2434
|
-
didExist: findExistingValue(
|
|
2435
|
-
"CLIENT_APP_URL",
|
|
2436
|
-
"VARIABLE",
|
|
2437
|
-
"ENVIRONMENT",
|
|
2438
|
-
existingValues
|
|
2439
|
-
),
|
|
2440
|
-
scope: "ENVIRONMENT"
|
|
2441
|
-
},
|
|
2442
|
-
{
|
|
2443
|
-
type: "VARIABLE",
|
|
2444
|
-
name: "LOGIN_URL",
|
|
2445
|
-
value: answerOrExisting(
|
|
2446
|
-
allAnswers.domain,
|
|
2447
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2448
|
-
(val) => `https://login.${val}`
|
|
2449
|
-
),
|
|
2450
|
-
didExist: findExistingValue(
|
|
2451
|
-
"LOGIN_URL",
|
|
2452
|
-
"VARIABLE",
|
|
2453
|
-
"ENVIRONMENT",
|
|
2454
|
-
existingValues
|
|
2455
|
-
),
|
|
2456
|
-
scope: "ENVIRONMENT"
|
|
2457
|
-
},
|
|
2458
|
-
{
|
|
2459
|
-
type: "VARIABLE",
|
|
2460
|
-
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2461
|
-
value: answerOrExisting(
|
|
2462
|
-
restoreEnvironmentName,
|
|
2463
|
-
findExistingValue(
|
|
2464
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2465
|
-
"VARIABLE",
|
|
2466
|
-
"ENVIRONMENT",
|
|
2467
|
-
existingValues
|
|
2468
|
-
),
|
|
2469
|
-
(val) => val || ""
|
|
2470
|
-
),
|
|
2471
|
-
didExist: findExistingValue(
|
|
2472
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2473
|
-
"VARIABLE",
|
|
2474
|
-
"ENVIRONMENT",
|
|
2475
|
-
existingValues
|
|
2476
|
-
),
|
|
2477
|
-
scope: "ENVIRONMENT"
|
|
2478
|
-
}
|
|
2479
|
-
];
|
|
2480
|
-
if (enableEncryption) {
|
|
2481
|
-
applicationServerUpdates.push({
|
|
2482
|
-
name: "ENCRYPTION_KEY",
|
|
2483
|
-
type: "SECRET",
|
|
2484
|
-
didExist: findExistingValue(
|
|
2485
|
-
"ENCRYPTION_KEY",
|
|
2486
|
-
"SECRET",
|
|
2487
|
-
"ENVIRONMENT",
|
|
2488
|
-
existingValues
|
|
2489
|
-
),
|
|
2490
|
-
value: findExistingOrDefine(
|
|
2491
|
-
"ENCRYPTION_KEY",
|
|
2492
|
-
"SECRET",
|
|
2493
|
-
"ENVIRONMENT",
|
|
2494
|
-
generateLongPassword()
|
|
2495
|
-
),
|
|
2496
|
-
scope: "ENVIRONMENT"
|
|
2497
|
-
});
|
|
2498
|
-
}
|
|
2499
|
-
if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
|
|
2500
|
-
applicationServerUpdates.push({
|
|
2501
|
-
name: "BACKUP_HOST_PRIVATE_KEY",
|
|
2502
|
-
type: "SECRET",
|
|
2503
|
-
didExist: void 0,
|
|
2504
|
-
value: backupHostPrivateKey,
|
|
2505
|
-
scope: "ENVIRONMENT"
|
|
2506
|
-
});
|
|
2507
|
-
applicationServerUpdates.push({
|
|
2508
|
-
name: "BACKUP_HOST_PUBLIC_KEY",
|
|
2509
|
-
type: "SECRET",
|
|
2510
|
-
didExist: void 0,
|
|
2511
|
-
value: backupHostPublicKey,
|
|
2512
|
-
scope: "ENVIRONMENT"
|
|
2513
|
-
});
|
|
2514
|
-
}
|
|
2515
|
-
derivedUpdates.push(...applicationServerUpdates);
|
|
2516
|
-
const updates = getAnswers(existingValues).concat(
|
|
2517
|
-
...derivedUpdates.filter(
|
|
2518
|
-
(update) => update.value !== null
|
|
2519
|
-
)
|
|
2520
|
-
).filter(
|
|
2521
|
-
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2522
|
-
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2523
|
-
);
|
|
2524
|
-
storeSecrets(environment, updates);
|
|
2525
|
-
const newSecrets = updates.filter(
|
|
2526
|
-
(update) => update.type === "SECRET" && !update.didExist
|
|
2527
|
-
);
|
|
2528
|
-
const updatedSecrets = updates.filter(
|
|
2529
|
-
(update) => update.type === "SECRET" && Boolean(update.didExist)
|
|
2530
|
-
);
|
|
2531
|
-
const newVariables = updates.filter(
|
|
2532
|
-
(update) => update.type === "VARIABLE" && !update.didExist
|
|
2533
|
-
);
|
|
2534
|
-
const updatedVariables = updates.filter(
|
|
2535
|
-
(update) => update.type === "VARIABLE" && Boolean(update.didExist)
|
|
2536
|
-
);
|
|
2537
|
-
const unknownVariables = existingValues.filter((value) => {
|
|
2538
|
-
return !ALL_QUESTIONS.find(
|
|
2539
|
-
(question) => question.valueLabel === value.name && question.valueType === value.type && question.scope === value.scope
|
|
2540
|
-
);
|
|
2541
|
-
});
|
|
2542
|
-
log("");
|
|
2543
|
-
if (newSecrets.length > 0) {
|
|
2544
|
-
log(
|
|
2545
|
-
import_kleur4.default.yellow(
|
|
2546
|
-
`The following secrets will be added to Github for environment ${environment}:`
|
|
2547
|
-
)
|
|
2548
|
-
);
|
|
2549
|
-
newSecrets.filter(({ scope }) => scope === "ENVIRONMENT").forEach((secret) => {
|
|
2550
|
-
log(secret.name, "=", secret.value);
|
|
2551
|
-
});
|
|
2552
|
-
log("");
|
|
2553
|
-
log(
|
|
2554
|
-
import_kleur4.default.yellow(`The following secrets will be added to Github repository:`)
|
|
2555
|
-
);
|
|
2556
|
-
newSecrets.filter(({ scope }) => scope === "REPOSITORY").forEach((secret) => {
|
|
2557
|
-
log(secret.name, "=", secret.value);
|
|
2558
|
-
});
|
|
2559
|
-
log("");
|
|
2560
|
-
}
|
|
2561
|
-
if (updatedSecrets.length > 0) {
|
|
2562
|
-
log(
|
|
2563
|
-
import_kleur4.default.yellow(
|
|
2564
|
-
`The following secrets will be updated in Github for environment ${environment}:`
|
|
2565
|
-
)
|
|
2566
|
-
);
|
|
2567
|
-
updatedSecrets.forEach((secret) => {
|
|
2568
|
-
log(secret.name, "=", secret.value);
|
|
2569
|
-
});
|
|
2570
|
-
log("");
|
|
2571
|
-
}
|
|
2572
|
-
if (newVariables.length > 0) {
|
|
2573
|
-
log(
|
|
2574
|
-
import_kleur4.default.yellow(
|
|
2575
|
-
`The following variables will be added to Github for environment ${environment}:`
|
|
2576
|
-
)
|
|
2577
|
-
);
|
|
2578
|
-
newVariables.forEach((variable) => {
|
|
2579
|
-
log(variable.name, "=", variable.value);
|
|
2580
|
-
});
|
|
2581
|
-
log("");
|
|
2582
|
-
}
|
|
2583
|
-
if (updatedVariables.length > 0) {
|
|
2584
|
-
log(
|
|
2585
|
-
import_kleur4.default.yellow(
|
|
2586
|
-
`The following variables will be updated in Github for environment ${environment}:`
|
|
2587
|
-
)
|
|
2588
|
-
);
|
|
2589
|
-
updatedVariables.forEach((variable) => {
|
|
2590
|
-
log(
|
|
2591
|
-
variable.name,
|
|
2592
|
-
"=",
|
|
2593
|
-
variable.value,
|
|
2594
|
-
`(was ${variable.didExist?.value})`
|
|
2595
|
-
);
|
|
2596
|
-
});
|
|
2597
|
-
log("");
|
|
2598
|
-
}
|
|
2599
|
-
if (unknownVariables.length > 0) {
|
|
2600
|
-
log(
|
|
2601
|
-
import_kleur4.default.yellow(
|
|
2602
|
-
`The following unknown variables/secrets were stored in Github are not managed by this script:`
|
|
2603
|
-
)
|
|
2604
|
-
);
|
|
2605
|
-
log("");
|
|
2606
|
-
log(import_kleur4.default.blue(`Repository:`));
|
|
2607
|
-
unknownVariables.filter(({ scope }) => scope === "REPOSITORY").forEach((variable) => {
|
|
2608
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2609
|
-
});
|
|
2610
|
-
log("");
|
|
2611
|
-
log(import_kleur4.default.blue(`Environment:`));
|
|
2612
|
-
unknownVariables.filter(({ scope }) => scope === "ENVIRONMENT").forEach((variable) => {
|
|
2613
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2614
|
-
});
|
|
2615
|
-
log("");
|
|
2616
|
-
log(
|
|
2617
|
-
import_kleur4.default.yellow(
|
|
2618
|
-
`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`
|
|
2619
|
-
)
|
|
2620
|
-
);
|
|
2621
|
-
log("");
|
|
2622
|
-
}
|
|
2623
|
-
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2624
|
-
process.exit(0);
|
|
2625
|
-
}
|
|
2626
|
-
const saveChanges = await confirm2({
|
|
2627
|
-
message: "Do you want to continue?",
|
|
2628
|
-
default: true
|
|
2629
|
-
});
|
|
2630
|
-
if (!saveChanges) {
|
|
2631
|
-
process.exit(0);
|
|
2632
|
-
}
|
|
2633
|
-
for (const newSecret of newSecrets) {
|
|
2634
|
-
log(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
|
|
2635
|
-
if (newSecret.scope === "ENVIRONMENT") {
|
|
2636
|
-
await createEnvironmentSecret(
|
|
2637
|
-
octokit,
|
|
2638
|
-
repositoryId,
|
|
2639
|
-
environment,
|
|
2640
|
-
newSecret.name,
|
|
2641
|
-
newSecret.value,
|
|
2642
|
-
githubOrganisation,
|
|
2643
|
-
githubRepository
|
|
2644
|
-
);
|
|
2645
|
-
} else {
|
|
2646
|
-
await createRepositorySecret(
|
|
2647
|
-
octokit,
|
|
2648
|
-
repositoryId,
|
|
2649
|
-
newSecret.name,
|
|
2650
|
-
newSecret.value,
|
|
2651
|
-
githubOrganisation,
|
|
2652
|
-
githubRepository
|
|
2653
|
-
);
|
|
2654
|
-
}
|
|
2655
|
-
}
|
|
2656
|
-
for (const updatedSecret of updatedSecrets) {
|
|
2657
|
-
log(
|
|
2658
|
-
`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`
|
|
2659
|
-
);
|
|
2660
|
-
if (updatedSecret.scope === "ENVIRONMENT") {
|
|
2661
|
-
await createEnvironmentSecret(
|
|
2662
|
-
octokit,
|
|
2663
|
-
repositoryId,
|
|
2664
|
-
environment,
|
|
2665
|
-
updatedSecret.name,
|
|
2666
|
-
updatedSecret.value,
|
|
2667
|
-
githubOrganisation,
|
|
2668
|
-
githubRepository
|
|
2669
|
-
);
|
|
2670
|
-
} else {
|
|
2671
|
-
await createRepositorySecret(
|
|
2672
|
-
octokit,
|
|
2673
|
-
repositoryId,
|
|
2674
|
-
updatedSecret.name,
|
|
2675
|
-
updatedSecret.value,
|
|
2676
|
-
githubOrganisation,
|
|
2677
|
-
githubRepository
|
|
2678
|
-
);
|
|
2679
|
-
}
|
|
2680
|
-
}
|
|
2681
|
-
for (const newVariable of newVariables) {
|
|
2682
|
-
log(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
|
|
2683
|
-
if (newVariable.scope === "ENVIRONMENT") {
|
|
2684
|
-
await createEnvironmentVariable(
|
|
2685
|
-
octokit,
|
|
2686
|
-
repositoryId,
|
|
2687
|
-
environment,
|
|
2688
|
-
newVariable.name,
|
|
2689
|
-
newVariable.value
|
|
2690
|
-
);
|
|
2691
|
-
} else {
|
|
2692
|
-
await createRepositoryVariable(
|
|
2693
|
-
octokit,
|
|
2694
|
-
repositoryId,
|
|
2695
|
-
newVariable.name,
|
|
2696
|
-
newVariable.value
|
|
2697
|
-
);
|
|
2698
|
-
}
|
|
2699
|
-
}
|
|
2700
|
-
for (const updatedVariable of updatedVariables) {
|
|
2701
|
-
log(
|
|
2702
|
-
`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`
|
|
2703
|
-
);
|
|
2704
|
-
if (updatedVariable.scope === "ENVIRONMENT") {
|
|
2705
|
-
await updateEnvironmentVariable(
|
|
2706
|
-
octokit,
|
|
2707
|
-
repositoryId,
|
|
2708
|
-
environment,
|
|
2709
|
-
updatedVariable.name,
|
|
2710
|
-
updatedVariable.value
|
|
2711
|
-
);
|
|
2712
|
-
} else {
|
|
2713
|
-
await updateRepositoryVariable(
|
|
2714
|
-
octokit,
|
|
2715
|
-
repositoryId,
|
|
2716
|
-
updatedVariable.name,
|
|
2717
|
-
updatedVariable.value
|
|
2718
|
-
);
|
|
2719
|
-
}
|
|
2720
|
-
}
|
|
2570
|
+
(val) => val || ""
|
|
2571
|
+
),
|
|
2572
|
+
didExist: findExistingValue(
|
|
2573
|
+
"RESTORE_HOST",
|
|
2574
|
+
"VARIABLE",
|
|
2575
|
+
"ENVIRONMENT",
|
|
2576
|
+
existingValues
|
|
2577
|
+
),
|
|
2578
|
+
scope: "ENVIRONMENT"
|
|
2579
|
+
}
|
|
2580
|
+
];
|
|
2581
|
+
if (enableEncryption) {
|
|
2582
|
+
applicationServerUpdates.push({
|
|
2583
|
+
name: "ENCRYPTION_KEY",
|
|
2584
|
+
type: "SECRET",
|
|
2585
|
+
didExist: findExistingValue(
|
|
2586
|
+
"ENCRYPTION_KEY",
|
|
2587
|
+
"SECRET",
|
|
2588
|
+
"ENVIRONMENT",
|
|
2589
|
+
existingValues
|
|
2590
|
+
),
|
|
2591
|
+
value: findExistingOrDefine(
|
|
2592
|
+
"ENCRYPTION_KEY",
|
|
2593
|
+
"SECRET",
|
|
2594
|
+
"ENVIRONMENT",
|
|
2595
|
+
generateLongPassword()
|
|
2596
|
+
),
|
|
2597
|
+
scope: "ENVIRONMENT"
|
|
2598
|
+
});
|
|
2599
|
+
}
|
|
2600
|
+
if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
|
|
2601
|
+
applicationServerUpdates.push({
|
|
2602
|
+
name: "BACKUP_HOST_PRIVATE_KEY",
|
|
2603
|
+
type: "SECRET",
|
|
2604
|
+
didExist: void 0,
|
|
2605
|
+
value: backupHostPrivateKey,
|
|
2606
|
+
scope: "ENVIRONMENT"
|
|
2607
|
+
});
|
|
2608
|
+
applicationServerUpdates.push({
|
|
2609
|
+
name: "BACKUP_HOST_PUBLIC_KEY",
|
|
2610
|
+
type: "SECRET",
|
|
2611
|
+
didExist: void 0,
|
|
2612
|
+
value: backupHostPublicKey,
|
|
2613
|
+
scope: "ENVIRONMENT"
|
|
2614
|
+
});
|
|
2615
|
+
}
|
|
2616
|
+
derivedUpdates.push(...applicationServerUpdates);
|
|
2617
|
+
const updates = getAnswers(existingValues).concat(
|
|
2618
|
+
...derivedUpdates.filter(
|
|
2619
|
+
(update) => update.value !== null
|
|
2620
|
+
)
|
|
2621
|
+
).filter(
|
|
2622
|
+
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2623
|
+
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2624
|
+
);
|
|
2625
|
+
const newSecrets = updates.filter(
|
|
2626
|
+
(update) => update.type === "SECRET" && !update.didExist
|
|
2627
|
+
);
|
|
2628
|
+
const updatedSecrets = updates.filter(
|
|
2629
|
+
(update) => update.type === "SECRET" && Boolean(update.didExist)
|
|
2630
|
+
);
|
|
2631
|
+
const newVariables = updates.filter(
|
|
2632
|
+
(update) => update.type === "VARIABLE" && !update.didExist
|
|
2633
|
+
);
|
|
2634
|
+
const updatedVariables = updates.filter(
|
|
2635
|
+
(update) => update.type === "VARIABLE" && Boolean(update.didExist)
|
|
2636
|
+
);
|
|
2637
|
+
const unknownVariables = existingValues.filter((value) => {
|
|
2638
|
+
return !ALL_QUESTIONS.find(
|
|
2639
|
+
(question) => question.valueLabel === value.name && question.valueType === value.type && question.scope === value.scope
|
|
2640
|
+
);
|
|
2641
|
+
});
|
|
2642
|
+
log("");
|
|
2643
|
+
if (newSecrets.length > 0) {
|
|
2644
|
+
log(
|
|
2645
|
+
import_kleur4.default.yellow(
|
|
2646
|
+
`The following secrets will be added to Github for environment ${environment}:`
|
|
2647
|
+
)
|
|
2648
|
+
);
|
|
2649
|
+
newSecrets.filter(({ scope }) => scope === "ENVIRONMENT").forEach((secret) => {
|
|
2650
|
+
log(secret.name, "=", secret.value);
|
|
2651
|
+
});
|
|
2652
|
+
log("");
|
|
2653
|
+
log(
|
|
2654
|
+
import_kleur4.default.yellow(`The following secrets will be added to Github repository:`)
|
|
2655
|
+
);
|
|
2656
|
+
newSecrets.filter(({ scope }) => scope === "REPOSITORY").forEach((secret) => {
|
|
2657
|
+
log(secret.name, "=", secret.value);
|
|
2658
|
+
});
|
|
2659
|
+
log("");
|
|
2660
|
+
}
|
|
2661
|
+
if (updatedSecrets.length > 0) {
|
|
2662
|
+
log(
|
|
2663
|
+
import_kleur4.default.yellow(
|
|
2664
|
+
`The following secrets will be updated in Github for environment ${environment}:`
|
|
2665
|
+
)
|
|
2666
|
+
);
|
|
2667
|
+
updatedSecrets.forEach((secret) => {
|
|
2668
|
+
log(secret.name, "=", secret.value);
|
|
2669
|
+
});
|
|
2670
|
+
log("");
|
|
2671
|
+
}
|
|
2672
|
+
if (newVariables.length > 0) {
|
|
2673
|
+
log(
|
|
2674
|
+
import_kleur4.default.yellow(
|
|
2675
|
+
`The following variables will be added to Github for environment ${environment}:`
|
|
2676
|
+
)
|
|
2677
|
+
);
|
|
2678
|
+
newVariables.forEach((variable) => {
|
|
2679
|
+
log(variable.name, "=", variable.value);
|
|
2680
|
+
});
|
|
2681
|
+
log("");
|
|
2682
|
+
}
|
|
2683
|
+
if (updatedVariables.length > 0) {
|
|
2684
|
+
log(
|
|
2685
|
+
import_kleur4.default.yellow(
|
|
2686
|
+
`The following variables will be updated in Github for environment ${environment}:`
|
|
2687
|
+
)
|
|
2688
|
+
);
|
|
2689
|
+
updatedVariables.forEach((variable) => {
|
|
2721
2690
|
log(
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2691
|
+
variable.name,
|
|
2692
|
+
"=",
|
|
2693
|
+
variable.value,
|
|
2694
|
+
`(was ${variable.didExist?.value})`
|
|
2725
2695
|
);
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
kube_worker_nodes: kubeWorkerNodes,
|
|
2729
|
-
kube_api_host: infrastructure.kubeApiHost || "",
|
|
2730
|
-
backup_host: backupHost || "",
|
|
2731
|
-
users
|
|
2732
|
-
});
|
|
2733
|
-
copyChartsValues(environment, {
|
|
2734
|
-
env: environment,
|
|
2735
|
-
environment_type,
|
|
2736
|
-
// FIXME: In general that should be environment_type,
|
|
2737
|
-
// Hardcode like this blocks us from being generic:
|
|
2738
|
-
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
2739
|
-
two_fa_enabled: environment !== "production" ? false : true,
|
|
2740
|
-
backup_enabled: configureBackup ? true : false,
|
|
2741
|
-
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2742
|
-
restore_environment_name: restoreEnvironmentName || "",
|
|
2743
|
-
restore_type: restoreType,
|
|
2744
|
-
traefik_mode: traefikConfOption,
|
|
2745
|
-
backup_type: backupType
|
|
2746
|
-
});
|
|
2747
|
-
let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
|
|
2748
|
-
|
|
2749
|
-
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("COPY the SSH public key from the master VM to your clipboard")}
|
|
2750
|
-
--------------------------------------------------------------------------------------------
|
|
2751
|
-
` : "";
|
|
2752
|
-
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:")}
|
|
2753
|
-
|
|
2754
|
-
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2755
|
-
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"
|
|
2756
|
-
` : "";
|
|
2757
|
-
addon_message += configureBackup ? `
|
|
2758
|
-
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on backup server to create provision user and setup SSH key:")}
|
|
2759
|
-
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2760
|
-
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"` : "";
|
|
2761
|
-
log(`
|
|
2762
|
-
${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")}
|
|
2763
|
-
Follow the steps below to complete the setup of your environment:
|
|
2764
|
-
${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")}
|
|
2765
|
-
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on Kubernetes master VM to bootstrap self-hosted runner:")}
|
|
2766
|
-
|
|
2767
|
-
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2768
|
-
bash opencrvs-bootstrap.sh --owner ${githubOrganisation} \\
|
|
2769
|
-
--repo ${githubRepository} \\
|
|
2770
|
-
--env ${environment} \\
|
|
2771
|
-
--token ${githubToken} \\
|
|
2772
|
-
--enable-runner
|
|
2773
|
-
|
|
2774
|
-
${addon_message}
|
|
2775
|
-
|
|
2776
|
-
${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")}
|
|
2777
|
-
${import_kleur4.default.yellow("Please KINDLY read hints above")}
|
|
2778
|
-
`);
|
|
2779
|
-
log("\nAll variables stored in", import_kleur4.default.cyan(`.env.${environment}`));
|
|
2780
|
-
log(import_kleur4.default.bold().yellow("DO NOT COMMIT THIS FILE TO GIT!"));
|
|
2781
|
-
})();
|
|
2782
|
-
}
|
|
2783
|
-
});
|
|
2784
|
-
|
|
2785
|
-
// src/environment/update-workflows.ts
|
|
2786
|
-
var update_workflows_exports = {};
|
|
2787
|
-
__export(update_workflows_exports, {
|
|
2788
|
-
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
2789
|
-
});
|
|
2790
|
-
function isDirectory(path8) {
|
|
2791
|
-
try {
|
|
2792
|
-
return (0, import_fs5.statSync)(path8).isDirectory();
|
|
2793
|
-
} catch {
|
|
2794
|
-
return false;
|
|
2696
|
+
});
|
|
2697
|
+
log("");
|
|
2795
2698
|
}
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
console.log(
|
|
2802
|
-
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
2699
|
+
if (unknownVariables.length > 0) {
|
|
2700
|
+
log(
|
|
2701
|
+
import_kleur4.default.yellow(
|
|
2702
|
+
`The following unknown variables/secrets were stored in Github are not managed by this script:`
|
|
2703
|
+
)
|
|
2803
2704
|
);
|
|
2804
|
-
|
|
2705
|
+
log("");
|
|
2706
|
+
log(import_kleur4.default.blue(`Repository:`));
|
|
2707
|
+
unknownVariables.filter(({ scope }) => scope === "REPOSITORY").forEach((variable) => {
|
|
2708
|
+
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2709
|
+
});
|
|
2710
|
+
log("");
|
|
2711
|
+
log(import_kleur4.default.blue(`Environment:`));
|
|
2712
|
+
unknownVariables.filter(({ scope }) => scope === "ENVIRONMENT").forEach((variable) => {
|
|
2713
|
+
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2714
|
+
});
|
|
2715
|
+
log("");
|
|
2716
|
+
log(
|
|
2717
|
+
import_kleur4.default.yellow(
|
|
2718
|
+
`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`
|
|
2719
|
+
)
|
|
2720
|
+
);
|
|
2721
|
+
log("");
|
|
2805
2722
|
}
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
}
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2723
|
+
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2724
|
+
process.exit(0);
|
|
2725
|
+
}
|
|
2726
|
+
log(
|
|
2727
|
+
import_kleur4.default.bold().red(
|
|
2728
|
+
"\u26A0\uFE0F COPY THESE NOW INTO A PASSWORD MANAGER \u2014 YOU WON'T SEE THEM AGAIN"
|
|
2729
|
+
)
|
|
2730
|
+
);
|
|
2731
|
+
log("");
|
|
2732
|
+
const saveChanges = await confirm2({
|
|
2733
|
+
message: "Do you want to continue?",
|
|
2734
|
+
default: true
|
|
2815
2735
|
});
|
|
2816
|
-
if (
|
|
2817
|
-
|
|
2818
|
-
"\u26A0\uFE0F Warning: No environment directories found in environments/"
|
|
2819
|
-
);
|
|
2820
|
-
return [];
|
|
2736
|
+
if (!saveChanges) {
|
|
2737
|
+
process.exit(0);
|
|
2821
2738
|
}
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2739
|
+
for (const newSecret of newSecrets) {
|
|
2740
|
+
log(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
|
|
2741
|
+
if (newSecret.scope === "ENVIRONMENT") {
|
|
2742
|
+
await createEnvironmentSecret(
|
|
2743
|
+
octokit,
|
|
2744
|
+
repositoryId,
|
|
2745
|
+
environment,
|
|
2746
|
+
newSecret.name,
|
|
2747
|
+
newSecret.value,
|
|
2748
|
+
githubOrganisation,
|
|
2749
|
+
githubRepository
|
|
2750
|
+
);
|
|
2751
|
+
} else {
|
|
2752
|
+
await createRepositorySecret(
|
|
2753
|
+
octokit,
|
|
2754
|
+
repositoryId,
|
|
2755
|
+
newSecret.name,
|
|
2756
|
+
newSecret.value,
|
|
2757
|
+
githubOrganisation,
|
|
2758
|
+
githubRepository
|
|
2759
|
+
);
|
|
2760
|
+
}
|
|
2830
2761
|
}
|
|
2831
|
-
const
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2762
|
+
for (const updatedSecret of updatedSecrets) {
|
|
2763
|
+
log(
|
|
2764
|
+
`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`
|
|
2765
|
+
);
|
|
2766
|
+
if (updatedSecret.scope === "ENVIRONMENT") {
|
|
2767
|
+
await createEnvironmentSecret(
|
|
2768
|
+
octokit,
|
|
2769
|
+
repositoryId,
|
|
2770
|
+
environment,
|
|
2771
|
+
updatedSecret.name,
|
|
2772
|
+
updatedSecret.value,
|
|
2773
|
+
githubOrganisation,
|
|
2774
|
+
githubRepository
|
|
2775
|
+
);
|
|
2776
|
+
} else {
|
|
2777
|
+
await createRepositorySecret(
|
|
2778
|
+
octokit,
|
|
2779
|
+
repositoryId,
|
|
2780
|
+
updatedSecret.name,
|
|
2781
|
+
updatedSecret.value,
|
|
2782
|
+
githubOrganisation,
|
|
2783
|
+
githubRepository
|
|
2854
2784
|
);
|
|
2855
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
|
|
2856
|
-
throw error3;
|
|
2857
2785
|
}
|
|
2858
2786
|
}
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
if (environments.length > 0) {
|
|
2877
|
-
const workflows = [
|
|
2878
|
-
".github/workflows/deploy-dependencies.yml",
|
|
2879
|
-
".github/workflows/deploy-opencrvs.yml",
|
|
2880
|
-
".github/workflows/clear-all-data.yml",
|
|
2881
|
-
".github/workflows/seed-data.yml",
|
|
2882
|
-
".github/workflows/reindex.yml",
|
|
2883
|
-
".github/workflows/github-to-k8s-sync-env.yml"
|
|
2884
|
-
];
|
|
2885
|
-
log("\u{1F4CB} Updating OpenCRVS application workflows:");
|
|
2886
|
-
await updateWorkflows(environments, {
|
|
2887
|
-
workflows,
|
|
2888
|
-
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2889
|
-
});
|
|
2890
|
-
didUpdateWorkflows = true;
|
|
2787
|
+
for (const newVariable of newVariables) {
|
|
2788
|
+
log(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
|
|
2789
|
+
if (newVariable.scope === "ENVIRONMENT") {
|
|
2790
|
+
await createEnvironmentVariable(
|
|
2791
|
+
octokit,
|
|
2792
|
+
repositoryId,
|
|
2793
|
+
environment,
|
|
2794
|
+
newVariable.name,
|
|
2795
|
+
newVariable.value
|
|
2796
|
+
);
|
|
2797
|
+
} else {
|
|
2798
|
+
await createRepositoryVariable(
|
|
2799
|
+
octokit,
|
|
2800
|
+
repositoryId,
|
|
2801
|
+
newVariable.name,
|
|
2802
|
+
newVariable.value
|
|
2803
|
+
);
|
|
2891
2804
|
}
|
|
2892
|
-
|
|
2893
|
-
|
|
2805
|
+
}
|
|
2806
|
+
for (const updatedVariable of updatedVariables) {
|
|
2807
|
+
log(
|
|
2808
|
+
`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`
|
|
2809
|
+
);
|
|
2810
|
+
if (updatedVariable.scope === "ENVIRONMENT") {
|
|
2811
|
+
await updateEnvironmentVariable(
|
|
2812
|
+
octokit,
|
|
2813
|
+
repositoryId,
|
|
2814
|
+
environment,
|
|
2815
|
+
updatedVariable.name,
|
|
2816
|
+
updatedVariable.value
|
|
2817
|
+
);
|
|
2894
2818
|
} else {
|
|
2895
|
-
|
|
2819
|
+
await updateRepositoryVariable(
|
|
2820
|
+
octokit,
|
|
2821
|
+
repositoryId,
|
|
2822
|
+
updatedVariable.name,
|
|
2823
|
+
updatedVariable.value
|
|
2824
|
+
);
|
|
2896
2825
|
}
|
|
2897
|
-
} catch (error3) {
|
|
2898
|
-
console.error("\n\u274C Error updating workflows:", error3);
|
|
2899
|
-
process.exit(1);
|
|
2900
2826
|
}
|
|
2827
|
+
log(
|
|
2828
|
+
import_kleur4.default.green(
|
|
2829
|
+
`Successfully updated Github secrets and variables for environment ${environment}`
|
|
2830
|
+
)
|
|
2831
|
+
);
|
|
2832
|
+
log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
|
|
2833
|
+
generateInventory(environment, {
|
|
2834
|
+
kube_worker_nodes: kubeWorkerNodes,
|
|
2835
|
+
kube_api_host: infrastructure.kubeApiHost || "",
|
|
2836
|
+
backup_host: backupHost || "",
|
|
2837
|
+
users
|
|
2838
|
+
});
|
|
2839
|
+
copyChartsValues(environment, {
|
|
2840
|
+
env: environment,
|
|
2841
|
+
environment_type,
|
|
2842
|
+
two_fa_enabled,
|
|
2843
|
+
traefik_mode: traefikConfOption,
|
|
2844
|
+
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2845
|
+
restore_environment_name: restoreEnvironmentName || "",
|
|
2846
|
+
restore_type: restoreType,
|
|
2847
|
+
restore_host: restoreHost || "",
|
|
2848
|
+
backup_enabled: configureBackup ? true : false,
|
|
2849
|
+
backup_type: backupType,
|
|
2850
|
+
backup_host: backupHost || ""
|
|
2851
|
+
});
|
|
2852
|
+
log("\n", import_kleur4.default.bold().underline("Updating workflow files"));
|
|
2853
|
+
await updateWorkflowEnvironments();
|
|
2854
|
+
let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
|
|
2855
|
+
|
|
2856
|
+
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("COPY the SSH public key from the master VM to your clipboard")}
|
|
2857
|
+
--------------------------------------------------------------------------------------------
|
|
2858
|
+
` : "";
|
|
2859
|
+
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:")}
|
|
2860
|
+
|
|
2861
|
+
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2862
|
+
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"
|
|
2863
|
+
` : "";
|
|
2864
|
+
addon_message += configureBackup ? `
|
|
2865
|
+
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on backup server to create provision user and setup SSH key:")}
|
|
2866
|
+
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2867
|
+
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"` : "";
|
|
2868
|
+
log(`
|
|
2869
|
+
${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")}
|
|
2870
|
+
Follow the steps below to complete the setup of your environment:
|
|
2871
|
+
${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")}
|
|
2872
|
+
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on Kubernetes master VM to bootstrap self-hosted runner:")}
|
|
2873
|
+
|
|
2874
|
+
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2875
|
+
bash opencrvs-bootstrap.sh --owner ${githubOrganisation} \\
|
|
2876
|
+
--repo ${githubRepository} \\
|
|
2877
|
+
--env ${environment} \\
|
|
2878
|
+
--token ${githubToken} \\
|
|
2879
|
+
--enable-runner
|
|
2880
|
+
|
|
2881
|
+
${addon_message}
|
|
2882
|
+
|
|
2883
|
+
${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")}
|
|
2884
|
+
${import_kleur4.default.yellow("Please KINDLY read hints above")}
|
|
2885
|
+
`);
|
|
2886
|
+
log(
|
|
2887
|
+
"\nAll secrets and variables were printed above.",
|
|
2888
|
+
import_kleur4.default.bold().yellow("Store them in a password manager \u2014 they are not saved to disk.")
|
|
2889
|
+
);
|
|
2901
2890
|
}
|
|
2902
|
-
var
|
|
2903
|
-
var
|
|
2904
|
-
"src/environment/
|
|
2891
|
+
var import_core, import_kleur4, import_prompts2, ALL_QUESTIONS, ALL_ANSWERS;
|
|
2892
|
+
var init_setup_environment = __esm({
|
|
2893
|
+
"src/environment/setup-environment.ts"() {
|
|
2905
2894
|
"use strict";
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2895
|
+
import_core = require("@octokit/core");
|
|
2896
|
+
import_kleur4 = __toESM(require("kleur"));
|
|
2897
|
+
import_prompts2 = __toESM(require("prompts"));
|
|
2898
|
+
init_github();
|
|
2899
|
+
init_derived_variables();
|
|
2900
|
+
init_utils();
|
|
2911
2901
|
init_logger();
|
|
2902
|
+
init_templates();
|
|
2903
|
+
init_ssh_keygen();
|
|
2904
|
+
init_update_workflows();
|
|
2905
|
+
init_questions();
|
|
2906
|
+
init_editor_questions();
|
|
2907
|
+
init_questions_helper();
|
|
2908
|
+
init_manage_users();
|
|
2912
2909
|
init_paths();
|
|
2910
|
+
ALL_QUESTIONS = [];
|
|
2911
|
+
ALL_ANSWERS = [];
|
|
2912
|
+
ALL_QUESTIONS.push(
|
|
2913
|
+
...githubTokenQuestion,
|
|
2914
|
+
...githubOtherQuestions,
|
|
2915
|
+
...dockerhubQuestions,
|
|
2916
|
+
...diskQuestions,
|
|
2917
|
+
...infrastructureQuestions,
|
|
2918
|
+
...backupQuestions,
|
|
2919
|
+
...countryQuestions,
|
|
2920
|
+
...databaseAndMonitoringQuestions,
|
|
2921
|
+
...emailQuestions,
|
|
2922
|
+
...sentryQuestions,
|
|
2923
|
+
...derivedVariables,
|
|
2924
|
+
...metabaseAdminQuestions
|
|
2925
|
+
);
|
|
2913
2926
|
}
|
|
2914
2927
|
});
|
|
2915
2928
|
|
|
@@ -2919,17 +2932,17 @@ __export(upgrade_exports, {
|
|
|
2919
2932
|
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2920
2933
|
});
|
|
2921
2934
|
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2922
|
-
if (!(0,
|
|
2935
|
+
if (!(0, import_fs12.existsSync)(sourcePath)) {
|
|
2923
2936
|
return false;
|
|
2924
2937
|
}
|
|
2925
|
-
if ((0,
|
|
2938
|
+
if ((0, import_fs12.existsSync)(destinationPath)) {
|
|
2926
2939
|
warn(
|
|
2927
2940
|
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2928
2941
|
);
|
|
2929
2942
|
return false;
|
|
2930
2943
|
}
|
|
2931
|
-
(0,
|
|
2932
|
-
(0,
|
|
2944
|
+
(0, import_fs12.mkdirSync)((0, import_path14.dirname)(destinationPath), { recursive: true });
|
|
2945
|
+
(0, import_fs12.renameSync)(sourcePath, destinationPath);
|
|
2933
2946
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2934
2947
|
return true;
|
|
2935
2948
|
}
|
|
@@ -2949,8 +2962,8 @@ function migrateInventoryFiles() {
|
|
|
2949
2962
|
) || didMoveInventory;
|
|
2950
2963
|
}
|
|
2951
2964
|
try {
|
|
2952
|
-
if ((0,
|
|
2953
|
-
(0,
|
|
2965
|
+
if ((0, import_fs12.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs12.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
2966
|
+
(0, import_fs12.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2954
2967
|
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2955
2968
|
}
|
|
2956
2969
|
} catch {
|
|
@@ -2968,12 +2981,12 @@ async function upgradeEnvironmentLayout() {
|
|
|
2968
2981
|
}
|
|
2969
2982
|
log("\nCommit changes into git after upgrade");
|
|
2970
2983
|
}
|
|
2971
|
-
var
|
|
2984
|
+
var import_fs12, import_path14, import_kleur5;
|
|
2972
2985
|
var init_upgrade = __esm({
|
|
2973
2986
|
"src/environment/upgrade.ts"() {
|
|
2974
2987
|
"use strict";
|
|
2975
|
-
|
|
2976
|
-
|
|
2988
|
+
import_fs12 = require("fs");
|
|
2989
|
+
import_path14 = require("path");
|
|
2977
2990
|
import_kleur5 = __toESM(require("kleur"));
|
|
2978
2991
|
init_logger();
|
|
2979
2992
|
init_paths();
|
|
@@ -2999,7 +3012,7 @@ async function selectInventoryFile(dirPath = "./environments") {
|
|
|
2999
3012
|
return null;
|
|
3000
3013
|
}
|
|
3001
3014
|
const environments = fs4.readdirSync(dirPath).filter((entry) => {
|
|
3002
|
-
const filePath =
|
|
3015
|
+
const filePath = path12.join(dirPath, entry);
|
|
3003
3016
|
return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
|
|
3004
3017
|
}).sort();
|
|
3005
3018
|
if (environments.length === 0) {
|
|
@@ -3027,12 +3040,12 @@ async function manageEnvironmentUsers() {
|
|
|
3027
3040
|
}
|
|
3028
3041
|
await manageUsers(inventory_file);
|
|
3029
3042
|
}
|
|
3030
|
-
var fs4,
|
|
3043
|
+
var fs4, path12, import_kleur6;
|
|
3031
3044
|
var init_users = __esm({
|
|
3032
3045
|
"src/environment/users.ts"() {
|
|
3033
3046
|
"use strict";
|
|
3034
3047
|
fs4 = __toESM(require("fs"));
|
|
3035
|
-
|
|
3048
|
+
path12 = __toESM(require("path"));
|
|
3036
3049
|
import_kleur6 = __toESM(require("kleur"));
|
|
3037
3050
|
init_manage_users();
|
|
3038
3051
|
init_logger();
|
|
@@ -3042,11 +3055,11 @@ var init_users = __esm({
|
|
|
3042
3055
|
|
|
3043
3056
|
// src/environment/swarm-to-k8s.ts
|
|
3044
3057
|
var swarm_to_k8s_exports = {};
|
|
3045
|
-
var
|
|
3058
|
+
var path13, import_kleur7, import_core2;
|
|
3046
3059
|
var init_swarm_to_k8s = __esm({
|
|
3047
3060
|
"src/environment/swarm-to-k8s.ts"() {
|
|
3048
3061
|
"use strict";
|
|
3049
|
-
|
|
3062
|
+
path13 = __toESM(require("path"));
|
|
3050
3063
|
import_kleur7 = __toESM(require("kleur"));
|
|
3051
3064
|
init_logger();
|
|
3052
3065
|
init_utils();
|
|
@@ -3098,7 +3111,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3098
3111
|
);
|
|
3099
3112
|
process.exit(1);
|
|
3100
3113
|
}
|
|
3101
|
-
const ansible_inventory =
|
|
3114
|
+
const ansible_inventory = path13.join(old_inventory_path, environment + ".yml");
|
|
3102
3115
|
const data = readYamlFile(ansible_inventory);
|
|
3103
3116
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
3104
3117
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3117,10 +3130,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3117
3130
|
copyChartsValues(environment, {
|
|
3118
3131
|
env: environment,
|
|
3119
3132
|
environment_type,
|
|
3120
|
-
|
|
3121
|
-
// Hardcode like this blocks us from being generic:
|
|
3122
|
-
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
3123
|
-
two_fa_enabled: environment !== "production" ? false : true,
|
|
3133
|
+
two_fa_enabled: process.env.TWO_FA_ENABLED ? process.env.TWO_FA_ENABLED === "true" : environment_type === "production",
|
|
3124
3134
|
backup_enabled: environment === "production" ? "true" : "false",
|
|
3125
3135
|
restore_enabled: environment === "staging" ? "true" : "false",
|
|
3126
3136
|
restore_environment_name: environment === "staging" ? "production" : "",
|
|
@@ -3401,8 +3411,88 @@ Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.l
|
|
|
3401
3411
|
|
|
3402
3412
|
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3403
3413
|
var import_ts_morph2 = require("ts-morph");
|
|
3404
|
-
var
|
|
3414
|
+
var import_fs2 = require("fs");
|
|
3405
3415
|
var import_path2 = __toESM(require("path"));
|
|
3416
|
+
|
|
3417
|
+
// src/csv.ts
|
|
3418
|
+
var import_fs = require("fs");
|
|
3419
|
+
function parseCsvLine(line2) {
|
|
3420
|
+
const values = [];
|
|
3421
|
+
let value = "";
|
|
3422
|
+
let quoted = false;
|
|
3423
|
+
for (let index = 0; index < line2.length; index++) {
|
|
3424
|
+
const character = line2[index];
|
|
3425
|
+
if (quoted) {
|
|
3426
|
+
if (character !== '"') {
|
|
3427
|
+
value += character;
|
|
3428
|
+
} else if (line2[index + 1] === '"') {
|
|
3429
|
+
value += '"';
|
|
3430
|
+
index++;
|
|
3431
|
+
} else {
|
|
3432
|
+
quoted = false;
|
|
3433
|
+
}
|
|
3434
|
+
continue;
|
|
3435
|
+
}
|
|
3436
|
+
if (character === '"') {
|
|
3437
|
+
quoted = true;
|
|
3438
|
+
} else if (character === ",") {
|
|
3439
|
+
values.push(value);
|
|
3440
|
+
value = "";
|
|
3441
|
+
} else {
|
|
3442
|
+
value += character;
|
|
3443
|
+
}
|
|
3444
|
+
}
|
|
3445
|
+
values.push(value);
|
|
3446
|
+
return values;
|
|
3447
|
+
}
|
|
3448
|
+
function toCsvLine(values) {
|
|
3449
|
+
return values.map(
|
|
3450
|
+
(value) => /["\n,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value
|
|
3451
|
+
).join(",");
|
|
3452
|
+
}
|
|
3453
|
+
function idOf(line2) {
|
|
3454
|
+
const comma = line2.indexOf(",");
|
|
3455
|
+
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3456
|
+
}
|
|
3457
|
+
function readCsvFile(path14) {
|
|
3458
|
+
if (!(0, import_fs.existsSync)(path14)) {
|
|
3459
|
+
return void 0;
|
|
3460
|
+
}
|
|
3461
|
+
const contents = (0, import_fs.readFileSync)(path14, "utf8");
|
|
3462
|
+
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3463
|
+
const trailingNewline = /\r?\n$/.test(contents);
|
|
3464
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3465
|
+
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3466
|
+
return { header: lines[0], body, newline, trailingNewline };
|
|
3467
|
+
}
|
|
3468
|
+
function writeCsvFile(path14, file) {
|
|
3469
|
+
(0, import_fs.writeFileSync)(
|
|
3470
|
+
path14,
|
|
3471
|
+
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3472
|
+
);
|
|
3473
|
+
}
|
|
3474
|
+
function addRows(file, rows) {
|
|
3475
|
+
const isSorted = file.body.every(
|
|
3476
|
+
(line2, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line2)
|
|
3477
|
+
);
|
|
3478
|
+
const added = [];
|
|
3479
|
+
for (const row of rows) {
|
|
3480
|
+
const id = idOf(row);
|
|
3481
|
+
if (file.body.some((line2) => idOf(line2) === id)) {
|
|
3482
|
+
continue;
|
|
3483
|
+
}
|
|
3484
|
+
const insertAt = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
|
|
3485
|
+
if (insertAt === -1) {
|
|
3486
|
+
file.body.push(row);
|
|
3487
|
+
} else {
|
|
3488
|
+
file.body.splice(insertAt, 0, row);
|
|
3489
|
+
}
|
|
3490
|
+
added.push(id);
|
|
3491
|
+
}
|
|
3492
|
+
return added;
|
|
3493
|
+
}
|
|
3494
|
+
|
|
3495
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3406
3496
|
var EMAIL_TEMPLATES_FILE = "src/api/notification/email-templates/index.ts";
|
|
3407
3497
|
var SMS_SERVICE_FILE = "src/api/notification/sms-service.ts";
|
|
3408
3498
|
var HANDLER_FILE = "src/api/notification/handler.ts";
|
|
@@ -3492,7 +3582,7 @@ function appendEntry(sourceFile, objectName, key, valueLines) {
|
|
|
3492
3582
|
const lastProperty = properties[properties.length - 1];
|
|
3493
3583
|
if (!lastProperty) return false;
|
|
3494
3584
|
const indent = lastProperty.getIndentationText();
|
|
3495
|
-
const entry = valueLines.map((
|
|
3585
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${key}: ${line2}` : line2}`).join("\n");
|
|
3496
3586
|
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
3497
3587
|
${entry}`);
|
|
3498
3588
|
return true;
|
|
@@ -3660,14 +3750,14 @@ function updateHandler(project, cwd) {
|
|
|
3660
3750
|
if (defaultClause) {
|
|
3661
3751
|
caseBlock.insertText(
|
|
3662
3752
|
anchor.getStart(),
|
|
3663
|
-
`${lines.map((
|
|
3753
|
+
`${lines.map((line2, index) => index === 0 ? line2 : `${indent}${line2}`).join("\n")}
|
|
3664
3754
|
${indent}`
|
|
3665
3755
|
);
|
|
3666
3756
|
} else {
|
|
3667
3757
|
caseBlock.insertText(
|
|
3668
3758
|
anchor.getEnd(),
|
|
3669
3759
|
`
|
|
3670
|
-
${lines.map((
|
|
3760
|
+
${lines.map((line2) => `${indent}${line2}`).join("\n")}`
|
|
3671
3761
|
);
|
|
3672
3762
|
}
|
|
3673
3763
|
for (const event of missing) {
|
|
@@ -3689,10 +3779,10 @@ function updateRoutes(project, cwd) {
|
|
|
3689
3779
|
return;
|
|
3690
3780
|
}
|
|
3691
3781
|
for (const event of RECOVERY_EVENTS) {
|
|
3692
|
-
if (routesArray.getText().includes(`/
|
|
3782
|
+
if (routesArray.getText().includes(`/trigger/user/${event.id}`)) continue;
|
|
3693
3783
|
routesArray.addElement(`{
|
|
3694
3784
|
method: 'POST',
|
|
3695
|
-
path: '/
|
|
3785
|
+
path: '/trigger/user/${event.id}',
|
|
3696
3786
|
handler: makeNotificationHandler('${event.id}'),
|
|
3697
3787
|
options: {
|
|
3698
3788
|
auth: false,
|
|
@@ -3700,7 +3790,7 @@ function updateRoutes(project, cwd) {
|
|
|
3700
3790
|
description: '${event.routeDescription}'
|
|
3701
3791
|
}
|
|
3702
3792
|
}`);
|
|
3703
|
-
console.log(` \u2713 ${ROUTES_FILE}: POST /
|
|
3793
|
+
console.log(` \u2713 ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
|
|
3704
3794
|
}
|
|
3705
3795
|
}
|
|
3706
3796
|
function renderEmailTemplate(event) {
|
|
@@ -3781,7 +3871,7 @@ Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencr
|
|
|
3781
3871
|
}
|
|
3782
3872
|
function writeEmailTemplates(cwd) {
|
|
3783
3873
|
const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
|
|
3784
|
-
if (!(0,
|
|
3874
|
+
if (!(0, import_fs2.existsSync)(templateDir)) {
|
|
3785
3875
|
warnSkipped(
|
|
3786
3876
|
`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
|
|
3787
3877
|
);
|
|
@@ -3789,79 +3879,198 @@ function writeEmailTemplates(cwd) {
|
|
|
3789
3879
|
}
|
|
3790
3880
|
for (const event of RECOVERY_EVENTS) {
|
|
3791
3881
|
const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
|
|
3792
|
-
if ((0,
|
|
3793
|
-
(0,
|
|
3882
|
+
if ((0, import_fs2.existsSync)(templatePath)) continue;
|
|
3883
|
+
(0, import_fs2.writeFileSync)(templatePath, renderEmailTemplate(event));
|
|
3794
3884
|
console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
|
|
3795
3885
|
}
|
|
3796
3886
|
}
|
|
3797
3887
|
function addCsvRows(cwd, relativePath, rows) {
|
|
3798
3888
|
const csvPath = import_path2.default.join(cwd, relativePath);
|
|
3799
|
-
|
|
3889
|
+
const file = readCsvFile(csvPath);
|
|
3890
|
+
if (!file) {
|
|
3800
3891
|
warnSkipped(`${relativePath} not found; translations not added`);
|
|
3801
3892
|
return;
|
|
3802
3893
|
}
|
|
3803
|
-
const
|
|
3804
|
-
|
|
3805
|
-
const
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3894
|
+
const added = addRows(file, rows);
|
|
3895
|
+
if (added.length === 0) return;
|
|
3896
|
+
for (const id of added) {
|
|
3897
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
3898
|
+
}
|
|
3899
|
+
writeCsvFile(csvPath, file);
|
|
3900
|
+
}
|
|
3901
|
+
async function main2() {
|
|
3902
|
+
const cwd = process.cwd();
|
|
3903
|
+
const tsConfigFilePath = import_path2.default.join(cwd, "tsconfig.json");
|
|
3904
|
+
console.log(
|
|
3905
|
+
"Registering the password-reset-link and username-reminder-link notifications...\n"
|
|
3812
3906
|
);
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3907
|
+
if (!(0, import_fs2.existsSync)(tsConfigFilePath)) {
|
|
3908
|
+
warnSkipped(
|
|
3909
|
+
`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
|
|
3910
|
+
);
|
|
3911
|
+
return;
|
|
3912
|
+
}
|
|
3913
|
+
const project = new import_ts_morph2.Project({
|
|
3914
|
+
tsConfigFilePath,
|
|
3915
|
+
skipAddingFilesFromTsConfig: false,
|
|
3916
|
+
// ts-morph indents inserted code with four spaces by default, which every
|
|
3917
|
+
// country config's prettier run would immediately undo.
|
|
3918
|
+
manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
|
|
3919
|
+
});
|
|
3920
|
+
updateEmailTemplates(project, cwd);
|
|
3921
|
+
updateSmsService(project, cwd);
|
|
3922
|
+
updateHandler(project, cwd);
|
|
3923
|
+
updateRoutes(project, cwd);
|
|
3924
|
+
await project.save();
|
|
3925
|
+
writeEmailTemplates(cwd);
|
|
3926
|
+
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
3927
|
+
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
3928
|
+
if (skipped.length > 0) {
|
|
3929
|
+
console.warn(
|
|
3930
|
+
`
|
|
3931
|
+
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Wire the following by hand before upgrading:`
|
|
3932
|
+
);
|
|
3933
|
+
for (const message of skipped) {
|
|
3934
|
+
console.warn(` - ${message}`);
|
|
3935
|
+
}
|
|
3936
|
+
}
|
|
3937
|
+
}
|
|
3938
|
+
|
|
3939
|
+
// src/migrations/v2.1/add-translations.ts
|
|
3940
|
+
var import_path3 = __toESM(require("path"));
|
|
3941
|
+
|
|
3942
|
+
// src/translations/template.ts
|
|
3943
|
+
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3944
|
+
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3945
|
+
async function matchingRefs(namespace, prefix) {
|
|
3946
|
+
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3947
|
+
const response = await fetch(url, {
|
|
3948
|
+
headers: { accept: "application/vnd.github+json" }
|
|
3949
|
+
});
|
|
3950
|
+
if (!response.ok) {
|
|
3951
|
+
throw new Error(
|
|
3952
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3953
|
+
);
|
|
3954
|
+
}
|
|
3955
|
+
const refs = await response.json();
|
|
3956
|
+
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3957
|
+
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3958
|
+
}
|
|
3959
|
+
async function candidateRefs(version) {
|
|
3960
|
+
return [
|
|
3961
|
+
...await matchingRefs("heads", `release/${version}.`),
|
|
3962
|
+
...await matchingRefs("tags", `v${version}.`),
|
|
3963
|
+
"develop"
|
|
3964
|
+
];
|
|
3965
|
+
}
|
|
3966
|
+
async function fetchTemplate(refs, application) {
|
|
3967
|
+
for (const ref of refs) {
|
|
3968
|
+
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
3969
|
+
const response = await fetch(url);
|
|
3970
|
+
if (response.ok) {
|
|
3971
|
+
return { ref, contents: await response.text() };
|
|
3972
|
+
}
|
|
3973
|
+
if (response.status !== 404) {
|
|
3974
|
+
throw new Error(
|
|
3975
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3976
|
+
);
|
|
3822
3977
|
}
|
|
3823
|
-
|
|
3978
|
+
}
|
|
3979
|
+
return void 0;
|
|
3980
|
+
}
|
|
3981
|
+
|
|
3982
|
+
// src/migrations/v2.1/add-translations.ts
|
|
3983
|
+
var APPLICATIONS = ["client", "login"];
|
|
3984
|
+
var TARGET_VERSION = "2.1";
|
|
3985
|
+
var skipped2 = [];
|
|
3986
|
+
function warnSkipped2(message) {
|
|
3987
|
+
skipped2.push(message);
|
|
3988
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3989
|
+
}
|
|
3990
|
+
function rowsToAdd(local, template) {
|
|
3991
|
+
const localColumns = parseCsvLine(local.header);
|
|
3992
|
+
const templateColumns = parseCsvLine(template.header);
|
|
3993
|
+
return template.body.filter((line2) => line2 !== "").map((line2) => {
|
|
3994
|
+
const values = parseCsvLine(line2);
|
|
3995
|
+
return toCsvLine(
|
|
3996
|
+
localColumns.map((column) => {
|
|
3997
|
+
const index = templateColumns.indexOf(column);
|
|
3998
|
+
return index === -1 ? "" : values[index] ?? "";
|
|
3999
|
+
})
|
|
4000
|
+
);
|
|
4001
|
+
});
|
|
4002
|
+
}
|
|
4003
|
+
async function updateApplication(cwd, refs, application) {
|
|
4004
|
+
const relativePath = `src/translations/${application}.csv`;
|
|
4005
|
+
const local = readCsvFile(import_path3.default.join(cwd, relativePath));
|
|
4006
|
+
if (!local) {
|
|
4007
|
+
warnSkipped2(`${relativePath} not found; translations not added`);
|
|
4008
|
+
return;
|
|
4009
|
+
}
|
|
4010
|
+
const fetched = await fetchTemplate(refs, application);
|
|
4011
|
+
if (!fetched) {
|
|
4012
|
+
warnSkipped2(
|
|
4013
|
+
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
4014
|
+
);
|
|
4015
|
+
return;
|
|
4016
|
+
}
|
|
4017
|
+
const template = readTemplate(fetched.contents);
|
|
4018
|
+
const added = addRows(local, rowsToAdd(local, template));
|
|
4019
|
+
if (added.length === 0) {
|
|
4020
|
+
return;
|
|
4021
|
+
}
|
|
4022
|
+
try {
|
|
4023
|
+
writeCsvFile(import_path3.default.join(cwd, relativePath), local);
|
|
4024
|
+
} catch (error3) {
|
|
4025
|
+
warnSkipped2(
|
|
4026
|
+
`Could not write ${relativePath} (${error3.message}); translations not added`
|
|
4027
|
+
);
|
|
4028
|
+
return;
|
|
4029
|
+
}
|
|
4030
|
+
for (const id of added) {
|
|
3824
4031
|
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
3825
4032
|
}
|
|
3826
|
-
if (added === 0) return;
|
|
3827
|
-
(0, import_fs.writeFileSync)(
|
|
3828
|
-
csvPath,
|
|
3829
|
-
[header, ...body].join(newline) + (hadTrailingNewline ? newline : "")
|
|
3830
|
-
);
|
|
3831
4033
|
}
|
|
3832
|
-
|
|
4034
|
+
function readTemplate(contents) {
|
|
4035
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
4036
|
+
return {
|
|
4037
|
+
header: lines[0],
|
|
4038
|
+
body: lines.slice(1),
|
|
4039
|
+
newline: "\n",
|
|
4040
|
+
trailingNewline: true
|
|
4041
|
+
};
|
|
4042
|
+
}
|
|
4043
|
+
async function listRefs() {
|
|
4044
|
+
try {
|
|
4045
|
+
return await candidateRefs(TARGET_VERSION);
|
|
4046
|
+
} catch (error3) {
|
|
4047
|
+
warnSkipped2(
|
|
4048
|
+
`Could not list the ${TARGET_VERSION} refs on GitHub (${error3.message}); translations not added`
|
|
4049
|
+
);
|
|
4050
|
+
return void 0;
|
|
4051
|
+
}
|
|
4052
|
+
}
|
|
4053
|
+
async function main3() {
|
|
3833
4054
|
const cwd = process.cwd();
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3842
|
-
|
|
4055
|
+
console.log("Adding the translation keys core gained this version...\n");
|
|
4056
|
+
const refs = await listRefs();
|
|
4057
|
+
if (refs) {
|
|
4058
|
+
for (const application of APPLICATIONS) {
|
|
4059
|
+
try {
|
|
4060
|
+
await updateApplication(cwd, refs, application);
|
|
4061
|
+
} catch (error3) {
|
|
4062
|
+
warnSkipped2(
|
|
4063
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${application}.csv not updated`
|
|
4064
|
+
);
|
|
4065
|
+
}
|
|
4066
|
+
}
|
|
3843
4067
|
}
|
|
3844
|
-
|
|
3845
|
-
tsConfigFilePath,
|
|
3846
|
-
skipAddingFilesFromTsConfig: false,
|
|
3847
|
-
// ts-morph indents inserted code with four spaces by default, which every
|
|
3848
|
-
// country config's prettier run would immediately undo.
|
|
3849
|
-
manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
|
|
3850
|
-
});
|
|
3851
|
-
updateEmailTemplates(project, cwd);
|
|
3852
|
-
updateSmsService(project, cwd);
|
|
3853
|
-
updateHandler(project, cwd);
|
|
3854
|
-
updateRoutes(project, cwd);
|
|
3855
|
-
await project.save();
|
|
3856
|
-
writeEmailTemplates(cwd);
|
|
3857
|
-
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
3858
|
-
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
3859
|
-
if (skipped.length > 0) {
|
|
4068
|
+
if (skipped2.length > 0) {
|
|
3860
4069
|
console.warn(
|
|
3861
4070
|
`
|
|
3862
|
-
\u26A0\uFE0F ${
|
|
4071
|
+
\u26A0\uFE0F ${skipped2.length} step(s) were skipped. Add the missing translations by hand before upgrading:`
|
|
3863
4072
|
);
|
|
3864
|
-
for (const message of
|
|
4073
|
+
for (const message of skipped2) {
|
|
3865
4074
|
console.warn(` - ${message}`);
|
|
3866
4075
|
}
|
|
3867
4076
|
}
|
|
@@ -3869,15 +4078,15 @@ async function main2() {
|
|
|
3869
4078
|
|
|
3870
4079
|
// src/migrations/v2.1/enable-telemetry.ts
|
|
3871
4080
|
var import_ts_morph3 = require("ts-morph");
|
|
3872
|
-
var
|
|
3873
|
-
var
|
|
4081
|
+
var import_fs3 = require("fs");
|
|
4082
|
+
var import_path4 = __toESM(require("path"));
|
|
3874
4083
|
var HANDLER_FILE2 = "src/api/telemetry/handler.ts";
|
|
3875
4084
|
var ENVIRONMENT_FILE = "src/environment.ts";
|
|
3876
4085
|
var INDEX_FILE = "src/index.ts";
|
|
3877
4086
|
var HANDLER_MODULE = "./api/telemetry/handler";
|
|
3878
|
-
var
|
|
3879
|
-
function
|
|
3880
|
-
|
|
4087
|
+
var skipped3 = [];
|
|
4088
|
+
function warnSkipped3(message) {
|
|
4089
|
+
skipped3.push(message);
|
|
3881
4090
|
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3882
4091
|
}
|
|
3883
4092
|
var TELEMETRY_HANDLER_SOURCE = `/*
|
|
@@ -3932,10 +4141,10 @@ export const TELEMETRY_DISABLED_NOTICE =
|
|
|
3932
4141
|
* telemetry is enabled or of the country code / domain / environment reported.
|
|
3933
4142
|
*/
|
|
3934
4143
|
export async function telemetryHandler(request: Request, h: ResponseToolkit) {
|
|
3935
|
-
// Only accept OpenCRVS *system* tokens (the events service's
|
|
4144
|
+
// Only accept OpenCRVS *system* tokens (the events service's service
|
|
3936
4145
|
// token has userType 'system'). A logged-in user's token is a 'user' token,
|
|
3937
4146
|
// so a user cannot submit telemetry with their own credentials \u2014 and the
|
|
3938
|
-
//
|
|
4147
|
+
// service-token endpoint is not reachable through the public gateway.
|
|
3939
4148
|
const credentials = request.auth.credentials as
|
|
3940
4149
|
| { userType?: string }
|
|
3941
4150
|
| undefined
|
|
@@ -4008,7 +4217,7 @@ async function promptTelemetryConfig() {
|
|
|
4008
4217
|
if (!process.stdin.isTTY) {
|
|
4009
4218
|
return TELEMETRY_DISABLED;
|
|
4010
4219
|
}
|
|
4011
|
-
const { confirm: confirm3, input:
|
|
4220
|
+
const { confirm: confirm3, input: input4 } = await import("@inquirer/prompts");
|
|
4012
4221
|
const enabled = await confirm3({
|
|
4013
4222
|
message: "Enable anonymous usage telemetry to help improve OpenCRVS? Only aggregate metrics are shared \u2014 no personal or protected data.",
|
|
4014
4223
|
default: true
|
|
@@ -4016,32 +4225,32 @@ async function promptTelemetryConfig() {
|
|
|
4016
4225
|
if (!enabled) {
|
|
4017
4226
|
return TELEMETRY_DISABLED;
|
|
4018
4227
|
}
|
|
4019
|
-
const countryCode = (await
|
|
4228
|
+
const countryCode = (await input4({
|
|
4020
4229
|
message: "Country code (ISO alpha-3, e.g. FAR):",
|
|
4021
4230
|
validate: (value) => /^[A-Za-z]{3}$/.test(value.trim()) || "Enter a 3-letter ISO alpha-3 code."
|
|
4022
4231
|
})).trim().toUpperCase();
|
|
4023
|
-
const organisation = (await
|
|
4232
|
+
const organisation = (await input4({
|
|
4024
4233
|
message: "Organisation running this instance:",
|
|
4025
4234
|
validate: (value) => value.trim() !== "" || "Enter an organisation name."
|
|
4026
4235
|
})).trim();
|
|
4027
4236
|
return { enabled: true, countryCode, organisation };
|
|
4028
4237
|
}
|
|
4029
4238
|
function writeTelemetryHandler(cwd) {
|
|
4030
|
-
const handlerPath =
|
|
4031
|
-
if ((0,
|
|
4239
|
+
const handlerPath = import_path4.default.join(cwd, HANDLER_FILE2);
|
|
4240
|
+
if ((0, import_fs3.existsSync)(handlerPath)) {
|
|
4032
4241
|
console.log(` ${HANDLER_FILE2} already present; left unchanged`);
|
|
4033
4242
|
return;
|
|
4034
4243
|
}
|
|
4035
|
-
(0,
|
|
4036
|
-
(0,
|
|
4244
|
+
(0, import_fs3.mkdirSync)(import_path4.default.dirname(handlerPath), { recursive: true });
|
|
4245
|
+
(0, import_fs3.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
|
|
4037
4246
|
console.log(` \u2713 ${HANDLER_FILE2}`);
|
|
4038
4247
|
}
|
|
4039
|
-
function appendProperty(sourceFile,
|
|
4040
|
-
const properties =
|
|
4248
|
+
function appendProperty(sourceFile, object2, name, valueLines) {
|
|
4249
|
+
const properties = object2.getProperties();
|
|
4041
4250
|
const lastProperty = properties[properties.length - 1];
|
|
4042
4251
|
if (!lastProperty) return false;
|
|
4043
4252
|
const indent = lastProperty.getIndentationText();
|
|
4044
|
-
const entry = valueLines.map((
|
|
4253
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${name}: ${line2}` : line2}`).join("\n");
|
|
4045
4254
|
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
4046
4255
|
${entry}`);
|
|
4047
4256
|
return true;
|
|
@@ -4049,7 +4258,7 @@ ${entry}`);
|
|
|
4049
4258
|
function ensureEnvalidNamedImports(sourceFile, names) {
|
|
4050
4259
|
const importDeclaration = sourceFile.getImportDeclarations().find((declaration) => declaration.getModuleSpecifierValue() === "envalid");
|
|
4051
4260
|
if (!importDeclaration) {
|
|
4052
|
-
|
|
4261
|
+
warnSkipped3(
|
|
4053
4262
|
`Could not find the 'envalid' import in ${ENVIRONMENT_FILE}; import { ${names.join(", ")} } by hand`
|
|
4054
4263
|
);
|
|
4055
4264
|
return;
|
|
@@ -4068,9 +4277,9 @@ function getCleanEnvObject(sourceFile) {
|
|
|
4068
4277
|
return options && import_ts_morph3.Node.isObjectLiteralExpression(options) ? options : void 0;
|
|
4069
4278
|
}
|
|
4070
4279
|
function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
4071
|
-
const
|
|
4072
|
-
if (!
|
|
4073
|
-
const existing =
|
|
4280
|
+
const object2 = getCleanEnvObject(sourceFile);
|
|
4281
|
+
if (!object2) return;
|
|
4282
|
+
const existing = object2.getProperty(name);
|
|
4074
4283
|
if (existing && import_ts_morph3.Node.isPropertyAssignment(existing)) {
|
|
4075
4284
|
if (!update) return;
|
|
4076
4285
|
const options = existing.getInitializerIfKind(import_ts_morph3.SyntaxKind.CallExpression)?.getArguments()[0];
|
|
@@ -4088,7 +4297,7 @@ function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
|
4088
4297
|
}
|
|
4089
4298
|
return;
|
|
4090
4299
|
}
|
|
4091
|
-
if (appendProperty(sourceFile,
|
|
4300
|
+
if (appendProperty(sourceFile, object2, name, [
|
|
4092
4301
|
`${kind}({`,
|
|
4093
4302
|
` default: ${defaultExpr},`,
|
|
4094
4303
|
` desc: ${JSON.stringify(desc)}`,
|
|
@@ -4099,16 +4308,16 @@ function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
|
4099
4308
|
}
|
|
4100
4309
|
function addEnvironmentVariables(project, cwd, config) {
|
|
4101
4310
|
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4102
|
-
|
|
4311
|
+
import_path4.default.join(cwd, ENVIRONMENT_FILE)
|
|
4103
4312
|
);
|
|
4104
4313
|
if (!sourceFile) {
|
|
4105
|
-
|
|
4314
|
+
warnSkipped3(
|
|
4106
4315
|
`${ENVIRONMENT_FILE} not found; add the telemetry env vars by hand`
|
|
4107
4316
|
);
|
|
4108
4317
|
return;
|
|
4109
4318
|
}
|
|
4110
4319
|
if (!getCleanEnvObject(sourceFile)) {
|
|
4111
|
-
|
|
4320
|
+
warnSkipped3(
|
|
4112
4321
|
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE}; add the telemetry env vars by hand`
|
|
4113
4322
|
);
|
|
4114
4323
|
return;
|
|
@@ -4147,27 +4356,46 @@ function addEnvironmentVariables(project, cwd, config) {
|
|
|
4147
4356
|
false
|
|
4148
4357
|
);
|
|
4149
4358
|
}
|
|
4359
|
+
function ensureHandlerNamedImports(sourceFile, names) {
|
|
4360
|
+
const importDeclaration = sourceFile.getImportDeclarations().find(
|
|
4361
|
+
(declaration) => declaration.getModuleSpecifierValue() === HANDLER_MODULE
|
|
4362
|
+
);
|
|
4363
|
+
if (!importDeclaration) {
|
|
4364
|
+
sourceFile.addImportDeclaration({
|
|
4365
|
+
moduleSpecifier: HANDLER_MODULE,
|
|
4366
|
+
namedImports: names
|
|
4367
|
+
});
|
|
4368
|
+
console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
|
|
4369
|
+
return;
|
|
4370
|
+
}
|
|
4371
|
+
const existing = new Set(
|
|
4372
|
+
importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4373
|
+
);
|
|
4374
|
+
const missing = names.filter((name) => !existing.has(name));
|
|
4375
|
+
for (const name of missing) {
|
|
4376
|
+
importDeclaration.addNamedImport(name);
|
|
4377
|
+
}
|
|
4378
|
+
if (missing.length > 0) {
|
|
4379
|
+
console.log(
|
|
4380
|
+
` \u2713 ${INDEX_FILE}: import ${missing.join(", ")} from ${HANDLER_MODULE}`
|
|
4381
|
+
);
|
|
4382
|
+
}
|
|
4383
|
+
}
|
|
4150
4384
|
function wireIndex(project, cwd) {
|
|
4151
4385
|
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4152
|
-
|
|
4386
|
+
import_path4.default.join(cwd, INDEX_FILE)
|
|
4153
4387
|
);
|
|
4154
4388
|
if (!sourceFile) {
|
|
4155
|
-
|
|
4389
|
+
warnSkipped3(
|
|
4156
4390
|
`${INDEX_FILE} not found; register POST /trigger/telemetry and the startup notice by hand`
|
|
4157
4391
|
);
|
|
4158
4392
|
return;
|
|
4159
4393
|
}
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4164
|
-
|
|
4165
|
-
"telemetrySchema",
|
|
4166
|
-
"TELEMETRY_DISABLED_NOTICE"
|
|
4167
|
-
]
|
|
4168
|
-
});
|
|
4169
|
-
console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
|
|
4170
|
-
}
|
|
4394
|
+
ensureHandlerNamedImports(sourceFile, [
|
|
4395
|
+
"telemetryHandler",
|
|
4396
|
+
"telemetrySchema",
|
|
4397
|
+
"TELEMETRY_DISABLED_NOTICE"
|
|
4398
|
+
]);
|
|
4171
4399
|
if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
|
|
4172
4400
|
const lastRouteStatement = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "server.route").map(
|
|
4173
4401
|
(call) => call.getFirstAncestorByKind(import_ts_morph3.SyntaxKind.ExpressionStatement)
|
|
@@ -4175,7 +4403,7 @@ function wireIndex(project, cwd) {
|
|
|
4175
4403
|
(statement) => Boolean(statement)
|
|
4176
4404
|
).pop();
|
|
4177
4405
|
if (!lastRouteStatement) {
|
|
4178
|
-
|
|
4406
|
+
warnSkipped3(
|
|
4179
4407
|
`Could not find a server.route(...) call in ${INDEX_FILE}; register POST /trigger/telemetry by hand`
|
|
4180
4408
|
);
|
|
4181
4409
|
} else {
|
|
@@ -4194,7 +4422,7 @@ function wireIndex(project, cwd) {
|
|
|
4194
4422
|
` 'Receives a usage report from the events service and forwards it to the status service when telemetry is enabled'`,
|
|
4195
4423
|
` }`,
|
|
4196
4424
|
`})`
|
|
4197
|
-
].map((
|
|
4425
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4198
4426
|
sourceFile.insertText(lastRouteStatement.getEnd(), `
|
|
4199
4427
|
|
|
4200
4428
|
${route}`);
|
|
@@ -4206,7 +4434,7 @@ ${route}`);
|
|
|
4206
4434
|
(statement) => statement.getText().includes("Server successfully started")
|
|
4207
4435
|
);
|
|
4208
4436
|
if (!startedLog) {
|
|
4209
|
-
|
|
4437
|
+
warnSkipped3(
|
|
4210
4438
|
`Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
|
|
4211
4439
|
);
|
|
4212
4440
|
} else {
|
|
@@ -4215,60 +4443,928 @@ ${route}`);
|
|
|
4215
4443
|
`if (!env.TELEMETRY_ENABLED) {`,
|
|
4216
4444
|
` logger.info(TELEMETRY_DISABLED_NOTICE)`,
|
|
4217
4445
|
`}`
|
|
4218
|
-
].map((
|
|
4446
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4219
4447
|
sourceFile.insertText(startedLog.getEnd(), `
|
|
4220
4448
|
|
|
4221
4449
|
${notice}`);
|
|
4222
4450
|
console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
|
|
4223
4451
|
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
|
|
4224
|
-
|
|
4452
|
+
warnSkipped3(
|
|
4225
4453
|
`The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
|
|
4226
4454
|
);
|
|
4227
4455
|
}
|
|
4228
4456
|
}
|
|
4229
4457
|
}
|
|
4230
4458
|
}
|
|
4231
|
-
async function
|
|
4459
|
+
async function main4() {
|
|
4460
|
+
const cwd = process.cwd();
|
|
4461
|
+
const config = await promptTelemetryConfig();
|
|
4462
|
+
console.log(
|
|
4463
|
+
`
|
|
4464
|
+
Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
|
|
4465
|
+
`
|
|
4466
|
+
);
|
|
4467
|
+
writeTelemetryHandler(cwd);
|
|
4468
|
+
const project = new import_ts_morph3.Project({
|
|
4469
|
+
// ts-morph indents inserted code with four spaces and double-quotes strings
|
|
4470
|
+
// by default, both of which the country config's prettier run would undo.
|
|
4471
|
+
manipulationSettings: {
|
|
4472
|
+
indentationText: import_ts_morph3.IndentationText.TwoSpaces,
|
|
4473
|
+
quoteKind: import_ts_morph3.QuoteKind.Single
|
|
4474
|
+
}
|
|
4475
|
+
});
|
|
4476
|
+
addEnvironmentVariables(project, cwd, config);
|
|
4477
|
+
wireIndex(project, cwd);
|
|
4478
|
+
await project.save();
|
|
4479
|
+
if (skipped3.length > 0) {
|
|
4480
|
+
console.warn(
|
|
4481
|
+
`
|
|
4482
|
+
\u26A0\uFE0F ${skipped3.length} telemetry step(s) were skipped. Wire the following by hand:`
|
|
4483
|
+
);
|
|
4484
|
+
for (const message of skipped3) {
|
|
4485
|
+
console.warn(` - ${message}`);
|
|
4486
|
+
}
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4489
|
+
|
|
4490
|
+
// src/migrations/v2.1/migrate-infrastructure-to-assets.ts
|
|
4491
|
+
var import_child_process = require("child_process");
|
|
4492
|
+
var import_fs5 = require("fs");
|
|
4493
|
+
var import_os = require("os");
|
|
4494
|
+
var import_path6 = __toESM(require("path"));
|
|
4495
|
+
|
|
4496
|
+
// src/migrations/v2.1/template-files.ts
|
|
4497
|
+
var import_fs4 = require("fs");
|
|
4498
|
+
var import_path5 = __toESM(require("path"));
|
|
4499
|
+
function findTemplateDir() {
|
|
4500
|
+
const candidates = [
|
|
4501
|
+
import_path5.default.resolve(__dirname, "templates", "countryconfig-template"),
|
|
4502
|
+
import_path5.default.resolve(__dirname, "../../../../countryconfig-template")
|
|
4503
|
+
];
|
|
4504
|
+
const templateDir = candidates.find(
|
|
4505
|
+
(candidate) => (0, import_fs4.existsSync)(import_path5.default.join(candidate, "Tiltfile"))
|
|
4506
|
+
);
|
|
4507
|
+
if (!templateDir) {
|
|
4508
|
+
throw new Error(
|
|
4509
|
+
`Country config template files not found in any of: ${candidates.join(", ")}`
|
|
4510
|
+
);
|
|
4511
|
+
}
|
|
4512
|
+
return templateDir;
|
|
4513
|
+
}
|
|
4514
|
+
function listFiles(root, dir) {
|
|
4515
|
+
const absolute = import_path5.default.join(root, dir);
|
|
4516
|
+
if (!(0, import_fs4.existsSync)(absolute)) {
|
|
4517
|
+
return [];
|
|
4518
|
+
}
|
|
4519
|
+
return (0, import_fs4.readdirSync)(absolute, { withFileTypes: true }).flatMap((entry) => {
|
|
4520
|
+
const relative = import_path5.default.posix.join(dir, entry.name);
|
|
4521
|
+
return entry.isDirectory() ? listFiles(root, relative) : [relative];
|
|
4522
|
+
});
|
|
4523
|
+
}
|
|
4524
|
+
|
|
4525
|
+
// src/migrations/v2.1/migrate-infrastructure-to-assets.ts
|
|
4526
|
+
var INFRASTRUCTURE_DIR = "infrastructure";
|
|
4527
|
+
var ASSETS_DIR = "assets";
|
|
4528
|
+
var BASE_URL = "https://raw.githubusercontent.com/opencrvs/opencrvs-farajaland/release/v2.0.0/infrastructure";
|
|
4529
|
+
var SOURCE_OF = {
|
|
4530
|
+
"elasticsearch/reindex.sh": "deployment/reindex.sh"
|
|
4531
|
+
};
|
|
4532
|
+
var MIGRATED_DIRS = ["metabase", "postgres", "deployment", "elasticsearch"];
|
|
4533
|
+
var NOT_MOVED = ["postgres/on-deploy.sh"];
|
|
4534
|
+
var isMigrated = (file) => MIGRATED_DIRS.some((dir) => file.startsWith(`${dir}/`));
|
|
4535
|
+
function tryGit(args2) {
|
|
4536
|
+
try {
|
|
4537
|
+
(0, import_child_process.execFileSync)("git", args2, { stdio: "ignore" });
|
|
4538
|
+
return true;
|
|
4539
|
+
} catch {
|
|
4540
|
+
return false;
|
|
4541
|
+
}
|
|
4542
|
+
}
|
|
4543
|
+
function assertIsGitRepo() {
|
|
4544
|
+
if (!tryGit(["rev-parse", "--is-inside-work-tree"])) {
|
|
4545
|
+
throw new Error(
|
|
4546
|
+
`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`
|
|
4547
|
+
);
|
|
4548
|
+
}
|
|
4549
|
+
}
|
|
4550
|
+
var toBytes = (buffer) => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
4551
|
+
var sameBytes = (a, b) => a.length === b.length && a.every((byte, index) => byte === b[index]);
|
|
4552
|
+
var isBinary = (contents) => contents.includes(0);
|
|
4553
|
+
function readIfExists(file) {
|
|
4554
|
+
return (0, import_fs5.existsSync)(file) ? toBytes((0, import_fs5.readFileSync)(file)) : void 0;
|
|
4555
|
+
}
|
|
4556
|
+
function mergeFile(file, ours, base, theirs) {
|
|
4557
|
+
const dir = (0, import_fs5.mkdtempSync)(import_path6.default.join((0, import_os.tmpdir)(), "opencrvs-merge-assets-"));
|
|
4558
|
+
try {
|
|
4559
|
+
const [oursPath, basePath, theirsPath] = ["ours", "base", "theirs"].map(
|
|
4560
|
+
(name) => import_path6.default.join(dir, name)
|
|
4561
|
+
);
|
|
4562
|
+
(0, import_fs5.writeFileSync)(oursPath, ours);
|
|
4563
|
+
(0, import_fs5.writeFileSync)(basePath, base);
|
|
4564
|
+
(0, import_fs5.writeFileSync)(theirsPath, theirs);
|
|
4565
|
+
const args2 = [
|
|
4566
|
+
"merge-file",
|
|
4567
|
+
"-p",
|
|
4568
|
+
"-L",
|
|
4569
|
+
`infrastructure/${file}`,
|
|
4570
|
+
"-L",
|
|
4571
|
+
"v2.0",
|
|
4572
|
+
"-L",
|
|
4573
|
+
`v2.1 template`,
|
|
4574
|
+
oursPath,
|
|
4575
|
+
basePath,
|
|
4576
|
+
theirsPath
|
|
4577
|
+
];
|
|
4578
|
+
try {
|
|
4579
|
+
return { contents: toBytes((0, import_child_process.execFileSync)("git", args2)), conflicts: 0 };
|
|
4580
|
+
} catch (error3) {
|
|
4581
|
+
const { status, stdout } = error3;
|
|
4582
|
+
if (status > 0 && status < 255) {
|
|
4583
|
+
return { contents: toBytes(stdout), conflicts: status };
|
|
4584
|
+
}
|
|
4585
|
+
throw error3;
|
|
4586
|
+
}
|
|
4587
|
+
} finally {
|
|
4588
|
+
(0, import_fs5.rmSync)(dir, { recursive: true, force: true });
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4591
|
+
async function fetchBases(files) {
|
|
4592
|
+
const bases = /* @__PURE__ */ new Map();
|
|
4593
|
+
for (const file of files) {
|
|
4594
|
+
const url = `${BASE_URL}/${file}`;
|
|
4595
|
+
const response = await fetch(url);
|
|
4596
|
+
if (response.ok) {
|
|
4597
|
+
bases.set(file, new Uint8Array(await response.arrayBuffer()));
|
|
4598
|
+
} else if (response.status !== 404) {
|
|
4599
|
+
throw new Error(
|
|
4600
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
4601
|
+
);
|
|
4602
|
+
}
|
|
4603
|
+
}
|
|
4604
|
+
return bases;
|
|
4605
|
+
}
|
|
4606
|
+
function migrateInfrastructureToAssets(cwd, templateDir, readBase) {
|
|
4607
|
+
const infrastructure = import_path6.default.join(cwd, INFRASTRUCTURE_DIR);
|
|
4608
|
+
const templateAssets = import_path6.default.join(templateDir, ASSETS_DIR);
|
|
4609
|
+
const relativeTo = (dir) => (file) => file.slice(dir.length + 1);
|
|
4610
|
+
const localFiles = listFiles(cwd, INFRASTRUCTURE_DIR).map(relativeTo(INFRASTRUCTURE_DIR)).filter(isMigrated);
|
|
4611
|
+
const templateFiles = listFiles(templateDir, ASSETS_DIR).map(
|
|
4612
|
+
relativeTo(ASSETS_DIR)
|
|
4613
|
+
);
|
|
4614
|
+
const outcomes = {};
|
|
4615
|
+
const migrated = /* @__PURE__ */ new Set();
|
|
4616
|
+
for (const file of [.../* @__PURE__ */ new Set([...templateFiles, ...localFiles])].sort()) {
|
|
4617
|
+
const sourceFile = !localFiles.includes(file) && localFiles.includes(SOURCE_OF[file]) ? SOURCE_OF[file] : file;
|
|
4618
|
+
const ours = readIfExists(import_path6.default.join(infrastructure, sourceFile));
|
|
4619
|
+
const theirsPath = import_path6.default.join(templateAssets, file);
|
|
4620
|
+
const theirs = readIfExists(theirsPath);
|
|
4621
|
+
const base = ours && readBase(sourceFile);
|
|
4622
|
+
const target = import_path6.default.join(cwd, ASSETS_DIR, file);
|
|
4623
|
+
if (NOT_MOVED.includes(file)) {
|
|
4624
|
+
if (ours && base && sameBytes(ours, base)) {
|
|
4625
|
+
migrated.add(file);
|
|
4626
|
+
outcomes[file] = "dropped";
|
|
4627
|
+
} else if (ours) {
|
|
4628
|
+
outcomes[file] = "not-moved";
|
|
4629
|
+
}
|
|
4630
|
+
continue;
|
|
4631
|
+
}
|
|
4632
|
+
const ownsSource = ours !== void 0 && sourceFile === file;
|
|
4633
|
+
if ((0, import_fs5.existsSync)(target)) {
|
|
4634
|
+
if (ownsSource) {
|
|
4635
|
+
const same = sameBytes(toBytes((0, import_fs5.readFileSync)(target)), ours);
|
|
4636
|
+
if (same) {
|
|
4637
|
+
migrated.add(file);
|
|
4638
|
+
}
|
|
4639
|
+
outcomes[file] = same ? "exists" : "exists-differs";
|
|
4640
|
+
}
|
|
4641
|
+
continue;
|
|
4642
|
+
}
|
|
4643
|
+
if (ownsSource) {
|
|
4644
|
+
migrated.add(file);
|
|
4645
|
+
}
|
|
4646
|
+
let contents;
|
|
4647
|
+
let outcome;
|
|
4648
|
+
if (!ours) {
|
|
4649
|
+
contents = theirs;
|
|
4650
|
+
outcome = "copied";
|
|
4651
|
+
} else if (!theirs) {
|
|
4652
|
+
const unchanged = base && sameBytes(ours, base);
|
|
4653
|
+
contents = unchanged ? void 0 : ours;
|
|
4654
|
+
outcome = unchanged ? "dropped" : "kept";
|
|
4655
|
+
} else if (sameBytes(ours, theirs) || base && sameBytes(ours, base)) {
|
|
4656
|
+
contents = theirs;
|
|
4657
|
+
outcome = "copied";
|
|
4658
|
+
} else if (!base || sameBytes(base, theirs) || isBinary(ours)) {
|
|
4659
|
+
contents = ours;
|
|
4660
|
+
outcome = "kept";
|
|
4661
|
+
} else {
|
|
4662
|
+
const result = mergeFile(sourceFile, ours, base, theirs);
|
|
4663
|
+
contents = result.contents;
|
|
4664
|
+
outcome = result.conflicts > 0 ? "conflict" : "merged";
|
|
4665
|
+
}
|
|
4666
|
+
outcomes[file] = outcome;
|
|
4667
|
+
if (contents === void 0) {
|
|
4668
|
+
continue;
|
|
4669
|
+
}
|
|
4670
|
+
(0, import_fs5.mkdirSync)(import_path6.default.dirname(target), { recursive: true });
|
|
4671
|
+
(0, import_fs5.writeFileSync)(target, contents);
|
|
4672
|
+
const modeSource = ours && outcome === "kept" ? import_path6.default.join(infrastructure, sourceFile) : theirsPath;
|
|
4673
|
+
if ((0, import_fs5.existsSync)(modeSource)) {
|
|
4674
|
+
(0, import_fs5.chmodSync)(target, (0, import_fs5.statSync)(modeSource).mode & 511);
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
return { outcomes, migrated: [...migrated].sort() };
|
|
4678
|
+
}
|
|
4679
|
+
function removeMigrated(cwd, migrated) {
|
|
4680
|
+
const infrastructure = import_path6.default.join(cwd, INFRASTRUCTURE_DIR);
|
|
4681
|
+
for (const file of migrated) {
|
|
4682
|
+
(0, import_fs5.rmSync)(import_path6.default.join(infrastructure, file), { force: true });
|
|
4683
|
+
}
|
|
4684
|
+
const pruneEmpty = (dir) => {
|
|
4685
|
+
if (!(0, import_fs5.existsSync)(dir)) {
|
|
4686
|
+
return true;
|
|
4687
|
+
}
|
|
4688
|
+
const empty = (0, import_fs5.readdirSync)(dir, { withFileTypes: true }).map(
|
|
4689
|
+
(entry) => entry.isDirectory() ? pruneEmpty(import_path6.default.join(dir, entry.name)) : false
|
|
4690
|
+
).every(Boolean);
|
|
4691
|
+
if (empty) {
|
|
4692
|
+
(0, import_fs5.rmdirSync)(dir);
|
|
4693
|
+
}
|
|
4694
|
+
return empty;
|
|
4695
|
+
};
|
|
4696
|
+
pruneEmpty(infrastructure);
|
|
4697
|
+
}
|
|
4698
|
+
var DESCRIPTIONS = {
|
|
4699
|
+
copied: "from the template",
|
|
4700
|
+
kept: "country's version",
|
|
4701
|
+
merged: "merged",
|
|
4702
|
+
conflict: "CONFLICT, resolve the markers by hand",
|
|
4703
|
+
dropped: "dropped, no longer used",
|
|
4704
|
+
exists: "already migrated",
|
|
4705
|
+
"exists-differs": "already exists with different contents; infrastructure/ copy kept for review",
|
|
4706
|
+
"not-moved": "changed locally but not moved: the chart runs its own on-deploy script, port your changes there"
|
|
4707
|
+
};
|
|
4708
|
+
async function main5(dockerSwarm = false) {
|
|
4709
|
+
const cwd = process.cwd();
|
|
4710
|
+
console.log("Moving infrastructure/ into assets/...\n");
|
|
4711
|
+
const templateDir = findTemplateDir();
|
|
4712
|
+
if ((0, import_fs5.existsSync)(import_path6.default.join(cwd, INFRASTRUCTURE_DIR))) {
|
|
4713
|
+
assertIsGitRepo();
|
|
4714
|
+
const needed = listFiles(cwd, INFRASTRUCTURE_DIR).map((file) => file.slice(INFRASTRUCTURE_DIR.length + 1)).filter(isMigrated);
|
|
4715
|
+
let bases;
|
|
4716
|
+
try {
|
|
4717
|
+
bases = await fetchBases(needed);
|
|
4718
|
+
} catch (error3) {
|
|
4719
|
+
console.warn(
|
|
4720
|
+
` \u26A0\uFE0F Could not read the v2.0 files to merge against (${error3.message}); infrastructure/ was not migrated. Re-run 'opencrvs upgrade' with network access.`
|
|
4721
|
+
);
|
|
4722
|
+
return;
|
|
4723
|
+
}
|
|
4724
|
+
const { outcomes, migrated } = migrateInfrastructureToAssets(
|
|
4725
|
+
cwd,
|
|
4726
|
+
templateDir,
|
|
4727
|
+
(file) => bases.get(file)
|
|
4728
|
+
);
|
|
4729
|
+
for (const [file, outcome] of Object.entries(outcomes)) {
|
|
4730
|
+
const needsReview = ["conflict", "not-moved", "exists-differs"].includes(
|
|
4731
|
+
outcome
|
|
4732
|
+
);
|
|
4733
|
+
const shown = outcome === "not-moved" ? INFRASTRUCTURE_DIR : ASSETS_DIR;
|
|
4734
|
+
const line2 = ` ${needsReview ? "\u26A0\uFE0F " : "\u2713"} ${shown}/${file}: ${DESCRIPTIONS[outcome]}`;
|
|
4735
|
+
if (needsReview) {
|
|
4736
|
+
console.warn(line2);
|
|
4737
|
+
} else {
|
|
4738
|
+
console.log(line2);
|
|
4739
|
+
}
|
|
4740
|
+
}
|
|
4741
|
+
if (dockerSwarm) {
|
|
4742
|
+
console.log(
|
|
4743
|
+
"\n infrastructure/ kept in place (--docker-swarm); assets/ now holds a copy."
|
|
4744
|
+
);
|
|
4745
|
+
} else {
|
|
4746
|
+
removeMigrated(cwd, migrated);
|
|
4747
|
+
}
|
|
4748
|
+
tryGit(["add", "-A", "--", ASSETS_DIR, INFRASTRUCTURE_DIR]);
|
|
4749
|
+
const conflicts = Object.keys(outcomes).filter(
|
|
4750
|
+
(file) => outcomes[file] === "conflict"
|
|
4751
|
+
);
|
|
4752
|
+
for (const file of conflicts) {
|
|
4753
|
+
tryGit(["restore", "--staged", "--", `${ASSETS_DIR}/${file}`]);
|
|
4754
|
+
}
|
|
4755
|
+
if (conflicts.length > 0) {
|
|
4756
|
+
console.warn(
|
|
4757
|
+
`
|
|
4758
|
+
\u26A0\uFE0F ${conflicts.length} file(s) need their conflicts resolved: ${conflicts.map((file) => `assets/${file}`).join(", ")}`
|
|
4759
|
+
);
|
|
4760
|
+
}
|
|
4761
|
+
if ((0, import_fs5.existsSync)(import_path6.default.join(cwd, INFRASTRUCTURE_DIR)) && !dockerSwarm) {
|
|
4762
|
+
console.warn(
|
|
4763
|
+
" \u26A0\uFE0F infrastructure/ still has files the Kubernetes deployment does not use. Review and delete them if they are no longer needed."
|
|
4764
|
+
);
|
|
4765
|
+
}
|
|
4766
|
+
} else {
|
|
4767
|
+
console.log(" infrastructure/ not found, nothing to move.");
|
|
4768
|
+
}
|
|
4769
|
+
const dockerfile = toBytes(
|
|
4770
|
+
(0, import_fs5.readFileSync)(import_path6.default.join(templateDir, "Dockerfile.assets"))
|
|
4771
|
+
);
|
|
4772
|
+
const current = readIfExists(import_path6.default.join(cwd, "Dockerfile.assets"));
|
|
4773
|
+
if (!current || !sameBytes(current, dockerfile)) {
|
|
4774
|
+
(0, import_fs5.writeFileSync)(import_path6.default.join(cwd, "Dockerfile.assets"), dockerfile);
|
|
4775
|
+
tryGit(["add", "--", "Dockerfile.assets"]);
|
|
4776
|
+
console.log(" \u2713 Dockerfile.assets replaced with the template version");
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
|
|
4780
|
+
// src/migrations/v2.1/remove-metabase-package-installs.ts
|
|
4781
|
+
var import_fs6 = require("fs");
|
|
4782
|
+
var import_path7 = require("path");
|
|
4783
|
+
var METABASE_DIRS = ["infrastructure/metabase", "assets/metabase"];
|
|
4784
|
+
var APK_BLOCK = [
|
|
4785
|
+
"apk update",
|
|
4786
|
+
"apk upgrade",
|
|
4787
|
+
"apk add --no-cache gettext",
|
|
4788
|
+
"apk add --no-cache util-linux",
|
|
4789
|
+
"",
|
|
4790
|
+
""
|
|
4791
|
+
].join("\n");
|
|
4792
|
+
var SALT_LINE = "export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=$(uuidgen)\n";
|
|
4793
|
+
var FIXED_SALT_LINE = "export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)\n\n";
|
|
4794
|
+
var FIXED_SALT_MARKER = "/proc/sys/kernel/random/uuid";
|
|
4795
|
+
var ENVSUBST_GUARD = [
|
|
4796
|
+
"if ! which envsubst >/dev/null; then",
|
|
4797
|
+
' echo "envsubst could not be found. Please install envsubst before continuing."',
|
|
4798
|
+
' echo "MacOS: brew install gettext && brew link --force gettext"',
|
|
4799
|
+
" exit 1",
|
|
4800
|
+
"fi",
|
|
4801
|
+
""
|
|
4802
|
+
].join("\n");
|
|
4803
|
+
var ENVSUBST_CALL = "envsubst < $environment_configuration_sql_file > $environment_configuration_sql_file.tmp\n";
|
|
4804
|
+
var FIXED_EXPANSION = [
|
|
4805
|
+
"",
|
|
4806
|
+
"# Expand $VAR / ${VAR} using bash's own heredoc expansion instead of envsubst,",
|
|
4807
|
+
"# because envsubst is not installed in the Metabase image",
|
|
4808
|
+
'eval "cat <<OPENCRVS_ENV_EOF',
|
|
4809
|
+
'$(cat "$environment_configuration_sql_file")',
|
|
4810
|
+
'OPENCRVS_ENV_EOF" > "$environment_configuration_sql_file.tmp"',
|
|
4811
|
+
""
|
|
4812
|
+
].join("\n");
|
|
4813
|
+
var FIXED_EXPANSION_MARKER = "OPENCRVS_ENV_EOF";
|
|
4814
|
+
function patchRunScript(source) {
|
|
4815
|
+
if (source.includes(FIXED_SALT_MARKER) && !source.includes(APK_BLOCK)) {
|
|
4816
|
+
return source;
|
|
4817
|
+
}
|
|
4818
|
+
if (!source.includes(APK_BLOCK) || !source.includes(SALT_LINE)) {
|
|
4819
|
+
return void 0;
|
|
4820
|
+
}
|
|
4821
|
+
return source.replace(APK_BLOCK, "").replace(SALT_LINE, FIXED_SALT_LINE);
|
|
4822
|
+
}
|
|
4823
|
+
function patchUpdateDatabaseScript(source) {
|
|
4824
|
+
if (source.includes(FIXED_EXPANSION_MARKER) && !source.includes(ENVSUBST_CALL)) {
|
|
4825
|
+
return source;
|
|
4826
|
+
}
|
|
4827
|
+
if (!source.includes(ENVSUBST_GUARD) || !source.includes(ENVSUBST_CALL)) {
|
|
4828
|
+
return void 0;
|
|
4829
|
+
}
|
|
4830
|
+
return source.replace(ENVSUBST_GUARD, "").replace(ENVSUBST_CALL, FIXED_EXPANSION);
|
|
4831
|
+
}
|
|
4832
|
+
function patchFile(relativePath, patch, removed) {
|
|
4833
|
+
const filePath = (0, import_path7.join)(process.cwd(), relativePath);
|
|
4834
|
+
if (!(0, import_fs6.existsSync)(filePath)) {
|
|
4835
|
+
return;
|
|
4836
|
+
}
|
|
4837
|
+
const source = (0, import_fs6.readFileSync)(filePath, "utf8");
|
|
4838
|
+
const patched = patch(source);
|
|
4839
|
+
if (patched === void 0) {
|
|
4840
|
+
console.warn(
|
|
4841
|
+
` \u26A0\uFE0F ${relativePath} does not match the upstream v2.0 version, so it was left alone. Apply https://github.com/opencrvs/opencrvs-core/pull/13778 by hand, or Metabase will fail to start behind the chart's private egress policy.`
|
|
4842
|
+
);
|
|
4843
|
+
return;
|
|
4844
|
+
}
|
|
4845
|
+
if (patched === source) {
|
|
4846
|
+
return;
|
|
4847
|
+
}
|
|
4848
|
+
(0, import_fs6.writeFileSync)(filePath, patched);
|
|
4849
|
+
console.log(` \u2713 ${relativePath}: ${removed}`);
|
|
4850
|
+
}
|
|
4851
|
+
async function main6() {
|
|
4852
|
+
console.log("\nRemoving the Metabase package installs...\n");
|
|
4853
|
+
for (const dir of METABASE_DIRS) {
|
|
4854
|
+
patchFile((0, import_path7.join)(dir, "run.sh"), patchRunScript, "apk add gettext util-linux");
|
|
4855
|
+
patchFile(
|
|
4856
|
+
(0, import_path7.join)(dir, "update-database.sh"),
|
|
4857
|
+
patchUpdateDatabaseScript,
|
|
4858
|
+
"envsubst"
|
|
4859
|
+
);
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4863
|
+
// src/migrations/v2.1/remove-sentry.ts
|
|
4864
|
+
var import_fs7 = require("fs");
|
|
4865
|
+
var import_path8 = __toESM(require("path"));
|
|
4866
|
+
var import_ts_morph4 = require("ts-morph");
|
|
4867
|
+
var CONFIG_FILES = [
|
|
4868
|
+
"src/client-config.ts",
|
|
4869
|
+
"src/client-config.prod.ts",
|
|
4870
|
+
"src/login-config.ts",
|
|
4871
|
+
"src/login-config.prod.ts"
|
|
4872
|
+
];
|
|
4873
|
+
var ENVIRONMENT_FILE2 = "src/environment.ts";
|
|
4874
|
+
var CONSTANTS_FILE = "src/constants.ts";
|
|
4875
|
+
var INDEX_FILE2 = "src/index.ts";
|
|
4876
|
+
var UTILS_FILE = "src/utils/index.ts";
|
|
4877
|
+
var PACKAGE_JSON_FILE = "package.json";
|
|
4878
|
+
var TYPINGS_FILE = "typings/hapi-sentry.d.ts";
|
|
4879
|
+
var SENTRY_PLUGIN = "hapi-sentry";
|
|
4880
|
+
var skipped4 = [];
|
|
4881
|
+
function warnSkipped4(message) {
|
|
4882
|
+
skipped4.push(message);
|
|
4883
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4884
|
+
}
|
|
4885
|
+
function isReferenced(sourceFile, name) {
|
|
4886
|
+
return sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.Identifier).some(
|
|
4887
|
+
(identifier) => identifier.getText() === name && !identifier.getFirstAncestorByKind(import_ts_morph4.SyntaxKind.ImportDeclaration)
|
|
4888
|
+
);
|
|
4889
|
+
}
|
|
4890
|
+
function removeIfUnused(sourceFile, importDeclaration) {
|
|
4891
|
+
const names = [
|
|
4892
|
+
importDeclaration.getDefaultImport()?.getText(),
|
|
4893
|
+
importDeclaration.getNamespaceImport()?.getText(),
|
|
4894
|
+
...importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4895
|
+
].filter((name) => Boolean(name));
|
|
4896
|
+
if (names.length > 0 && names.every((name) => !isReferenced(sourceFile, name))) {
|
|
4897
|
+
importDeclaration.remove();
|
|
4898
|
+
return true;
|
|
4899
|
+
}
|
|
4900
|
+
return false;
|
|
4901
|
+
}
|
|
4902
|
+
function removeNamedImport(sourceFile, moduleSpecifier, name) {
|
|
4903
|
+
const importDeclaration = sourceFile.getImportDeclarations().find(
|
|
4904
|
+
(declaration) => declaration.getModuleSpecifierValue() === moduleSpecifier
|
|
4905
|
+
);
|
|
4906
|
+
if (!importDeclaration) return false;
|
|
4907
|
+
const named = importDeclaration.getNamedImports().find((namedImport) => namedImport.getName() === name);
|
|
4908
|
+
if (!named) return false;
|
|
4909
|
+
named.remove();
|
|
4910
|
+
if (importDeclaration.getNamedImports().length === 0 && !importDeclaration.getDefaultImport() && !importDeclaration.getNamespaceImport()) {
|
|
4911
|
+
importDeclaration.remove();
|
|
4912
|
+
}
|
|
4913
|
+
return true;
|
|
4914
|
+
}
|
|
4915
|
+
function removeSentryFromConfigs(project, cwd) {
|
|
4916
|
+
for (const file of CONFIG_FILES) {
|
|
4917
|
+
const sourceFile = project.addSourceFileAtPathIfExists(import_path8.default.join(cwd, file));
|
|
4918
|
+
if (!sourceFile) continue;
|
|
4919
|
+
const property = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.PropertyAssignment).find((assignment) => assignment.getName() === "SENTRY");
|
|
4920
|
+
if (!property) continue;
|
|
4921
|
+
const usedNames = new Set(
|
|
4922
|
+
property.getDescendantsOfKind(import_ts_morph4.SyntaxKind.Identifier).map((identifier) => identifier.getText())
|
|
4923
|
+
);
|
|
4924
|
+
property.remove();
|
|
4925
|
+
for (const importDeclaration of [...sourceFile.getImportDeclarations()]) {
|
|
4926
|
+
const imported = [
|
|
4927
|
+
importDeclaration.getDefaultImport()?.getText(),
|
|
4928
|
+
importDeclaration.getNamespaceImport()?.getText(),
|
|
4929
|
+
...importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4930
|
+
].filter((name) => Boolean(name));
|
|
4931
|
+
if (imported.some((name) => usedNames.has(name))) {
|
|
4932
|
+
removeIfUnused(sourceFile, importDeclaration);
|
|
4933
|
+
}
|
|
4934
|
+
}
|
|
4935
|
+
console.log(` \u2713 ${file}: SENTRY`);
|
|
4936
|
+
}
|
|
4937
|
+
}
|
|
4938
|
+
function removeEnvironmentVariable(project, cwd) {
|
|
4939
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4940
|
+
import_path8.default.join(cwd, ENVIRONMENT_FILE2)
|
|
4941
|
+
);
|
|
4942
|
+
if (!sourceFile) return;
|
|
4943
|
+
const options = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.CallExpression).find((call) => call.getExpression().getText() === "cleanEnv")?.getArguments()[1];
|
|
4944
|
+
if (!options || !import_ts_morph4.Node.isObjectLiteralExpression(options)) {
|
|
4945
|
+
warnSkipped4(
|
|
4946
|
+
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE2}; remove SENTRY_DSN by hand`
|
|
4947
|
+
);
|
|
4948
|
+
return;
|
|
4949
|
+
}
|
|
4950
|
+
const property = options.getProperty("SENTRY_DSN");
|
|
4951
|
+
if (!property) return;
|
|
4952
|
+
property.remove();
|
|
4953
|
+
console.log(` \u2713 ${ENVIRONMENT_FILE2}: SENTRY_DSN`);
|
|
4954
|
+
}
|
|
4955
|
+
function removeConstant(project, cwd) {
|
|
4956
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4957
|
+
import_path8.default.join(cwd, CONSTANTS_FILE)
|
|
4958
|
+
);
|
|
4959
|
+
if (!sourceFile) return;
|
|
4960
|
+
for (const statement of [...sourceFile.getVariableStatements()]) {
|
|
4961
|
+
const declarations = statement.getDeclarations();
|
|
4962
|
+
const matching = declarations.filter(
|
|
4963
|
+
(declaration) => declaration.getName() === "SENTRY_DSN" || /\benv\.SENTRY_DSN\b/.test(
|
|
4964
|
+
declaration.getInitializer()?.getText() ?? ""
|
|
4965
|
+
)
|
|
4966
|
+
);
|
|
4967
|
+
if (matching.length === 0) continue;
|
|
4968
|
+
const names = matching.map((declaration) => declaration.getName());
|
|
4969
|
+
if (matching.length === declarations.length) {
|
|
4970
|
+
statement.remove();
|
|
4971
|
+
} else {
|
|
4972
|
+
for (const declaration of matching) {
|
|
4973
|
+
declaration.remove();
|
|
4974
|
+
}
|
|
4975
|
+
}
|
|
4976
|
+
console.log(` \u2713 ${CONSTANTS_FILE}: ${names.join(", ")}`);
|
|
4977
|
+
}
|
|
4978
|
+
}
|
|
4979
|
+
function unwireIndex(project, cwd) {
|
|
4980
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4981
|
+
import_path8.default.join(cwd, INDEX_FILE2)
|
|
4982
|
+
);
|
|
4983
|
+
if (!sourceFile) return;
|
|
4984
|
+
const pluginImport = sourceFile.getImportDeclarations().find(
|
|
4985
|
+
(declaration) => declaration.getModuleSpecifierValue() === SENTRY_PLUGIN
|
|
4986
|
+
);
|
|
4987
|
+
const pluginName = pluginImport?.getNamespaceImport()?.getText() ?? pluginImport?.getDefaultImport()?.getText() ?? "Sentry";
|
|
4988
|
+
const registration = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.IfStatement).find(
|
|
4989
|
+
(statement) => /\bSENTRY_DSN\b/.test(statement.getExpression().getText()) && new RegExp(`\\bplugin:\\s*${pluginName}\\b`).test(statement.getText())
|
|
4990
|
+
);
|
|
4991
|
+
if (registration) {
|
|
4992
|
+
registration.remove();
|
|
4993
|
+
console.log(` \u2713 ${INDEX_FILE2}: hapi-sentry plugin registration`);
|
|
4994
|
+
} else if (sourceFile.getText().includes(SENTRY_PLUGIN)) {
|
|
4995
|
+
warnSkipped4(
|
|
4996
|
+
`Could not find the hapi-sentry plugin registration in ${INDEX_FILE2}; remove it by hand`
|
|
4997
|
+
);
|
|
4998
|
+
}
|
|
4999
|
+
const scopeExtension = sourceFile.getDescendantsOfKind(import_ts_morph4.SyntaxKind.ExpressionStatement).find(
|
|
5000
|
+
(statement) => statement.getText().includes("sentryScope") && statement.getText().startsWith("server.ext")
|
|
5001
|
+
);
|
|
5002
|
+
if (scopeExtension) {
|
|
5003
|
+
scopeExtension.remove();
|
|
5004
|
+
console.log(` \u2713 ${INDEX_FILE2}: onRequest Sentry scope extension`);
|
|
5005
|
+
} else if (sourceFile.getText().includes("sentryScope")) {
|
|
5006
|
+
warnSkipped4(
|
|
5007
|
+
`Found 'sentryScope' in ${INDEX_FILE2} outside a server.ext(...) call; remove it by hand`
|
|
5008
|
+
);
|
|
5009
|
+
}
|
|
5010
|
+
if (pluginImport && removeIfUnused(sourceFile, pluginImport)) {
|
|
5011
|
+
console.log(` \u2713 ${INDEX_FILE2}: import '${SENTRY_PLUGIN}'`);
|
|
5012
|
+
}
|
|
5013
|
+
if (!isReferenced(sourceFile, "SENTRY_DSN")) {
|
|
5014
|
+
for (const declaration of [...sourceFile.getImportDeclarations()]) {
|
|
5015
|
+
const specifier = declaration.getModuleSpecifierValue();
|
|
5016
|
+
if (removeNamedImport(sourceFile, specifier, "SENTRY_DSN")) {
|
|
5017
|
+
console.log(` \u2713 ${INDEX_FILE2}: import SENTRY_DSN from '${specifier}'`);
|
|
5018
|
+
break;
|
|
5019
|
+
}
|
|
5020
|
+
}
|
|
5021
|
+
}
|
|
5022
|
+
}
|
|
5023
|
+
function removeApplicationConfigField(project, cwd) {
|
|
5024
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
5025
|
+
import_path8.default.join(cwd, UTILS_FILE)
|
|
5026
|
+
);
|
|
5027
|
+
if (!sourceFile) return;
|
|
5028
|
+
const property = sourceFile.getInterface("IApplicationConfig")?.getProperty("SENTRY");
|
|
5029
|
+
if (!property) return;
|
|
5030
|
+
property.remove();
|
|
5031
|
+
console.log(` \u2713 ${UTILS_FILE}: IApplicationConfig.SENTRY`);
|
|
5032
|
+
}
|
|
5033
|
+
function isSentryPackage(name) {
|
|
5034
|
+
return name === SENTRY_PLUGIN || name.startsWith("@sentry/");
|
|
5035
|
+
}
|
|
5036
|
+
function removeDependencies(cwd) {
|
|
5037
|
+
const packageJsonPath = import_path8.default.join(cwd, PACKAGE_JSON_FILE);
|
|
5038
|
+
if (!(0, import_fs7.existsSync)(packageJsonPath)) return;
|
|
5039
|
+
const raw = (0, import_fs7.readFileSync)(packageJsonPath, "utf8");
|
|
5040
|
+
let parsed;
|
|
5041
|
+
try {
|
|
5042
|
+
parsed = JSON.parse(raw);
|
|
5043
|
+
} catch (error3) {
|
|
5044
|
+
warnSkipped4(
|
|
5045
|
+
`${PACKAGE_JSON_FILE} could not be parsed (${error3.message}); remove the Sentry dependencies by hand`
|
|
5046
|
+
);
|
|
5047
|
+
return;
|
|
5048
|
+
}
|
|
5049
|
+
const removed = [];
|
|
5050
|
+
for (const bucket of ["dependencies", "devDependencies"]) {
|
|
5051
|
+
const dependencies = parsed[bucket];
|
|
5052
|
+
if (!dependencies) continue;
|
|
5053
|
+
for (const name of Object.keys(dependencies)) {
|
|
5054
|
+
if (isSentryPackage(name)) {
|
|
5055
|
+
delete dependencies[name];
|
|
5056
|
+
removed.push(name);
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
if (removed.length === 0) return;
|
|
5061
|
+
const trailingNewline = raw.endsWith("\n") ? "\n" : "";
|
|
5062
|
+
(0, import_fs7.writeFileSync)(
|
|
5063
|
+
packageJsonPath,
|
|
5064
|
+
`${JSON.stringify(parsed, null, 2)}${trailingNewline}`
|
|
5065
|
+
);
|
|
5066
|
+
console.log(` \u2713 ${PACKAGE_JSON_FILE}: ${removed.join(", ")}`);
|
|
5067
|
+
}
|
|
5068
|
+
function removeTypings(cwd) {
|
|
5069
|
+
const typingsPath = import_path8.default.join(cwd, TYPINGS_FILE);
|
|
5070
|
+
if (!(0, import_fs7.existsSync)(typingsPath)) return;
|
|
5071
|
+
const declarations = (0, import_fs7.readFileSync)(typingsPath, "utf8").replace(/\/\*[\s\S]*?\*\//g, "").replace(/^\s*\/\/.*$/gm, "").trim();
|
|
5072
|
+
if (!/^declare module ['"]hapi-sentry['"];?$/.test(declarations)) {
|
|
5073
|
+
warnSkipped4(
|
|
5074
|
+
`${TYPINGS_FILE} declares more than the 'hapi-sentry' module; remove the declaration by hand`
|
|
5075
|
+
);
|
|
5076
|
+
return;
|
|
5077
|
+
}
|
|
5078
|
+
(0, import_fs7.rmSync)(typingsPath);
|
|
5079
|
+
console.log(` \u2713 ${TYPINGS_FILE}: deleted`);
|
|
5080
|
+
}
|
|
5081
|
+
async function main7() {
|
|
4232
5082
|
const cwd = process.cwd();
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
`
|
|
4238
|
-
);
|
|
4239
|
-
writeTelemetryHandler(cwd);
|
|
4240
|
-
const project = new import_ts_morph3.Project({
|
|
4241
|
-
// ts-morph indents inserted code with four spaces and double-quotes strings
|
|
4242
|
-
// by default, both of which the country config's prettier run would undo.
|
|
5083
|
+
console.log("\nRemoving Sentry...\n");
|
|
5084
|
+
const project = new import_ts_morph4.Project({
|
|
5085
|
+
// ts-morph indents with four spaces and double-quotes strings by default,
|
|
5086
|
+
// both of which the country config's prettier run would undo.
|
|
4243
5087
|
manipulationSettings: {
|
|
4244
|
-
indentationText:
|
|
4245
|
-
quoteKind:
|
|
5088
|
+
indentationText: import_ts_morph4.IndentationText.TwoSpaces,
|
|
5089
|
+
quoteKind: import_ts_morph4.QuoteKind.Single
|
|
4246
5090
|
}
|
|
4247
5091
|
});
|
|
4248
|
-
|
|
4249
|
-
|
|
5092
|
+
removeSentryFromConfigs(project, cwd);
|
|
5093
|
+
removeEnvironmentVariable(project, cwd);
|
|
5094
|
+
removeConstant(project, cwd);
|
|
5095
|
+
unwireIndex(project, cwd);
|
|
5096
|
+
removeApplicationConfigField(project, cwd);
|
|
4250
5097
|
await project.save();
|
|
4251
|
-
|
|
5098
|
+
removeDependencies(cwd);
|
|
5099
|
+
removeTypings(cwd);
|
|
5100
|
+
if (skipped4.length > 0) {
|
|
4252
5101
|
console.warn(
|
|
4253
5102
|
`
|
|
4254
|
-
\u26A0\uFE0F ${
|
|
5103
|
+
\u26A0\uFE0F ${skipped4.length} Sentry removal step(s) were skipped. Handle the following by hand:`
|
|
4255
5104
|
);
|
|
4256
|
-
for (const message of
|
|
5105
|
+
for (const message of skipped4) {
|
|
4257
5106
|
console.warn(` - ${message}`);
|
|
4258
5107
|
}
|
|
4259
5108
|
}
|
|
4260
5109
|
}
|
|
4261
5110
|
|
|
5111
|
+
// src/migrations/v2.1/rename-trigger-paths.ts
|
|
5112
|
+
var import_ts_morph5 = require("ts-morph");
|
|
5113
|
+
var import_path9 = __toESM(require("path"));
|
|
5114
|
+
var PATH_PREFIX_RENAMES = {
|
|
5115
|
+
"/triggers/user/": "/trigger/user/",
|
|
5116
|
+
"/triggers/system/": "/trigger/system/"
|
|
5117
|
+
};
|
|
5118
|
+
var STALE_PREFIX = "/triggers/";
|
|
5119
|
+
var METHOD_PROPERTY_NAME = "method";
|
|
5120
|
+
var PATH_PROPERTY_NAME = "path";
|
|
5121
|
+
var HTTP_VERBS = /* @__PURE__ */ new Set([
|
|
5122
|
+
"GET",
|
|
5123
|
+
"POST",
|
|
5124
|
+
"PUT",
|
|
5125
|
+
"PATCH",
|
|
5126
|
+
"DELETE",
|
|
5127
|
+
"OPTIONS",
|
|
5128
|
+
"HEAD",
|
|
5129
|
+
"*"
|
|
5130
|
+
]);
|
|
5131
|
+
function isRouteConfig(obj) {
|
|
5132
|
+
const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
|
|
5133
|
+
if (!methodProp || !import_ts_morph5.Node.isPropertyAssignment(methodProp)) return false;
|
|
5134
|
+
const methodInit = methodProp.getInitializer();
|
|
5135
|
+
if (!methodInit) return false;
|
|
5136
|
+
if (import_ts_morph5.Node.isStringLiteral(methodInit)) {
|
|
5137
|
+
if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
|
|
5138
|
+
return false;
|
|
5139
|
+
} else if (import_ts_morph5.Node.isArrayLiteralExpression(methodInit)) {
|
|
5140
|
+
const allVerbs = methodInit.getElements().every(
|
|
5141
|
+
(el) => import_ts_morph5.Node.isStringLiteral(el) && HTTP_VERBS.has(el.getLiteralValue().toUpperCase())
|
|
5142
|
+
);
|
|
5143
|
+
if (!allVerbs) return false;
|
|
5144
|
+
} else {
|
|
5145
|
+
return false;
|
|
5146
|
+
}
|
|
5147
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
5148
|
+
if (!pathProp || !import_ts_morph5.Node.isPropertyAssignment(pathProp)) return false;
|
|
5149
|
+
const pathInit = pathProp.getInitializer();
|
|
5150
|
+
return !!pathInit && import_ts_morph5.Node.isStringLiteral(pathInit);
|
|
5151
|
+
}
|
|
5152
|
+
function renameRoutePath(obj) {
|
|
5153
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
5154
|
+
if (!pathProp || !import_ts_morph5.Node.isPropertyAssignment(pathProp)) return null;
|
|
5155
|
+
const pathInit = pathProp.getInitializer();
|
|
5156
|
+
if (!pathInit || !import_ts_morph5.Node.isStringLiteral(pathInit)) return null;
|
|
5157
|
+
const oldPath = pathInit.getLiteralValue();
|
|
5158
|
+
const match = Object.entries(PATH_PREFIX_RENAMES).find(
|
|
5159
|
+
([from2]) => oldPath.startsWith(from2)
|
|
5160
|
+
);
|
|
5161
|
+
if (!match) return null;
|
|
5162
|
+
const [from, to] = match;
|
|
5163
|
+
const newPath = to + oldPath.slice(from.length);
|
|
5164
|
+
pathInit.replaceWithText(`'${newPath}'`);
|
|
5165
|
+
return newPath;
|
|
5166
|
+
}
|
|
5167
|
+
function processFile2(filePath, project) {
|
|
5168
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
5169
|
+
if (!sourceFile) return 0;
|
|
5170
|
+
let renamedCount = 0;
|
|
5171
|
+
const relPath = import_path9.default.relative(process.cwd(), filePath);
|
|
5172
|
+
const candidates = sourceFile.getDescendantsOfKind(
|
|
5173
|
+
import_ts_morph5.SyntaxKind.ObjectLiteralExpression
|
|
5174
|
+
);
|
|
5175
|
+
for (const obj of candidates) {
|
|
5176
|
+
if (!isRouteConfig(obj)) continue;
|
|
5177
|
+
const newPath = renameRoutePath(obj);
|
|
5178
|
+
if (newPath) {
|
|
5179
|
+
renamedCount++;
|
|
5180
|
+
console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
|
|
5181
|
+
}
|
|
5182
|
+
}
|
|
5183
|
+
return renamedCount;
|
|
5184
|
+
}
|
|
5185
|
+
function warnAboutStalePaths(sourceFiles) {
|
|
5186
|
+
const stale = [];
|
|
5187
|
+
for (const sourceFile of sourceFiles) {
|
|
5188
|
+
const relPath = import_path9.default.relative(process.cwd(), sourceFile.getFilePath());
|
|
5189
|
+
const lines = sourceFile.getFullText().split("\n");
|
|
5190
|
+
lines.forEach((line2, index) => {
|
|
5191
|
+
if (line2.includes(STALE_PREFIX)) {
|
|
5192
|
+
stale.push(` ${relPath}:${index + 1}: ${line2.trim()}`);
|
|
5193
|
+
}
|
|
5194
|
+
});
|
|
5195
|
+
}
|
|
5196
|
+
if (stale.length === 0) return;
|
|
5197
|
+
console.log(
|
|
5198
|
+
`
|
|
5199
|
+
WARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be renamed by hand:`
|
|
5200
|
+
);
|
|
5201
|
+
console.log(stale.join("\n"));
|
|
5202
|
+
}
|
|
5203
|
+
async function main8() {
|
|
5204
|
+
const srcDir = import_path9.default.join(process.cwd(), "src");
|
|
5205
|
+
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
5206
|
+
`);
|
|
5207
|
+
console.log("Active path renames:");
|
|
5208
|
+
for (const [from, to] of Object.entries(PATH_PREFIX_RENAMES)) {
|
|
5209
|
+
console.log(` '${from}*' \u2192 '${to}*'`);
|
|
5210
|
+
}
|
|
5211
|
+
console.log();
|
|
5212
|
+
const project = new import_ts_morph5.Project({
|
|
5213
|
+
tsConfigFilePath: import_path9.default.resolve(srcDir, "../tsconfig.json"),
|
|
5214
|
+
skipAddingFilesFromTsConfig: false
|
|
5215
|
+
});
|
|
5216
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
5217
|
+
const fp = sf.getFilePath();
|
|
5218
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
5219
|
+
});
|
|
5220
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
5221
|
+
`);
|
|
5222
|
+
let totalRenamed = 0;
|
|
5223
|
+
const modifiedFiles = [];
|
|
5224
|
+
for (const sourceFile of sourceFiles) {
|
|
5225
|
+
const filePath = sourceFile.getFilePath();
|
|
5226
|
+
const renamed = processFile2(filePath, project);
|
|
5227
|
+
if (renamed > 0) {
|
|
5228
|
+
totalRenamed += renamed;
|
|
5229
|
+
modifiedFiles.push(filePath);
|
|
5230
|
+
}
|
|
5231
|
+
}
|
|
5232
|
+
if (modifiedFiles.length === 0) {
|
|
5233
|
+
console.log("No trigger route paths to rename.");
|
|
5234
|
+
} else {
|
|
5235
|
+
console.log(`
|
|
5236
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
5237
|
+
for (const filePath of modifiedFiles) {
|
|
5238
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
5239
|
+
await sourceFile.save();
|
|
5240
|
+
console.log(` Saved: ${import_path9.default.relative(process.cwd(), filePath)}`);
|
|
5241
|
+
}
|
|
5242
|
+
console.log(`
|
|
5243
|
+
Done. Renamed ${totalRenamed} route path(s).`);
|
|
5244
|
+
}
|
|
5245
|
+
warnAboutStalePaths(sourceFiles);
|
|
5246
|
+
}
|
|
5247
|
+
|
|
5248
|
+
// src/migrations/v2.1/upgrade-tilt.ts
|
|
5249
|
+
var import_fs8 = require("fs");
|
|
5250
|
+
var import_path10 = __toESM(require("path"));
|
|
5251
|
+
var COUNTRY_OWNED_DIR = "tilt/helm/";
|
|
5252
|
+
var CHARTS_CHECKOUT_DIR = ".opencrvs-core-charts";
|
|
5253
|
+
var IMAGE_NAME_PATTERN = /^countryconfig_image_name\s*=\s*(["'])(.*?)\1/m;
|
|
5254
|
+
function writeIfChanged(cwd, relativePath, contents, mode) {
|
|
5255
|
+
const target = import_path10.default.join(cwd, relativePath);
|
|
5256
|
+
const existed = (0, import_fs8.existsSync)(target);
|
|
5257
|
+
if (existed && (0, import_fs8.readFileSync)(target, "utf8") === contents) {
|
|
5258
|
+
return "unchanged";
|
|
5259
|
+
}
|
|
5260
|
+
(0, import_fs8.mkdirSync)(import_path10.default.dirname(target), { recursive: true });
|
|
5261
|
+
(0, import_fs8.writeFileSync)(target, contents);
|
|
5262
|
+
if (mode !== void 0) {
|
|
5263
|
+
(0, import_fs8.chmodSync)(target, mode & 511);
|
|
5264
|
+
}
|
|
5265
|
+
return existed ? "updated" : "created";
|
|
5266
|
+
}
|
|
5267
|
+
function report(relativePath, change) {
|
|
5268
|
+
if (change !== "unchanged") {
|
|
5269
|
+
console.log(` \u2713 ${change} ${relativePath}`);
|
|
5270
|
+
}
|
|
5271
|
+
}
|
|
5272
|
+
function renderTiltfile(template, existing) {
|
|
5273
|
+
const imageName = existing?.match(IMAGE_NAME_PATTERN)?.[2];
|
|
5274
|
+
if (!imageName) {
|
|
5275
|
+
return template;
|
|
5276
|
+
}
|
|
5277
|
+
return template.replace(
|
|
5278
|
+
IMAGE_NAME_PATTERN,
|
|
5279
|
+
(_line, quote) => `countryconfig_image_name=${quote}${imageName}${quote}`
|
|
5280
|
+
);
|
|
5281
|
+
}
|
|
5282
|
+
function withIgnoreEntry(contents, line2) {
|
|
5283
|
+
const normalise = (entry) => entry.trim().replace(/^\//, "").replace(/\/$/, "");
|
|
5284
|
+
const alreadyIgnored = contents.split(/\r?\n/).some((entry) => normalise(entry) === normalise(line2));
|
|
5285
|
+
if (alreadyIgnored) {
|
|
5286
|
+
return contents;
|
|
5287
|
+
}
|
|
5288
|
+
const separator = contents === "" || contents.endsWith("\n") ? "" : "\n";
|
|
5289
|
+
return `${contents}${separator}${line2}
|
|
5290
|
+
`;
|
|
5291
|
+
}
|
|
5292
|
+
function ensureIgnored(cwd, file, line2) {
|
|
5293
|
+
const target = import_path10.default.join(cwd, file);
|
|
5294
|
+
const contents = (0, import_fs8.existsSync)(target) ? (0, import_fs8.readFileSync)(target, "utf8") : "";
|
|
5295
|
+
report(file, writeIfChanged(cwd, file, withIgnoreEntry(contents, line2)));
|
|
5296
|
+
}
|
|
5297
|
+
function upgradeTilt(cwd, templateDir) {
|
|
5298
|
+
const tiltfilePath = import_path10.default.join(cwd, "Tiltfile");
|
|
5299
|
+
const existingTiltfile = (0, import_fs8.existsSync)(tiltfilePath) ? (0, import_fs8.readFileSync)(tiltfilePath, "utf8") : void 0;
|
|
5300
|
+
report(
|
|
5301
|
+
"Tiltfile",
|
|
5302
|
+
writeIfChanged(
|
|
5303
|
+
cwd,
|
|
5304
|
+
"Tiltfile",
|
|
5305
|
+
renderTiltfile(
|
|
5306
|
+
(0, import_fs8.readFileSync)(import_path10.default.join(templateDir, "Tiltfile"), "utf8"),
|
|
5307
|
+
existingTiltfile
|
|
5308
|
+
)
|
|
5309
|
+
)
|
|
5310
|
+
);
|
|
5311
|
+
const templateFiles = listFiles(templateDir, "tilt");
|
|
5312
|
+
for (const file of templateFiles) {
|
|
5313
|
+
const source = import_path10.default.join(templateDir, file);
|
|
5314
|
+
const countryOwned = file.startsWith(COUNTRY_OWNED_DIR);
|
|
5315
|
+
if (countryOwned && (0, import_fs8.existsSync)(import_path10.default.join(cwd, file))) {
|
|
5316
|
+
continue;
|
|
5317
|
+
}
|
|
5318
|
+
report(
|
|
5319
|
+
file,
|
|
5320
|
+
writeIfChanged(
|
|
5321
|
+
cwd,
|
|
5322
|
+
file,
|
|
5323
|
+
(0, import_fs8.readFileSync)(source, "utf8"),
|
|
5324
|
+
(0, import_fs8.statSync)(source).mode
|
|
5325
|
+
)
|
|
5326
|
+
);
|
|
5327
|
+
}
|
|
5328
|
+
const unknownFiles = listFiles(cwd, "tilt").filter(
|
|
5329
|
+
(file) => !file.startsWith(COUNTRY_OWNED_DIR) && !templateFiles.includes(file)
|
|
5330
|
+
);
|
|
5331
|
+
for (const file of unknownFiles) {
|
|
5332
|
+
console.warn(
|
|
5333
|
+
` \u26A0\uFE0F ${file} is not part of the template and was left in place. Move chart overrides into ${COUNTRY_OWNED_DIR}`
|
|
5334
|
+
);
|
|
5335
|
+
}
|
|
5336
|
+
ensureIgnored(cwd, ".tiltignore", `${CHARTS_CHECKOUT_DIR}/`);
|
|
5337
|
+
ensureIgnored(cwd, ".gitignore", CHARTS_CHECKOUT_DIR);
|
|
5338
|
+
if (existingTiltfile?.includes("opencrvs-helm-charts")) {
|
|
5339
|
+
console.log(
|
|
5340
|
+
` \u2139\uFE0F The Tiltfile no longer uses ../opencrvs-helm-charts; charts are cloned into ${CHARTS_CHECKOUT_DIR}/ instead. The old checkout can be deleted.`
|
|
5341
|
+
);
|
|
5342
|
+
}
|
|
5343
|
+
}
|
|
5344
|
+
async function main9() {
|
|
5345
|
+
console.log("Upgrading the local Tilt setup...\n");
|
|
5346
|
+
upgradeTilt(process.cwd(), findTemplateDir());
|
|
5347
|
+
console.log(
|
|
5348
|
+
"\n Review local customisations with: git diff -- Tiltfile tilt/ .tiltignore .gitignore\n"
|
|
5349
|
+
);
|
|
5350
|
+
}
|
|
5351
|
+
|
|
4262
5352
|
// src/migrations/v2.1/index.ts
|
|
4263
5353
|
async function runUpgrade(dockerSwarm) {
|
|
4264
5354
|
await main();
|
|
5355
|
+
await main8();
|
|
4265
5356
|
await main2();
|
|
4266
5357
|
await main3();
|
|
5358
|
+
await main7();
|
|
5359
|
+
await main4();
|
|
5360
|
+
await main6();
|
|
5361
|
+
await main5(dockerSwarm);
|
|
5362
|
+
await main9();
|
|
4267
5363
|
}
|
|
4268
5364
|
|
|
4269
5365
|
// src/environment/index.ts
|
|
4270
|
-
var
|
|
4271
|
-
var
|
|
5366
|
+
var import_fs13 = require("fs");
|
|
5367
|
+
var import_path15 = require("path");
|
|
4272
5368
|
init_paths();
|
|
4273
5369
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
4274
5370
|
".github/workflows",
|
|
@@ -4279,7 +5375,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
4279
5375
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
4280
5376
|
(directory) => {
|
|
4281
5377
|
try {
|
|
4282
|
-
return !(0,
|
|
5378
|
+
return !(0, import_fs13.statSync)((0, import_path15.resolve)(repositoryRoot, directory)).isDirectory();
|
|
4283
5379
|
} catch {
|
|
4284
5380
|
return true;
|
|
4285
5381
|
}
|
|
@@ -4294,7 +5390,8 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
4294
5390
|
async function runEnvironmentInit() {
|
|
4295
5391
|
validateRepositoryStructure();
|
|
4296
5392
|
assertNoOldInventoryLayout();
|
|
4297
|
-
await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
5393
|
+
const { runSetupEnvironment: runSetupEnvironment2 } = await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
5394
|
+
await runSetupEnvironment2();
|
|
4298
5395
|
}
|
|
4299
5396
|
async function runEnvironmentUpgrade() {
|
|
4300
5397
|
validateRepositoryStructure();
|
|
@@ -4316,6 +5413,396 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
4316
5413
|
await Promise.resolve().then(() => (init_swarm_to_k8s(), swarm_to_k8s_exports));
|
|
4317
5414
|
}
|
|
4318
5415
|
|
|
5416
|
+
// src/verify/endpoints.ts
|
|
5417
|
+
var import_colors = require("kleur/colors");
|
|
5418
|
+
var z = __toESM(require("zod/v4"));
|
|
5419
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
5420
|
+
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
5421
|
+
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
5422
|
+
{ method: "GET", path: "/client-config.js" },
|
|
5423
|
+
{ method: "GET", path: "/login-config.js" },
|
|
5424
|
+
{ method: "GET", path: "/handlebars.js" },
|
|
5425
|
+
{ method: "GET", path: "/content/client" },
|
|
5426
|
+
{ method: "GET", path: "/content/login" },
|
|
5427
|
+
{ method: "GET", path: "/content/map.geojson" },
|
|
5428
|
+
{ method: "GET", path: "/content/country-logo" },
|
|
5429
|
+
{ method: "GET", path: "/config/application" },
|
|
5430
|
+
{ method: "GET", path: "/config/workqueues" },
|
|
5431
|
+
{ method: "GET", path: "/config/locations" },
|
|
5432
|
+
{ method: "GET", path: "/config/roles" },
|
|
5433
|
+
{ method: "GET", path: "/config/events" }
|
|
5434
|
+
];
|
|
5435
|
+
var PROBE_SEGMENT = "verify-endpoints-probe";
|
|
5436
|
+
var SECURED_TRIGGER_USER_EVENTS = [
|
|
5437
|
+
"user-created",
|
|
5438
|
+
"user-updated",
|
|
5439
|
+
"username-reminder",
|
|
5440
|
+
"reset-password",
|
|
5441
|
+
"reset-password-by-admin",
|
|
5442
|
+
"password-reset-link",
|
|
5443
|
+
"username-reminder-link",
|
|
5444
|
+
"resend-invite",
|
|
5445
|
+
"2fa",
|
|
5446
|
+
"all-user-notification",
|
|
5447
|
+
"change-phone-number",
|
|
5448
|
+
"change-email-address"
|
|
5449
|
+
];
|
|
5450
|
+
var SECURED_ENDPOINTS = [
|
|
5451
|
+
...SECURED_TRIGGER_USER_EVENTS.map(
|
|
5452
|
+
(event) => ({
|
|
5453
|
+
method: "POST",
|
|
5454
|
+
path: `/trigger/user/${event}`
|
|
5455
|
+
})
|
|
5456
|
+
),
|
|
5457
|
+
{ method: "POST", path: "/trigger/telemetry" },
|
|
5458
|
+
{ method: "GET", path: "/trigger/system/ready" },
|
|
5459
|
+
{
|
|
5460
|
+
method: "GET",
|
|
5461
|
+
path: `/certificates/${PROBE_SEGMENT}`,
|
|
5462
|
+
label: "/certificates/{id}"
|
|
5463
|
+
},
|
|
5464
|
+
{ method: "GET", path: "/certificates" },
|
|
5465
|
+
{ method: "GET", path: "/config/users" }
|
|
5466
|
+
];
|
|
5467
|
+
var FALLBACK_EVENT_TRIGGERS = [
|
|
5468
|
+
{
|
|
5469
|
+
method: "POST",
|
|
5470
|
+
path: `/trigger/events/${PROBE_SEGMENT}/actions/${PROBE_SEGMENT}`,
|
|
5471
|
+
label: "/trigger/events/{event}/actions/{action}"
|
|
5472
|
+
},
|
|
5473
|
+
{
|
|
5474
|
+
method: "POST",
|
|
5475
|
+
path: `/trigger/events/birth/actions/${PROBE_SEGMENT}`,
|
|
5476
|
+
label: "/trigger/events/birth/actions/{action}"
|
|
5477
|
+
},
|
|
5478
|
+
{
|
|
5479
|
+
method: "POST",
|
|
5480
|
+
path: `/trigger/events/death/actions/${PROBE_SEGMENT}`,
|
|
5481
|
+
label: "/trigger/events/death/actions/{action}"
|
|
5482
|
+
}
|
|
5483
|
+
];
|
|
5484
|
+
var isSuccess = (status) => status !== "error" && status >= 200 && status < 300;
|
|
5485
|
+
var requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
|
|
5486
|
+
async function requestStatus(url, method) {
|
|
5487
|
+
try {
|
|
5488
|
+
const response = await fetch(url, {
|
|
5489
|
+
method,
|
|
5490
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
5491
|
+
// Sent without an Authorization header on purpose. A secured route
|
|
5492
|
+
// rejects with 401/403 before ever reading the body.
|
|
5493
|
+
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
5494
|
+
body: method === "POST" ? "{}" : void 0
|
|
5495
|
+
});
|
|
5496
|
+
return response.status;
|
|
5497
|
+
} catch {
|
|
5498
|
+
return "error";
|
|
5499
|
+
}
|
|
5500
|
+
}
|
|
5501
|
+
function toEventTriggerConfig(value) {
|
|
5502
|
+
if (typeof value !== "object" || value === null) {
|
|
5503
|
+
return null;
|
|
5504
|
+
}
|
|
5505
|
+
const record2 = value;
|
|
5506
|
+
if (typeof record2.id !== "string") {
|
|
5507
|
+
return null;
|
|
5508
|
+
}
|
|
5509
|
+
const actions = Array.isArray(record2.actions) ? Array.from(
|
|
5510
|
+
new Set(
|
|
5511
|
+
record2.actions.map((action) => {
|
|
5512
|
+
if (typeof action !== "object" || action === null) {
|
|
5513
|
+
return null;
|
|
5514
|
+
}
|
|
5515
|
+
const type = action.type;
|
|
5516
|
+
return typeof type === "string" ? type : null;
|
|
5517
|
+
}).filter((type) => type !== null)
|
|
5518
|
+
)
|
|
5519
|
+
) : [];
|
|
5520
|
+
return { id: record2.id, actions };
|
|
5521
|
+
}
|
|
5522
|
+
async function fetchEventConfigs(baseUrl) {
|
|
5523
|
+
try {
|
|
5524
|
+
const response = await fetch(`${baseUrl}/config/events`, {
|
|
5525
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
5526
|
+
});
|
|
5527
|
+
if (!response.ok) {
|
|
5528
|
+
return null;
|
|
5529
|
+
}
|
|
5530
|
+
const body = await response.json();
|
|
5531
|
+
if (!Array.isArray(body)) {
|
|
5532
|
+
return null;
|
|
5533
|
+
}
|
|
5534
|
+
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
5535
|
+
} catch {
|
|
5536
|
+
return null;
|
|
5537
|
+
}
|
|
5538
|
+
}
|
|
5539
|
+
function resolveBaseUrl(input4) {
|
|
5540
|
+
const withProtocol = /^https?:\/\//i.test(input4) ? input4 : `https://${input4}`;
|
|
5541
|
+
return withProtocol.replace(/\/+$/, "");
|
|
5542
|
+
}
|
|
5543
|
+
function describeStatus(status) {
|
|
5544
|
+
return status === "error" ? "no response" : `HTTP ${status}`;
|
|
5545
|
+
}
|
|
5546
|
+
function endpointLabel(check) {
|
|
5547
|
+
const shown = check.label ?? check.path;
|
|
5548
|
+
const suffix = check.label ? (0, import_colors.dim)(` \u2192 ${check.path}`) : "";
|
|
5549
|
+
return `${check.method} ${shown}${suffix}`;
|
|
5550
|
+
}
|
|
5551
|
+
function line(ok, label, detail) {
|
|
5552
|
+
const mark = ok ? (0, import_colors.green)("\u2713") : (0, import_colors.red)("\u2717");
|
|
5553
|
+
return ` ${mark} ${label} ${(0, import_colors.dim)(`(${detail})`)}`;
|
|
5554
|
+
}
|
|
5555
|
+
function securedDetail(status) {
|
|
5556
|
+
if (status === 401 || status === 403) {
|
|
5557
|
+
return `${describeStatus(status)} \u2014 auth required`;
|
|
5558
|
+
}
|
|
5559
|
+
if (status === 404) {
|
|
5560
|
+
return `${describeStatus(status)} \u2014 not implemented`;
|
|
5561
|
+
}
|
|
5562
|
+
if (status === "error") {
|
|
5563
|
+
return `${describeStatus(status)} \u2014 request failed`;
|
|
5564
|
+
}
|
|
5565
|
+
return `${describeStatus(status)} \u2014 INSECURE: ensure this endpoint requires authentication!`;
|
|
5566
|
+
}
|
|
5567
|
+
var TEMPLATE_VERSION = "2.1";
|
|
5568
|
+
var TRANSLATED_APPLICATIONS = ["client", "login"];
|
|
5569
|
+
function readTemplateTranslations(contents) {
|
|
5570
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
5571
|
+
return {
|
|
5572
|
+
ids: lines.slice(1).filter((line2) => line2 !== "").map(idOf),
|
|
5573
|
+
languages: parseCsvLine(lines[0]).filter(
|
|
5574
|
+
(column) => column !== "id" && column !== "description"
|
|
5575
|
+
)
|
|
5576
|
+
};
|
|
5577
|
+
}
|
|
5578
|
+
var ServedTranslations = z.object({
|
|
5579
|
+
languages: z.array(
|
|
5580
|
+
z.object({
|
|
5581
|
+
lang: z.string(),
|
|
5582
|
+
messages: z.record(z.string(), z.string())
|
|
5583
|
+
})
|
|
5584
|
+
)
|
|
5585
|
+
});
|
|
5586
|
+
async function fetchServedTranslations(baseUrl, application) {
|
|
5587
|
+
try {
|
|
5588
|
+
const response = await fetch(`${baseUrl}/content/${application}`, {
|
|
5589
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
5590
|
+
});
|
|
5591
|
+
if (!response.ok) {
|
|
5592
|
+
return null;
|
|
5593
|
+
}
|
|
5594
|
+
const parsed = ServedTranslations.safeParse(await response.json());
|
|
5595
|
+
return parsed.success ? parsed.data.languages : null;
|
|
5596
|
+
} catch {
|
|
5597
|
+
return null;
|
|
5598
|
+
}
|
|
5599
|
+
}
|
|
5600
|
+
var MISSING_IDS_SHOWN = 10;
|
|
5601
|
+
async function verifyTranslations(baseUrl) {
|
|
5602
|
+
let refs;
|
|
5603
|
+
try {
|
|
5604
|
+
refs = await candidateRefs(TEMPLATE_VERSION);
|
|
5605
|
+
} catch (error3) {
|
|
5606
|
+
console.log(
|
|
5607
|
+
" " + (0, import_colors.yellow)(
|
|
5608
|
+
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${error3.message}); translations not checked.`
|
|
5609
|
+
)
|
|
5610
|
+
);
|
|
5611
|
+
return 0;
|
|
5612
|
+
}
|
|
5613
|
+
let failures = 0;
|
|
5614
|
+
for (const application of TRANSLATED_APPLICATIONS) {
|
|
5615
|
+
const endpoint = `GET /content/${application}`;
|
|
5616
|
+
let fetched;
|
|
5617
|
+
try {
|
|
5618
|
+
fetched = await fetchTemplate(refs, application);
|
|
5619
|
+
} catch (error3) {
|
|
5620
|
+
console.log(
|
|
5621
|
+
" " + (0, import_colors.yellow)(
|
|
5622
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${endpoint} not checked.`
|
|
5623
|
+
)
|
|
5624
|
+
);
|
|
5625
|
+
continue;
|
|
5626
|
+
}
|
|
5627
|
+
if (!fetched) {
|
|
5628
|
+
console.log(
|
|
5629
|
+
" " + (0, import_colors.yellow)(
|
|
5630
|
+
`No ${application}.csv in the ${TEMPLATE_VERSION} country config template on GitHub; ${endpoint} not checked.`
|
|
5631
|
+
)
|
|
5632
|
+
);
|
|
5633
|
+
continue;
|
|
5634
|
+
}
|
|
5635
|
+
const template = readTemplateTranslations(fetched.contents);
|
|
5636
|
+
const served = await fetchServedTranslations(baseUrl, application);
|
|
5637
|
+
if (!served) {
|
|
5638
|
+
console.log(
|
|
5639
|
+
" " + (0, import_colors.yellow)(`Could not read ${endpoint}; translations not checked.`)
|
|
5640
|
+
);
|
|
5641
|
+
continue;
|
|
5642
|
+
}
|
|
5643
|
+
const servedIds = new Set(
|
|
5644
|
+
served.flatMap(({ messages }) => Object.keys(messages))
|
|
5645
|
+
);
|
|
5646
|
+
const missing = template.ids.filter((id) => !servedIds.has(id));
|
|
5647
|
+
const servedLanguages = new Set(served.map(({ lang }) => lang));
|
|
5648
|
+
const absentLanguages = template.languages.filter(
|
|
5649
|
+
(lang) => !servedLanguages.has(lang)
|
|
5650
|
+
);
|
|
5651
|
+
if (missing.length === 0) {
|
|
5652
|
+
console.log(
|
|
5653
|
+
line(
|
|
5654
|
+
true,
|
|
5655
|
+
endpoint,
|
|
5656
|
+
`all ${template.ids.length} id(s) from the ${fetched.ref} template served`
|
|
5657
|
+
)
|
|
5658
|
+
);
|
|
5659
|
+
} else {
|
|
5660
|
+
failures++;
|
|
5661
|
+
console.log(
|
|
5662
|
+
line(
|
|
5663
|
+
false,
|
|
5664
|
+
endpoint,
|
|
5665
|
+
`${missing.length} of ${template.ids.length} id(s) from the ${fetched.ref} template not served`
|
|
5666
|
+
)
|
|
5667
|
+
);
|
|
5668
|
+
for (const id of missing.slice(0, MISSING_IDS_SHOWN)) {
|
|
5669
|
+
console.log(` ${(0, import_colors.dim)(id)}`);
|
|
5670
|
+
}
|
|
5671
|
+
if (missing.length > MISSING_IDS_SHOWN) {
|
|
5672
|
+
console.log(
|
|
5673
|
+
` ${(0, import_colors.dim)(`\u2026 and ${missing.length - MISSING_IDS_SHOWN} more`)}`
|
|
5674
|
+
);
|
|
5675
|
+
}
|
|
5676
|
+
}
|
|
5677
|
+
if (absentLanguages.length > 0) {
|
|
5678
|
+
console.log(
|
|
5679
|
+
" " + (0, import_colors.yellow)(
|
|
5680
|
+
`${application}: the template carries ${absentLanguages.join(
|
|
5681
|
+
", "
|
|
5682
|
+
)}, which this country config does not serve.`
|
|
5683
|
+
)
|
|
5684
|
+
);
|
|
5685
|
+
}
|
|
5686
|
+
}
|
|
5687
|
+
return failures;
|
|
5688
|
+
}
|
|
5689
|
+
async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
5690
|
+
const baseUrl = resolveBaseUrl(target);
|
|
5691
|
+
console.log((0, import_colors.bold)(`Verifying country config endpoints at ${baseUrl}
|
|
5692
|
+
`));
|
|
5693
|
+
let failures = 0;
|
|
5694
|
+
console.log((0, import_colors.bold)("Required public endpoints (must respond 2xx):"));
|
|
5695
|
+
for (const check of REQUIRED_PUBLIC_ENDPOINTS) {
|
|
5696
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
5697
|
+
const ok = isSuccess(status);
|
|
5698
|
+
if (!ok) {
|
|
5699
|
+
failures++;
|
|
5700
|
+
}
|
|
5701
|
+
const detail = status === 404 ? `${describeStatus(status)} \u2014 missing` : ok ? describeStatus(status) : `${describeStatus(status)} \u2014 unexpected`;
|
|
5702
|
+
console.log(line(ok, endpointLabel(check), detail));
|
|
5703
|
+
}
|
|
5704
|
+
{
|
|
5705
|
+
const path14 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
5706
|
+
const status = await requestStatus(`${baseUrl}${path14}`, "GET");
|
|
5707
|
+
const ok = status === 200 || status === 404;
|
|
5708
|
+
if (!ok) {
|
|
5709
|
+
failures++;
|
|
5710
|
+
}
|
|
5711
|
+
let detail;
|
|
5712
|
+
if (status === 404) {
|
|
5713
|
+
detail = `${describeStatus(status)} \u2014 reachable (made-up filename)`;
|
|
5714
|
+
} else if (status === 200) {
|
|
5715
|
+
detail = describeStatus(status);
|
|
5716
|
+
} else if (status === 401 || status === 403) {
|
|
5717
|
+
detail = `${describeStatus(status)} \u2014 must be public`;
|
|
5718
|
+
} else {
|
|
5719
|
+
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
5720
|
+
}
|
|
5721
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path14}`)}`, detail));
|
|
5722
|
+
}
|
|
5723
|
+
console.log();
|
|
5724
|
+
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
5725
|
+
for (const check of SECURED_ENDPOINTS) {
|
|
5726
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
5727
|
+
const ok = requiresAuthOrAbsent(status);
|
|
5728
|
+
if (!ok) {
|
|
5729
|
+
failures++;
|
|
5730
|
+
}
|
|
5731
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
5732
|
+
}
|
|
5733
|
+
console.log();
|
|
5734
|
+
console.log((0, import_colors.bold)("Event action triggers (must be absent or require auth):"));
|
|
5735
|
+
const events = await fetchEventConfigs(baseUrl);
|
|
5736
|
+
if (!events) {
|
|
5737
|
+
console.log(
|
|
5738
|
+
" " + (0, import_colors.yellow)(
|
|
5739
|
+
"Could not read /config/events; falling back to route-pattern checks."
|
|
5740
|
+
)
|
|
5741
|
+
);
|
|
5742
|
+
for (const check of FALLBACK_EVENT_TRIGGERS) {
|
|
5743
|
+
const status = await requestStatus(
|
|
5744
|
+
`${baseUrl}${check.path}`,
|
|
5745
|
+
check.method
|
|
5746
|
+
);
|
|
5747
|
+
const ok = requiresAuthOrAbsent(status);
|
|
5748
|
+
if (!ok) {
|
|
5749
|
+
failures++;
|
|
5750
|
+
}
|
|
5751
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
5752
|
+
}
|
|
5753
|
+
} else if (events.length === 0) {
|
|
5754
|
+
console.log(" " + (0, import_colors.yellow)("No events configured."));
|
|
5755
|
+
} else {
|
|
5756
|
+
for (const event of events) {
|
|
5757
|
+
const actions = event.actions.length ? event.actions : [PROBE_SEGMENT];
|
|
5758
|
+
const failed = [];
|
|
5759
|
+
for (const action of actions) {
|
|
5760
|
+
const status = await requestStatus(
|
|
5761
|
+
`${baseUrl}/trigger/events/${event.id}/actions/${action}`,
|
|
5762
|
+
"POST"
|
|
5763
|
+
);
|
|
5764
|
+
if (!requiresAuthOrAbsent(status)) {
|
|
5765
|
+
failed.push({ action, status });
|
|
5766
|
+
}
|
|
5767
|
+
}
|
|
5768
|
+
const pattern = `POST /trigger/events/${event.id}/actions/{action}`;
|
|
5769
|
+
if (failed.length === 0) {
|
|
5770
|
+
console.log(
|
|
5771
|
+
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
5772
|
+
);
|
|
5773
|
+
} else {
|
|
5774
|
+
for (const failure of failed) {
|
|
5775
|
+
failures++;
|
|
5776
|
+
console.log(
|
|
5777
|
+
line(
|
|
5778
|
+
false,
|
|
5779
|
+
`POST /trigger/events/${event.id}/actions/${failure.action}`,
|
|
5780
|
+
securedDetail(failure.status)
|
|
5781
|
+
)
|
|
5782
|
+
);
|
|
5783
|
+
}
|
|
5784
|
+
const okCount = actions.length - failed.length;
|
|
5785
|
+
if (okCount > 0) {
|
|
5786
|
+
console.log(
|
|
5787
|
+
line(true, pattern, `${okCount} other action(s) require auth`)
|
|
5788
|
+
);
|
|
5789
|
+
}
|
|
5790
|
+
}
|
|
5791
|
+
}
|
|
5792
|
+
}
|
|
5793
|
+
console.log();
|
|
5794
|
+
console.log((0, import_colors.bold)("Translations served (must cover the copy core requires):"));
|
|
5795
|
+
failures += await verifyTranslations(baseUrl);
|
|
5796
|
+
console.log();
|
|
5797
|
+
if (failures > 0) {
|
|
5798
|
+
console.log(
|
|
5799
|
+
(0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
|
|
5800
|
+
);
|
|
5801
|
+
process.exit(1);
|
|
5802
|
+
}
|
|
5803
|
+
console.log((0, import_colors.green)((0, import_colors.bold)("\u2713 All endpoint checks passed.")));
|
|
5804
|
+
}
|
|
5805
|
+
|
|
4319
5806
|
// src/cli.ts
|
|
4320
5807
|
var args = process.argv.slice(2);
|
|
4321
5808
|
var USAGE = `
|
|
@@ -4324,10 +5811,37 @@ Usage: opencrvs <command>
|
|
|
4324
5811
|
Commands:
|
|
4325
5812
|
environment Manage deployment environments
|
|
4326
5813
|
upgrade Upgrade an existing environment
|
|
4327
|
-
|
|
5814
|
+
verify-endpoints Verify the locally-running country config exposes the
|
|
5815
|
+
expected endpoints, keeps secured ones locked down and
|
|
5816
|
+
serves the translations core requires
|
|
4328
5817
|
|
|
4329
5818
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
4330
5819
|
`.trim();
|
|
5820
|
+
var VERIFY_ENDPOINTS_USAGE = `
|
|
5821
|
+
Usage: opencrvs verify-endpoints [country-config-url]
|
|
5822
|
+
|
|
5823
|
+
Run this after 'opencrvs upgrade', with the upgraded country config running
|
|
5824
|
+
locally, to confirm it still behaves correctly. It checks over HTTP that:
|
|
5825
|
+
- required public endpoints exist (respond 2xx),
|
|
5826
|
+
- user-notification trigger endpoints are either absent or reject
|
|
5827
|
+
unauthenticated requests (never processed without a token), and
|
|
5828
|
+
- '/content/client' and '/content/login' serve every message id the country
|
|
5829
|
+
config template of this version carries.
|
|
5830
|
+
|
|
5831
|
+
Checking the translations reads the template off GitHub. When GitHub cannot be
|
|
5832
|
+
reached the other checks still run and that one is skipped with a warning.
|
|
5833
|
+
|
|
5834
|
+
Arguments:
|
|
5835
|
+
[country-config-url] Optional. Domain or URL of the country config
|
|
5836
|
+
service. Defaults to 'http://localhost:3040', the
|
|
5837
|
+
port country config listens on locally. A bare
|
|
5838
|
+
domain is assumed to use https.
|
|
5839
|
+
|
|
5840
|
+
Options:
|
|
5841
|
+
-h, --help Show this message.
|
|
5842
|
+
|
|
5843
|
+
Exits with a non-zero status if any check fails.
|
|
5844
|
+
`.trim();
|
|
4331
5845
|
var UPGRADE_USAGE = `
|
|
4332
5846
|
Usage: opencrvs upgrade [options]
|
|
4333
5847
|
|
|
@@ -4335,13 +5849,14 @@ Upgrade the country config in the current working directory to the next
|
|
|
4335
5849
|
major version of OpenCRVS.
|
|
4336
5850
|
|
|
4337
5851
|
Options:
|
|
4338
|
-
--docker-swarm Keep
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
'infrastructure/'
|
|
5852
|
+
--docker-swarm Keep the 'infrastructure/' directory where it is and
|
|
5853
|
+
only copy what the assets image needs into 'assets/'.
|
|
5854
|
+
Use this if your country deploys OpenCRVS via Docker
|
|
5855
|
+
Swarm. When omitted, 'infrastructure/' moves to
|
|
5856
|
+
'assets/' (default).
|
|
4342
5857
|
-h, --help Show this message.
|
|
4343
5858
|
`.trim();
|
|
4344
|
-
function
|
|
5859
|
+
function main10() {
|
|
4345
5860
|
const command = args[0];
|
|
4346
5861
|
if (!command || command === "--help" || command === "-h") {
|
|
4347
5862
|
console.log(USAGE);
|
|
@@ -4352,8 +5867,8 @@ function main4() {
|
|
|
4352
5867
|
return handleEnvironment();
|
|
4353
5868
|
case "upgrade":
|
|
4354
5869
|
return handleUpgrade();
|
|
4355
|
-
case "
|
|
4356
|
-
return
|
|
5870
|
+
case "verify-endpoints":
|
|
5871
|
+
return handleVerifyEndpoints();
|
|
4357
5872
|
default:
|
|
4358
5873
|
console.error(`Unknown command: ${command}
|
|
4359
5874
|
`);
|
|
@@ -4437,9 +5952,29 @@ async function handleUpgrade() {
|
|
|
4437
5952
|
process.exit(1);
|
|
4438
5953
|
}
|
|
4439
5954
|
}
|
|
4440
|
-
function
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
5955
|
+
async function handleVerifyEndpoints() {
|
|
5956
|
+
const verifyArgs = args.slice(1);
|
|
5957
|
+
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
5958
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5959
|
+
process.exit(0);
|
|
5960
|
+
}
|
|
5961
|
+
const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
|
|
5962
|
+
if (positional.length > 1) {
|
|
5963
|
+
console.error(
|
|
5964
|
+
`Unexpected extra argument(s): ${positional.slice(1).join(", ")}
|
|
5965
|
+
`
|
|
5966
|
+
);
|
|
5967
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5968
|
+
process.exit(1);
|
|
5969
|
+
}
|
|
5970
|
+
try {
|
|
5971
|
+
await runVerifyEndpoints(positional[0]);
|
|
5972
|
+
} catch (error3) {
|
|
5973
|
+
console.error(
|
|
5974
|
+
"Endpoint verification failed:",
|
|
5975
|
+
error3 instanceof Error ? error3.message : error3
|
|
5976
|
+
);
|
|
5977
|
+
process.exit(1);
|
|
5978
|
+
}
|
|
4444
5979
|
}
|
|
4445
|
-
|
|
5980
|
+
main10();
|