@opencrvs/toolkit 2.1.0-rc.12673aa → 2.1.0-rc.14fb6a5
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/build.sh +14 -4
- package/create-countryconfig/index.js +59 -30
- package/dist/application-config/index.js +26 -13
- package/dist/authentication/index.d.ts +8 -9
- package/dist/authentication/index.js +23 -8
- package/dist/cli.js +2268 -1385
- 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 +18 -3
- 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 +20 -10
- 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/scopes.d.ts +21 -1
- package/dist/commons/events/test.utils.d.ts +53 -21
- package/dist/commons/events/utils.d.ts +26 -2
- package/dist/conditionals/index.js +21 -7
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +2 -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 +586 -569
- package/dist/environment/swarm-to-k8s.js +3 -4
- package/dist/events/index.js +282 -138
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +4 -4
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -1
- package/dist/migrations/v2.1/add-translations.js +4 -68
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -1
- package/dist/migrations/v2.1/enable-telemetry.js +30 -13
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +927 -33
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
- package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-sentry.js +354 -0
- package/dist/migrations/{v2.0/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 +105 -61
- package/dist/scopes/index.d.ts +288 -5
- package/dist/scopes/index.js +22 -7
- package/dist/telemetry/index.js +4 -0
- package/dist/templates/charts-values/dependencies/values.yaml +6 -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.map +1 -1
- package/dist/verify/endpoints.js +179 -14
- package/opencrvs-toolkit-2.1.0-rc.14fb6a5.tgz +0 -0
- package/package.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- 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/dist/translations/check.d.ts +0 -21
- package/dist/translations/check.d.ts.map +0 -1
- package/dist/translations/check.js +0 -132
- package/opencrvs-toolkit-2.1.0-rc.12673aa.tgz +0 -0
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"
|
|
@@ -504,7 +504,7 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
504
504
|
);
|
|
505
505
|
}
|
|
506
506
|
function readYamlFile(filePath) {
|
|
507
|
-
const fileContent =
|
|
507
|
+
const fileContent = import_fs9.default.readFileSync(filePath, "utf8");
|
|
508
508
|
return yaml.load(fileContent);
|
|
509
509
|
}
|
|
510
510
|
function writeYamlFile(filePath, data) {
|
|
@@ -517,16 +517,16 @@ function writeYamlFile(filePath, data) {
|
|
|
517
517
|
noRefs: true,
|
|
518
518
|
sortKeys: false
|
|
519
519
|
});
|
|
520
|
-
|
|
520
|
+
import_fs9.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
521
521
|
} catch (error3) {
|
|
522
522
|
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
|
-
var
|
|
525
|
+
var import_fs9, yaml;
|
|
526
526
|
var init_utils = __esm({
|
|
527
527
|
"src/environment/utils.ts"() {
|
|
528
528
|
"use strict";
|
|
529
|
-
|
|
529
|
+
import_fs9 = __toESM(require("fs"));
|
|
530
530
|
yaml = __toESM(require("js-yaml"));
|
|
531
531
|
}
|
|
532
532
|
});
|
|
@@ -575,29 +575,29 @@ function extractWorkerNodes(data) {
|
|
|
575
575
|
return worker_hosts;
|
|
576
576
|
}
|
|
577
577
|
function copyChartsValues(env, values) {
|
|
578
|
-
const srcDir =
|
|
579
|
-
const destDir =
|
|
580
|
-
|
|
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 });
|
|
581
581
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
582
582
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
583
583
|
values["opencrvs_environment"] = env;
|
|
584
584
|
function copyRecursive(src, dest) {
|
|
585
|
-
const stat =
|
|
585
|
+
const stat = import_fs10.default.statSync(src);
|
|
586
586
|
if (stat.isDirectory()) {
|
|
587
|
-
|
|
588
|
-
for (const item of
|
|
589
|
-
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));
|
|
590
590
|
}
|
|
591
591
|
} else {
|
|
592
|
-
const content =
|
|
592
|
+
const content = import_fs10.default.readFileSync(src, "utf8");
|
|
593
593
|
const template = import_handlebars.default.compile(content);
|
|
594
594
|
const updated = template(values);
|
|
595
595
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
596
|
-
if (isOverridesFile &&
|
|
596
|
+
if (isOverridesFile && import_fs10.default.existsSync(dest)) {
|
|
597
597
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
598
598
|
return;
|
|
599
599
|
}
|
|
600
|
-
|
|
600
|
+
import_fs10.default.writeFileSync(dest, updated, "utf8");
|
|
601
601
|
log(` \u2713 Created: ${dest}`);
|
|
602
602
|
}
|
|
603
603
|
}
|
|
@@ -608,29 +608,29 @@ function copyChartsValues(env, values) {
|
|
|
608
608
|
`);
|
|
609
609
|
}
|
|
610
610
|
function generateInventory(env, values) {
|
|
611
|
-
const templatePath =
|
|
611
|
+
const templatePath = import_path12.default.join(
|
|
612
612
|
__dirname,
|
|
613
613
|
"templates",
|
|
614
614
|
"inventory",
|
|
615
615
|
"inventory.template.yml"
|
|
616
616
|
);
|
|
617
|
-
const outputPath =
|
|
618
|
-
const templateFile =
|
|
617
|
+
const outputPath = import_path12.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
618
|
+
const templateFile = import_fs10.default.readFileSync(templatePath, "utf-8");
|
|
619
619
|
const template = import_handlebars.default.compile(templateFile);
|
|
620
620
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
621
621
|
const updated = template(values);
|
|
622
|
-
|
|
623
|
-
|
|
622
|
+
import_fs10.default.mkdirSync(import_path12.default.dirname(outputPath), { recursive: true });
|
|
623
|
+
import_fs10.default.writeFileSync(outputPath, updated);
|
|
624
624
|
log(`
|
|
625
625
|
\u2705 Generated inventory file at ${outputPath}
|
|
626
626
|
`);
|
|
627
627
|
}
|
|
628
|
-
var
|
|
628
|
+
var import_fs10, import_path12, import_handlebars;
|
|
629
629
|
var init_templates = __esm({
|
|
630
630
|
"src/environment/templates.ts"() {
|
|
631
631
|
"use strict";
|
|
632
|
-
|
|
633
|
-
|
|
632
|
+
import_fs10 = __toESM(require("fs"));
|
|
633
|
+
import_path12 = __toESM(require("path"));
|
|
634
634
|
init_logger();
|
|
635
635
|
init_paths();
|
|
636
636
|
import_handlebars = __toESM(require("handlebars"));
|
|
@@ -656,10 +656,145 @@ var init_ssh_keygen = __esm({
|
|
|
656
656
|
}
|
|
657
657
|
});
|
|
658
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
|
+
|
|
659
794
|
// src/environment/git.ts
|
|
660
795
|
function getRepoInfo() {
|
|
661
796
|
try {
|
|
662
|
-
const remoteUrl = (0,
|
|
797
|
+
const remoteUrl = (0, import_child_process2.execSync)("git config --get remote.origin.url", {
|
|
663
798
|
stdio: ["ignore", "pipe", "ignore"]
|
|
664
799
|
}).toString().trim();
|
|
665
800
|
const match = remoteUrl.match(/github\.com[:/](.+?)\/(.+?)(\.git)?$/);
|
|
@@ -677,11 +812,11 @@ function getRepoInfo() {
|
|
|
677
812
|
};
|
|
678
813
|
}
|
|
679
814
|
}
|
|
680
|
-
var
|
|
815
|
+
var import_child_process2;
|
|
681
816
|
var init_git = __esm({
|
|
682
817
|
"src/environment/git.ts"() {
|
|
683
818
|
"use strict";
|
|
684
|
-
|
|
819
|
+
import_child_process2 = require("child_process");
|
|
685
820
|
}
|
|
686
821
|
});
|
|
687
822
|
|
|
@@ -1237,7 +1372,7 @@ function getCurrentUsername() {
|
|
|
1237
1372
|
}
|
|
1238
1373
|
function getCurrentUserSSHKeys() {
|
|
1239
1374
|
const homeDir = os.homedir();
|
|
1240
|
-
const sshDir =
|
|
1375
|
+
const sshDir = path11.join(homeDir, ".ssh");
|
|
1241
1376
|
const keys = [];
|
|
1242
1377
|
const keyFiles = [
|
|
1243
1378
|
"id_rsa.pub",
|
|
@@ -1246,7 +1381,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1246
1381
|
"id_dsa.pub"
|
|
1247
1382
|
];
|
|
1248
1383
|
for (const keyFile of keyFiles) {
|
|
1249
|
-
const keyPath =
|
|
1384
|
+
const keyPath = path11.join(sshDir, keyFile);
|
|
1250
1385
|
try {
|
|
1251
1386
|
if (fs3.existsSync(keyPath)) {
|
|
1252
1387
|
const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
|
|
@@ -1587,13 +1722,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1587
1722
|
}
|
|
1588
1723
|
return users;
|
|
1589
1724
|
}
|
|
1590
|
-
var os, fs3,
|
|
1725
|
+
var os, fs3, path11, input2, select2, confirm, editor, checkbox;
|
|
1591
1726
|
var init_manage_users = __esm({
|
|
1592
1727
|
"src/environment/manage-users.ts"() {
|
|
1593
1728
|
"use strict";
|
|
1594
1729
|
os = __toESM(require("os"));
|
|
1595
1730
|
fs3 = __toESM(require("fs"));
|
|
1596
|
-
|
|
1731
|
+
path11 = __toESM(require("path"));
|
|
1597
1732
|
init_logger();
|
|
1598
1733
|
init_utils();
|
|
1599
1734
|
init_templates();
|
|
@@ -1607,6 +1742,9 @@ var init_manage_users = __esm({
|
|
|
1607
1742
|
|
|
1608
1743
|
// src/environment/setup-environment.ts
|
|
1609
1744
|
var setup_environment_exports = {};
|
|
1745
|
+
__export(setup_environment_exports, {
|
|
1746
|
+
runSetupEnvironment: () => runSetupEnvironment
|
|
1747
|
+
});
|
|
1610
1748
|
async function confirm2(options) {
|
|
1611
1749
|
const inquirer = await import("@inquirer/prompts");
|
|
1612
1750
|
return inquirer.confirm(options);
|
|
@@ -1775,978 +1913,959 @@ async function promptAndStoreAnswer(questions, existingValues) {
|
|
|
1775
1913
|
]);
|
|
1776
1914
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1777
1915
|
}
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
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."
|
|
1811
1987
|
);
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
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
|
+
[
|
|
1816
2100
|
{
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
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)
|
|
1820
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
|
+
)
|
|
1821
2124
|
);
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
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")
|
|
2136
|
+
);
|
|
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
|
|
2142
|
+
);
|
|
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}`)
|
|
1831
2190
|
);
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
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: [
|
|
1835
2218
|
{
|
|
1836
|
-
name: "
|
|
1837
|
-
value: "
|
|
2219
|
+
name: "Full dump (daily full database backup)",
|
|
2220
|
+
value: "dump"
|
|
1838
2221
|
},
|
|
1839
2222
|
{
|
|
1840
|
-
name: "
|
|
1841
|
-
value: "
|
|
2223
|
+
name: "Differential (weekly full, daily diff backup)",
|
|
2224
|
+
value: "differential"
|
|
1842
2225
|
}
|
|
1843
|
-
]
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
value: "production"
|
|
1871
|
-
}
|
|
1872
|
-
]
|
|
1873
|
-
});
|
|
1874
|
-
}
|
|
1875
|
-
const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
|
|
1876
|
-
if (!environment) {
|
|
1877
|
-
process.exit(1);
|
|
1878
|
-
}
|
|
1879
|
-
await createEnvironment(
|
|
1880
|
-
octokit,
|
|
1881
|
-
environment,
|
|
1882
|
-
githubOrganisation,
|
|
1883
|
-
githubRepository
|
|
1884
|
-
);
|
|
1885
|
-
const repositoryId = await getRepositoryId(
|
|
1886
|
-
octokit,
|
|
1887
|
-
githubOrganisation,
|
|
1888
|
-
githubRepository
|
|
1889
|
-
);
|
|
1890
|
-
const existingRepositorySecrets = await listRepositorySecrets(
|
|
1891
|
-
octokit,
|
|
1892
|
-
githubOrganisation,
|
|
1893
|
-
githubRepository
|
|
1894
|
-
);
|
|
1895
|
-
const existingRepositoryVariables = await listRepositoryVariables(
|
|
1896
|
-
octokit,
|
|
1897
|
-
githubOrganisation,
|
|
1898
|
-
githubRepository
|
|
1899
|
-
);
|
|
1900
|
-
const existingEnvironmentVariables = await listEnvironmentVariables(
|
|
1901
|
-
octokit,
|
|
1902
|
-
repositoryId,
|
|
1903
|
-
environment
|
|
1904
|
-
);
|
|
1905
|
-
const existingEnvironmentSecrets = await listEnvironmentSecrets(
|
|
1906
|
-
octokit,
|
|
1907
|
-
githubOrganisation,
|
|
1908
|
-
repositoryId,
|
|
1909
|
-
environment
|
|
1910
|
-
);
|
|
1911
|
-
const existingValues = [
|
|
1912
|
-
...existingEnvironmentVariables,
|
|
1913
|
-
...existingRepositoryVariables,
|
|
1914
|
-
...existingRepositorySecrets,
|
|
1915
|
-
...existingEnvironmentSecrets
|
|
1916
|
-
];
|
|
1917
|
-
if (existingEnvironmentVariables.length > 0 || existingEnvironmentSecrets.length > 0) {
|
|
1918
|
-
log(
|
|
1919
|
-
"\nEnvironment with the name",
|
|
1920
|
-
environment,
|
|
1921
|
-
"already exists in Github.",
|
|
1922
|
-
"\nFound",
|
|
1923
|
-
existingEnvironmentVariables.length,
|
|
1924
|
-
"existing variables and",
|
|
1925
|
-
existingEnvironmentSecrets.length,
|
|
1926
|
-
"secrets"
|
|
1927
|
-
);
|
|
1928
|
-
}
|
|
1929
|
-
if (environment_type === "production") {
|
|
1930
|
-
log(
|
|
1931
|
-
"\n",
|
|
1932
|
-
import_kleur4.default.yellow().bold(
|
|
1933
|
-
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
1934
|
-
)
|
|
1935
|
-
);
|
|
1936
|
-
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
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)
|
|
1937
2253
|
}
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
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",
|
|
1943
2278
|
existingValues
|
|
1944
|
-
)
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
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",
|
|
1951
2313
|
"SECRET",
|
|
1952
2314
|
"ENVIRONMENT",
|
|
1953
2315
|
existingValues
|
|
1954
|
-
)
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
ssl_answers = await askQuestionWithEditor(
|
|
1971
|
-
staticSSLCertQuestions,
|
|
1972
|
-
existingEnvironmentSecrets
|
|
1973
|
-
);
|
|
1974
|
-
}
|
|
1975
|
-
log("\n", import_kleur4.default.bold().underline("Storage"), "\n");
|
|
1976
|
-
let enableEncryption = false;
|
|
1977
|
-
const encryption_key_defined = findExistingValue(
|
|
1978
|
-
"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",
|
|
1979
2332
|
"SECRET",
|
|
1980
2333
|
"ENVIRONMENT",
|
|
1981
2334
|
existingValues
|
|
1982
|
-
)
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
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",
|
|
2035
2452
|
"VARIABLE",
|
|
2036
2453
|
"ENVIRONMENT",
|
|
2037
2454
|
existingValues
|
|
2038
|
-
)
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
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",
|
|
2042
2468
|
"VARIABLE",
|
|
2043
2469
|
"ENVIRONMENT",
|
|
2044
2470
|
existingValues
|
|
2045
|
-
)
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
existingValues
|
|
2060
|
-
);
|
|
2061
|
-
const backupHostPrivateKeyExists = findExistingValue(
|
|
2062
|
-
"BACKUP_HOST_PRIVATE_KEY",
|
|
2063
|
-
"SECRET",
|
|
2064
|
-
"ENVIRONMENT",
|
|
2065
|
-
existingValues
|
|
2066
|
-
);
|
|
2067
|
-
backupType = backupAnswers.backupType;
|
|
2068
|
-
backupHost = backupAnswers.backupHost || backupHost;
|
|
2069
|
-
if (!backupHostPrivateKeyExists) {
|
|
2070
|
-
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2071
|
-
backupHostPublicKey = publicKey;
|
|
2072
|
-
backupHostPrivateKey = privateKey;
|
|
2073
|
-
log(
|
|
2074
|
-
import_kleur4.default.bold().green("\u2714"),
|
|
2075
|
-
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
2076
|
-
);
|
|
2077
|
-
}
|
|
2078
|
-
} else {
|
|
2079
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
2080
|
-
}
|
|
2081
|
-
log("\n", import_kleur4.default.bold().underline("Restore"));
|
|
2082
|
-
let configureRestore = restoreEnvironmentName ? true : false;
|
|
2083
|
-
if (!restoreEnvironmentName && !configureBackup) {
|
|
2084
|
-
configureRestore = await confirm2({
|
|
2085
|
-
message: "Do you want to configure restore?",
|
|
2086
|
-
default: Boolean(process.env.CONFIGURE_RESTORE)
|
|
2087
|
-
});
|
|
2088
|
-
}
|
|
2089
|
-
if (configureRestore) {
|
|
2090
|
-
const env_list_filtered = existingEnvironments.filter(
|
|
2091
|
-
(env) => env !== environment
|
|
2092
|
-
);
|
|
2093
|
-
restoreEnvironmentName = await selectWithCustom({
|
|
2094
|
-
message: "What is the name of your environment to restore?",
|
|
2095
|
-
choices: env_list_filtered.map((env) => ({
|
|
2096
|
-
name: env,
|
|
2097
|
-
value: env
|
|
2098
|
-
})),
|
|
2099
|
-
initial: restoreEnvironmentName
|
|
2100
|
-
});
|
|
2101
|
-
restoreType = await select3({
|
|
2102
|
-
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2103
|
-
choices: [
|
|
2104
|
-
{
|
|
2105
|
-
name: "Full dump (daily full database backup)",
|
|
2106
|
-
value: "dump"
|
|
2107
|
-
},
|
|
2108
|
-
{
|
|
2109
|
-
name: "Differential (weekly full, daily diff backup)",
|
|
2110
|
-
value: "differential"
|
|
2111
|
-
}
|
|
2112
|
-
]
|
|
2113
|
-
});
|
|
2114
|
-
restoreHost = await input3({
|
|
2115
|
-
message: "What is the host/IP address of the restore backup server?",
|
|
2116
|
-
default: restoreHost
|
|
2117
|
-
});
|
|
2118
|
-
} else {
|
|
2119
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2120
|
-
}
|
|
2121
|
-
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2122
|
-
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2123
|
-
const sentryDSNExists = findExistingValue(
|
|
2124
|
-
"SENTRY_DSN",
|
|
2125
|
-
"SECRET",
|
|
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",
|
|
2126
2485
|
"ENVIRONMENT",
|
|
2127
2486
|
existingValues
|
|
2128
|
-
)
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
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",
|
|
2501
|
+
"ENVIRONMENT",
|
|
2502
|
+
existingValues
|
|
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",
|
|
2518
|
+
existingValues
|
|
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",
|
|
2180
2545
|
"VARIABLE",
|
|
2181
2546
|
"ENVIRONMENT",
|
|
2182
2547
|
existingValues
|
|
2183
2548
|
),
|
|
2184
|
-
|
|
2185
|
-
|
|
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",
|
|
2186
2566
|
"VARIABLE",
|
|
2187
2567
|
"ENVIRONMENT",
|
|
2188
|
-
|
|
2568
|
+
existingValues
|
|
2189
2569
|
),
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
}
|
|
2315
|
-
{
|
|
2316
|
-
name: "SUPER_USER_PASSWORD",
|
|
2317
|
-
type: "SECRET",
|
|
2318
|
-
didExist: findExistingValue(
|
|
2319
|
-
"SUPER_USER_PASSWORD",
|
|
2320
|
-
"SECRET",
|
|
2321
|
-
"ENVIRONMENT",
|
|
2322
|
-
existingValues
|
|
2323
|
-
),
|
|
2324
|
-
value: findExistingOrDefine(
|
|
2325
|
-
"SUPER_USER_PASSWORD",
|
|
2326
|
-
"SECRET",
|
|
2327
|
-
"ENVIRONMENT",
|
|
2328
|
-
generateLongPassword()
|
|
2329
|
-
),
|
|
2330
|
-
scope: "ENVIRONMENT"
|
|
2331
|
-
},
|
|
2332
|
-
{
|
|
2333
|
-
type: "VARIABLE",
|
|
2334
|
-
name: "ACTIVATE_USERS",
|
|
2335
|
-
value: "production" === environment_type ? "false" : "true",
|
|
2336
|
-
didExist: findExistingValue(
|
|
2337
|
-
"ACTIVATE_USERS",
|
|
2338
|
-
"VARIABLE",
|
|
2339
|
-
"ENVIRONMENT",
|
|
2340
|
-
existingValues
|
|
2341
|
-
),
|
|
2342
|
-
scope: "ENVIRONMENT"
|
|
2343
|
-
},
|
|
2344
|
-
{
|
|
2345
|
-
type: "VARIABLE",
|
|
2346
|
-
name: "COUNTRY_CONFIG_HOST",
|
|
2347
|
-
value: answerOrExisting(
|
|
2348
|
-
allAnswers.domain,
|
|
2349
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2350
|
-
(val) => `https://countryconfig.${val}`
|
|
2351
|
-
),
|
|
2352
|
-
didExist: findExistingValue(
|
|
2353
|
-
"COUNTRY_CONFIG_HOST",
|
|
2354
|
-
"VARIABLE",
|
|
2355
|
-
"ENVIRONMENT",
|
|
2356
|
-
existingValues
|
|
2357
|
-
),
|
|
2358
|
-
scope: "ENVIRONMENT"
|
|
2359
|
-
},
|
|
2360
|
-
{
|
|
2361
|
-
type: "VARIABLE",
|
|
2362
|
-
name: "GATEWAY_HOST",
|
|
2363
|
-
value: answerOrExisting(
|
|
2364
|
-
allAnswers.domain,
|
|
2365
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2366
|
-
(val) => `https://gateway.${val}`
|
|
2367
|
-
),
|
|
2368
|
-
didExist: findExistingValue(
|
|
2369
|
-
"GATEWAY_HOST",
|
|
2370
|
-
"VARIABLE",
|
|
2371
|
-
"ENVIRONMENT",
|
|
2372
|
-
existingValues
|
|
2373
|
-
),
|
|
2374
|
-
scope: "ENVIRONMENT"
|
|
2375
|
-
},
|
|
2376
|
-
{
|
|
2377
|
-
type: "VARIABLE",
|
|
2378
|
-
name: "CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2379
|
-
value: answerOrExisting(
|
|
2380
|
-
allAnswers.domain,
|
|
2381
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2382
|
-
(val) => `*.${val}`
|
|
2383
|
-
),
|
|
2384
|
-
didExist: findExistingValue(
|
|
2385
|
-
"CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2386
|
-
"VARIABLE",
|
|
2387
|
-
"ENVIRONMENT",
|
|
2388
|
-
existingValues
|
|
2389
|
-
),
|
|
2390
|
-
scope: "ENVIRONMENT"
|
|
2391
|
-
},
|
|
2392
|
-
{
|
|
2393
|
-
type: "VARIABLE",
|
|
2394
|
-
name: "CLIENT_APP_URL",
|
|
2395
|
-
value: answerOrExisting(
|
|
2396
|
-
allAnswers.domain,
|
|
2397
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2398
|
-
(val) => `https://register.${val}`
|
|
2399
|
-
),
|
|
2400
|
-
didExist: findExistingValue(
|
|
2401
|
-
"CLIENT_APP_URL",
|
|
2402
|
-
"VARIABLE",
|
|
2403
|
-
"ENVIRONMENT",
|
|
2404
|
-
existingValues
|
|
2405
|
-
),
|
|
2406
|
-
scope: "ENVIRONMENT"
|
|
2407
|
-
},
|
|
2408
|
-
{
|
|
2409
|
-
type: "VARIABLE",
|
|
2410
|
-
name: "LOGIN_URL",
|
|
2411
|
-
value: answerOrExisting(
|
|
2412
|
-
allAnswers.domain,
|
|
2413
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2414
|
-
(val) => `https://login.${val}`
|
|
2415
|
-
),
|
|
2416
|
-
didExist: findExistingValue(
|
|
2417
|
-
"LOGIN_URL",
|
|
2418
|
-
"VARIABLE",
|
|
2419
|
-
"ENVIRONMENT",
|
|
2420
|
-
existingValues
|
|
2421
|
-
),
|
|
2422
|
-
scope: "ENVIRONMENT"
|
|
2423
|
-
},
|
|
2424
|
-
{
|
|
2425
|
-
type: "VARIABLE",
|
|
2426
|
-
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2427
|
-
value: answerOrExisting(
|
|
2428
|
-
restoreEnvironmentName,
|
|
2429
|
-
findExistingValue(
|
|
2430
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2431
|
-
"VARIABLE",
|
|
2432
|
-
"ENVIRONMENT",
|
|
2433
|
-
existingValues
|
|
2434
|
-
),
|
|
2435
|
-
(val) => val || ""
|
|
2436
|
-
),
|
|
2437
|
-
didExist: findExistingValue(
|
|
2438
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2439
|
-
"VARIABLE",
|
|
2440
|
-
"ENVIRONMENT",
|
|
2441
|
-
existingValues
|
|
2442
|
-
),
|
|
2443
|
-
scope: "ENVIRONMENT"
|
|
2444
|
-
},
|
|
2445
|
-
{
|
|
2446
|
-
type: "VARIABLE",
|
|
2447
|
-
name: "RESTORE_HOST",
|
|
2448
|
-
value: answerOrExisting(
|
|
2449
|
-
restoreHost,
|
|
2450
|
-
findExistingValue(
|
|
2451
|
-
"RESTORE_HOST",
|
|
2452
|
-
"VARIABLE",
|
|
2453
|
-
"ENVIRONMENT",
|
|
2454
|
-
existingValues
|
|
2455
|
-
),
|
|
2456
|
-
(val) => val || ""
|
|
2457
|
-
),
|
|
2458
|
-
didExist: findExistingValue(
|
|
2459
|
-
"RESTORE_HOST",
|
|
2460
|
-
"VARIABLE",
|
|
2461
|
-
"ENVIRONMENT",
|
|
2462
|
-
existingValues
|
|
2463
|
-
),
|
|
2464
|
-
scope: "ENVIRONMENT"
|
|
2465
|
-
}
|
|
2466
|
-
];
|
|
2467
|
-
if (enableEncryption) {
|
|
2468
|
-
applicationServerUpdates.push({
|
|
2469
|
-
name: "ENCRYPTION_KEY",
|
|
2470
|
-
type: "SECRET",
|
|
2471
|
-
didExist: findExistingValue(
|
|
2472
|
-
"ENCRYPTION_KEY",
|
|
2473
|
-
"SECRET",
|
|
2474
|
-
"ENVIRONMENT",
|
|
2475
|
-
existingValues
|
|
2476
|
-
),
|
|
2477
|
-
value: findExistingOrDefine(
|
|
2478
|
-
"ENCRYPTION_KEY",
|
|
2479
|
-
"SECRET",
|
|
2480
|
-
"ENVIRONMENT",
|
|
2481
|
-
generateLongPassword()
|
|
2482
|
-
),
|
|
2483
|
-
scope: "ENVIRONMENT"
|
|
2484
|
-
});
|
|
2485
|
-
}
|
|
2486
|
-
if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
|
|
2487
|
-
applicationServerUpdates.push({
|
|
2488
|
-
name: "BACKUP_HOST_PRIVATE_KEY",
|
|
2489
|
-
type: "SECRET",
|
|
2490
|
-
didExist: void 0,
|
|
2491
|
-
value: backupHostPrivateKey,
|
|
2492
|
-
scope: "ENVIRONMENT"
|
|
2493
|
-
});
|
|
2494
|
-
applicationServerUpdates.push({
|
|
2495
|
-
name: "BACKUP_HOST_PUBLIC_KEY",
|
|
2496
|
-
type: "SECRET",
|
|
2497
|
-
didExist: void 0,
|
|
2498
|
-
value: backupHostPublicKey,
|
|
2499
|
-
scope: "ENVIRONMENT"
|
|
2500
|
-
});
|
|
2501
|
-
}
|
|
2502
|
-
derivedUpdates.push(...applicationServerUpdates);
|
|
2503
|
-
const updates = getAnswers(existingValues).concat(
|
|
2504
|
-
...derivedUpdates.filter(
|
|
2505
|
-
(update) => update.value !== null
|
|
2506
|
-
)
|
|
2507
|
-
).filter(
|
|
2508
|
-
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2509
|
-
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
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) => {
|
|
2690
|
+
log(
|
|
2691
|
+
variable.name,
|
|
2692
|
+
"=",
|
|
2693
|
+
variable.value,
|
|
2694
|
+
`(was ${variable.didExist?.value})`
|
|
2510
2695
|
);
|
|
2511
|
-
|
|
2512
|
-
|
|
2696
|
+
});
|
|
2697
|
+
log("");
|
|
2698
|
+
}
|
|
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
|
+
)
|
|
2704
|
+
);
|
|
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("");
|
|
2722
|
+
}
|
|
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
|
|
2735
|
+
});
|
|
2736
|
+
if (!saveChanges) {
|
|
2737
|
+
process.exit(0);
|
|
2738
|
+
}
|
|
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
|
+
}
|
|
2761
|
+
}
|
|
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
|
|
2513
2784
|
);
|
|
2514
|
-
|
|
2515
|
-
|
|
2785
|
+
}
|
|
2786
|
+
}
|
|
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
|
|
2516
2796
|
);
|
|
2517
|
-
|
|
2518
|
-
|
|
2797
|
+
} else {
|
|
2798
|
+
await createRepositoryVariable(
|
|
2799
|
+
octokit,
|
|
2800
|
+
repositoryId,
|
|
2801
|
+
newVariable.name,
|
|
2802
|
+
newVariable.value
|
|
2519
2803
|
);
|
|
2520
|
-
|
|
2521
|
-
|
|
2804
|
+
}
|
|
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
|
|
2522
2817
|
);
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
if (newSecrets.length > 0) {
|
|
2530
|
-
log(
|
|
2531
|
-
import_kleur4.default.yellow(
|
|
2532
|
-
`The following secrets will be added to Github for environment ${environment}:`
|
|
2533
|
-
)
|
|
2534
|
-
);
|
|
2535
|
-
newSecrets.filter(({ scope }) => scope === "ENVIRONMENT").forEach((secret) => {
|
|
2536
|
-
log(secret.name, "=", secret.value);
|
|
2537
|
-
});
|
|
2538
|
-
log("");
|
|
2539
|
-
log(
|
|
2540
|
-
import_kleur4.default.yellow(`The following secrets will be added to Github repository:`)
|
|
2541
|
-
);
|
|
2542
|
-
newSecrets.filter(({ scope }) => scope === "REPOSITORY").forEach((secret) => {
|
|
2543
|
-
log(secret.name, "=", secret.value);
|
|
2544
|
-
});
|
|
2545
|
-
log("");
|
|
2546
|
-
}
|
|
2547
|
-
if (updatedSecrets.length > 0) {
|
|
2548
|
-
log(
|
|
2549
|
-
import_kleur4.default.yellow(
|
|
2550
|
-
`The following secrets will be updated in Github for environment ${environment}:`
|
|
2551
|
-
)
|
|
2552
|
-
);
|
|
2553
|
-
updatedSecrets.forEach((secret) => {
|
|
2554
|
-
log(secret.name, "=", secret.value);
|
|
2555
|
-
});
|
|
2556
|
-
log("");
|
|
2557
|
-
}
|
|
2558
|
-
if (newVariables.length > 0) {
|
|
2559
|
-
log(
|
|
2560
|
-
import_kleur4.default.yellow(
|
|
2561
|
-
`The following variables will be added to Github for environment ${environment}:`
|
|
2562
|
-
)
|
|
2563
|
-
);
|
|
2564
|
-
newVariables.forEach((variable) => {
|
|
2565
|
-
log(variable.name, "=", variable.value);
|
|
2566
|
-
});
|
|
2567
|
-
log("");
|
|
2568
|
-
}
|
|
2569
|
-
if (updatedVariables.length > 0) {
|
|
2570
|
-
log(
|
|
2571
|
-
import_kleur4.default.yellow(
|
|
2572
|
-
`The following variables will be updated in Github for environment ${environment}:`
|
|
2573
|
-
)
|
|
2574
|
-
);
|
|
2575
|
-
updatedVariables.forEach((variable) => {
|
|
2576
|
-
log(
|
|
2577
|
-
variable.name,
|
|
2578
|
-
"=",
|
|
2579
|
-
variable.value,
|
|
2580
|
-
`(was ${variable.didExist?.value})`
|
|
2581
|
-
);
|
|
2582
|
-
});
|
|
2583
|
-
log("");
|
|
2584
|
-
}
|
|
2585
|
-
if (unknownVariables.length > 0) {
|
|
2586
|
-
log(
|
|
2587
|
-
import_kleur4.default.yellow(
|
|
2588
|
-
`The following unknown variables/secrets were stored in Github are not managed by this script:`
|
|
2589
|
-
)
|
|
2590
|
-
);
|
|
2591
|
-
log("");
|
|
2592
|
-
log(import_kleur4.default.blue(`Repository:`));
|
|
2593
|
-
unknownVariables.filter(({ scope }) => scope === "REPOSITORY").forEach((variable) => {
|
|
2594
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2595
|
-
});
|
|
2596
|
-
log("");
|
|
2597
|
-
log(import_kleur4.default.blue(`Environment:`));
|
|
2598
|
-
unknownVariables.filter(({ scope }) => scope === "ENVIRONMENT").forEach((variable) => {
|
|
2599
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2600
|
-
});
|
|
2601
|
-
log("");
|
|
2602
|
-
log(
|
|
2603
|
-
import_kleur4.default.yellow(
|
|
2604
|
-
`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`
|
|
2605
|
-
)
|
|
2606
|
-
);
|
|
2607
|
-
log("");
|
|
2608
|
-
}
|
|
2609
|
-
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2610
|
-
process.exit(0);
|
|
2611
|
-
}
|
|
2612
|
-
const saveChanges = await confirm2({
|
|
2613
|
-
message: "Do you want to continue?",
|
|
2614
|
-
default: true
|
|
2615
|
-
});
|
|
2616
|
-
if (!saveChanges) {
|
|
2617
|
-
process.exit(0);
|
|
2618
|
-
}
|
|
2619
|
-
for (const newSecret of newSecrets) {
|
|
2620
|
-
log(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
|
|
2621
|
-
if (newSecret.scope === "ENVIRONMENT") {
|
|
2622
|
-
await createEnvironmentSecret(
|
|
2623
|
-
octokit,
|
|
2624
|
-
repositoryId,
|
|
2625
|
-
environment,
|
|
2626
|
-
newSecret.name,
|
|
2627
|
-
newSecret.value,
|
|
2628
|
-
githubOrganisation,
|
|
2629
|
-
githubRepository
|
|
2630
|
-
);
|
|
2631
|
-
} else {
|
|
2632
|
-
await createRepositorySecret(
|
|
2633
|
-
octokit,
|
|
2634
|
-
repositoryId,
|
|
2635
|
-
newSecret.name,
|
|
2636
|
-
newSecret.value,
|
|
2637
|
-
githubOrganisation,
|
|
2638
|
-
githubRepository
|
|
2639
|
-
);
|
|
2640
|
-
}
|
|
2641
|
-
}
|
|
2642
|
-
for (const updatedSecret of updatedSecrets) {
|
|
2643
|
-
log(
|
|
2644
|
-
`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`
|
|
2645
|
-
);
|
|
2646
|
-
if (updatedSecret.scope === "ENVIRONMENT") {
|
|
2647
|
-
await createEnvironmentSecret(
|
|
2648
|
-
octokit,
|
|
2649
|
-
repositoryId,
|
|
2650
|
-
environment,
|
|
2651
|
-
updatedSecret.name,
|
|
2652
|
-
updatedSecret.value,
|
|
2653
|
-
githubOrganisation,
|
|
2654
|
-
githubRepository
|
|
2655
|
-
);
|
|
2656
|
-
} else {
|
|
2657
|
-
await createRepositorySecret(
|
|
2658
|
-
octokit,
|
|
2659
|
-
repositoryId,
|
|
2660
|
-
updatedSecret.name,
|
|
2661
|
-
updatedSecret.value,
|
|
2662
|
-
githubOrganisation,
|
|
2663
|
-
githubRepository
|
|
2664
|
-
);
|
|
2665
|
-
}
|
|
2666
|
-
}
|
|
2667
|
-
for (const newVariable of newVariables) {
|
|
2668
|
-
log(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
|
|
2669
|
-
if (newVariable.scope === "ENVIRONMENT") {
|
|
2670
|
-
await createEnvironmentVariable(
|
|
2671
|
-
octokit,
|
|
2672
|
-
repositoryId,
|
|
2673
|
-
environment,
|
|
2674
|
-
newVariable.name,
|
|
2675
|
-
newVariable.value
|
|
2676
|
-
);
|
|
2677
|
-
} else {
|
|
2678
|
-
await createRepositoryVariable(
|
|
2679
|
-
octokit,
|
|
2680
|
-
repositoryId,
|
|
2681
|
-
newVariable.name,
|
|
2682
|
-
newVariable.value
|
|
2683
|
-
);
|
|
2684
|
-
}
|
|
2685
|
-
}
|
|
2686
|
-
for (const updatedVariable of updatedVariables) {
|
|
2687
|
-
log(
|
|
2688
|
-
`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`
|
|
2689
|
-
);
|
|
2690
|
-
if (updatedVariable.scope === "ENVIRONMENT") {
|
|
2691
|
-
await updateEnvironmentVariable(
|
|
2692
|
-
octokit,
|
|
2693
|
-
repositoryId,
|
|
2694
|
-
environment,
|
|
2695
|
-
updatedVariable.name,
|
|
2696
|
-
updatedVariable.value
|
|
2697
|
-
);
|
|
2698
|
-
} else {
|
|
2699
|
-
await updateRepositoryVariable(
|
|
2700
|
-
octokit,
|
|
2701
|
-
repositoryId,
|
|
2702
|
-
updatedVariable.name,
|
|
2703
|
-
updatedVariable.value
|
|
2704
|
-
);
|
|
2705
|
-
}
|
|
2706
|
-
}
|
|
2707
|
-
log(
|
|
2708
|
-
import_kleur4.default.green(
|
|
2709
|
-
`Successfully updated Github secrets and variables for environment ${environment}`
|
|
2710
|
-
)
|
|
2818
|
+
} else {
|
|
2819
|
+
await updateRepositoryVariable(
|
|
2820
|
+
octokit,
|
|
2821
|
+
repositoryId,
|
|
2822
|
+
updatedVariable.name,
|
|
2823
|
+
updatedVariable.value
|
|
2711
2824
|
);
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2825
|
+
}
|
|
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 ? `--------------------------------------------------------------------------------------------
|
|
2736
2855
|
|
|
2737
2856
|
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("COPY the SSH public key from the master VM to your clipboard")}
|
|
2738
2857
|
--------------------------------------------------------------------------------------------
|
|
2739
2858
|
` : "";
|
|
2740
|
-
|
|
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:")}
|
|
2741
2860
|
|
|
2742
2861
|
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2743
2862
|
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"
|
|
2744
2863
|
` : "";
|
|
2745
|
-
|
|
2864
|
+
addon_message += configureBackup ? `
|
|
2746
2865
|
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on backup server to create provision user and setup SSH key:")}
|
|
2747
2866
|
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2748
2867
|
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"` : "";
|
|
2749
|
-
|
|
2868
|
+
log(`
|
|
2750
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")}
|
|
2751
2870
|
Follow the steps below to complete the setup of your environment:
|
|
2752
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")}
|
|
@@ -2764,146 +2883,46 @@ ${addon_message}
|
|
|
2764
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")}
|
|
2765
2884
|
${import_kleur4.default.yellow("Please KINDLY read hints above")}
|
|
2766
2885
|
`);
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
})();
|
|
2772
|
-
}
|
|
2773
|
-
});
|
|
2774
|
-
|
|
2775
|
-
// src/environment/update-workflows.ts
|
|
2776
|
-
var update_workflows_exports = {};
|
|
2777
|
-
__export(update_workflows_exports, {
|
|
2778
|
-
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
2779
|
-
});
|
|
2780
|
-
function isDirectory(path10) {
|
|
2781
|
-
try {
|
|
2782
|
-
return (0, import_fs6.statSync)(path10).isDirectory();
|
|
2783
|
-
} catch {
|
|
2784
|
-
return false;
|
|
2785
|
-
}
|
|
2786
|
-
}
|
|
2787
|
-
async function extractInfrastructureNames() {
|
|
2788
|
-
const files = glob2.sync((0, import_path8.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
2789
|
-
const infraEnvironments = files.map((file) => (0, import_path8.basename)((0, import_path8.dirname)(file)));
|
|
2790
|
-
if (infraEnvironments.length === 0) {
|
|
2791
|
-
console.log(
|
|
2792
|
-
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
2793
|
-
);
|
|
2794
|
-
return [];
|
|
2795
|
-
}
|
|
2796
|
-
log("\u{1F50D} Found infrastructure configurations:", infraEnvironments.join(", "));
|
|
2797
|
-
return infraEnvironments;
|
|
2798
|
-
}
|
|
2799
|
-
async function extractEnvironmentNames() {
|
|
2800
|
-
const entries = await (0, import_promises.readdir)("environments");
|
|
2801
|
-
const environments = entries.filter((entry) => {
|
|
2802
|
-
const environmentPath = (0, import_path8.join)("environments", entry);
|
|
2803
|
-
const opencrvsServicesPath = (0, import_path8.join)(environmentPath, "opencrvs-services");
|
|
2804
|
-
return isDirectory(environmentPath) && (0, import_fs6.existsSync)(opencrvsServicesPath) && isDirectory(opencrvsServicesPath);
|
|
2805
|
-
});
|
|
2806
|
-
if (environments.length === 0) {
|
|
2807
|
-
console.log(
|
|
2808
|
-
"\u26A0\uFE0F Warning: No environment directories found in environments/"
|
|
2809
|
-
);
|
|
2810
|
-
return [];
|
|
2811
|
-
}
|
|
2812
|
-
log("\u{1F50D} Found OpenCRVS configurations:", environments.join(", "));
|
|
2813
|
-
return environments;
|
|
2814
|
-
}
|
|
2815
|
-
function updateOptionsInYaml(content, envList) {
|
|
2816
|
-
const optionsRegex = /([ ]*options:[ ]*\n)((?:[ ]*-[^\n]*\n)+)/;
|
|
2817
|
-
const match = content.match(optionsRegex);
|
|
2818
|
-
if (!match) {
|
|
2819
|
-
throw new Error("Could not find options array in workflow file");
|
|
2820
|
-
}
|
|
2821
|
-
const firstItemMatch = match[2].match(/^([ ]*)-/);
|
|
2822
|
-
const itemIndent = firstItemMatch ? firstItemMatch[1] : " ";
|
|
2823
|
-
const newOptions = match[1] + envList.map((env) => `${itemIndent}- ${env}`).join("\n") + "\n";
|
|
2824
|
-
return content.replace(optionsRegex, newOptions);
|
|
2825
|
-
}
|
|
2826
|
-
async function updateWorkflows(envList, config) {
|
|
2827
|
-
const { workflows } = config;
|
|
2828
|
-
for (const workflowPath of workflows) {
|
|
2829
|
-
if (!(0, import_fs6.existsSync)(workflowPath)) {
|
|
2830
|
-
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
2831
|
-
continue;
|
|
2832
|
-
}
|
|
2833
|
-
try {
|
|
2834
|
-
const fileContents = (0, import_fs6.readFileSync)(workflowPath, "utf8");
|
|
2835
|
-
const workflowData = yaml2.load(fileContents);
|
|
2836
|
-
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2837
|
-
throw new Error(
|
|
2838
|
-
"Workflow does not have the expected structure: on.workflow_dispatch.inputs.environment.options"
|
|
2839
|
-
);
|
|
2840
|
-
}
|
|
2841
|
-
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2842
|
-
(0, import_fs6.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2843
|
-
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2844
|
-
} catch (error3) {
|
|
2845
|
-
console.error(
|
|
2846
|
-
`
|
|
2847
|
-
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2848
|
-
);
|
|
2849
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
|
|
2850
|
-
throw error3;
|
|
2851
|
-
}
|
|
2852
|
-
}
|
|
2853
|
-
}
|
|
2854
|
-
async function updateWorkflowEnvironments() {
|
|
2855
|
-
try {
|
|
2856
|
-
let didUpdateWorkflows = false;
|
|
2857
|
-
const infraEnvironments = await extractInfrastructureNames();
|
|
2858
|
-
if (infraEnvironments.length > 0) {
|
|
2859
|
-
console.log("\u{1F504} Updating infrastructure workflows:");
|
|
2860
|
-
await updateWorkflows(infraEnvironments, {
|
|
2861
|
-
workflows: [
|
|
2862
|
-
".github/workflows/provision.yml",
|
|
2863
|
-
".github/workflows/reset-2fa.yml"
|
|
2864
|
-
],
|
|
2865
|
-
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2866
|
-
});
|
|
2867
|
-
didUpdateWorkflows = true;
|
|
2868
|
-
}
|
|
2869
|
-
const environments = await extractEnvironmentNames();
|
|
2870
|
-
if (environments.length > 0) {
|
|
2871
|
-
const workflows = [
|
|
2872
|
-
".github/workflows/deploy-dependencies.yml",
|
|
2873
|
-
".github/workflows/deploy-opencrvs.yml",
|
|
2874
|
-
".github/workflows/clear-all-data.yml",
|
|
2875
|
-
".github/workflows/seed-data.yml",
|
|
2876
|
-
".github/workflows/reindex.yml",
|
|
2877
|
-
".github/workflows/github-to-k8s-sync-env.yml"
|
|
2878
|
-
];
|
|
2879
|
-
log("\u{1F4CB} Updating OpenCRVS application workflows:");
|
|
2880
|
-
await updateWorkflows(environments, {
|
|
2881
|
-
workflows,
|
|
2882
|
-
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2883
|
-
});
|
|
2884
|
-
didUpdateWorkflows = true;
|
|
2885
|
-
}
|
|
2886
|
-
if (didUpdateWorkflows) {
|
|
2887
|
-
success("\u2705 Workflow updates completed successfully!");
|
|
2888
|
-
} else {
|
|
2889
|
-
log("\u2139\uFE0F No workflows were updated.");
|
|
2890
|
-
}
|
|
2891
|
-
} catch (error3) {
|
|
2892
|
-
console.error("\n\u274C Error updating workflows:", error3);
|
|
2893
|
-
process.exit(1);
|
|
2894
|
-
}
|
|
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
|
+
);
|
|
2895
2890
|
}
|
|
2896
|
-
var
|
|
2897
|
-
var
|
|
2898
|
-
"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"() {
|
|
2899
2894
|
"use strict";
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
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();
|
|
2905
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();
|
|
2906
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
|
+
);
|
|
2907
2926
|
}
|
|
2908
2927
|
});
|
|
2909
2928
|
|
|
@@ -2913,17 +2932,17 @@ __export(upgrade_exports, {
|
|
|
2913
2932
|
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2914
2933
|
});
|
|
2915
2934
|
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2916
|
-
if (!(0,
|
|
2935
|
+
if (!(0, import_fs12.existsSync)(sourcePath)) {
|
|
2917
2936
|
return false;
|
|
2918
2937
|
}
|
|
2919
|
-
if ((0,
|
|
2938
|
+
if ((0, import_fs12.existsSync)(destinationPath)) {
|
|
2920
2939
|
warn(
|
|
2921
2940
|
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2922
2941
|
);
|
|
2923
2942
|
return false;
|
|
2924
2943
|
}
|
|
2925
|
-
(0,
|
|
2926
|
-
(0,
|
|
2944
|
+
(0, import_fs12.mkdirSync)((0, import_path14.dirname)(destinationPath), { recursive: true });
|
|
2945
|
+
(0, import_fs12.renameSync)(sourcePath, destinationPath);
|
|
2927
2946
|
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2928
2947
|
return true;
|
|
2929
2948
|
}
|
|
@@ -2943,8 +2962,8 @@ function migrateInventoryFiles() {
|
|
|
2943
2962
|
) || didMoveInventory;
|
|
2944
2963
|
}
|
|
2945
2964
|
try {
|
|
2946
|
-
if ((0,
|
|
2947
|
-
(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);
|
|
2948
2967
|
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2949
2968
|
}
|
|
2950
2969
|
} catch {
|
|
@@ -2962,12 +2981,12 @@ async function upgradeEnvironmentLayout() {
|
|
|
2962
2981
|
}
|
|
2963
2982
|
log("\nCommit changes into git after upgrade");
|
|
2964
2983
|
}
|
|
2965
|
-
var
|
|
2984
|
+
var import_fs12, import_path14, import_kleur5;
|
|
2966
2985
|
var init_upgrade = __esm({
|
|
2967
2986
|
"src/environment/upgrade.ts"() {
|
|
2968
2987
|
"use strict";
|
|
2969
|
-
|
|
2970
|
-
|
|
2988
|
+
import_fs12 = require("fs");
|
|
2989
|
+
import_path14 = require("path");
|
|
2971
2990
|
import_kleur5 = __toESM(require("kleur"));
|
|
2972
2991
|
init_logger();
|
|
2973
2992
|
init_paths();
|
|
@@ -2993,7 +3012,7 @@ async function selectInventoryFile(dirPath = "./environments") {
|
|
|
2993
3012
|
return null;
|
|
2994
3013
|
}
|
|
2995
3014
|
const environments = fs4.readdirSync(dirPath).filter((entry) => {
|
|
2996
|
-
const filePath =
|
|
3015
|
+
const filePath = path12.join(dirPath, entry);
|
|
2997
3016
|
return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
|
|
2998
3017
|
}).sort();
|
|
2999
3018
|
if (environments.length === 0) {
|
|
@@ -3021,12 +3040,12 @@ async function manageEnvironmentUsers() {
|
|
|
3021
3040
|
}
|
|
3022
3041
|
await manageUsers(inventory_file);
|
|
3023
3042
|
}
|
|
3024
|
-
var fs4,
|
|
3043
|
+
var fs4, path12, import_kleur6;
|
|
3025
3044
|
var init_users = __esm({
|
|
3026
3045
|
"src/environment/users.ts"() {
|
|
3027
3046
|
"use strict";
|
|
3028
3047
|
fs4 = __toESM(require("fs"));
|
|
3029
|
-
|
|
3048
|
+
path12 = __toESM(require("path"));
|
|
3030
3049
|
import_kleur6 = __toESM(require("kleur"));
|
|
3031
3050
|
init_manage_users();
|
|
3032
3051
|
init_logger();
|
|
@@ -3036,11 +3055,11 @@ var init_users = __esm({
|
|
|
3036
3055
|
|
|
3037
3056
|
// src/environment/swarm-to-k8s.ts
|
|
3038
3057
|
var swarm_to_k8s_exports = {};
|
|
3039
|
-
var
|
|
3058
|
+
var path13, import_kleur7, import_core2;
|
|
3040
3059
|
var init_swarm_to_k8s = __esm({
|
|
3041
3060
|
"src/environment/swarm-to-k8s.ts"() {
|
|
3042
3061
|
"use strict";
|
|
3043
|
-
|
|
3062
|
+
path13 = __toESM(require("path"));
|
|
3044
3063
|
import_kleur7 = __toESM(require("kleur"));
|
|
3045
3064
|
init_logger();
|
|
3046
3065
|
init_utils();
|
|
@@ -3092,7 +3111,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3092
3111
|
);
|
|
3093
3112
|
process.exit(1);
|
|
3094
3113
|
}
|
|
3095
|
-
const ansible_inventory =
|
|
3114
|
+
const ansible_inventory = path13.join(old_inventory_path, environment + ".yml");
|
|
3096
3115
|
const data = readYamlFile(ansible_inventory);
|
|
3097
3116
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
3098
3117
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3111,10 +3130,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3111
3130
|
copyChartsValues(environment, {
|
|
3112
3131
|
env: environment,
|
|
3113
3132
|
environment_type,
|
|
3114
|
-
|
|
3115
|
-
// Hardcode like this blocks us from being generic:
|
|
3116
|
-
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
3117
|
-
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",
|
|
3118
3134
|
backup_enabled: environment === "production" ? "true" : "false",
|
|
3119
3135
|
restore_enabled: environment === "staging" ? "true" : "false",
|
|
3120
3136
|
restore_environment_name: environment === "staging" ? "production" : "",
|
|
@@ -3438,20 +3454,20 @@ function idOf(line2) {
|
|
|
3438
3454
|
const comma = line2.indexOf(",");
|
|
3439
3455
|
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3440
3456
|
}
|
|
3441
|
-
function readCsvFile(
|
|
3442
|
-
if (!(0, import_fs.existsSync)(
|
|
3457
|
+
function readCsvFile(path14) {
|
|
3458
|
+
if (!(0, import_fs.existsSync)(path14)) {
|
|
3443
3459
|
return void 0;
|
|
3444
3460
|
}
|
|
3445
|
-
const contents = (0, import_fs.readFileSync)(
|
|
3461
|
+
const contents = (0, import_fs.readFileSync)(path14, "utf8");
|
|
3446
3462
|
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3447
3463
|
const trailingNewline = /\r?\n$/.test(contents);
|
|
3448
3464
|
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3449
3465
|
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3450
3466
|
return { header: lines[0], body, newline, trailingNewline };
|
|
3451
3467
|
}
|
|
3452
|
-
function writeCsvFile(
|
|
3468
|
+
function writeCsvFile(path14, file) {
|
|
3453
3469
|
(0, import_fs.writeFileSync)(
|
|
3454
|
-
|
|
3470
|
+
path14,
|
|
3455
3471
|
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3456
3472
|
);
|
|
3457
3473
|
}
|
|
@@ -3763,10 +3779,10 @@ function updateRoutes(project, cwd) {
|
|
|
3763
3779
|
return;
|
|
3764
3780
|
}
|
|
3765
3781
|
for (const event of RECOVERY_EVENTS) {
|
|
3766
|
-
if (routesArray.getText().includes(`/
|
|
3782
|
+
if (routesArray.getText().includes(`/trigger/user/${event.id}`)) continue;
|
|
3767
3783
|
routesArray.addElement(`{
|
|
3768
3784
|
method: 'POST',
|
|
3769
|
-
path: '/
|
|
3785
|
+
path: '/trigger/user/${event.id}',
|
|
3770
3786
|
handler: makeNotificationHandler('${event.id}'),
|
|
3771
3787
|
options: {
|
|
3772
3788
|
auth: false,
|
|
@@ -3774,7 +3790,7 @@ function updateRoutes(project, cwd) {
|
|
|
3774
3790
|
description: '${event.routeDescription}'
|
|
3775
3791
|
}
|
|
3776
3792
|
}`);
|
|
3777
|
-
console.log(` \u2713 ${ROUTES_FILE}: POST /
|
|
3793
|
+
console.log(` \u2713 ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
|
|
3778
3794
|
}
|
|
3779
3795
|
}
|
|
3780
3796
|
function renderEmailTemplate(event) {
|
|
@@ -3922,15 +3938,10 @@ async function main2() {
|
|
|
3922
3938
|
|
|
3923
3939
|
// src/migrations/v2.1/add-translations.ts
|
|
3924
3940
|
var import_path3 = __toESM(require("path"));
|
|
3941
|
+
|
|
3942
|
+
// src/translations/template.ts
|
|
3925
3943
|
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3926
3944
|
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3927
|
-
var APPLICATIONS = ["client", "login"];
|
|
3928
|
-
var TARGET_VERSION = "2.1";
|
|
3929
|
-
var skipped2 = [];
|
|
3930
|
-
function warnSkipped2(message) {
|
|
3931
|
-
skipped2.push(message);
|
|
3932
|
-
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3933
|
-
}
|
|
3934
3945
|
async function matchingRefs(namespace, prefix) {
|
|
3935
3946
|
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3936
3947
|
const response = await fetch(url, {
|
|
@@ -3945,10 +3956,10 @@ async function matchingRefs(namespace, prefix) {
|
|
|
3945
3956
|
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3946
3957
|
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3947
3958
|
}
|
|
3948
|
-
async function candidateRefs() {
|
|
3959
|
+
async function candidateRefs(version) {
|
|
3949
3960
|
return [
|
|
3950
|
-
...await matchingRefs("heads", `release/${
|
|
3951
|
-
...await matchingRefs("tags", `v${
|
|
3961
|
+
...await matchingRefs("heads", `release/${version}.`),
|
|
3962
|
+
...await matchingRefs("tags", `v${version}.`),
|
|
3952
3963
|
"develop"
|
|
3953
3964
|
];
|
|
3954
3965
|
}
|
|
@@ -3965,11 +3976,17 @@ async function fetchTemplate(refs, application) {
|
|
|
3965
3976
|
);
|
|
3966
3977
|
}
|
|
3967
3978
|
}
|
|
3968
|
-
warnSkipped2(
|
|
3969
|
-
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
3970
|
-
);
|
|
3971
3979
|
return void 0;
|
|
3972
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
|
+
}
|
|
3973
3990
|
function rowsToAdd(local, template) {
|
|
3974
3991
|
const localColumns = parseCsvLine(local.header);
|
|
3975
3992
|
const templateColumns = parseCsvLine(template.header);
|
|
@@ -3992,6 +4009,9 @@ async function updateApplication(cwd, refs, application) {
|
|
|
3992
4009
|
}
|
|
3993
4010
|
const fetched = await fetchTemplate(refs, application);
|
|
3994
4011
|
if (!fetched) {
|
|
4012
|
+
warnSkipped2(
|
|
4013
|
+
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
4014
|
+
);
|
|
3995
4015
|
return;
|
|
3996
4016
|
}
|
|
3997
4017
|
const template = readTemplate(fetched.contents);
|
|
@@ -4022,7 +4042,7 @@ function readTemplate(contents) {
|
|
|
4022
4042
|
}
|
|
4023
4043
|
async function listRefs() {
|
|
4024
4044
|
try {
|
|
4025
|
-
return await candidateRefs();
|
|
4045
|
+
return await candidateRefs(TARGET_VERSION);
|
|
4026
4046
|
} catch (error3) {
|
|
4027
4047
|
warnSkipped2(
|
|
4028
4048
|
`Could not list the ${TARGET_VERSION} refs on GitHub (${error3.message}); translations not added`
|
|
@@ -4225,8 +4245,8 @@ function writeTelemetryHandler(cwd) {
|
|
|
4225
4245
|
(0, import_fs3.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
|
|
4226
4246
|
console.log(` \u2713 ${HANDLER_FILE2}`);
|
|
4227
4247
|
}
|
|
4228
|
-
function appendProperty(sourceFile,
|
|
4229
|
-
const properties =
|
|
4248
|
+
function appendProperty(sourceFile, object2, name, valueLines) {
|
|
4249
|
+
const properties = object2.getProperties();
|
|
4230
4250
|
const lastProperty = properties[properties.length - 1];
|
|
4231
4251
|
if (!lastProperty) return false;
|
|
4232
4252
|
const indent = lastProperty.getIndentationText();
|
|
@@ -4257,9 +4277,9 @@ function getCleanEnvObject(sourceFile) {
|
|
|
4257
4277
|
return options && import_ts_morph3.Node.isObjectLiteralExpression(options) ? options : void 0;
|
|
4258
4278
|
}
|
|
4259
4279
|
function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
4260
|
-
const
|
|
4261
|
-
if (!
|
|
4262
|
-
const existing =
|
|
4280
|
+
const object2 = getCleanEnvObject(sourceFile);
|
|
4281
|
+
if (!object2) return;
|
|
4282
|
+
const existing = object2.getProperty(name);
|
|
4263
4283
|
if (existing && import_ts_morph3.Node.isPropertyAssignment(existing)) {
|
|
4264
4284
|
if (!update) return;
|
|
4265
4285
|
const options = existing.getInitializerIfKind(import_ts_morph3.SyntaxKind.CallExpression)?.getArguments()[0];
|
|
@@ -4277,7 +4297,7 @@ function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
|
4277
4297
|
}
|
|
4278
4298
|
return;
|
|
4279
4299
|
}
|
|
4280
|
-
if (appendProperty(sourceFile,
|
|
4300
|
+
if (appendProperty(sourceFile, object2, name, [
|
|
4281
4301
|
`${kind}({`,
|
|
4282
4302
|
` default: ${defaultExpr},`,
|
|
4283
4303
|
` desc: ${JSON.stringify(desc)}`,
|
|
@@ -4336,6 +4356,31 @@ function addEnvironmentVariables(project, cwd, config) {
|
|
|
4336
4356
|
false
|
|
4337
4357
|
);
|
|
4338
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
|
+
}
|
|
4339
4384
|
function wireIndex(project, cwd) {
|
|
4340
4385
|
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4341
4386
|
import_path4.default.join(cwd, INDEX_FILE)
|
|
@@ -4346,17 +4391,11 @@ function wireIndex(project, cwd) {
|
|
|
4346
4391
|
);
|
|
4347
4392
|
return;
|
|
4348
4393
|
}
|
|
4349
|
-
|
|
4350
|
-
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
"telemetrySchema",
|
|
4355
|
-
"TELEMETRY_DISABLED_NOTICE"
|
|
4356
|
-
]
|
|
4357
|
-
});
|
|
4358
|
-
console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
|
|
4359
|
-
}
|
|
4394
|
+
ensureHandlerNamedImports(sourceFile, [
|
|
4395
|
+
"telemetryHandler",
|
|
4396
|
+
"telemetrySchema",
|
|
4397
|
+
"TELEMETRY_DISABLED_NOTICE"
|
|
4398
|
+
]);
|
|
4360
4399
|
if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
|
|
4361
4400
|
const lastRouteStatement = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "server.route").map(
|
|
4362
4401
|
(call) => call.getFirstAncestorByKind(import_ts_morph3.SyntaxKind.ExpressionStatement)
|
|
@@ -4390,160 +4429,942 @@ ${route}`);
|
|
|
4390
4429
|
console.log(` \u2713 ${INDEX_FILE}: POST /trigger/telemetry`);
|
|
4391
4430
|
}
|
|
4392
4431
|
}
|
|
4393
|
-
if (!sourceFile.getText().includes("logger.info(TELEMETRY_DISABLED_NOTICE)")) {
|
|
4394
|
-
const startedLog = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.ExpressionStatement).find(
|
|
4395
|
-
(statement) => statement.getText().includes("Server successfully started")
|
|
4432
|
+
if (!sourceFile.getText().includes("logger.info(TELEMETRY_DISABLED_NOTICE)")) {
|
|
4433
|
+
const startedLog = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.ExpressionStatement).find(
|
|
4434
|
+
(statement) => statement.getText().includes("Server successfully started")
|
|
4435
|
+
);
|
|
4436
|
+
if (!startedLog) {
|
|
4437
|
+
warnSkipped3(
|
|
4438
|
+
`Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
|
|
4439
|
+
);
|
|
4440
|
+
} else {
|
|
4441
|
+
const indent = startedLog.getIndentationText();
|
|
4442
|
+
const notice = [
|
|
4443
|
+
`if (!env.TELEMETRY_ENABLED) {`,
|
|
4444
|
+
` logger.info(TELEMETRY_DISABLED_NOTICE)`,
|
|
4445
|
+
`}`
|
|
4446
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4447
|
+
sourceFile.insertText(startedLog.getEnd(), `
|
|
4448
|
+
|
|
4449
|
+
${notice}`);
|
|
4450
|
+
console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
|
|
4451
|
+
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
|
|
4452
|
+
warnSkipped3(
|
|
4453
|
+
`The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
|
|
4454
|
+
);
|
|
4455
|
+
}
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
4458
|
+
}
|
|
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
|
+
"-q",
|
|
4568
|
+
"-L",
|
|
4569
|
+
`infrastructure/${file}`,
|
|
4570
|
+
"-L",
|
|
4571
|
+
"v2.0",
|
|
4572
|
+
"-L",
|
|
4573
|
+
`v2.1 template`,
|
|
4574
|
+
oursPath,
|
|
4575
|
+
basePath,
|
|
4576
|
+
theirsPath
|
|
4577
|
+
];
|
|
4578
|
+
let conflicts = 0;
|
|
4579
|
+
try {
|
|
4580
|
+
(0, import_child_process.execFileSync)("git", args2, { stdio: "ignore" });
|
|
4581
|
+
} catch (error3) {
|
|
4582
|
+
const { status } = error3;
|
|
4583
|
+
if (!status || status >= 255) throw error3;
|
|
4584
|
+
conflicts = status;
|
|
4585
|
+
}
|
|
4586
|
+
return { contents: toBytes((0, import_fs5.readFileSync)(oursPath)), conflicts };
|
|
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`
|
|
4396
4997
|
);
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4401
|
-
|
|
4402
|
-
|
|
4403
|
-
|
|
4404
|
-
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
${
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
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;
|
|
4416
5019
|
}
|
|
4417
5020
|
}
|
|
4418
5021
|
}
|
|
4419
5022
|
}
|
|
4420
|
-
|
|
4421
|
-
const
|
|
4422
|
-
|
|
4423
|
-
console.log(
|
|
4424
|
-
`
|
|
4425
|
-
Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
|
|
4426
|
-
`
|
|
5023
|
+
function removeApplicationConfigField(project, cwd) {
|
|
5024
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
5025
|
+
import_path8.default.join(cwd, UTILS_FILE)
|
|
4427
5026
|
);
|
|
4428
|
-
|
|
4429
|
-
const
|
|
4430
|
-
|
|
4431
|
-
|
|
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() {
|
|
5082
|
+
const cwd = process.cwd();
|
|
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.
|
|
4432
5087
|
manipulationSettings: {
|
|
4433
|
-
indentationText:
|
|
4434
|
-
quoteKind:
|
|
5088
|
+
indentationText: import_ts_morph4.IndentationText.TwoSpaces,
|
|
5089
|
+
quoteKind: import_ts_morph4.QuoteKind.Single
|
|
4435
5090
|
}
|
|
4436
5091
|
});
|
|
4437
|
-
|
|
4438
|
-
|
|
5092
|
+
removeSentryFromConfigs(project, cwd);
|
|
5093
|
+
removeEnvironmentVariable(project, cwd);
|
|
5094
|
+
removeConstant(project, cwd);
|
|
5095
|
+
unwireIndex(project, cwd);
|
|
5096
|
+
removeApplicationConfigField(project, cwd);
|
|
4439
5097
|
await project.save();
|
|
4440
|
-
|
|
5098
|
+
removeDependencies(cwd);
|
|
5099
|
+
removeTypings(cwd);
|
|
5100
|
+
if (skipped4.length > 0) {
|
|
4441
5101
|
console.warn(
|
|
4442
5102
|
`
|
|
4443
|
-
\u26A0\uFE0F ${
|
|
5103
|
+
\u26A0\uFE0F ${skipped4.length} Sentry removal step(s) were skipped. Handle the following by hand:`
|
|
4444
5104
|
);
|
|
4445
|
-
for (const message of
|
|
5105
|
+
for (const message of skipped4) {
|
|
4446
5106
|
console.warn(` - ${message}`);
|
|
4447
5107
|
}
|
|
4448
5108
|
}
|
|
4449
5109
|
}
|
|
4450
5110
|
|
|
4451
|
-
// src/migrations/v2.1/
|
|
4452
|
-
|
|
4453
|
-
|
|
4454
|
-
|
|
4455
|
-
|
|
4456
|
-
|
|
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;
|
|
4457
5166
|
}
|
|
4458
|
-
|
|
4459
|
-
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
const
|
|
4467
|
-
|
|
4468
|
-
|
|
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
|
+
}
|
|
4469
5182
|
}
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
const
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
`!${import_path5.default.join(cwd, "src/**/*.stories.ts")}`,
|
|
4481
|
-
`!${import_path5.default.join(cwd, "src/**/*.stories.tsx")}`
|
|
4482
|
-
]);
|
|
4483
|
-
const messages = [];
|
|
4484
|
-
const dynamicIds = [];
|
|
4485
|
-
for (const sourceFile of project.getSourceFiles()) {
|
|
4486
|
-
sourceFile.forEachDescendant((node) => {
|
|
4487
|
-
if (!import_ts_morph4.Node.isObjectLiteralExpression(node)) {
|
|
4488
|
-
return;
|
|
4489
|
-
}
|
|
4490
|
-
if (!(node.getProperty("id") && node.getProperty("defaultMessage"))) {
|
|
4491
|
-
return;
|
|
4492
|
-
}
|
|
4493
|
-
const id = staticStringOf(node, "id");
|
|
4494
|
-
if (id === void 0) {
|
|
4495
|
-
dynamicIds.push(import_path5.default.relative(cwd, sourceFile.getFilePath()));
|
|
4496
|
-
return;
|
|
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()}`);
|
|
4497
5193
|
}
|
|
4498
|
-
messages.push({
|
|
4499
|
-
id,
|
|
4500
|
-
defaultMessage: staticStringOf(node, "defaultMessage") ?? "",
|
|
4501
|
-
description: staticStringOf(node, "description") ?? ""
|
|
4502
|
-
});
|
|
4503
5194
|
});
|
|
4504
5195
|
}
|
|
4505
|
-
|
|
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);
|
|
4506
5246
|
}
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
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}`
|
|
4512
5280
|
);
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
}
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
|
|
4530
|
-
const
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
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
|
+
)
|
|
4537
5309
|
)
|
|
4538
5310
|
);
|
|
4539
|
-
const
|
|
4540
|
-
|
|
4541
|
-
|
|
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
|
+
|
|
5352
|
+
// src/migrations/v2.1/index.ts
|
|
5353
|
+
async function runUpgrade(dockerSwarm) {
|
|
5354
|
+
await main();
|
|
5355
|
+
await main8();
|
|
5356
|
+
await main2();
|
|
5357
|
+
await main3();
|
|
5358
|
+
await main7();
|
|
5359
|
+
await main6();
|
|
5360
|
+
await main5(dockerSwarm);
|
|
5361
|
+
await main9();
|
|
5362
|
+
await main4();
|
|
4542
5363
|
}
|
|
4543
5364
|
|
|
4544
5365
|
// src/environment/index.ts
|
|
4545
|
-
var
|
|
4546
|
-
var
|
|
5366
|
+
var import_fs13 = require("fs");
|
|
5367
|
+
var import_path15 = require("path");
|
|
4547
5368
|
init_paths();
|
|
4548
5369
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
4549
5370
|
".github/workflows",
|
|
@@ -4554,7 +5375,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
4554
5375
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
4555
5376
|
(directory) => {
|
|
4556
5377
|
try {
|
|
4557
|
-
return !(0,
|
|
5378
|
+
return !(0, import_fs13.statSync)((0, import_path15.resolve)(repositoryRoot, directory)).isDirectory();
|
|
4558
5379
|
} catch {
|
|
4559
5380
|
return true;
|
|
4560
5381
|
}
|
|
@@ -4569,7 +5390,8 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
4569
5390
|
async function runEnvironmentInit() {
|
|
4570
5391
|
validateRepositoryStructure();
|
|
4571
5392
|
assertNoOldInventoryLayout();
|
|
4572
|
-
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();
|
|
4573
5395
|
}
|
|
4574
5396
|
async function runEnvironmentUpgrade() {
|
|
4575
5397
|
validateRepositoryStructure();
|
|
@@ -4593,6 +5415,7 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
4593
5415
|
|
|
4594
5416
|
// src/verify/endpoints.ts
|
|
4595
5417
|
var import_colors = require("kleur/colors");
|
|
5418
|
+
var z = __toESM(require("zod/v4"));
|
|
4596
5419
|
var REQUEST_TIMEOUT_MS = 15e3;
|
|
4597
5420
|
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
4598
5421
|
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
@@ -4628,11 +5451,11 @@ var SECURED_ENDPOINTS = [
|
|
|
4628
5451
|
...SECURED_TRIGGER_USER_EVENTS.map(
|
|
4629
5452
|
(event) => ({
|
|
4630
5453
|
method: "POST",
|
|
4631
|
-
path: `/
|
|
5454
|
+
path: `/trigger/user/${event}`
|
|
4632
5455
|
})
|
|
4633
5456
|
),
|
|
4634
5457
|
{ method: "POST", path: "/trigger/telemetry" },
|
|
4635
|
-
{ method: "GET", path: "/
|
|
5458
|
+
{ method: "GET", path: "/trigger/system/ready" },
|
|
4636
5459
|
{
|
|
4637
5460
|
method: "GET",
|
|
4638
5461
|
path: `/certificates/${PROBE_SEGMENT}`,
|
|
@@ -4661,12 +5484,10 @@ var FALLBACK_EVENT_TRIGGERS = [
|
|
|
4661
5484
|
var isSuccess = (status) => status !== "error" && status >= 200 && status < 300;
|
|
4662
5485
|
var requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
|
|
4663
5486
|
async function requestStatus(url, method) {
|
|
4664
|
-
const controller = new AbortController();
|
|
4665
|
-
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
4666
5487
|
try {
|
|
4667
5488
|
const response = await fetch(url, {
|
|
4668
5489
|
method,
|
|
4669
|
-
signal:
|
|
5490
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
4670
5491
|
// Sent without an Authorization header on purpose. A secured route
|
|
4671
5492
|
// rejects with 401/403 before ever reading the body.
|
|
4672
5493
|
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
@@ -4675,21 +5496,19 @@ async function requestStatus(url, method) {
|
|
|
4675
5496
|
return response.status;
|
|
4676
5497
|
} catch {
|
|
4677
5498
|
return "error";
|
|
4678
|
-
} finally {
|
|
4679
|
-
clearTimeout(timer);
|
|
4680
5499
|
}
|
|
4681
5500
|
}
|
|
4682
5501
|
function toEventTriggerConfig(value) {
|
|
4683
5502
|
if (typeof value !== "object" || value === null) {
|
|
4684
5503
|
return null;
|
|
4685
5504
|
}
|
|
4686
|
-
const
|
|
4687
|
-
if (typeof
|
|
5505
|
+
const record2 = value;
|
|
5506
|
+
if (typeof record2.id !== "string") {
|
|
4688
5507
|
return null;
|
|
4689
5508
|
}
|
|
4690
|
-
const actions = Array.isArray(
|
|
5509
|
+
const actions = Array.isArray(record2.actions) ? Array.from(
|
|
4691
5510
|
new Set(
|
|
4692
|
-
|
|
5511
|
+
record2.actions.map((action) => {
|
|
4693
5512
|
if (typeof action !== "object" || action === null) {
|
|
4694
5513
|
return null;
|
|
4695
5514
|
}
|
|
@@ -4698,14 +5517,12 @@ function toEventTriggerConfig(value) {
|
|
|
4698
5517
|
}).filter((type) => type !== null)
|
|
4699
5518
|
)
|
|
4700
5519
|
) : [];
|
|
4701
|
-
return { id:
|
|
5520
|
+
return { id: record2.id, actions };
|
|
4702
5521
|
}
|
|
4703
5522
|
async function fetchEventConfigs(baseUrl) {
|
|
4704
|
-
const controller = new AbortController();
|
|
4705
|
-
const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);
|
|
4706
5523
|
try {
|
|
4707
5524
|
const response = await fetch(`${baseUrl}/config/events`, {
|
|
4708
|
-
signal:
|
|
5525
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
4709
5526
|
});
|
|
4710
5527
|
if (!response.ok) {
|
|
4711
5528
|
return null;
|
|
@@ -4717,8 +5534,6 @@ async function fetchEventConfigs(baseUrl) {
|
|
|
4717
5534
|
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
4718
5535
|
} catch {
|
|
4719
5536
|
return null;
|
|
4720
|
-
} finally {
|
|
4721
|
-
clearTimeout(timer);
|
|
4722
5537
|
}
|
|
4723
5538
|
}
|
|
4724
5539
|
function resolveBaseUrl(input4) {
|
|
@@ -4728,10 +5543,10 @@ function resolveBaseUrl(input4) {
|
|
|
4728
5543
|
function describeStatus(status) {
|
|
4729
5544
|
return status === "error" ? "no response" : `HTTP ${status}`;
|
|
4730
5545
|
}
|
|
4731
|
-
function endpointLabel(
|
|
4732
|
-
const shown =
|
|
4733
|
-
const suffix =
|
|
4734
|
-
return `${
|
|
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}`;
|
|
4735
5550
|
}
|
|
4736
5551
|
function line(ok, label, detail) {
|
|
4737
5552
|
const mark = ok ? (0, import_colors.green)("\u2713") : (0, import_colors.red)("\u2717");
|
|
@@ -4749,24 +5564,146 @@ function securedDetail(status) {
|
|
|
4749
5564
|
}
|
|
4750
5565
|
return `${describeStatus(status)} \u2014 INSECURE: ensure this endpoint requires authentication!`;
|
|
4751
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
|
+
}
|
|
4752
5689
|
async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
4753
5690
|
const baseUrl = resolveBaseUrl(target);
|
|
4754
5691
|
console.log((0, import_colors.bold)(`Verifying country config endpoints at ${baseUrl}
|
|
4755
5692
|
`));
|
|
4756
5693
|
let failures = 0;
|
|
4757
5694
|
console.log((0, import_colors.bold)("Required public endpoints (must respond 2xx):"));
|
|
4758
|
-
for (const
|
|
4759
|
-
const status = await requestStatus(`${baseUrl}${
|
|
5695
|
+
for (const check of REQUIRED_PUBLIC_ENDPOINTS) {
|
|
5696
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
4760
5697
|
const ok = isSuccess(status);
|
|
4761
5698
|
if (!ok) {
|
|
4762
5699
|
failures++;
|
|
4763
5700
|
}
|
|
4764
5701
|
const detail = status === 404 ? `${describeStatus(status)} \u2014 missing` : ok ? describeStatus(status) : `${describeStatus(status)} \u2014 unexpected`;
|
|
4765
|
-
console.log(line(ok, endpointLabel(
|
|
5702
|
+
console.log(line(ok, endpointLabel(check), detail));
|
|
4766
5703
|
}
|
|
4767
5704
|
{
|
|
4768
|
-
const
|
|
4769
|
-
const status = await requestStatus(`${baseUrl}${
|
|
5705
|
+
const path14 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
5706
|
+
const status = await requestStatus(`${baseUrl}${path14}`, "GET");
|
|
4770
5707
|
const ok = status === 200 || status === 404;
|
|
4771
5708
|
if (!ok) {
|
|
4772
5709
|
failures++;
|
|
@@ -4781,17 +5718,17 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4781
5718
|
} else {
|
|
4782
5719
|
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
4783
5720
|
}
|
|
4784
|
-
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${
|
|
5721
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path14}`)}`, detail));
|
|
4785
5722
|
}
|
|
4786
5723
|
console.log();
|
|
4787
5724
|
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
4788
|
-
for (const
|
|
4789
|
-
const status = await requestStatus(`${baseUrl}${
|
|
5725
|
+
for (const check of SECURED_ENDPOINTS) {
|
|
5726
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
4790
5727
|
const ok = requiresAuthOrAbsent(status);
|
|
4791
5728
|
if (!ok) {
|
|
4792
5729
|
failures++;
|
|
4793
5730
|
}
|
|
4794
|
-
console.log(line(ok, endpointLabel(
|
|
5731
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
4795
5732
|
}
|
|
4796
5733
|
console.log();
|
|
4797
5734
|
console.log((0, import_colors.bold)("Event action triggers (must be absent or require auth):"));
|
|
@@ -4802,16 +5739,16 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4802
5739
|
"Could not read /config/events; falling back to route-pattern checks."
|
|
4803
5740
|
)
|
|
4804
5741
|
);
|
|
4805
|
-
for (const
|
|
5742
|
+
for (const check of FALLBACK_EVENT_TRIGGERS) {
|
|
4806
5743
|
const status = await requestStatus(
|
|
4807
|
-
`${baseUrl}${
|
|
4808
|
-
|
|
5744
|
+
`${baseUrl}${check.path}`,
|
|
5745
|
+
check.method
|
|
4809
5746
|
);
|
|
4810
5747
|
const ok = requiresAuthOrAbsent(status);
|
|
4811
5748
|
if (!ok) {
|
|
4812
5749
|
failures++;
|
|
4813
5750
|
}
|
|
4814
|
-
console.log(line(ok, endpointLabel(
|
|
5751
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
4815
5752
|
}
|
|
4816
5753
|
} else if (events.length === 0) {
|
|
4817
5754
|
console.log(" " + (0, import_colors.yellow)("No events configured."));
|
|
@@ -4854,6 +5791,9 @@ async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
|
4854
5791
|
}
|
|
4855
5792
|
}
|
|
4856
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();
|
|
4857
5797
|
if (failures > 0) {
|
|
4858
5798
|
console.log(
|
|
4859
5799
|
(0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
|
|
@@ -4871,9 +5811,9 @@ Usage: opencrvs <command>
|
|
|
4871
5811
|
Commands:
|
|
4872
5812
|
environment Manage deployment environments
|
|
4873
5813
|
upgrade Upgrade an existing environment
|
|
4874
|
-
check-translations Check translation files for completeness
|
|
4875
5814
|
verify-endpoints Verify the locally-running country config exposes the
|
|
4876
|
-
expected endpoints
|
|
5815
|
+
expected endpoints, keeps secured ones locked down and
|
|
5816
|
+
serves the translations core requires
|
|
4877
5817
|
|
|
4878
5818
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
4879
5819
|
`.trim();
|
|
@@ -4882,9 +5822,14 @@ Usage: opencrvs verify-endpoints [country-config-url]
|
|
|
4882
5822
|
|
|
4883
5823
|
Run this after 'opencrvs upgrade', with the upgraded country config running
|
|
4884
5824
|
locally, to confirm it still behaves correctly. It checks over HTTP that:
|
|
4885
|
-
- required public endpoints exist (respond 2xx),
|
|
5825
|
+
- required public endpoints exist (respond 2xx),
|
|
4886
5826
|
- user-notification trigger endpoints are either absent or reject
|
|
4887
|
-
unauthenticated requests (never processed without a token)
|
|
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.
|
|
4888
5833
|
|
|
4889
5834
|
Arguments:
|
|
4890
5835
|
[country-config-url] Optional. Domain or URL of the country config
|
|
@@ -4904,13 +5849,14 @@ Upgrade the country config in the current working directory to the next
|
|
|
4904
5849
|
major version of OpenCRVS.
|
|
4905
5850
|
|
|
4906
5851
|
Options:
|
|
4907
|
-
--docker-swarm Keep
|
|
4908
|
-
|
|
4909
|
-
|
|
4910
|
-
'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).
|
|
4911
5857
|
-h, --help Show this message.
|
|
4912
5858
|
`.trim();
|
|
4913
|
-
function
|
|
5859
|
+
function main10() {
|
|
4914
5860
|
const command = args[0];
|
|
4915
5861
|
if (!command || command === "--help" || command === "-h") {
|
|
4916
5862
|
console.log(USAGE);
|
|
@@ -4921,8 +5867,6 @@ function main5() {
|
|
|
4921
5867
|
return handleEnvironment();
|
|
4922
5868
|
case "upgrade":
|
|
4923
5869
|
return handleUpgrade();
|
|
4924
|
-
case "check-translations":
|
|
4925
|
-
return handleCheckTranslations();
|
|
4926
5870
|
case "verify-endpoints":
|
|
4927
5871
|
return handleVerifyEndpoints();
|
|
4928
5872
|
default:
|
|
@@ -5008,67 +5952,6 @@ async function handleUpgrade() {
|
|
|
5008
5952
|
process.exit(1);
|
|
5009
5953
|
}
|
|
5010
5954
|
}
|
|
5011
|
-
var CHECK_TRANSLATIONS_USAGE = `
|
|
5012
|
-
Usage: opencrvs check-translations [options]
|
|
5013
|
-
|
|
5014
|
-
Check that every message this country config declares has a row in
|
|
5015
|
-
src/translations/countryconfig.csv.
|
|
5016
|
-
|
|
5017
|
-
Options:
|
|
5018
|
-
--write Add the missing rows, filling in English only
|
|
5019
|
-
--outdated List rows nothing in the source declares any more
|
|
5020
|
-
-h, --help Show this help
|
|
5021
|
-
`;
|
|
5022
|
-
function handleCheckTranslations() {
|
|
5023
|
-
const checkArgs = args.slice(1);
|
|
5024
|
-
if (checkArgs.includes("--help") || checkArgs.includes("-h")) {
|
|
5025
|
-
console.log(CHECK_TRANSLATIONS_USAGE);
|
|
5026
|
-
return;
|
|
5027
|
-
}
|
|
5028
|
-
const unknownFlags = checkArgs.filter(
|
|
5029
|
-
(arg) => arg.startsWith("-") && !["--write", "--outdated"].includes(arg)
|
|
5030
|
-
);
|
|
5031
|
-
if (unknownFlags.length > 0) {
|
|
5032
|
-
console.error(`Unknown option: ${unknownFlags.join(", ")}
|
|
5033
|
-
`);
|
|
5034
|
-
console.log(CHECK_TRANSLATIONS_USAGE);
|
|
5035
|
-
process.exit(1);
|
|
5036
|
-
}
|
|
5037
|
-
const cwd = process.cwd();
|
|
5038
|
-
const { missing, outdated, dynamicIds } = check(cwd);
|
|
5039
|
-
for (const file of dynamicIds) {
|
|
5040
|
-
console.warn(
|
|
5041
|
-
`Warning: ${file} declares a message whose id is built at runtime. Ids have to be hardcoded to be checked.`
|
|
5042
|
-
);
|
|
5043
|
-
}
|
|
5044
|
-
if (checkArgs.includes("--outdated")) {
|
|
5045
|
-
console.log(
|
|
5046
|
-
`${outdated.length} row(s) in countryconfig.csv are not declared in src:
|
|
5047
|
-
`
|
|
5048
|
-
);
|
|
5049
|
-
console.log(outdated.join("\n"));
|
|
5050
|
-
return;
|
|
5051
|
-
}
|
|
5052
|
-
if (missing.length === 0) {
|
|
5053
|
-
console.log("Every message declared in src has a translation row.");
|
|
5054
|
-
return;
|
|
5055
|
-
}
|
|
5056
|
-
console.error(
|
|
5057
|
-
`${missing.length} message(s) declared in src have no row in src/translations/countryconfig.csv:
|
|
5058
|
-
`
|
|
5059
|
-
);
|
|
5060
|
-
console.error(missing.map(({ id }) => ` ${id}`).join("\n"));
|
|
5061
|
-
if (!checkArgs.includes("--write")) {
|
|
5062
|
-
console.error(
|
|
5063
|
-
"\nRun `pnpm extract:translations --write` to add them with their English copy."
|
|
5064
|
-
);
|
|
5065
|
-
process.exit(1);
|
|
5066
|
-
}
|
|
5067
|
-
const added = writeMissing(cwd, missing);
|
|
5068
|
-
console.log(`
|
|
5069
|
-
Added ${added.length} row(s) to countryconfig.csv.`);
|
|
5070
|
-
console.log("The languages other than English are still yours to write.");
|
|
5071
|
-
}
|
|
5072
5955
|
async function handleVerifyEndpoints() {
|
|
5073
5956
|
const verifyArgs = args.slice(1);
|
|
5074
5957
|
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
@@ -5094,4 +5977,4 @@ async function handleVerifyEndpoints() {
|
|
|
5094
5977
|
process.exit(1);
|
|
5095
5978
|
}
|
|
5096
5979
|
}
|
|
5097
|
-
|
|
5980
|
+
main10();
|