@opencrvs/toolkit 2.1.0-rc.c3b24ba → 2.1.0-rc.c500a81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -12
- package/build.sh +12 -4
- package/create-countryconfig/index.js +441 -59
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +347 -283
- package/dist/authentication/index.d.ts +67 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +751 -0
- package/dist/cli.js +3011 -1226
- package/dist/commons/api/router.d.ts +658 -132
- 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 +16 -5
- package/dist/commons/events/ActionConfig.d.ts +4 -0
- package/dist/commons/events/ActionDocument.d.ts +35 -15
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/ActionStatus.d.ts +14 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +30 -12
- package/dist/commons/events/AuditLog.d.ts +110 -0
- package/dist/commons/events/EventConfig.d.ts +3 -0
- package/dist/commons/events/EventDocument.d.ts +472 -4
- package/dist/commons/events/EventIndex.d.ts +3 -26
- package/dist/commons/events/EventMetadata.d.ts +1 -11
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +94 -63
- package/dist/commons/events/FieldTypeMapping.d.ts +27 -27
- package/dist/commons/events/FieldValue.d.ts +3 -2
- package/dist/commons/events/Flag.d.ts +42 -0
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/PlainDate.d.ts +8 -0
- package/dist/commons/events/SummaryConfig.d.ts +249 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
- package/dist/commons/events/event.d.ts +12 -0
- package/dist/commons/events/locations.d.ts +162 -26
- package/dist/commons/events/mocks.test.utils.d.ts +30 -0
- package/dist/commons/events/test.utils.d.ts +73 -18
- package/dist/commons/events/utils.d.ts +34 -4
- package/dist/commons/notification/UserNotifications.d.ts +28 -13
- package/dist/commons/notification/dispatch.d.ts +10 -0
- package/dist/commons/notification/index.d.ts +1 -0
- package/dist/conditionals/index.js +334 -64
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +12 -1
- package/dist/environment/logger.d.ts +15 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +1 -1
- package/dist/environment/paths.d.ts +7 -0
- package/dist/environment/paths.d.ts.map +1 -0
- package/dist/environment/paths.js +72 -0
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +20 -14
- 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 +587 -562
- package/dist/environment/templates.d.ts +0 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +5 -9
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +21 -5
- package/dist/environment/upgrade.d.ts +2 -0
- package/dist/environment/upgrade.d.ts.map +1 -0
- package/dist/environment/upgrade.js +82 -0
- package/dist/environment/users.js +11 -13
- package/dist/environment/utils.d.ts +0 -12
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +1 -28
- package/dist/events/index.js +7597 -7129
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +2 -2
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +2 -2
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +1 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +3 -10
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +3 -3
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
- package/dist/migrations/v2.1/add-translations.d.ts +9 -0
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-translations.js +149 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts +3 -0
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
- package/dist/migrations/v2.1/enable-telemetry.js +455 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1223 -0
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts +3 -0
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
- package/dist/migrations/v2.1/rename-trigger-paths.js +216 -0
- package/dist/notification/index.js +1800 -1454
- package/dist/scopes/index.d.ts +433 -36
- package/dist/scopes/index.js +335 -64
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +43 -0
- package/dist/templates/charts-values/dependencies/values.yaml +2 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -3
- package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
- package/dist/templates/charts-values/traefik/values.yaml +23 -9
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/dist/translations/template.d.ts +11 -0
- package/dist/translations/template.d.ts.map +1 -0
- package/dist/translations/template.js +100 -0
- package/dist/verify/endpoints.d.ts +2 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +510 -0
- package/opencrvs-toolkit-2.1.0-rc.c500a81.tgz +0 -0
- package/package.json +13 -7
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/dist/templates/inventory/production.example.yml +0 -77
- package/dist/templates/inventory/qa.example.yml +0 -48
- package/opencrvs-toolkit-2.1.0-rc.c3b24ba.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
package/dist/cli.js
CHANGED
|
@@ -30,6 +30,42 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
+
// src/environment/paths.ts
|
|
34
|
+
function getEnvironmentInventoryPath(environment) {
|
|
35
|
+
return (0, import_path6.join)("environments", environment, INVENTORY_FILE_NAME);
|
|
36
|
+
}
|
|
37
|
+
function findOldInventoryFiles() {
|
|
38
|
+
return glob.sync((0, import_path6.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
39
|
+
}
|
|
40
|
+
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
41
|
+
return (0, import_path6.basename)(filePath, ".yml");
|
|
42
|
+
}
|
|
43
|
+
function assertNoOldInventoryLayout() {
|
|
44
|
+
if (findOldInventoryFiles().length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw new Error(
|
|
48
|
+
[
|
|
49
|
+
`Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
|
|
50
|
+
"Please run `yarn environment:upgrade` before running `yarn environment:init`."
|
|
51
|
+
].join(" ")
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
var import_path6, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
|
|
55
|
+
var init_paths = __esm({
|
|
56
|
+
"src/environment/paths.ts"() {
|
|
57
|
+
"use strict";
|
|
58
|
+
import_path6 = require("path");
|
|
59
|
+
glob = __toESM(require("glob"));
|
|
60
|
+
OLD_INVENTORY_DIR = (0, import_path6.join)(
|
|
61
|
+
"infrastructure",
|
|
62
|
+
"server-setup",
|
|
63
|
+
"inventory"
|
|
64
|
+
);
|
|
65
|
+
INVENTORY_FILE_NAME = "inventory.yml";
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
33
69
|
// src/environment/logger.ts
|
|
34
70
|
var import_kleur, log, warn, success, info, error;
|
|
35
71
|
var init_logger = __esm({
|
|
@@ -467,24 +503,8 @@ function findExistingValue(name, type, scope, existingValues) {
|
|
|
467
503
|
(value) => value.name === name && value.type === type && value.scope === scope
|
|
468
504
|
);
|
|
469
505
|
}
|
|
470
|
-
function storeSecrets(environment, answers) {
|
|
471
|
-
let envConfig = {};
|
|
472
|
-
try {
|
|
473
|
-
envConfig = import_dotenv.default.parse(
|
|
474
|
-
(0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
475
|
-
);
|
|
476
|
-
} catch (error4) {
|
|
477
|
-
envConfig = {};
|
|
478
|
-
}
|
|
479
|
-
const linesFromAnswers = answers.map(
|
|
480
|
-
(update) => `${update.name}="${update.value}"`
|
|
481
|
-
);
|
|
482
|
-
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
483
|
-
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
484
|
-
(0, import_fs.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
485
|
-
}
|
|
486
506
|
function readYamlFile(filePath) {
|
|
487
|
-
const fileContent =
|
|
507
|
+
const fileContent = import_fs4.default.readFileSync(filePath, "utf8");
|
|
488
508
|
return yaml.load(fileContent);
|
|
489
509
|
}
|
|
490
510
|
function writeYamlFile(filePath, data) {
|
|
@@ -497,33 +517,29 @@ function writeYamlFile(filePath, data) {
|
|
|
497
517
|
noRefs: true,
|
|
498
518
|
sortKeys: false
|
|
499
519
|
});
|
|
500
|
-
|
|
501
|
-
} catch (
|
|
502
|
-
throw new Error(`Failed to write inventory file: ${
|
|
520
|
+
import_fs4.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
521
|
+
} catch (error3) {
|
|
522
|
+
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
503
523
|
}
|
|
504
524
|
}
|
|
505
|
-
var
|
|
525
|
+
var import_fs4, yaml;
|
|
506
526
|
var init_utils = __esm({
|
|
507
527
|
"src/environment/utils.ts"() {
|
|
508
528
|
"use strict";
|
|
509
|
-
|
|
529
|
+
import_fs4 = __toESM(require("fs"));
|
|
510
530
|
yaml = __toESM(require("js-yaml"));
|
|
511
|
-
import_dotenv = __toESM(require("dotenv"));
|
|
512
531
|
}
|
|
513
532
|
});
|
|
514
533
|
|
|
515
534
|
// src/environment/templates.ts
|
|
516
|
-
function getUsers(data) {
|
|
517
|
-
if (!data?.all?.vars?.users) {
|
|
518
|
-
return { users: [] };
|
|
519
|
-
}
|
|
520
|
-
return data.all.vars.users;
|
|
521
|
-
}
|
|
522
535
|
function extractAndModifyUsers(data) {
|
|
523
536
|
if (!data?.all?.vars?.users) {
|
|
524
537
|
return { users: [] };
|
|
525
538
|
}
|
|
526
539
|
const users = data.all.vars.users.map((user) => {
|
|
540
|
+
if (user.role) {
|
|
541
|
+
return user;
|
|
542
|
+
}
|
|
527
543
|
const { sudoer, ...rest } = user;
|
|
528
544
|
return {
|
|
529
545
|
...rest,
|
|
@@ -559,29 +575,29 @@ function extractWorkerNodes(data) {
|
|
|
559
575
|
return worker_hosts;
|
|
560
576
|
}
|
|
561
577
|
function copyChartsValues(env, values) {
|
|
562
|
-
const srcDir =
|
|
563
|
-
const destDir =
|
|
564
|
-
|
|
578
|
+
const srcDir = import_path7.default.resolve(__dirname, "templates", "charts-values");
|
|
579
|
+
const destDir = import_path7.default.resolve(process.cwd(), "environments", env);
|
|
580
|
+
import_fs5.default.mkdirSync(destDir, { recursive: true });
|
|
565
581
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
566
582
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
567
583
|
values["opencrvs_environment"] = env;
|
|
568
584
|
function copyRecursive(src, dest) {
|
|
569
|
-
const stat =
|
|
585
|
+
const stat = import_fs5.default.statSync(src);
|
|
570
586
|
if (stat.isDirectory()) {
|
|
571
|
-
|
|
572
|
-
for (const item of
|
|
573
|
-
copyRecursive(
|
|
587
|
+
import_fs5.default.mkdirSync(dest, { recursive: true });
|
|
588
|
+
for (const item of import_fs5.default.readdirSync(src)) {
|
|
589
|
+
copyRecursive(import_path7.default.join(src, item), import_path7.default.join(dest, item));
|
|
574
590
|
}
|
|
575
591
|
} else {
|
|
576
|
-
const content =
|
|
592
|
+
const content = import_fs5.default.readFileSync(src, "utf8");
|
|
577
593
|
const template = import_handlebars.default.compile(content);
|
|
578
594
|
const updated = template(values);
|
|
579
595
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
580
|
-
if (isOverridesFile &&
|
|
596
|
+
if (isOverridesFile && import_fs5.default.existsSync(dest)) {
|
|
581
597
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
582
598
|
return;
|
|
583
599
|
}
|
|
584
|
-
|
|
600
|
+
import_fs5.default.writeFileSync(dest, updated, "utf8");
|
|
585
601
|
log(` \u2713 Created: ${dest}`);
|
|
586
602
|
}
|
|
587
603
|
}
|
|
@@ -592,36 +608,31 @@ function copyChartsValues(env, values) {
|
|
|
592
608
|
`);
|
|
593
609
|
}
|
|
594
610
|
function generateInventory(env, values) {
|
|
595
|
-
const templatePath =
|
|
611
|
+
const templatePath = import_path7.default.join(
|
|
596
612
|
__dirname,
|
|
597
613
|
"templates",
|
|
598
614
|
"inventory",
|
|
599
615
|
"inventory.template.yml"
|
|
600
616
|
);
|
|
601
|
-
const outputPath =
|
|
602
|
-
|
|
603
|
-
"infrastructure",
|
|
604
|
-
"server-setup",
|
|
605
|
-
"inventory",
|
|
606
|
-
`${env}.yml`
|
|
607
|
-
);
|
|
608
|
-
const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
|
|
617
|
+
const outputPath = import_path7.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
618
|
+
const templateFile = import_fs5.default.readFileSync(templatePath, "utf-8");
|
|
609
619
|
const template = import_handlebars.default.compile(templateFile);
|
|
610
620
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
611
621
|
const updated = template(values);
|
|
612
|
-
|
|
613
|
-
|
|
622
|
+
import_fs5.default.mkdirSync(import_path7.default.dirname(outputPath), { recursive: true });
|
|
623
|
+
import_fs5.default.writeFileSync(outputPath, updated);
|
|
614
624
|
log(`
|
|
615
625
|
\u2705 Generated inventory file at ${outputPath}
|
|
616
626
|
`);
|
|
617
627
|
}
|
|
618
|
-
var
|
|
628
|
+
var import_fs5, import_path7, import_handlebars;
|
|
619
629
|
var init_templates = __esm({
|
|
620
630
|
"src/environment/templates.ts"() {
|
|
621
631
|
"use strict";
|
|
622
|
-
|
|
623
|
-
|
|
632
|
+
import_fs5 = __toESM(require("fs"));
|
|
633
|
+
import_path7 = __toESM(require("path"));
|
|
624
634
|
init_logger();
|
|
635
|
+
init_paths();
|
|
625
636
|
import_handlebars = __toESM(require("handlebars"));
|
|
626
637
|
import_handlebars.default.registerHelper("data_label_idx", function(value) {
|
|
627
638
|
return parseInt(value) + 2;
|
|
@@ -645,6 +656,141 @@ var init_ssh_keygen = __esm({
|
|
|
645
656
|
}
|
|
646
657
|
});
|
|
647
658
|
|
|
659
|
+
// src/environment/update-workflows.ts
|
|
660
|
+
var update_workflows_exports = {};
|
|
661
|
+
__export(update_workflows_exports, {
|
|
662
|
+
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
663
|
+
});
|
|
664
|
+
function isDirectory(path10) {
|
|
665
|
+
try {
|
|
666
|
+
return (0, import_fs6.statSync)(path10).isDirectory();
|
|
667
|
+
} catch {
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
async function extractInfrastructureNames() {
|
|
672
|
+
const files = glob2.sync((0, import_path8.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
673
|
+
const infraEnvironments = files.map((file) => (0, import_path8.basename)((0, import_path8.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_path8.join)("environments", entry);
|
|
687
|
+
const opencrvsServicesPath = (0, import_path8.join)(environmentPath, "opencrvs-services");
|
|
688
|
+
return isDirectory(environmentPath) && (0, import_fs6.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_fs6.existsSync)(workflowPath)) {
|
|
714
|
+
log(` \u21B7 Skipped ${workflowPath} (not found in this repository)`);
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
try {
|
|
718
|
+
const fileContents = (0, import_fs6.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_fs6.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_fs6, import_path8, 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_fs6 = require("fs");
|
|
786
|
+
import_path8 = require("path");
|
|
787
|
+
glob2 = __toESM(require("glob"));
|
|
788
|
+
yaml2 = __toESM(require("js-yaml"));
|
|
789
|
+
init_logger();
|
|
790
|
+
init_paths();
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
|
|
648
794
|
// src/environment/git.ts
|
|
649
795
|
function getRepoInfo() {
|
|
650
796
|
try {
|
|
@@ -675,18 +821,18 @@ var init_git = __esm({
|
|
|
675
821
|
});
|
|
676
822
|
|
|
677
823
|
// src/environment/questions.ts
|
|
678
|
-
function validateCIDR(
|
|
679
|
-
if (!
|
|
824
|
+
function validateCIDR(input4) {
|
|
825
|
+
if (!input4.trim()) {
|
|
680
826
|
return true;
|
|
681
827
|
}
|
|
682
828
|
const cidrRegex = /^((25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\.){3}(25[0-5]|(2[0-4]|1\d|[1-9]?\d)\d?)\/([0-9]|[12][0-9]|3[0-2])$/;
|
|
683
|
-
return cidrRegex.test(
|
|
829
|
+
return cidrRegex.test(input4.trim()) ? true : "Please enter a valid CIDR (e.g. 10.0.0.0/24)";
|
|
684
830
|
}
|
|
685
|
-
function validateCIDRs(
|
|
686
|
-
if (!
|
|
831
|
+
function validateCIDRs(input4) {
|
|
832
|
+
if (!input4.trim()) {
|
|
687
833
|
return true;
|
|
688
834
|
}
|
|
689
|
-
const cidrs =
|
|
835
|
+
const cidrs = input4.split(",").map((v) => v.trim());
|
|
690
836
|
for (const cidr of cidrs) {
|
|
691
837
|
const result = validateCIDR(cidr);
|
|
692
838
|
if (result !== true) {
|
|
@@ -829,11 +975,28 @@ var init_questions = __esm({
|
|
|
829
975
|
scope: "ENVIRONMENT"
|
|
830
976
|
},
|
|
831
977
|
{
|
|
832
|
-
name: "
|
|
978
|
+
name: "kubeMasterNode",
|
|
979
|
+
type: "text",
|
|
980
|
+
message: `Kubernetes master node hostnames or IP (default: auto-detect)`,
|
|
981
|
+
valueType: "VARIABLE",
|
|
982
|
+
valueLabel: "KUBE_MASTER_NODE",
|
|
983
|
+
initial: process.env.KUBE_MASTER_NODE,
|
|
984
|
+
scope: "ENVIRONMENT"
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
name: "kubeWorkerNodes",
|
|
988
|
+
type: "text",
|
|
989
|
+
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
990
|
+
valueType: "VARIABLE",
|
|
991
|
+
valueLabel: "KUBE_WORKER_NODES",
|
|
992
|
+
initial: process.env.KUBE_WORKER_NODES || "",
|
|
993
|
+
scope: "ENVIRONMENT"
|
|
994
|
+
},
|
|
995
|
+
{
|
|
996
|
+
name: "kubeApiHost",
|
|
833
997
|
type: "text",
|
|
834
|
-
message: `Kubernetes API endpoint (default:
|
|
998
|
+
message: `Kubernetes API endpoint IP (default: KUBE_MASTER_NODE)`,
|
|
835
999
|
valueType: "VARIABLE",
|
|
836
|
-
// validate: notEmpty,
|
|
837
1000
|
valueLabel: "KUBE_API_HOST",
|
|
838
1001
|
initial: process.env.KUBE_API_HOST,
|
|
839
1002
|
scope: "ENVIRONMENT"
|
|
@@ -847,16 +1010,6 @@ var init_questions = __esm({
|
|
|
847
1010
|
valueLabel: "KUBE_API_ALLOWED_CIDRS",
|
|
848
1011
|
initial: process.env.KUBE_API_ALLOWED_CIDRS || "",
|
|
849
1012
|
scope: "ENVIRONMENT"
|
|
850
|
-
},
|
|
851
|
-
{
|
|
852
|
-
name: "kubeWorkerNodes",
|
|
853
|
-
type: "text",
|
|
854
|
-
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
855
|
-
valueType: "VARIABLE",
|
|
856
|
-
// validate: notEmpty,
|
|
857
|
-
valueLabel: "KUBE_WORKER_NODES",
|
|
858
|
-
initial: process.env.KUBE_WORKER_NODES || "",
|
|
859
|
-
scope: "ENVIRONMENT"
|
|
860
1013
|
}
|
|
861
1014
|
];
|
|
862
1015
|
staticSSLCertQuestions = [
|
|
@@ -887,7 +1040,6 @@ var init_questions = __esm({
|
|
|
887
1040
|
type: "text",
|
|
888
1041
|
message: `Please enter backup server host/IP address, (default: no backup):`,
|
|
889
1042
|
valueType: "VARIABLE",
|
|
890
|
-
// validate: notEmpty,
|
|
891
1043
|
valueLabel: "BACKUP_HOST",
|
|
892
1044
|
initial: process.env.BACKUP_HOST || "",
|
|
893
1045
|
scope: "ENVIRONMENT"
|
|
@@ -1210,7 +1362,7 @@ function updateInventoryFile(filePath, users) {
|
|
|
1210
1362
|
function parseInventoryFile(filePath) {
|
|
1211
1363
|
try {
|
|
1212
1364
|
const data = readYamlFile(filePath);
|
|
1213
|
-
return
|
|
1365
|
+
return extractAndModifyUsers(data);
|
|
1214
1366
|
} catch {
|
|
1215
1367
|
return [];
|
|
1216
1368
|
}
|
|
@@ -1220,7 +1372,7 @@ function getCurrentUsername() {
|
|
|
1220
1372
|
}
|
|
1221
1373
|
function getCurrentUserSSHKeys() {
|
|
1222
1374
|
const homeDir = os.homedir();
|
|
1223
|
-
const sshDir =
|
|
1375
|
+
const sshDir = path7.join(homeDir, ".ssh");
|
|
1224
1376
|
const keys = [];
|
|
1225
1377
|
const keyFiles = [
|
|
1226
1378
|
"id_rsa.pub",
|
|
@@ -1229,7 +1381,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1229
1381
|
"id_dsa.pub"
|
|
1230
1382
|
];
|
|
1231
1383
|
for (const keyFile of keyFiles) {
|
|
1232
|
-
const keyPath =
|
|
1384
|
+
const keyPath = path7.join(sshDir, keyFile);
|
|
1233
1385
|
try {
|
|
1234
1386
|
if (fs3.existsSync(keyPath)) {
|
|
1235
1387
|
const keyContent = fs3.readFileSync(keyPath, "utf8").trim();
|
|
@@ -1237,7 +1389,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1237
1389
|
keys.push(keyContent);
|
|
1238
1390
|
}
|
|
1239
1391
|
}
|
|
1240
|
-
} catch (
|
|
1392
|
+
} catch (error3) {
|
|
1241
1393
|
continue;
|
|
1242
1394
|
}
|
|
1243
1395
|
}
|
|
@@ -1570,13 +1722,13 @@ async function manageUsers(inventoryPath) {
|
|
|
1570
1722
|
}
|
|
1571
1723
|
return users;
|
|
1572
1724
|
}
|
|
1573
|
-
var os, fs3,
|
|
1725
|
+
var os, fs3, path7, input2, select2, confirm, editor, checkbox;
|
|
1574
1726
|
var init_manage_users = __esm({
|
|
1575
1727
|
"src/environment/manage-users.ts"() {
|
|
1576
1728
|
"use strict";
|
|
1577
1729
|
os = __toESM(require("os"));
|
|
1578
1730
|
fs3 = __toESM(require("fs"));
|
|
1579
|
-
|
|
1731
|
+
path7 = __toESM(require("path"));
|
|
1580
1732
|
init_logger();
|
|
1581
1733
|
init_utils();
|
|
1582
1734
|
init_templates();
|
|
@@ -1590,6 +1742,9 @@ var init_manage_users = __esm({
|
|
|
1590
1742
|
|
|
1591
1743
|
// src/environment/setup-environment.ts
|
|
1592
1744
|
var setup_environment_exports = {};
|
|
1745
|
+
__export(setup_environment_exports, {
|
|
1746
|
+
runSetupEnvironment: () => runSetupEnvironment
|
|
1747
|
+
});
|
|
1593
1748
|
async function confirm2(options) {
|
|
1594
1749
|
const inquirer = await import("@inquirer/prompts");
|
|
1595
1750
|
return inquirer.confirm(options);
|
|
@@ -1598,6 +1753,10 @@ async function select3(options) {
|
|
|
1598
1753
|
const inquirer = await import("@inquirer/prompts");
|
|
1599
1754
|
return inquirer.select(options);
|
|
1600
1755
|
}
|
|
1756
|
+
async function input3(options) {
|
|
1757
|
+
const inquirer = await import("@inquirer/prompts");
|
|
1758
|
+
return inquirer.input(options);
|
|
1759
|
+
}
|
|
1601
1760
|
function questionToPrompt({
|
|
1602
1761
|
valueType,
|
|
1603
1762
|
valueLabel,
|
|
@@ -1664,7 +1823,7 @@ function getAnswers(existingValues) {
|
|
|
1664
1823
|
});
|
|
1665
1824
|
});
|
|
1666
1825
|
}
|
|
1667
|
-
async function promptAndStoreAnswer(
|
|
1826
|
+
async function promptAndStoreAnswer(questions, existingValues) {
|
|
1668
1827
|
log("");
|
|
1669
1828
|
const processedQuestions = questions.flatMap((question) => {
|
|
1670
1829
|
const questionWithVariableLabel = {
|
|
@@ -1743,7 +1902,6 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1743
1902
|
}
|
|
1744
1903
|
});
|
|
1745
1904
|
ALL_ANSWERS.push(result);
|
|
1746
|
-
storeSecrets(environment, getAnswers(existingValues));
|
|
1747
1905
|
const existingValuesForQuestions = questions.filter((question) => question.valueType === "VARIABLE").map((question) => [
|
|
1748
1906
|
question.name,
|
|
1749
1907
|
findExistingValue(
|
|
@@ -1755,974 +1913,952 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1755
1913
|
]);
|
|
1756
1914
|
return { ...Object.fromEntries(existingValuesForQuestions), ...result };
|
|
1757
1915
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
(
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
log(import_kleur4.default.green("\nSuccessfully logged in to Github\n"));
|
|
1811
|
-
const existingEnvironments = await getRepositoryEnvironments(
|
|
1812
|
-
octokit,
|
|
1813
|
-
githubOrganisation,
|
|
1814
|
-
githubRepository
|
|
1815
|
-
);
|
|
1816
|
-
const defaultChoices = [
|
|
1817
|
-
{ name: "Development", value: "development" },
|
|
1818
|
-
{ name: "Quality assurance (no PII data)", value: "qa" },
|
|
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: [
|
|
1819
1968
|
{
|
|
1820
|
-
name: "
|
|
1821
|
-
value: "
|
|
1969
|
+
name: "Development/Quality assurance/Testing (no PII data)",
|
|
1970
|
+
value: "non-production"
|
|
1822
1971
|
},
|
|
1823
1972
|
{
|
|
1824
|
-
name: "Production (hosts PII data, requires frequent backups)",
|
|
1973
|
+
name: "Staging/Production (hosts PII data, requires frequent backups)",
|
|
1825
1974
|
value: "production"
|
|
1826
1975
|
}
|
|
1827
|
-
]
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1976
|
+
]
|
|
1977
|
+
});
|
|
1978
|
+
}
|
|
1979
|
+
const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
|
|
1980
|
+
if (!environment) {
|
|
1981
|
+
process.exit(1);
|
|
1982
|
+
}
|
|
1983
|
+
await createEnvironment(
|
|
1984
|
+
octokit,
|
|
1985
|
+
environment,
|
|
1986
|
+
githubOrganisation,
|
|
1987
|
+
githubRepository
|
|
1988
|
+
);
|
|
1989
|
+
const repositoryId = await getRepositoryId(
|
|
1990
|
+
octokit,
|
|
1991
|
+
githubOrganisation,
|
|
1992
|
+
githubRepository
|
|
1993
|
+
);
|
|
1994
|
+
const existingRepositorySecrets = await listRepositorySecrets(
|
|
1995
|
+
octokit,
|
|
1996
|
+
githubOrganisation,
|
|
1997
|
+
githubRepository
|
|
1998
|
+
);
|
|
1999
|
+
const existingRepositoryVariables = await listRepositoryVariables(
|
|
2000
|
+
octokit,
|
|
2001
|
+
githubOrganisation,
|
|
2002
|
+
githubRepository
|
|
2003
|
+
);
|
|
2004
|
+
const existingEnvironmentVariables = await listEnvironmentVariables(
|
|
2005
|
+
octokit,
|
|
2006
|
+
repositoryId,
|
|
2007
|
+
environment
|
|
2008
|
+
);
|
|
2009
|
+
const existingEnvironmentSecrets = await listEnvironmentSecrets(
|
|
2010
|
+
octokit,
|
|
2011
|
+
githubOrganisation,
|
|
2012
|
+
repositoryId,
|
|
2013
|
+
environment
|
|
2014
|
+
);
|
|
2015
|
+
const existingValues = [
|
|
2016
|
+
...existingEnvironmentVariables,
|
|
2017
|
+
...existingRepositoryVariables,
|
|
2018
|
+
...existingRepositorySecrets,
|
|
2019
|
+
...existingEnvironmentSecrets
|
|
2020
|
+
];
|
|
2021
|
+
if (existingEnvironmentVariables.length > 0 || existingEnvironmentSecrets.length > 0) {
|
|
2022
|
+
log(
|
|
2023
|
+
"\nEnvironment with the name",
|
|
2024
|
+
environment,
|
|
2025
|
+
"already exists in Github.",
|
|
2026
|
+
"\nFound",
|
|
2027
|
+
existingEnvironmentVariables.length,
|
|
2028
|
+
"existing variables and",
|
|
2029
|
+
existingEnvironmentSecrets.length,
|
|
2030
|
+
"secrets"
|
|
2031
|
+
);
|
|
2032
|
+
}
|
|
2033
|
+
if (environment_type === "production") {
|
|
2034
|
+
log(
|
|
2035
|
+
"\n",
|
|
2036
|
+
import_kleur4.default.yellow().bold(
|
|
2037
|
+
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
2038
|
+
)
|
|
2039
|
+
);
|
|
2040
|
+
await promptAndStoreAnswer(githubOtherQuestions, existingValues);
|
|
2041
|
+
}
|
|
2042
|
+
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
2043
|
+
await promptAndStoreAnswer(dockerhubQuestions, existingValues);
|
|
2044
|
+
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
2045
|
+
const infrastructure = await promptAndStoreAnswer(
|
|
2046
|
+
infrastructureQuestions,
|
|
2047
|
+
existingValues
|
|
2048
|
+
);
|
|
2049
|
+
const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
|
|
2050
|
+
log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
|
|
2051
|
+
const users = await manageUsers(getEnvironmentInventoryPath(environment));
|
|
2052
|
+
log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
|
|
2053
|
+
const sslCertExists = findExistingValue(
|
|
2054
|
+
"SSL_CRT",
|
|
2055
|
+
"SECRET",
|
|
2056
|
+
"ENVIRONMENT",
|
|
2057
|
+
existingValues
|
|
2058
|
+
);
|
|
2059
|
+
let ssl_answers = [];
|
|
2060
|
+
const traefikConfOption = (await (0, import_prompts2.default)([
|
|
2061
|
+
{
|
|
2062
|
+
name: "traefikConfOption",
|
|
2063
|
+
type: "select",
|
|
2064
|
+
message: "Choose option to configure Traefik SSL Certificate",
|
|
2065
|
+
choices: [
|
|
2066
|
+
{ title: "Let's Encrypt certificate", value: "lets_encrypt" },
|
|
2067
|
+
{ title: "Static SSL certificate", value: "static_ssl" },
|
|
2068
|
+
{ title: "Custom configuration", value: "custom" }
|
|
2069
|
+
],
|
|
2070
|
+
initial: sslCertExists ? 1 : 0
|
|
2071
|
+
}
|
|
2072
|
+
])).traefikConfOption;
|
|
2073
|
+
if (traefikConfOption === "static_ssl") {
|
|
2074
|
+
ssl_answers = await askQuestionWithEditor(
|
|
2075
|
+
staticSSLCertQuestions,
|
|
2076
|
+
existingEnvironmentSecrets
|
|
2077
|
+
);
|
|
2078
|
+
}
|
|
2079
|
+
log("\n", import_kleur4.default.bold().underline("Storage"), "\n");
|
|
2080
|
+
let enableEncryption = false;
|
|
2081
|
+
const encryption_key_defined = findExistingValue(
|
|
2082
|
+
"ENCRYPTION_KEY",
|
|
2083
|
+
"SECRET",
|
|
2084
|
+
"ENVIRONMENT",
|
|
2085
|
+
existingValues
|
|
2086
|
+
);
|
|
2087
|
+
if (!encryption_key_defined && !environment_exists) {
|
|
2088
|
+
const answers_enable_encryption = await (0, import_prompts2.default)(
|
|
2089
|
+
[
|
|
2090
|
+
{
|
|
2091
|
+
name: "enableEncryption",
|
|
2092
|
+
type: "confirm",
|
|
2093
|
+
message: "Do you want to enable disk encryption?",
|
|
2094
|
+
scope: "ENVIRONMENT",
|
|
2095
|
+
initial: Boolean(process.env.ENABLE_ENCRYPTION)
|
|
2096
|
+
}
|
|
2097
|
+
].map(questionToPrompt)
|
|
2098
|
+
);
|
|
2099
|
+
enableEncryption = answers_enable_encryption.enableEncryption;
|
|
2100
|
+
}
|
|
2101
|
+
if (enableEncryption && !encryption_key_defined && !environment_exists) {
|
|
2102
|
+
log(
|
|
2103
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2104
|
+
import_kleur4.default.bold().yellow(" Disk encryption is enabled")
|
|
2105
|
+
);
|
|
2106
|
+
await promptAndStoreAnswer(diskQuestions, existingValues);
|
|
2107
|
+
} else {
|
|
2108
|
+
if (!enableEncryption && !encryption_key_defined && environment_exists) {
|
|
2109
|
+
log(
|
|
2110
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2111
|
+
import_kleur4.default.bold().grey(
|
|
2112
|
+
`Environment ${environment} is already configured, skipping disk encryption question`
|
|
2113
|
+
)
|
|
1897
2114
|
);
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
"\nFound",
|
|
1910
|
-
existingEnvironmentVariables.length,
|
|
1911
|
-
"existing variables and",
|
|
1912
|
-
existingEnvironmentSecrets.length,
|
|
1913
|
-
"secrets"
|
|
1914
|
-
);
|
|
1915
|
-
}
|
|
1916
|
-
if (environment_type === "production") {
|
|
1917
|
-
log(
|
|
1918
|
-
"\n",
|
|
1919
|
-
import_kleur4.default.yellow().bold(
|
|
1920
|
-
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
1921
|
-
)
|
|
1922
|
-
);
|
|
1923
|
-
await promptAndStoreAnswer(
|
|
1924
|
-
environment,
|
|
1925
|
-
githubOtherQuestions,
|
|
1926
|
-
existingValues
|
|
1927
|
-
);
|
|
1928
|
-
}
|
|
1929
|
-
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
1930
|
-
await promptAndStoreAnswer(environment, dockerhubQuestions, existingValues);
|
|
1931
|
-
log("\n", import_kleur4.default.bold().underline("Kubernetes & Runtime"));
|
|
1932
|
-
const infrastructure = await promptAndStoreAnswer(
|
|
1933
|
-
environment,
|
|
1934
|
-
infrastructureQuestions,
|
|
1935
|
-
existingValues
|
|
2115
|
+
}
|
|
2116
|
+
const DISK_SPACE = findExistingValue(
|
|
2117
|
+
"DISK_SPACE",
|
|
2118
|
+
"VARIABLE",
|
|
2119
|
+
"ENVIRONMENT",
|
|
2120
|
+
existingValues
|
|
2121
|
+
);
|
|
2122
|
+
if (!DISK_SPACE) {
|
|
2123
|
+
log(
|
|
2124
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2125
|
+
import_kleur4.default.bold().grey("All available disk space at /data will be used")
|
|
1936
2126
|
);
|
|
1937
|
-
|
|
1938
|
-
log(
|
|
1939
|
-
|
|
1940
|
-
|
|
2127
|
+
} else {
|
|
2128
|
+
log(
|
|
2129
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2130
|
+
import_kleur4.default.bold().yellow("Variable DISK_SPACE is read-only, allocated space:"),
|
|
2131
|
+
DISK_SPACE?.value
|
|
1941
2132
|
);
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
let backupHost = findExistingValue("BACKUP_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2136
|
+
let backupType = "";
|
|
2137
|
+
let restoreEnvironmentName = findExistingValue(
|
|
2138
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2139
|
+
"VARIABLE",
|
|
2140
|
+
"ENVIRONMENT",
|
|
2141
|
+
existingValues
|
|
2142
|
+
)?.value;
|
|
2143
|
+
let restoreHost = findExistingValue("RESTORE_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2144
|
+
let restoreType = findExistingValue(
|
|
2145
|
+
"RESTORE_ENVIRONMENT_MODE",
|
|
2146
|
+
"VARIABLE",
|
|
2147
|
+
"ENVIRONMENT",
|
|
2148
|
+
existingValues
|
|
2149
|
+
)?.value || process.env.RESTORE_ENVIRONMENT_MODE || "dump";
|
|
2150
|
+
log("\n", import_kleur4.default.bold().underline("Backup"));
|
|
2151
|
+
let configureBackup = backupHost ? true : false;
|
|
2152
|
+
if (!configureBackup && !restoreEnvironmentName) {
|
|
2153
|
+
configureBackup = await confirm2({
|
|
2154
|
+
message: "Do you want to configure backup?",
|
|
2155
|
+
default: Boolean(process.env.CONFIGURE_BACKUP)
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
let backupHostPrivateKey = "";
|
|
2159
|
+
let backupHostPublicKey = "";
|
|
2160
|
+
if (configureBackup) {
|
|
2161
|
+
const backupAnswers = await promptAndStoreAnswer(
|
|
2162
|
+
backupQuestions,
|
|
2163
|
+
existingValues
|
|
2164
|
+
);
|
|
2165
|
+
const backupHostPrivateKeyExists = findExistingValue(
|
|
2166
|
+
"BACKUP_HOST_PRIVATE_KEY",
|
|
2167
|
+
"SECRET",
|
|
2168
|
+
"ENVIRONMENT",
|
|
2169
|
+
existingValues
|
|
2170
|
+
);
|
|
2171
|
+
backupType = backupAnswers.backupType;
|
|
2172
|
+
backupHost = backupAnswers.backupHost || backupHost;
|
|
2173
|
+
if (!backupHostPrivateKeyExists) {
|
|
2174
|
+
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2175
|
+
backupHostPublicKey = publicKey;
|
|
2176
|
+
backupHostPrivateKey = privateKey;
|
|
2177
|
+
log(
|
|
2178
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2179
|
+
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
1948
2180
|
);
|
|
1949
|
-
|
|
1950
|
-
|
|
2181
|
+
}
|
|
2182
|
+
} else {
|
|
2183
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
2184
|
+
}
|
|
2185
|
+
log("\n", import_kleur4.default.bold().underline("Restore"));
|
|
2186
|
+
let configureRestore = restoreEnvironmentName ? true : false;
|
|
2187
|
+
if (!restoreEnvironmentName && !configureBackup) {
|
|
2188
|
+
configureRestore = await confirm2({
|
|
2189
|
+
message: "Do you want to configure restore?",
|
|
2190
|
+
default: Boolean(process.env.CONFIGURE_RESTORE)
|
|
2191
|
+
});
|
|
2192
|
+
}
|
|
2193
|
+
if (configureRestore) {
|
|
2194
|
+
const env_list_filtered = existingEnvironments.filter(
|
|
2195
|
+
(env) => env !== environment
|
|
2196
|
+
);
|
|
2197
|
+
restoreEnvironmentName = await selectWithCustom({
|
|
2198
|
+
message: "What is the name of your environment to restore?",
|
|
2199
|
+
choices: env_list_filtered.map((env) => ({
|
|
2200
|
+
name: env,
|
|
2201
|
+
value: env
|
|
2202
|
+
})),
|
|
2203
|
+
initial: restoreEnvironmentName
|
|
2204
|
+
});
|
|
2205
|
+
restoreType = await select3({
|
|
2206
|
+
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2207
|
+
choices: [
|
|
2208
|
+
{
|
|
2209
|
+
name: "Full dump (daily full database backup)",
|
|
2210
|
+
value: "dump"
|
|
2211
|
+
},
|
|
1951
2212
|
{
|
|
1952
|
-
name: "
|
|
1953
|
-
|
|
1954
|
-
message: "Choose option to configure Traefik SSL Certificate",
|
|
1955
|
-
choices: [
|
|
1956
|
-
{ title: "Let's Encrypt certificate", value: "lets_encrypt" },
|
|
1957
|
-
{ title: "Static SSL certificate", value: "static_ssl" },
|
|
1958
|
-
{ title: "Custom configuration", value: "custom" }
|
|
1959
|
-
],
|
|
1960
|
-
initial: sslCertExists ? 1 : 0
|
|
2213
|
+
name: "Differential (weekly full, daily diff backup)",
|
|
2214
|
+
value: "differential"
|
|
1961
2215
|
}
|
|
1962
|
-
]
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
2216
|
+
]
|
|
2217
|
+
});
|
|
2218
|
+
restoreHost = await input3({
|
|
2219
|
+
message: "What is the host/IP address of the restore backup server?",
|
|
2220
|
+
default: restoreHost
|
|
2221
|
+
});
|
|
2222
|
+
} else {
|
|
2223
|
+
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2224
|
+
}
|
|
2225
|
+
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2226
|
+
await promptAndStoreAnswer(databaseAndMonitoringQuestions, existingValues);
|
|
2227
|
+
const sentryDSNExists = findExistingValue(
|
|
2228
|
+
"SENTRY_DSN",
|
|
2229
|
+
"SECRET",
|
|
2230
|
+
"ENVIRONMENT",
|
|
2231
|
+
existingValues
|
|
2232
|
+
);
|
|
2233
|
+
log("\n", import_kleur4.default.bold().underline("Sentry"));
|
|
2234
|
+
if (sentryDSNExists) {
|
|
2235
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2236
|
+
} else {
|
|
2237
|
+
const { useSentry } = await (0, import_prompts2.default)([
|
|
2238
|
+
{
|
|
2239
|
+
name: "useSentry",
|
|
2240
|
+
type: "confirm",
|
|
2241
|
+
message: "Do you want to use Sentry?",
|
|
2242
|
+
initial: Boolean(process.env.SENTRY_DNS)
|
|
1968
2243
|
}
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
2244
|
+
]);
|
|
2245
|
+
if (useSentry) {
|
|
2246
|
+
await promptAndStoreAnswer(sentryQuestions, existingValues);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2250
|
+
await promptAndStoreAnswer(metabaseAdminQuestions, existingValues);
|
|
2251
|
+
log("\n", import_kleur4.default.bold().underline("SMTP"));
|
|
2252
|
+
await promptAndStoreAnswer(emailQuestions, existingValues);
|
|
2253
|
+
const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
|
|
2254
|
+
return { ...acc, ...answer };
|
|
2255
|
+
});
|
|
2256
|
+
const answerOrExisting = (variable, existingValue, fn) => fn(variable || existingValue?.value) || "";
|
|
2257
|
+
function findExistingOrDefine(name, type, scope, newValue) {
|
|
2258
|
+
return findExistingValue(name, type, scope, existingValues) ? null : process.env[name] || newValue;
|
|
2259
|
+
}
|
|
2260
|
+
const derivedUpdates = [
|
|
2261
|
+
{
|
|
2262
|
+
name: "GH_ENCRYPTION_PASSWORD",
|
|
2263
|
+
type: "SECRET",
|
|
2264
|
+
didExist: findExistingValue(
|
|
2265
|
+
"GH_ENCRYPTION_PASSWORD",
|
|
2266
|
+
"SECRET",
|
|
2267
|
+
"REPOSITORY",
|
|
2268
|
+
existingValues
|
|
2269
|
+
),
|
|
2270
|
+
value: findExistingOrDefine(
|
|
2271
|
+
"GH_ENCRYPTION_PASSWORD",
|
|
2272
|
+
"SECRET",
|
|
2273
|
+
"REPOSITORY",
|
|
2274
|
+
generateLongPassword()
|
|
2275
|
+
),
|
|
2276
|
+
scope: "REPOSITORY"
|
|
2277
|
+
}
|
|
2278
|
+
];
|
|
2279
|
+
derivedUpdates.push({
|
|
2280
|
+
name: "NOTIFICATION_TRANSPORT",
|
|
2281
|
+
type: "VARIABLE",
|
|
2282
|
+
didExist: findExistingValue(
|
|
2283
|
+
"NOTIFICATION_TRANSPORT",
|
|
2284
|
+
"VARIABLE",
|
|
2285
|
+
"ENVIRONMENT",
|
|
2286
|
+
existingValues
|
|
2287
|
+
),
|
|
2288
|
+
value: findExistingOrDefine(
|
|
2289
|
+
"NOTIFICATION_TRANSPORT",
|
|
2290
|
+
"VARIABLE",
|
|
2291
|
+
"ENVIRONMENT",
|
|
2292
|
+
"email"
|
|
2293
|
+
),
|
|
2294
|
+
scope: "ENVIRONMENT"
|
|
2295
|
+
});
|
|
2296
|
+
derivedUpdates.push(...ssl_answers);
|
|
2297
|
+
if (configureBackup) {
|
|
2298
|
+
derivedUpdates.push({
|
|
2299
|
+
name: "BACKUP_ENCRYPTION_PASSPHRASE",
|
|
2300
|
+
type: "SECRET",
|
|
2301
|
+
didExist: findExistingValue(
|
|
2302
|
+
"BACKUP_ENCRYPTION_PASSPHRASE",
|
|
1973
2303
|
"SECRET",
|
|
1974
2304
|
"ENVIRONMENT",
|
|
1975
2305
|
existingValues
|
|
1976
|
-
)
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2306
|
+
),
|
|
2307
|
+
value: findExistingOrDefine(
|
|
2308
|
+
"BACKUP_ENCRYPTION_PASSPHRASE",
|
|
2309
|
+
"SECRET",
|
|
2310
|
+
"ENVIRONMENT",
|
|
2311
|
+
generateLongPassword()
|
|
2312
|
+
),
|
|
2313
|
+
scope: "ENVIRONMENT"
|
|
2314
|
+
});
|
|
2315
|
+
}
|
|
2316
|
+
const applicationServerUpdates = [
|
|
2317
|
+
{
|
|
2318
|
+
name: "ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2319
|
+
type: "SECRET",
|
|
2320
|
+
didExist: findExistingValue(
|
|
2321
|
+
"ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2322
|
+
"SECRET",
|
|
2323
|
+
"ENVIRONMENT",
|
|
2324
|
+
existingValues
|
|
2325
|
+
),
|
|
2326
|
+
value: findExistingOrDefine(
|
|
2327
|
+
"ELASTICSEARCH_SUPERUSER_PASSWORD",
|
|
2328
|
+
"SECRET",
|
|
2329
|
+
"ENVIRONMENT",
|
|
2330
|
+
generateLongPassword()
|
|
2331
|
+
),
|
|
2332
|
+
scope: "ENVIRONMENT"
|
|
2333
|
+
},
|
|
2334
|
+
{
|
|
2335
|
+
name: "KIBANA_SYSTEM_PASSWORD",
|
|
2336
|
+
type: "SECRET",
|
|
2337
|
+
didExist: findExistingValue(
|
|
2338
|
+
"KIBANA_SYSTEM_PASSWORD",
|
|
2339
|
+
"SECRET",
|
|
2340
|
+
"ENVIRONMENT",
|
|
2341
|
+
existingValues
|
|
2342
|
+
),
|
|
2343
|
+
value: findExistingOrDefine(
|
|
2344
|
+
"KIBANA_SYSTEM_PASSWORD",
|
|
2345
|
+
"SECRET",
|
|
2346
|
+
"ENVIRONMENT",
|
|
2347
|
+
generateLongPassword()
|
|
2348
|
+
),
|
|
2349
|
+
scope: "ENVIRONMENT"
|
|
2350
|
+
},
|
|
2351
|
+
{
|
|
2352
|
+
name: "MINIO_ROOT_USER",
|
|
2353
|
+
type: "SECRET",
|
|
2354
|
+
didExist: findExistingValue(
|
|
2355
|
+
"MINIO_ROOT_USER",
|
|
2356
|
+
"SECRET",
|
|
2357
|
+
"ENVIRONMENT",
|
|
2358
|
+
existingValues
|
|
2359
|
+
),
|
|
2360
|
+
value: findExistingOrDefine(
|
|
2361
|
+
"MINIO_ROOT_USER",
|
|
2362
|
+
"SECRET",
|
|
2363
|
+
"ENVIRONMENT",
|
|
2364
|
+
generateLongPassword()
|
|
2365
|
+
),
|
|
2366
|
+
scope: "ENVIRONMENT"
|
|
2367
|
+
},
|
|
2368
|
+
{
|
|
2369
|
+
name: "MINIO_ROOT_PASSWORD",
|
|
2370
|
+
type: "SECRET",
|
|
2371
|
+
didExist: findExistingValue(
|
|
2372
|
+
"MINIO_ROOT_PASSWORD",
|
|
2373
|
+
"SECRET",
|
|
2374
|
+
"ENVIRONMENT",
|
|
2375
|
+
existingValues
|
|
2376
|
+
),
|
|
2377
|
+
value: findExistingOrDefine(
|
|
2378
|
+
"MINIO_ROOT_PASSWORD",
|
|
2379
|
+
"SECRET",
|
|
2380
|
+
"ENVIRONMENT",
|
|
2381
|
+
generateLongPassword()
|
|
2382
|
+
),
|
|
2383
|
+
scope: "ENVIRONMENT"
|
|
2384
|
+
},
|
|
2385
|
+
{
|
|
2386
|
+
name: "POSTGRES_USER",
|
|
2387
|
+
type: "SECRET",
|
|
2388
|
+
didExist: findExistingValue(
|
|
2389
|
+
"POSTGRES_USER",
|
|
2390
|
+
"SECRET",
|
|
2391
|
+
"ENVIRONMENT",
|
|
2392
|
+
existingValues
|
|
2393
|
+
),
|
|
2394
|
+
value: findExistingOrDefine(
|
|
2395
|
+
"POSTGRES_USER",
|
|
2396
|
+
"SECRET",
|
|
2397
|
+
"ENVIRONMENT",
|
|
2398
|
+
generateLongPassword()
|
|
2399
|
+
),
|
|
2400
|
+
scope: "ENVIRONMENT"
|
|
2401
|
+
},
|
|
2402
|
+
{
|
|
2403
|
+
name: "POSTGRES_PASSWORD",
|
|
2404
|
+
type: "SECRET",
|
|
2405
|
+
didExist: findExistingValue(
|
|
2406
|
+
"POSTGRES_PASSWORD",
|
|
2407
|
+
"SECRET",
|
|
2408
|
+
"ENVIRONMENT",
|
|
2409
|
+
existingValues
|
|
2410
|
+
),
|
|
2411
|
+
value: findExistingOrDefine(
|
|
2412
|
+
"POSTGRES_PASSWORD",
|
|
2413
|
+
"SECRET",
|
|
2414
|
+
"ENVIRONMENT",
|
|
2415
|
+
generateLongPassword()
|
|
2416
|
+
),
|
|
2417
|
+
scope: "ENVIRONMENT"
|
|
2418
|
+
},
|
|
2419
|
+
{
|
|
2420
|
+
name: "SUPER_USER_PASSWORD",
|
|
2421
|
+
type: "SECRET",
|
|
2422
|
+
didExist: findExistingValue(
|
|
2423
|
+
"SUPER_USER_PASSWORD",
|
|
2424
|
+
"SECRET",
|
|
2425
|
+
"ENVIRONMENT",
|
|
2426
|
+
existingValues
|
|
2427
|
+
),
|
|
2428
|
+
value: findExistingOrDefine(
|
|
2429
|
+
"SUPER_USER_PASSWORD",
|
|
2430
|
+
"SECRET",
|
|
2431
|
+
"ENVIRONMENT",
|
|
2432
|
+
generateLongPassword()
|
|
2433
|
+
),
|
|
2434
|
+
scope: "ENVIRONMENT"
|
|
2435
|
+
},
|
|
2436
|
+
{
|
|
2437
|
+
type: "VARIABLE",
|
|
2438
|
+
name: "ACTIVATE_USERS",
|
|
2439
|
+
value: "production" === environment_type ? "false" : "true",
|
|
2440
|
+
didExist: findExistingValue(
|
|
2441
|
+
"ACTIVATE_USERS",
|
|
2029
2442
|
"VARIABLE",
|
|
2030
2443
|
"ENVIRONMENT",
|
|
2031
2444
|
existingValues
|
|
2032
|
-
)
|
|
2033
|
-
|
|
2034
|
-
|
|
2445
|
+
),
|
|
2446
|
+
scope: "ENVIRONMENT"
|
|
2447
|
+
},
|
|
2448
|
+
{
|
|
2449
|
+
type: "VARIABLE",
|
|
2450
|
+
name: "COUNTRY_CONFIG_HOST",
|
|
2451
|
+
value: answerOrExisting(
|
|
2452
|
+
allAnswers.domain,
|
|
2453
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2454
|
+
(val) => `https://countryconfig.${val}`
|
|
2455
|
+
),
|
|
2456
|
+
didExist: findExistingValue(
|
|
2457
|
+
"COUNTRY_CONFIG_HOST",
|
|
2035
2458
|
"VARIABLE",
|
|
2036
2459
|
"ENVIRONMENT",
|
|
2037
2460
|
existingValues
|
|
2038
|
-
)
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
existingValues
|
|
2054
|
-
);
|
|
2055
|
-
const backupHostPrivateKeyExists = findExistingValue(
|
|
2056
|
-
"BACKUP_HOST_PRIVATE_KEY",
|
|
2057
|
-
"SECRET",
|
|
2058
|
-
"ENVIRONMENT",
|
|
2059
|
-
existingValues
|
|
2060
|
-
);
|
|
2061
|
-
backupType = backupAnswers.backupType;
|
|
2062
|
-
backupHost = backupAnswers.backupHost || backupHost;
|
|
2063
|
-
if (!backupHostPrivateKeyExists) {
|
|
2064
|
-
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2065
|
-
backupHostPublicKey = publicKey;
|
|
2066
|
-
backupHostPrivateKey = privateKey;
|
|
2067
|
-
log(
|
|
2068
|
-
import_kleur4.default.bold().green("\u2714"),
|
|
2069
|
-
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
2070
|
-
);
|
|
2071
|
-
}
|
|
2072
|
-
} else {
|
|
2073
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
2074
|
-
}
|
|
2075
|
-
log("\n", import_kleur4.default.bold().underline("Restore"));
|
|
2076
|
-
let configureRestore = restoreEnvironmentName ? true : false;
|
|
2077
|
-
if (!restoreEnvironmentName && !configureBackup) {
|
|
2078
|
-
configureRestore = await confirm2({
|
|
2079
|
-
message: "Do you want to configure restore?",
|
|
2080
|
-
default: Boolean(process.env.CONFIGURE_RESTORE)
|
|
2081
|
-
});
|
|
2082
|
-
}
|
|
2083
|
-
if (configureRestore) {
|
|
2084
|
-
const env_list_filtered = existingEnvironments.filter(
|
|
2085
|
-
(env) => env !== environment
|
|
2086
|
-
);
|
|
2087
|
-
restoreEnvironmentName = await selectWithCustom({
|
|
2088
|
-
message: "What is the name of your environment to restore?",
|
|
2089
|
-
choices: env_list_filtered.map((env) => ({
|
|
2090
|
-
name: env,
|
|
2091
|
-
value: env
|
|
2092
|
-
})),
|
|
2093
|
-
initial: restoreEnvironmentName
|
|
2094
|
-
});
|
|
2095
|
-
restoreType = await select3({
|
|
2096
|
-
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2097
|
-
choices: [
|
|
2098
|
-
{
|
|
2099
|
-
name: "Full dump (daily full database backup)",
|
|
2100
|
-
value: "dump"
|
|
2101
|
-
},
|
|
2102
|
-
{
|
|
2103
|
-
name: "Differential (weekly full, daily diff backup)",
|
|
2104
|
-
value: "differential"
|
|
2105
|
-
}
|
|
2106
|
-
]
|
|
2107
|
-
});
|
|
2108
|
-
} else {
|
|
2109
|
-
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2110
|
-
}
|
|
2111
|
-
log("\n", import_kleur4.default.bold().underline("Monitoring"));
|
|
2112
|
-
await promptAndStoreAnswer(
|
|
2113
|
-
environment,
|
|
2114
|
-
databaseAndMonitoringQuestions,
|
|
2461
|
+
),
|
|
2462
|
+
scope: "ENVIRONMENT"
|
|
2463
|
+
},
|
|
2464
|
+
{
|
|
2465
|
+
type: "VARIABLE",
|
|
2466
|
+
name: "GATEWAY_HOST",
|
|
2467
|
+
value: answerOrExisting(
|
|
2468
|
+
allAnswers.domain,
|
|
2469
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2470
|
+
(val) => `https://gateway.${val}`
|
|
2471
|
+
),
|
|
2472
|
+
didExist: findExistingValue(
|
|
2473
|
+
"GATEWAY_HOST",
|
|
2474
|
+
"VARIABLE",
|
|
2475
|
+
"ENVIRONMENT",
|
|
2115
2476
|
existingValues
|
|
2116
|
-
)
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2477
|
+
),
|
|
2478
|
+
scope: "ENVIRONMENT"
|
|
2479
|
+
},
|
|
2480
|
+
{
|
|
2481
|
+
type: "VARIABLE",
|
|
2482
|
+
name: "CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2483
|
+
value: answerOrExisting(
|
|
2484
|
+
allAnswers.domain,
|
|
2485
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2486
|
+
(val) => `*.${val}`
|
|
2487
|
+
),
|
|
2488
|
+
didExist: findExistingValue(
|
|
2489
|
+
"CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2490
|
+
"VARIABLE",
|
|
2120
2491
|
"ENVIRONMENT",
|
|
2121
2492
|
existingValues
|
|
2122
|
-
)
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
log("\n", import_kleur4.default.bold().underline("METABASE ADMIN"));
|
|
2140
|
-
await promptAndStoreAnswer(
|
|
2141
|
-
environment,
|
|
2142
|
-
metabaseAdminQuestions,
|
|
2493
|
+
),
|
|
2494
|
+
scope: "ENVIRONMENT"
|
|
2495
|
+
},
|
|
2496
|
+
{
|
|
2497
|
+
type: "VARIABLE",
|
|
2498
|
+
name: "CLIENT_APP_URL",
|
|
2499
|
+
value: answerOrExisting(
|
|
2500
|
+
allAnswers.domain,
|
|
2501
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2502
|
+
(val) => `https://register.${val}`
|
|
2503
|
+
),
|
|
2504
|
+
didExist: findExistingValue(
|
|
2505
|
+
"CLIENT_APP_URL",
|
|
2506
|
+
"VARIABLE",
|
|
2507
|
+
"ENVIRONMENT",
|
|
2143
2508
|
existingValues
|
|
2144
|
-
)
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
scope: "REPOSITORY"
|
|
2171
|
-
}
|
|
2172
|
-
];
|
|
2173
|
-
derivedUpdates.push({
|
|
2174
|
-
name: "NOTIFICATION_TRANSPORT",
|
|
2175
|
-
type: "VARIABLE",
|
|
2176
|
-
didExist: findExistingValue(
|
|
2177
|
-
"NOTIFICATION_TRANSPORT",
|
|
2509
|
+
),
|
|
2510
|
+
scope: "ENVIRONMENT"
|
|
2511
|
+
},
|
|
2512
|
+
{
|
|
2513
|
+
type: "VARIABLE",
|
|
2514
|
+
name: "LOGIN_URL",
|
|
2515
|
+
value: answerOrExisting(
|
|
2516
|
+
allAnswers.domain,
|
|
2517
|
+
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2518
|
+
(val) => `https://login.${val}`
|
|
2519
|
+
),
|
|
2520
|
+
didExist: findExistingValue(
|
|
2521
|
+
"LOGIN_URL",
|
|
2522
|
+
"VARIABLE",
|
|
2523
|
+
"ENVIRONMENT",
|
|
2524
|
+
existingValues
|
|
2525
|
+
),
|
|
2526
|
+
scope: "ENVIRONMENT"
|
|
2527
|
+
},
|
|
2528
|
+
{
|
|
2529
|
+
type: "VARIABLE",
|
|
2530
|
+
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2531
|
+
value: answerOrExisting(
|
|
2532
|
+
restoreEnvironmentName,
|
|
2533
|
+
findExistingValue(
|
|
2534
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2178
2535
|
"VARIABLE",
|
|
2179
2536
|
"ENVIRONMENT",
|
|
2180
2537
|
existingValues
|
|
2181
2538
|
),
|
|
2182
|
-
|
|
2183
|
-
|
|
2539
|
+
(val) => val || ""
|
|
2540
|
+
),
|
|
2541
|
+
didExist: findExistingValue(
|
|
2542
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2543
|
+
"VARIABLE",
|
|
2544
|
+
"ENVIRONMENT",
|
|
2545
|
+
existingValues
|
|
2546
|
+
),
|
|
2547
|
+
scope: "ENVIRONMENT"
|
|
2548
|
+
},
|
|
2549
|
+
{
|
|
2550
|
+
type: "VARIABLE",
|
|
2551
|
+
name: "RESTORE_HOST",
|
|
2552
|
+
value: answerOrExisting(
|
|
2553
|
+
restoreHost,
|
|
2554
|
+
findExistingValue(
|
|
2555
|
+
"RESTORE_HOST",
|
|
2184
2556
|
"VARIABLE",
|
|
2185
2557
|
"ENVIRONMENT",
|
|
2186
|
-
|
|
2558
|
+
existingValues
|
|
2187
2559
|
),
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
}
|
|
2313
|
-
{
|
|
2314
|
-
name: "SUPER_USER_PASSWORD",
|
|
2315
|
-
type: "SECRET",
|
|
2316
|
-
didExist: findExistingValue(
|
|
2317
|
-
"SUPER_USER_PASSWORD",
|
|
2318
|
-
"SECRET",
|
|
2319
|
-
"ENVIRONMENT",
|
|
2320
|
-
existingValues
|
|
2321
|
-
),
|
|
2322
|
-
value: findExistingOrDefine(
|
|
2323
|
-
"SUPER_USER_PASSWORD",
|
|
2324
|
-
"SECRET",
|
|
2325
|
-
"ENVIRONMENT",
|
|
2326
|
-
generateLongPassword()
|
|
2327
|
-
),
|
|
2328
|
-
scope: "ENVIRONMENT"
|
|
2329
|
-
},
|
|
2330
|
-
{
|
|
2331
|
-
type: "VARIABLE",
|
|
2332
|
-
name: "ACTIVATE_USERS",
|
|
2333
|
-
value: "production" === environment_type ? "false" : "true",
|
|
2334
|
-
didExist: findExistingValue(
|
|
2335
|
-
"ACTIVATE_USERS",
|
|
2336
|
-
"VARIABLE",
|
|
2337
|
-
"ENVIRONMENT",
|
|
2338
|
-
existingValues
|
|
2339
|
-
),
|
|
2340
|
-
scope: "ENVIRONMENT"
|
|
2341
|
-
},
|
|
2342
|
-
{
|
|
2343
|
-
type: "VARIABLE",
|
|
2344
|
-
name: "COUNTRY_CONFIG_HOST",
|
|
2345
|
-
value: answerOrExisting(
|
|
2346
|
-
allAnswers.domain,
|
|
2347
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2348
|
-
(val) => `https://countryconfig.${val}`
|
|
2349
|
-
),
|
|
2350
|
-
didExist: findExistingValue(
|
|
2351
|
-
"COUNTRY_CONFIG_HOST",
|
|
2352
|
-
"VARIABLE",
|
|
2353
|
-
"ENVIRONMENT",
|
|
2354
|
-
existingValues
|
|
2355
|
-
),
|
|
2356
|
-
scope: "ENVIRONMENT"
|
|
2357
|
-
},
|
|
2358
|
-
{
|
|
2359
|
-
type: "VARIABLE",
|
|
2360
|
-
name: "GATEWAY_HOST",
|
|
2361
|
-
value: answerOrExisting(
|
|
2362
|
-
allAnswers.domain,
|
|
2363
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2364
|
-
(val) => `https://gateway.${val}`
|
|
2365
|
-
),
|
|
2366
|
-
didExist: findExistingValue(
|
|
2367
|
-
"GATEWAY_HOST",
|
|
2368
|
-
"VARIABLE",
|
|
2369
|
-
"ENVIRONMENT",
|
|
2370
|
-
existingValues
|
|
2371
|
-
),
|
|
2372
|
-
scope: "ENVIRONMENT"
|
|
2373
|
-
},
|
|
2374
|
-
{
|
|
2375
|
-
type: "VARIABLE",
|
|
2376
|
-
name: "CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2377
|
-
value: answerOrExisting(
|
|
2378
|
-
allAnswers.domain,
|
|
2379
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2380
|
-
(val) => `*.${val}`
|
|
2381
|
-
),
|
|
2382
|
-
didExist: findExistingValue(
|
|
2383
|
-
"CONTENT_SECURITY_POLICY_WILDCARD",
|
|
2384
|
-
"VARIABLE",
|
|
2385
|
-
"ENVIRONMENT",
|
|
2386
|
-
existingValues
|
|
2387
|
-
),
|
|
2388
|
-
scope: "ENVIRONMENT"
|
|
2389
|
-
},
|
|
2390
|
-
{
|
|
2391
|
-
type: "VARIABLE",
|
|
2392
|
-
name: "CLIENT_APP_URL",
|
|
2393
|
-
value: answerOrExisting(
|
|
2394
|
-
allAnswers.domain,
|
|
2395
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2396
|
-
(val) => `https://register.${val}`
|
|
2397
|
-
),
|
|
2398
|
-
didExist: findExistingValue(
|
|
2399
|
-
"CLIENT_APP_URL",
|
|
2400
|
-
"VARIABLE",
|
|
2401
|
-
"ENVIRONMENT",
|
|
2402
|
-
existingValues
|
|
2403
|
-
),
|
|
2404
|
-
scope: "ENVIRONMENT"
|
|
2405
|
-
},
|
|
2406
|
-
{
|
|
2407
|
-
type: "VARIABLE",
|
|
2408
|
-
name: "LOGIN_URL",
|
|
2409
|
-
value: answerOrExisting(
|
|
2410
|
-
allAnswers.domain,
|
|
2411
|
-
findExistingValue("DOMAIN", "VARIABLE", "ENVIRONMENT", existingValues),
|
|
2412
|
-
(val) => `https://login.${val}`
|
|
2413
|
-
),
|
|
2414
|
-
didExist: findExistingValue(
|
|
2415
|
-
"LOGIN_URL",
|
|
2416
|
-
"VARIABLE",
|
|
2417
|
-
"ENVIRONMENT",
|
|
2418
|
-
existingValues
|
|
2419
|
-
),
|
|
2420
|
-
scope: "ENVIRONMENT"
|
|
2421
|
-
},
|
|
2422
|
-
{
|
|
2423
|
-
type: "VARIABLE",
|
|
2424
|
-
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2425
|
-
value: answerOrExisting(
|
|
2426
|
-
restoreEnvironmentName,
|
|
2427
|
-
findExistingValue(
|
|
2428
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2429
|
-
"VARIABLE",
|
|
2430
|
-
"ENVIRONMENT",
|
|
2431
|
-
existingValues
|
|
2432
|
-
),
|
|
2433
|
-
(val) => val || ""
|
|
2434
|
-
),
|
|
2435
|
-
didExist: findExistingValue(
|
|
2436
|
-
"RESTORE_ENVIRONMENT_NAME",
|
|
2437
|
-
"VARIABLE",
|
|
2438
|
-
"ENVIRONMENT",
|
|
2439
|
-
existingValues
|
|
2440
|
-
),
|
|
2441
|
-
scope: "ENVIRONMENT"
|
|
2442
|
-
}
|
|
2443
|
-
];
|
|
2444
|
-
if (enableEncryption) {
|
|
2445
|
-
applicationServerUpdates.push({
|
|
2446
|
-
name: "ENCRYPTION_KEY",
|
|
2447
|
-
type: "SECRET",
|
|
2448
|
-
didExist: findExistingValue(
|
|
2449
|
-
"ENCRYPTION_KEY",
|
|
2450
|
-
"SECRET",
|
|
2451
|
-
"ENVIRONMENT",
|
|
2452
|
-
existingValues
|
|
2453
|
-
),
|
|
2454
|
-
value: findExistingOrDefine(
|
|
2455
|
-
"ENCRYPTION_KEY",
|
|
2456
|
-
"SECRET",
|
|
2457
|
-
"ENVIRONMENT",
|
|
2458
|
-
generateLongPassword()
|
|
2459
|
-
),
|
|
2460
|
-
scope: "ENVIRONMENT"
|
|
2461
|
-
});
|
|
2462
|
-
}
|
|
2463
|
-
if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
|
|
2464
|
-
applicationServerUpdates.push({
|
|
2465
|
-
name: "BACKUP_HOST_PRIVATE_KEY",
|
|
2466
|
-
type: "SECRET",
|
|
2467
|
-
didExist: void 0,
|
|
2468
|
-
value: backupHostPrivateKey,
|
|
2469
|
-
scope: "ENVIRONMENT"
|
|
2470
|
-
});
|
|
2471
|
-
applicationServerUpdates.push({
|
|
2472
|
-
name: "BACKUP_HOST_PUBLIC_KEY",
|
|
2473
|
-
type: "SECRET",
|
|
2474
|
-
didExist: void 0,
|
|
2475
|
-
value: backupHostPublicKey,
|
|
2476
|
-
scope: "ENVIRONMENT"
|
|
2477
|
-
});
|
|
2478
|
-
}
|
|
2479
|
-
derivedUpdates.push(...applicationServerUpdates);
|
|
2480
|
-
const updates = getAnswers(existingValues).concat(
|
|
2481
|
-
...derivedUpdates.filter(
|
|
2482
|
-
(update) => update.value !== null
|
|
2483
|
-
)
|
|
2484
|
-
).filter(
|
|
2485
|
-
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2486
|
-
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2560
|
+
(val) => val || ""
|
|
2561
|
+
),
|
|
2562
|
+
didExist: findExistingValue(
|
|
2563
|
+
"RESTORE_HOST",
|
|
2564
|
+
"VARIABLE",
|
|
2565
|
+
"ENVIRONMENT",
|
|
2566
|
+
existingValues
|
|
2567
|
+
),
|
|
2568
|
+
scope: "ENVIRONMENT"
|
|
2569
|
+
}
|
|
2570
|
+
];
|
|
2571
|
+
if (enableEncryption) {
|
|
2572
|
+
applicationServerUpdates.push({
|
|
2573
|
+
name: "ENCRYPTION_KEY",
|
|
2574
|
+
type: "SECRET",
|
|
2575
|
+
didExist: findExistingValue(
|
|
2576
|
+
"ENCRYPTION_KEY",
|
|
2577
|
+
"SECRET",
|
|
2578
|
+
"ENVIRONMENT",
|
|
2579
|
+
existingValues
|
|
2580
|
+
),
|
|
2581
|
+
value: findExistingOrDefine(
|
|
2582
|
+
"ENCRYPTION_KEY",
|
|
2583
|
+
"SECRET",
|
|
2584
|
+
"ENVIRONMENT",
|
|
2585
|
+
generateLongPassword()
|
|
2586
|
+
),
|
|
2587
|
+
scope: "ENVIRONMENT"
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
|
|
2591
|
+
applicationServerUpdates.push({
|
|
2592
|
+
name: "BACKUP_HOST_PRIVATE_KEY",
|
|
2593
|
+
type: "SECRET",
|
|
2594
|
+
didExist: void 0,
|
|
2595
|
+
value: backupHostPrivateKey,
|
|
2596
|
+
scope: "ENVIRONMENT"
|
|
2597
|
+
});
|
|
2598
|
+
applicationServerUpdates.push({
|
|
2599
|
+
name: "BACKUP_HOST_PUBLIC_KEY",
|
|
2600
|
+
type: "SECRET",
|
|
2601
|
+
didExist: void 0,
|
|
2602
|
+
value: backupHostPublicKey,
|
|
2603
|
+
scope: "ENVIRONMENT"
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2606
|
+
derivedUpdates.push(...applicationServerUpdates);
|
|
2607
|
+
const updates = getAnswers(existingValues).concat(
|
|
2608
|
+
...derivedUpdates.filter(
|
|
2609
|
+
(update) => update.value !== null
|
|
2610
|
+
)
|
|
2611
|
+
).filter(
|
|
2612
|
+
(variable) => Boolean(variable.value) && // Only update values that changed
|
|
2613
|
+
(variable.type !== "VARIABLE" || variable.value !== variable.didExist?.value)
|
|
2614
|
+
);
|
|
2615
|
+
const newSecrets = updates.filter(
|
|
2616
|
+
(update) => update.type === "SECRET" && !update.didExist
|
|
2617
|
+
);
|
|
2618
|
+
const updatedSecrets = updates.filter(
|
|
2619
|
+
(update) => update.type === "SECRET" && Boolean(update.didExist)
|
|
2620
|
+
);
|
|
2621
|
+
const newVariables = updates.filter(
|
|
2622
|
+
(update) => update.type === "VARIABLE" && !update.didExist
|
|
2623
|
+
);
|
|
2624
|
+
const updatedVariables = updates.filter(
|
|
2625
|
+
(update) => update.type === "VARIABLE" && Boolean(update.didExist)
|
|
2626
|
+
);
|
|
2627
|
+
const unknownVariables = existingValues.filter((value) => {
|
|
2628
|
+
return !ALL_QUESTIONS.find(
|
|
2629
|
+
(question) => question.valueLabel === value.name && question.valueType === value.type && question.scope === value.scope
|
|
2630
|
+
);
|
|
2631
|
+
});
|
|
2632
|
+
log("");
|
|
2633
|
+
if (newSecrets.length > 0) {
|
|
2634
|
+
log(
|
|
2635
|
+
import_kleur4.default.yellow(
|
|
2636
|
+
`The following secrets will be added to Github for environment ${environment}:`
|
|
2637
|
+
)
|
|
2638
|
+
);
|
|
2639
|
+
newSecrets.filter(({ scope }) => scope === "ENVIRONMENT").forEach((secret) => {
|
|
2640
|
+
log(secret.name, "=", secret.value);
|
|
2641
|
+
});
|
|
2642
|
+
log("");
|
|
2643
|
+
log(
|
|
2644
|
+
import_kleur4.default.yellow(`The following secrets will be added to Github repository:`)
|
|
2645
|
+
);
|
|
2646
|
+
newSecrets.filter(({ scope }) => scope === "REPOSITORY").forEach((secret) => {
|
|
2647
|
+
log(secret.name, "=", secret.value);
|
|
2648
|
+
});
|
|
2649
|
+
log("");
|
|
2650
|
+
}
|
|
2651
|
+
if (updatedSecrets.length > 0) {
|
|
2652
|
+
log(
|
|
2653
|
+
import_kleur4.default.yellow(
|
|
2654
|
+
`The following secrets will be updated in Github for environment ${environment}:`
|
|
2655
|
+
)
|
|
2656
|
+
);
|
|
2657
|
+
updatedSecrets.forEach((secret) => {
|
|
2658
|
+
log(secret.name, "=", secret.value);
|
|
2659
|
+
});
|
|
2660
|
+
log("");
|
|
2661
|
+
}
|
|
2662
|
+
if (newVariables.length > 0) {
|
|
2663
|
+
log(
|
|
2664
|
+
import_kleur4.default.yellow(
|
|
2665
|
+
`The following variables will be added to Github for environment ${environment}:`
|
|
2666
|
+
)
|
|
2667
|
+
);
|
|
2668
|
+
newVariables.forEach((variable) => {
|
|
2669
|
+
log(variable.name, "=", variable.value);
|
|
2670
|
+
});
|
|
2671
|
+
log("");
|
|
2672
|
+
}
|
|
2673
|
+
if (updatedVariables.length > 0) {
|
|
2674
|
+
log(
|
|
2675
|
+
import_kleur4.default.yellow(
|
|
2676
|
+
`The following variables will be updated in Github for environment ${environment}:`
|
|
2677
|
+
)
|
|
2678
|
+
);
|
|
2679
|
+
updatedVariables.forEach((variable) => {
|
|
2680
|
+
log(
|
|
2681
|
+
variable.name,
|
|
2682
|
+
"=",
|
|
2683
|
+
variable.value,
|
|
2684
|
+
`(was ${variable.didExist?.value})`
|
|
2487
2685
|
);
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2686
|
+
});
|
|
2687
|
+
log("");
|
|
2688
|
+
}
|
|
2689
|
+
if (unknownVariables.length > 0) {
|
|
2690
|
+
log(
|
|
2691
|
+
import_kleur4.default.yellow(
|
|
2692
|
+
`The following unknown variables/secrets were stored in Github are not managed by this script:`
|
|
2693
|
+
)
|
|
2694
|
+
);
|
|
2695
|
+
log("");
|
|
2696
|
+
log(import_kleur4.default.blue(`Repository:`));
|
|
2697
|
+
unknownVariables.filter(({ scope }) => scope === "REPOSITORY").forEach((variable) => {
|
|
2698
|
+
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2699
|
+
});
|
|
2700
|
+
log("");
|
|
2701
|
+
log(import_kleur4.default.blue(`Environment:`));
|
|
2702
|
+
unknownVariables.filter(({ scope }) => scope === "ENVIRONMENT").forEach((variable) => {
|
|
2703
|
+
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2704
|
+
});
|
|
2705
|
+
log("");
|
|
2706
|
+
log(
|
|
2707
|
+
import_kleur4.default.yellow(
|
|
2708
|
+
`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`
|
|
2709
|
+
)
|
|
2710
|
+
);
|
|
2711
|
+
log("");
|
|
2712
|
+
}
|
|
2713
|
+
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2714
|
+
process.exit(0);
|
|
2715
|
+
}
|
|
2716
|
+
log(
|
|
2717
|
+
import_kleur4.default.bold().red(
|
|
2718
|
+
"\u26A0\uFE0F COPY THESE NOW INTO A PASSWORD MANAGER \u2014 YOU WON'T SEE THEM AGAIN"
|
|
2719
|
+
)
|
|
2720
|
+
);
|
|
2721
|
+
log("");
|
|
2722
|
+
const saveChanges = await confirm2({
|
|
2723
|
+
message: "Do you want to continue?",
|
|
2724
|
+
default: true
|
|
2725
|
+
});
|
|
2726
|
+
if (!saveChanges) {
|
|
2727
|
+
process.exit(0);
|
|
2728
|
+
}
|
|
2729
|
+
for (const newSecret of newSecrets) {
|
|
2730
|
+
log(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
|
|
2731
|
+
if (newSecret.scope === "ENVIRONMENT") {
|
|
2732
|
+
await createEnvironmentSecret(
|
|
2733
|
+
octokit,
|
|
2734
|
+
repositoryId,
|
|
2735
|
+
environment,
|
|
2736
|
+
newSecret.name,
|
|
2737
|
+
newSecret.value,
|
|
2738
|
+
githubOrganisation,
|
|
2739
|
+
githubRepository
|
|
2491
2740
|
);
|
|
2492
|
-
|
|
2493
|
-
|
|
2741
|
+
} else {
|
|
2742
|
+
await createRepositorySecret(
|
|
2743
|
+
octokit,
|
|
2744
|
+
repositoryId,
|
|
2745
|
+
newSecret.name,
|
|
2746
|
+
newSecret.value,
|
|
2747
|
+
githubOrganisation,
|
|
2748
|
+
githubRepository
|
|
2494
2749
|
);
|
|
2495
|
-
|
|
2496
|
-
|
|
2750
|
+
}
|
|
2751
|
+
}
|
|
2752
|
+
for (const updatedSecret of updatedSecrets) {
|
|
2753
|
+
log(
|
|
2754
|
+
`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`
|
|
2755
|
+
);
|
|
2756
|
+
if (updatedSecret.scope === "ENVIRONMENT") {
|
|
2757
|
+
await createEnvironmentSecret(
|
|
2758
|
+
octokit,
|
|
2759
|
+
repositoryId,
|
|
2760
|
+
environment,
|
|
2761
|
+
updatedSecret.name,
|
|
2762
|
+
updatedSecret.value,
|
|
2763
|
+
githubOrganisation,
|
|
2764
|
+
githubRepository
|
|
2497
2765
|
);
|
|
2498
|
-
|
|
2499
|
-
|
|
2766
|
+
} else {
|
|
2767
|
+
await createRepositorySecret(
|
|
2768
|
+
octokit,
|
|
2769
|
+
repositoryId,
|
|
2770
|
+
updatedSecret.name,
|
|
2771
|
+
updatedSecret.value,
|
|
2772
|
+
githubOrganisation,
|
|
2773
|
+
githubRepository
|
|
2500
2774
|
);
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
);
|
|
2513
|
-
newSecrets.filter(({ scope }) => scope === "ENVIRONMENT").forEach((secret) => {
|
|
2514
|
-
log(secret.name, "=", secret.value);
|
|
2515
|
-
});
|
|
2516
|
-
log("");
|
|
2517
|
-
log(
|
|
2518
|
-
import_kleur4.default.yellow(`The following secrets will be added to Github repository:`)
|
|
2519
|
-
);
|
|
2520
|
-
newSecrets.filter(({ scope }) => scope === "REPOSITORY").forEach((secret) => {
|
|
2521
|
-
log(secret.name, "=", secret.value);
|
|
2522
|
-
});
|
|
2523
|
-
log("");
|
|
2524
|
-
}
|
|
2525
|
-
if (updatedSecrets.length > 0) {
|
|
2526
|
-
log(
|
|
2527
|
-
import_kleur4.default.yellow(
|
|
2528
|
-
`The following secrets will be updated in Github for environment ${environment}:`
|
|
2529
|
-
)
|
|
2530
|
-
);
|
|
2531
|
-
updatedSecrets.forEach((secret) => {
|
|
2532
|
-
log(secret.name, "=", secret.value);
|
|
2533
|
-
});
|
|
2534
|
-
log("");
|
|
2535
|
-
}
|
|
2536
|
-
if (newVariables.length > 0) {
|
|
2537
|
-
log(
|
|
2538
|
-
import_kleur4.default.yellow(
|
|
2539
|
-
`The following variables will be added to Github for environment ${environment}:`
|
|
2540
|
-
)
|
|
2541
|
-
);
|
|
2542
|
-
newVariables.forEach((variable) => {
|
|
2543
|
-
log(variable.name, "=", variable.value);
|
|
2544
|
-
});
|
|
2545
|
-
log("");
|
|
2546
|
-
}
|
|
2547
|
-
if (updatedVariables.length > 0) {
|
|
2548
|
-
log(
|
|
2549
|
-
import_kleur4.default.yellow(
|
|
2550
|
-
`The following variables will be updated in Github for environment ${environment}:`
|
|
2551
|
-
)
|
|
2552
|
-
);
|
|
2553
|
-
updatedVariables.forEach((variable) => {
|
|
2554
|
-
log(
|
|
2555
|
-
variable.name,
|
|
2556
|
-
"=",
|
|
2557
|
-
variable.value,
|
|
2558
|
-
`(was ${variable.didExist?.value})`
|
|
2559
|
-
);
|
|
2560
|
-
});
|
|
2561
|
-
log("");
|
|
2562
|
-
}
|
|
2563
|
-
if (unknownVariables.length > 0) {
|
|
2564
|
-
log(
|
|
2565
|
-
import_kleur4.default.yellow(
|
|
2566
|
-
`The following unknown variables/secrets were stored in Github are not managed by this script:`
|
|
2567
|
-
)
|
|
2568
|
-
);
|
|
2569
|
-
log("");
|
|
2570
|
-
log(import_kleur4.default.blue(`Repository:`));
|
|
2571
|
-
unknownVariables.filter(({ scope }) => scope === "REPOSITORY").forEach((variable) => {
|
|
2572
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2573
|
-
});
|
|
2574
|
-
log("");
|
|
2575
|
-
log(import_kleur4.default.blue(`Environment:`));
|
|
2576
|
-
unknownVariables.filter(({ scope }) => scope === "ENVIRONMENT").forEach((variable) => {
|
|
2577
|
-
log(import_kleur4.default.cyan(variable.type) + ":", variable.name);
|
|
2578
|
-
});
|
|
2579
|
-
log("");
|
|
2580
|
-
log(
|
|
2581
|
-
import_kleur4.default.yellow(
|
|
2582
|
-
`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`
|
|
2583
|
-
)
|
|
2584
|
-
);
|
|
2585
|
-
log("");
|
|
2586
|
-
}
|
|
2587
|
-
if ([].concat(newSecrets).concat(updatedSecrets).concat(newVariables).concat(updatedVariables).length === 0) {
|
|
2588
|
-
process.exit(0);
|
|
2589
|
-
}
|
|
2590
|
-
const saveChanges = await confirm2({
|
|
2591
|
-
message: "Do you want to continue?",
|
|
2592
|
-
default: true
|
|
2593
|
-
});
|
|
2594
|
-
if (!saveChanges) {
|
|
2595
|
-
process.exit(0);
|
|
2596
|
-
}
|
|
2597
|
-
for (const newSecret of newSecrets) {
|
|
2598
|
-
log(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
|
|
2599
|
-
if (newSecret.scope === "ENVIRONMENT") {
|
|
2600
|
-
await createEnvironmentSecret(
|
|
2601
|
-
octokit,
|
|
2602
|
-
repositoryId,
|
|
2603
|
-
environment,
|
|
2604
|
-
newSecret.name,
|
|
2605
|
-
newSecret.value,
|
|
2606
|
-
githubOrganisation,
|
|
2607
|
-
githubRepository
|
|
2608
|
-
);
|
|
2609
|
-
} else {
|
|
2610
|
-
await createRepositorySecret(
|
|
2611
|
-
octokit,
|
|
2612
|
-
repositoryId,
|
|
2613
|
-
newSecret.name,
|
|
2614
|
-
newSecret.value,
|
|
2615
|
-
githubOrganisation,
|
|
2616
|
-
githubRepository
|
|
2617
|
-
);
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
for (const updatedSecret of updatedSecrets) {
|
|
2621
|
-
log(
|
|
2622
|
-
`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`
|
|
2623
|
-
);
|
|
2624
|
-
if (updatedSecret.scope === "ENVIRONMENT") {
|
|
2625
|
-
await createEnvironmentSecret(
|
|
2626
|
-
octokit,
|
|
2627
|
-
repositoryId,
|
|
2628
|
-
environment,
|
|
2629
|
-
updatedSecret.name,
|
|
2630
|
-
updatedSecret.value,
|
|
2631
|
-
githubOrganisation,
|
|
2632
|
-
githubRepository
|
|
2633
|
-
);
|
|
2634
|
-
} else {
|
|
2635
|
-
await createRepositorySecret(
|
|
2636
|
-
octokit,
|
|
2637
|
-
repositoryId,
|
|
2638
|
-
updatedSecret.name,
|
|
2639
|
-
updatedSecret.value,
|
|
2640
|
-
githubOrganisation,
|
|
2641
|
-
githubRepository
|
|
2642
|
-
);
|
|
2643
|
-
}
|
|
2644
|
-
}
|
|
2645
|
-
for (const newVariable of newVariables) {
|
|
2646
|
-
log(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
|
|
2647
|
-
if (newVariable.scope === "ENVIRONMENT") {
|
|
2648
|
-
await createEnvironmentVariable(
|
|
2649
|
-
octokit,
|
|
2650
|
-
repositoryId,
|
|
2651
|
-
environment,
|
|
2652
|
-
newVariable.name,
|
|
2653
|
-
newVariable.value
|
|
2654
|
-
);
|
|
2655
|
-
} else {
|
|
2656
|
-
await createRepositoryVariable(
|
|
2657
|
-
octokit,
|
|
2658
|
-
repositoryId,
|
|
2659
|
-
newVariable.name,
|
|
2660
|
-
newVariable.value
|
|
2661
|
-
);
|
|
2662
|
-
}
|
|
2663
|
-
}
|
|
2664
|
-
for (const updatedVariable of updatedVariables) {
|
|
2665
|
-
log(
|
|
2666
|
-
`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`
|
|
2667
|
-
);
|
|
2668
|
-
if (updatedVariable.scope === "ENVIRONMENT") {
|
|
2669
|
-
await updateEnvironmentVariable(
|
|
2670
|
-
octokit,
|
|
2671
|
-
repositoryId,
|
|
2672
|
-
environment,
|
|
2673
|
-
updatedVariable.name,
|
|
2674
|
-
updatedVariable.value
|
|
2675
|
-
);
|
|
2676
|
-
} else {
|
|
2677
|
-
await updateRepositoryVariable(
|
|
2678
|
-
octokit,
|
|
2679
|
-
repositoryId,
|
|
2680
|
-
updatedVariable.name,
|
|
2681
|
-
updatedVariable.value
|
|
2682
|
-
);
|
|
2683
|
-
}
|
|
2684
|
-
}
|
|
2685
|
-
log(
|
|
2686
|
-
import_kleur4.default.green(
|
|
2687
|
-
`Successfully updated Github secrets and variables for environment ${environment}`
|
|
2688
|
-
)
|
|
2775
|
+
}
|
|
2776
|
+
}
|
|
2777
|
+
for (const newVariable of newVariables) {
|
|
2778
|
+
log(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
|
|
2779
|
+
if (newVariable.scope === "ENVIRONMENT") {
|
|
2780
|
+
await createEnvironmentVariable(
|
|
2781
|
+
octokit,
|
|
2782
|
+
repositoryId,
|
|
2783
|
+
environment,
|
|
2784
|
+
newVariable.name,
|
|
2785
|
+
newVariable.value
|
|
2689
2786
|
);
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2787
|
+
} else {
|
|
2788
|
+
await createRepositoryVariable(
|
|
2789
|
+
octokit,
|
|
2790
|
+
repositoryId,
|
|
2791
|
+
newVariable.name,
|
|
2792
|
+
newVariable.value
|
|
2793
|
+
);
|
|
2794
|
+
}
|
|
2795
|
+
}
|
|
2796
|
+
for (const updatedVariable of updatedVariables) {
|
|
2797
|
+
log(
|
|
2798
|
+
`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`
|
|
2799
|
+
);
|
|
2800
|
+
if (updatedVariable.scope === "ENVIRONMENT") {
|
|
2801
|
+
await updateEnvironmentVariable(
|
|
2802
|
+
octokit,
|
|
2803
|
+
repositoryId,
|
|
2804
|
+
environment,
|
|
2805
|
+
updatedVariable.name,
|
|
2806
|
+
updatedVariable.value
|
|
2807
|
+
);
|
|
2808
|
+
} else {
|
|
2809
|
+
await updateRepositoryVariable(
|
|
2810
|
+
octokit,
|
|
2811
|
+
repositoryId,
|
|
2812
|
+
updatedVariable.name,
|
|
2813
|
+
updatedVariable.value
|
|
2814
|
+
);
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
log(
|
|
2818
|
+
import_kleur4.default.green(
|
|
2819
|
+
`Successfully updated Github secrets and variables for environment ${environment}`
|
|
2820
|
+
)
|
|
2821
|
+
);
|
|
2822
|
+
log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
|
|
2823
|
+
generateInventory(environment, {
|
|
2824
|
+
kube_worker_nodes: kubeWorkerNodes,
|
|
2825
|
+
kube_api_host: infrastructure.kubeApiHost || "",
|
|
2826
|
+
backup_host: backupHost || "",
|
|
2827
|
+
users
|
|
2828
|
+
});
|
|
2829
|
+
copyChartsValues(environment, {
|
|
2830
|
+
env: environment,
|
|
2831
|
+
environment_type,
|
|
2832
|
+
// FIXME: In general that should be environment_type,
|
|
2833
|
+
// Hardcode like this blocks us from being generic:
|
|
2834
|
+
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
2835
|
+
two_fa_enabled: environment !== "production" ? false : true,
|
|
2836
|
+
traefik_mode: traefikConfOption,
|
|
2837
|
+
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2838
|
+
restore_environment_name: restoreEnvironmentName || "",
|
|
2839
|
+
restore_type: restoreType,
|
|
2840
|
+
restore_host: restoreHost || "",
|
|
2841
|
+
backup_enabled: configureBackup ? true : false,
|
|
2842
|
+
backup_type: backupType,
|
|
2843
|
+
backup_host: backupHost || ""
|
|
2844
|
+
});
|
|
2845
|
+
log("\n", import_kleur4.default.bold().underline("Updating workflow files"));
|
|
2846
|
+
await updateWorkflowEnvironments();
|
|
2847
|
+
let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
|
|
2712
2848
|
|
|
2713
2849
|
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("COPY the SSH public key from the master VM to your clipboard")}
|
|
2714
2850
|
--------------------------------------------------------------------------------------------
|
|
2715
2851
|
` : "";
|
|
2716
|
-
|
|
2852
|
+
addon_message += kubeWorkerNodes.length > 0 ? `\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on Kubernetes worker VM to create provision user and setup SSH key:")}
|
|
2717
2853
|
|
|
2718
2854
|
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2719
2855
|
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"
|
|
2720
2856
|
` : "";
|
|
2721
|
-
|
|
2857
|
+
addon_message += configureBackup ? `
|
|
2722
2858
|
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("Run following command on backup server to create provision user and setup SSH key:")}
|
|
2723
2859
|
curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
|
|
2724
2860
|
bash opencrvs-bootstrap.sh --ssh-public-key "${import_kleur4.default.bold("[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]")}"` : "";
|
|
2725
|
-
|
|
2861
|
+
log(`
|
|
2726
2862
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
2727
2863
|
Follow the steps below to complete the setup of your environment:
|
|
2728
2864
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
@@ -2740,131 +2876,114 @@ ${addon_message}
|
|
|
2740
2876
|
${import_kleur4.default.yellow("\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501")}
|
|
2741
2877
|
${import_kleur4.default.yellow("Please KINDLY read hints above")}
|
|
2742
2878
|
`);
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2879
|
+
log(
|
|
2880
|
+
"\nAll secrets and variables were printed above.",
|
|
2881
|
+
import_kleur4.default.bold().yellow("Store them in a password manager \u2014 they are not saved to disk.")
|
|
2882
|
+
);
|
|
2883
|
+
}
|
|
2884
|
+
var import_core, import_kleur4, import_prompts2, ALL_QUESTIONS, ALL_ANSWERS;
|
|
2885
|
+
var init_setup_environment = __esm({
|
|
2886
|
+
"src/environment/setup-environment.ts"() {
|
|
2887
|
+
"use strict";
|
|
2888
|
+
import_core = require("@octokit/core");
|
|
2889
|
+
import_kleur4 = __toESM(require("kleur"));
|
|
2890
|
+
import_prompts2 = __toESM(require("prompts"));
|
|
2891
|
+
init_github();
|
|
2892
|
+
init_derived_variables();
|
|
2893
|
+
init_utils();
|
|
2894
|
+
init_logger();
|
|
2895
|
+
init_templates();
|
|
2896
|
+
init_ssh_keygen();
|
|
2897
|
+
init_update_workflows();
|
|
2898
|
+
init_questions();
|
|
2899
|
+
init_editor_questions();
|
|
2900
|
+
init_questions_helper();
|
|
2901
|
+
init_manage_users();
|
|
2902
|
+
init_paths();
|
|
2903
|
+
ALL_QUESTIONS = [];
|
|
2904
|
+
ALL_ANSWERS = [];
|
|
2905
|
+
ALL_QUESTIONS.push(
|
|
2906
|
+
...githubTokenQuestion,
|
|
2907
|
+
...githubOtherQuestions,
|
|
2908
|
+
...dockerhubQuestions,
|
|
2909
|
+
...diskQuestions,
|
|
2910
|
+
...infrastructureQuestions,
|
|
2911
|
+
...backupQuestions,
|
|
2912
|
+
...countryQuestions,
|
|
2913
|
+
...databaseAndMonitoringQuestions,
|
|
2914
|
+
...emailQuestions,
|
|
2915
|
+
...sentryQuestions,
|
|
2916
|
+
...derivedVariables,
|
|
2917
|
+
...metabaseAdminQuestions
|
|
2918
|
+
);
|
|
2746
2919
|
}
|
|
2747
2920
|
});
|
|
2748
2921
|
|
|
2749
|
-
// src/environment/
|
|
2750
|
-
var
|
|
2751
|
-
__export(
|
|
2752
|
-
|
|
2922
|
+
// src/environment/upgrade.ts
|
|
2923
|
+
var upgrade_exports = {};
|
|
2924
|
+
__export(upgrade_exports, {
|
|
2925
|
+
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2753
2926
|
});
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2927
|
+
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2928
|
+
if (!(0, import_fs7.existsSync)(sourcePath)) {
|
|
2929
|
+
return false;
|
|
2930
|
+
}
|
|
2931
|
+
if ((0, import_fs7.existsSync)(destinationPath)) {
|
|
2932
|
+
warn(
|
|
2933
|
+
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2760
2934
|
);
|
|
2761
|
-
return
|
|
2935
|
+
return false;
|
|
2762
2936
|
}
|
|
2763
|
-
|
|
2764
|
-
|
|
2937
|
+
(0, import_fs7.mkdirSync)((0, import_path9.dirname)(destinationPath), { recursive: true });
|
|
2938
|
+
(0, import_fs7.renameSync)(sourcePath, destinationPath);
|
|
2939
|
+
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2940
|
+
return true;
|
|
2765
2941
|
}
|
|
2766
|
-
|
|
2767
|
-
const
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
return
|
|
2771
|
-
});
|
|
2772
|
-
if (environments.length === 0) {
|
|
2773
|
-
console.log(
|
|
2774
|
-
"\u26A0\uFE0F Warning: No environment directories found in environments/"
|
|
2775
|
-
);
|
|
2776
|
-
return [];
|
|
2942
|
+
function migrateInventoryFiles() {
|
|
2943
|
+
const oldInventoryFiles = findOldInventoryFiles();
|
|
2944
|
+
if (oldInventoryFiles.length === 0) {
|
|
2945
|
+
log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
|
|
2946
|
+
return false;
|
|
2777
2947
|
}
|
|
2778
|
-
log("\
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2948
|
+
log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
|
|
2949
|
+
let didMoveInventory = false;
|
|
2950
|
+
for (const oldInventoryFile of oldInventoryFiles) {
|
|
2951
|
+
const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
|
|
2952
|
+
didMoveInventory = moveFileIfDestinationMissing(
|
|
2953
|
+
oldInventoryFile,
|
|
2954
|
+
getEnvironmentInventoryPath(environment)
|
|
2955
|
+
) || didMoveInventory;
|
|
2786
2956
|
}
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
}
|
|
2792
|
-
async function updateWorkflows(envList, config) {
|
|
2793
|
-
const { workflows } = config;
|
|
2794
|
-
for (const workflowPath of workflows) {
|
|
2795
|
-
try {
|
|
2796
|
-
const fileContents = (0, import_fs3.readFileSync)(workflowPath, "utf8");
|
|
2797
|
-
const workflowData = yaml2.load(fileContents);
|
|
2798
|
-
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2799
|
-
throw new Error(
|
|
2800
|
-
"Workflow does not have the expected structure: on.workflow_dispatch.inputs.environment.options"
|
|
2801
|
-
);
|
|
2802
|
-
}
|
|
2803
|
-
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2804
|
-
(0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2805
|
-
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2806
|
-
} catch (error4) {
|
|
2807
|
-
console.error(
|
|
2808
|
-
`
|
|
2809
|
-
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2810
|
-
);
|
|
2811
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
|
|
2812
|
-
throw error4;
|
|
2957
|
+
try {
|
|
2958
|
+
if ((0, import_fs7.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs7.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
2959
|
+
(0, import_fs7.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2960
|
+
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2813
2961
|
}
|
|
2962
|
+
} catch {
|
|
2963
|
+
warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
|
|
2814
2964
|
}
|
|
2965
|
+
return didMoveInventory;
|
|
2815
2966
|
}
|
|
2816
|
-
async function
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
workflows: [
|
|
2824
|
-
".github/workflows/provision.yml",
|
|
2825
|
-
".github/workflows/reset-2fa.yml"
|
|
2826
|
-
],
|
|
2827
|
-
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2828
|
-
});
|
|
2829
|
-
didUpdateWorkflows = true;
|
|
2830
|
-
}
|
|
2831
|
-
const environments = await extractEnvironmentNames();
|
|
2832
|
-
if (environments.length > 0) {
|
|
2833
|
-
const workflows = [
|
|
2834
|
-
".github/workflows/deploy-dependencies.yml",
|
|
2835
|
-
".github/workflows/deploy-opencrvs.yml",
|
|
2836
|
-
".github/workflows/clear-all-data.yml",
|
|
2837
|
-
".github/workflows/seed-data.yml",
|
|
2838
|
-
".github/workflows/reindex.yml",
|
|
2839
|
-
".github/workflows/github-to-k8s-sync-env.yml"
|
|
2840
|
-
];
|
|
2841
|
-
log("\u{1F4CB} Updating OpenCRVS application workflows:");
|
|
2842
|
-
await updateWorkflows(environments, {
|
|
2843
|
-
workflows,
|
|
2844
|
-
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2845
|
-
});
|
|
2846
|
-
didUpdateWorkflows = true;
|
|
2847
|
-
}
|
|
2848
|
-
if (didUpdateWorkflows) {
|
|
2849
|
-
success("\u2705 Workflow updates completed successfully!");
|
|
2850
|
-
} else {
|
|
2851
|
-
log("\u2139\uFE0F No workflows were updated.");
|
|
2852
|
-
}
|
|
2853
|
-
} catch (error4) {
|
|
2854
|
-
console.error("\n\u274C Error updating workflows:", error4);
|
|
2855
|
-
process.exit(1);
|
|
2967
|
+
async function upgradeEnvironmentLayout() {
|
|
2968
|
+
const didMoveInventory = migrateInventoryFiles();
|
|
2969
|
+
await updateWorkflowEnvironments();
|
|
2970
|
+
if (didMoveInventory) {
|
|
2971
|
+
success("\n\u2705 Environment layout upgrade completed successfully.");
|
|
2972
|
+
} else {
|
|
2973
|
+
success("\n\u2705 Environment layout already uses the current structure.");
|
|
2856
2974
|
}
|
|
2975
|
+
log("\nCommit changes into git after upgrade");
|
|
2857
2976
|
}
|
|
2858
|
-
var
|
|
2859
|
-
var
|
|
2860
|
-
"src/environment/
|
|
2977
|
+
var import_fs7, import_path9, import_kleur5;
|
|
2978
|
+
var init_upgrade = __esm({
|
|
2979
|
+
"src/environment/upgrade.ts"() {
|
|
2861
2980
|
"use strict";
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
glob = __toESM(require("glob"));
|
|
2866
|
-
yaml2 = __toESM(require("js-yaml"));
|
|
2981
|
+
import_fs7 = require("fs");
|
|
2982
|
+
import_path9 = require("path");
|
|
2983
|
+
import_kleur5 = __toESM(require("kleur"));
|
|
2867
2984
|
init_logger();
|
|
2985
|
+
init_paths();
|
|
2986
|
+
init_update_workflows();
|
|
2868
2987
|
}
|
|
2869
2988
|
});
|
|
2870
2989
|
|
|
@@ -2877,7 +2996,7 @@ async function select4(options) {
|
|
|
2877
2996
|
const inquirer = await import("@inquirer/prompts");
|
|
2878
2997
|
return inquirer.select(options);
|
|
2879
2998
|
}
|
|
2880
|
-
async function selectInventoryFile(dirPath = "./
|
|
2999
|
+
async function selectInventoryFile(dirPath = "./environments") {
|
|
2881
3000
|
if (!fs4.existsSync(dirPath)) {
|
|
2882
3001
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
2883
3002
|
warn(
|
|
@@ -2885,22 +3004,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2885
3004
|
);
|
|
2886
3005
|
return null;
|
|
2887
3006
|
}
|
|
2888
|
-
const
|
|
2889
|
-
const filePath =
|
|
2890
|
-
|
|
2891
|
-
const ext = path4.extname(file).slice(1).toLowerCase();
|
|
2892
|
-
return isFile && (ext === "yml" || ext === "yaml");
|
|
3007
|
+
const environments = fs4.readdirSync(dirPath).filter((entry) => {
|
|
3008
|
+
const filePath = path8.join(dirPath, entry);
|
|
3009
|
+
return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
|
|
2893
3010
|
}).sort();
|
|
2894
|
-
if (
|
|
3011
|
+
if (environments.length === 0) {
|
|
2895
3012
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
2896
3013
|
warn(
|
|
2897
3014
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
2898
3015
|
);
|
|
2899
3016
|
return null;
|
|
2900
3017
|
}
|
|
2901
|
-
const choices =
|
|
2902
|
-
name:
|
|
2903
|
-
value:
|
|
3018
|
+
const choices = environments.map((environment) => ({
|
|
3019
|
+
name: environment,
|
|
3020
|
+
value: getEnvironmentInventoryPath(environment)
|
|
2904
3021
|
}));
|
|
2905
3022
|
const selectedFile = await select4({
|
|
2906
3023
|
message: "Select environment (inventory file) to load users:",
|
|
@@ -2909,33 +3026,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2909
3026
|
return selectedFile;
|
|
2910
3027
|
}
|
|
2911
3028
|
async function manageEnvironmentUsers() {
|
|
2912
|
-
console.log("\n",
|
|
3029
|
+
console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
|
|
2913
3030
|
const inventory_file = await selectInventoryFile();
|
|
2914
3031
|
if (!inventory_file) {
|
|
2915
3032
|
return;
|
|
2916
3033
|
}
|
|
2917
3034
|
await manageUsers(inventory_file);
|
|
2918
3035
|
}
|
|
2919
|
-
var fs4,
|
|
3036
|
+
var fs4, path8, import_kleur6;
|
|
2920
3037
|
var init_users = __esm({
|
|
2921
3038
|
"src/environment/users.ts"() {
|
|
2922
3039
|
"use strict";
|
|
2923
3040
|
fs4 = __toESM(require("fs"));
|
|
2924
|
-
|
|
2925
|
-
|
|
3041
|
+
path8 = __toESM(require("path"));
|
|
3042
|
+
import_kleur6 = __toESM(require("kleur"));
|
|
2926
3043
|
init_manage_users();
|
|
2927
3044
|
init_logger();
|
|
3045
|
+
init_paths();
|
|
2928
3046
|
}
|
|
2929
3047
|
});
|
|
2930
3048
|
|
|
2931
3049
|
// src/environment/swarm-to-k8s.ts
|
|
2932
3050
|
var swarm_to_k8s_exports = {};
|
|
2933
|
-
var
|
|
3051
|
+
var path9, import_kleur7, import_core2;
|
|
2934
3052
|
var init_swarm_to_k8s = __esm({
|
|
2935
3053
|
"src/environment/swarm-to-k8s.ts"() {
|
|
2936
3054
|
"use strict";
|
|
2937
|
-
|
|
2938
|
-
|
|
3055
|
+
path9 = __toESM(require("path"));
|
|
3056
|
+
import_kleur7 = __toESM(require("kleur"));
|
|
2939
3057
|
init_logger();
|
|
2940
3058
|
init_utils();
|
|
2941
3059
|
init_templates();
|
|
@@ -2944,7 +3062,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2944
3062
|
init_github();
|
|
2945
3063
|
(async () => {
|
|
2946
3064
|
log(
|
|
2947
|
-
|
|
3065
|
+
import_kleur7.default.bold(
|
|
2948
3066
|
"------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
|
|
2949
3067
|
)
|
|
2950
3068
|
);
|
|
@@ -2975,7 +3093,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2975
3093
|
);
|
|
2976
3094
|
process.exit(0);
|
|
2977
3095
|
}
|
|
2978
|
-
log(
|
|
3096
|
+
log(import_kleur7.default.bold().underline("Migration properties:"));
|
|
2979
3097
|
log(` \u2713 Environment: ${environment}`);
|
|
2980
3098
|
const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
|
|
2981
3099
|
if (!old_inventory_path) {
|
|
@@ -2986,7 +3104,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2986
3104
|
);
|
|
2987
3105
|
process.exit(1);
|
|
2988
3106
|
}
|
|
2989
|
-
const ansible_inventory =
|
|
3107
|
+
const ansible_inventory = path9.join(old_inventory_path, environment + ".yml");
|
|
2990
3108
|
const data = readYamlFile(ansible_inventory);
|
|
2991
3109
|
log(` \u2713 Loaded old inventory file: ${ansible_inventory}`);
|
|
2992
3110
|
const master = dockerManagerFirst(data) || "";
|
|
@@ -3179,77 +3297,1295 @@ function buildCorrectionActionText(spec, typeStyle, flagsText, conditionalsText)
|
|
|
3179
3297
|
if (conditionalsText) {
|
|
3180
3298
|
lines.push(`${CONDITIONALS_PROPERTY_NAME}: ${conditionalsText}`);
|
|
3181
3299
|
}
|
|
3182
|
-
return `{
|
|
3183
|
-
${lines.join(",\n ")}
|
|
3184
|
-
}`;
|
|
3300
|
+
return `{
|
|
3301
|
+
${lines.join(",\n ")}
|
|
3302
|
+
}`;
|
|
3303
|
+
}
|
|
3304
|
+
function processFile(filePath, project) {
|
|
3305
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
3306
|
+
if (!sourceFile) return 0;
|
|
3307
|
+
let changes = 0;
|
|
3308
|
+
const relPath = import_path.default.relative(process.cwd(), filePath);
|
|
3309
|
+
const callExpressions = sourceFile.getDescendantsOfKind(
|
|
3310
|
+
import_ts_morph.SyntaxKind.CallExpression
|
|
3311
|
+
);
|
|
3312
|
+
for (const call of callExpressions) {
|
|
3313
|
+
const expression = call.getExpression();
|
|
3314
|
+
if (!import_ts_morph.Node.isIdentifier(expression) || expression.getText() !== DEFINE_CONFIG_NAME) {
|
|
3315
|
+
continue;
|
|
3316
|
+
}
|
|
3317
|
+
const args2 = call.getArguments();
|
|
3318
|
+
if (args2.length === 0) continue;
|
|
3319
|
+
const configArg = args2[0];
|
|
3320
|
+
if (!import_ts_morph.Node.isObjectLiteralExpression(configArg)) continue;
|
|
3321
|
+
const actionsProperty = configArg.getProperty(ACTIONS_PROPERTY_NAME);
|
|
3322
|
+
if (!actionsProperty || !import_ts_morph.Node.isPropertyAssignment(actionsProperty))
|
|
3323
|
+
continue;
|
|
3324
|
+
const actionsInitializer = actionsProperty.getInitializer();
|
|
3325
|
+
if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
|
|
3326
|
+
continue;
|
|
3327
|
+
const elements = actionsInitializer.getElements();
|
|
3328
|
+
const requestCorrectionIndex = elements.findIndex(
|
|
3329
|
+
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, REQUEST_CORRECTION_TYPE)
|
|
3330
|
+
);
|
|
3331
|
+
if (requestCorrectionIndex === -1) continue;
|
|
3332
|
+
const requestCorrection = elements[requestCorrectionIndex];
|
|
3333
|
+
const flagsText = getNonEmptyArrayPropertyText(
|
|
3334
|
+
requestCorrection,
|
|
3335
|
+
FLAGS_PROPERTY_NAME
|
|
3336
|
+
);
|
|
3337
|
+
const conditionalsText = getNonEmptyArrayPropertyText(
|
|
3338
|
+
requestCorrection,
|
|
3339
|
+
CONDITIONALS_PROPERTY_NAME
|
|
3340
|
+
);
|
|
3341
|
+
if (!flagsText && !conditionalsText) continue;
|
|
3342
|
+
const typeStyle = getTypeInitializerStyle(requestCorrection);
|
|
3343
|
+
let insertAt = requestCorrectionIndex + 1;
|
|
3344
|
+
for (const spec of CORRECTION_ACTIONS_TO_ADD) {
|
|
3345
|
+
const alreadyPresent = actionsInitializer.getElements().some(
|
|
3346
|
+
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, spec.actionType)
|
|
3347
|
+
);
|
|
3348
|
+
if (alreadyPresent) continue;
|
|
3349
|
+
const text = buildCorrectionActionText(
|
|
3350
|
+
spec,
|
|
3351
|
+
typeStyle,
|
|
3352
|
+
flagsText,
|
|
3353
|
+
conditionalsText
|
|
3354
|
+
);
|
|
3355
|
+
actionsInitializer.insertElement(insertAt, text);
|
|
3356
|
+
insertAt++;
|
|
3357
|
+
changes++;
|
|
3358
|
+
console.log(
|
|
3359
|
+
` [${relPath}] Added ${spec.actionType} action carrying over REQUEST_CORRECTION's flags/conditionals`
|
|
3360
|
+
);
|
|
3361
|
+
}
|
|
3362
|
+
}
|
|
3363
|
+
return changes;
|
|
3364
|
+
}
|
|
3365
|
+
async function main() {
|
|
3366
|
+
const srcDir = import_path.default.join(process.cwd(), "src");
|
|
3367
|
+
console.log(`Scanning for defineConfig calls in: ${srcDir}
|
|
3368
|
+
`);
|
|
3369
|
+
const project = new import_ts_morph.Project({
|
|
3370
|
+
tsConfigFilePath: import_path.default.resolve(srcDir, "../tsconfig.json"),
|
|
3371
|
+
skipAddingFilesFromTsConfig: false
|
|
3372
|
+
});
|
|
3373
|
+
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
3374
|
+
const fp = sf.getFilePath();
|
|
3375
|
+
return fp.includes("/src/") && !fp.includes("/node_modules/");
|
|
3376
|
+
});
|
|
3377
|
+
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3378
|
+
`);
|
|
3379
|
+
let totalChanges = 0;
|
|
3380
|
+
const modifiedFiles = [];
|
|
3381
|
+
for (const sourceFile of sourceFiles) {
|
|
3382
|
+
const filePath = sourceFile.getFilePath();
|
|
3383
|
+
const changes = processFile(filePath, project);
|
|
3384
|
+
if (changes > 0) {
|
|
3385
|
+
totalChanges += changes;
|
|
3386
|
+
modifiedFiles.push(filePath);
|
|
3387
|
+
}
|
|
3388
|
+
}
|
|
3389
|
+
if (modifiedFiles.length === 0) {
|
|
3390
|
+
console.log(
|
|
3391
|
+
"No REQUEST_CORRECTION actions with flags/conditionals found. Nothing to do."
|
|
3392
|
+
);
|
|
3393
|
+
return;
|
|
3394
|
+
}
|
|
3395
|
+
console.log(`
|
|
3396
|
+
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3397
|
+
for (const filePath of modifiedFiles) {
|
|
3398
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
3399
|
+
await sourceFile.save();
|
|
3400
|
+
console.log(` Saved: ${import_path.default.relative(process.cwd(), filePath)}`);
|
|
3401
|
+
}
|
|
3402
|
+
console.log(
|
|
3403
|
+
`
|
|
3404
|
+
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
3405
|
+
);
|
|
3406
|
+
}
|
|
3407
|
+
|
|
3408
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3409
|
+
var import_ts_morph2 = require("ts-morph");
|
|
3410
|
+
var import_fs2 = require("fs");
|
|
3411
|
+
var import_path2 = __toESM(require("path"));
|
|
3412
|
+
|
|
3413
|
+
// src/csv.ts
|
|
3414
|
+
var import_fs = require("fs");
|
|
3415
|
+
function parseCsvLine(line2) {
|
|
3416
|
+
const values = [];
|
|
3417
|
+
let value = "";
|
|
3418
|
+
let quoted = false;
|
|
3419
|
+
for (let index = 0; index < line2.length; index++) {
|
|
3420
|
+
const character = line2[index];
|
|
3421
|
+
if (quoted) {
|
|
3422
|
+
if (character !== '"') {
|
|
3423
|
+
value += character;
|
|
3424
|
+
} else if (line2[index + 1] === '"') {
|
|
3425
|
+
value += '"';
|
|
3426
|
+
index++;
|
|
3427
|
+
} else {
|
|
3428
|
+
quoted = false;
|
|
3429
|
+
}
|
|
3430
|
+
continue;
|
|
3431
|
+
}
|
|
3432
|
+
if (character === '"') {
|
|
3433
|
+
quoted = true;
|
|
3434
|
+
} else if (character === ",") {
|
|
3435
|
+
values.push(value);
|
|
3436
|
+
value = "";
|
|
3437
|
+
} else {
|
|
3438
|
+
value += character;
|
|
3439
|
+
}
|
|
3440
|
+
}
|
|
3441
|
+
values.push(value);
|
|
3442
|
+
return values;
|
|
3443
|
+
}
|
|
3444
|
+
function toCsvLine(values) {
|
|
3445
|
+
return values.map(
|
|
3446
|
+
(value) => /["\n,]/.test(value) ? `"${value.replace(/"/g, '""')}"` : value
|
|
3447
|
+
).join(",");
|
|
3448
|
+
}
|
|
3449
|
+
function idOf(line2) {
|
|
3450
|
+
const comma = line2.indexOf(",");
|
|
3451
|
+
return comma === -1 ? line2 : line2.slice(0, comma);
|
|
3452
|
+
}
|
|
3453
|
+
function readCsvFile(path10) {
|
|
3454
|
+
if (!(0, import_fs.existsSync)(path10)) {
|
|
3455
|
+
return void 0;
|
|
3456
|
+
}
|
|
3457
|
+
const contents = (0, import_fs.readFileSync)(path10, "utf8");
|
|
3458
|
+
const newline = contents.includes("\r\n") ? "\r\n" : "\n";
|
|
3459
|
+
const trailingNewline = /\r?\n$/.test(contents);
|
|
3460
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
3461
|
+
const body = lines.slice(1).filter((line2) => line2 !== "");
|
|
3462
|
+
return { header: lines[0], body, newline, trailingNewline };
|
|
3463
|
+
}
|
|
3464
|
+
function writeCsvFile(path10, file) {
|
|
3465
|
+
(0, import_fs.writeFileSync)(
|
|
3466
|
+
path10,
|
|
3467
|
+
[file.header, ...file.body].join(file.newline) + (file.trailingNewline ? file.newline : "")
|
|
3468
|
+
);
|
|
3469
|
+
}
|
|
3470
|
+
function addRows(file, rows) {
|
|
3471
|
+
const isSorted = file.body.every(
|
|
3472
|
+
(line2, index) => index === 0 || idOf(file.body[index - 1]) <= idOf(line2)
|
|
3473
|
+
);
|
|
3474
|
+
const added = [];
|
|
3475
|
+
for (const row of rows) {
|
|
3476
|
+
const id = idOf(row);
|
|
3477
|
+
if (file.body.some((line2) => idOf(line2) === id)) {
|
|
3478
|
+
continue;
|
|
3479
|
+
}
|
|
3480
|
+
const insertAt = isSorted ? file.body.findIndex((line2) => idOf(line2) > id) : -1;
|
|
3481
|
+
if (insertAt === -1) {
|
|
3482
|
+
file.body.push(row);
|
|
3483
|
+
} else {
|
|
3484
|
+
file.body.splice(insertAt, 0, row);
|
|
3485
|
+
}
|
|
3486
|
+
added.push(id);
|
|
3487
|
+
}
|
|
3488
|
+
return added;
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3491
|
+
// src/migrations/v2.1/add-recovery-link-notifications.ts
|
|
3492
|
+
var EMAIL_TEMPLATES_FILE = "src/api/notification/email-templates/index.ts";
|
|
3493
|
+
var SMS_SERVICE_FILE = "src/api/notification/sms-service.ts";
|
|
3494
|
+
var HANDLER_FILE = "src/api/notification/handler.ts";
|
|
3495
|
+
var ROUTES_FILE = "src/config/routes/userNotificationRoutes.ts";
|
|
3496
|
+
var EMAIL_TEMPLATE_DIR = "src/api/notification/email-templates/other";
|
|
3497
|
+
var NOTIFICATION_CSV = "src/translations/notification.csv";
|
|
3498
|
+
var LOGIN_CSV = "src/translations/login.csv";
|
|
3499
|
+
var TRIGGER_VARIABLE_OBJECT = "TriggerVariable";
|
|
3500
|
+
var TEMPLATES_OBJECT = "templates";
|
|
3501
|
+
var OTHER_TEMPLATES_OBJECT = "otherTemplates";
|
|
3502
|
+
var TRIGGER_TO_SMS_TEMPLATE_OBJECT = "TriggerToSMSTemplate";
|
|
3503
|
+
var CONVERT_PAYLOAD_FUNCTION = "convertPayloadToVariable";
|
|
3504
|
+
var ROUTES_FUNCTION = "getUserNotificationRoutes";
|
|
3505
|
+
var RECOVERY_EVENTS = [
|
|
3506
|
+
{
|
|
3507
|
+
id: "password-reset-link",
|
|
3508
|
+
constant: "PASSWORD_RESET_LINK",
|
|
3509
|
+
smsTemplate: "resetPasswordLinkNotification",
|
|
3510
|
+
emailSubject: "Reset your password",
|
|
3511
|
+
routeDescription: "Handles notification for password reset recovery link",
|
|
3512
|
+
heading: "Reset your password",
|
|
3513
|
+
reason: "Someone asked to reset the password for your {{applicationName}}\n account.",
|
|
3514
|
+
linkLabel: "Reset your password"
|
|
3515
|
+
},
|
|
3516
|
+
{
|
|
3517
|
+
id: "username-reminder-link",
|
|
3518
|
+
constant: "USERNAME_REMINDER_LINK",
|
|
3519
|
+
smsTemplate: "retrieveUsernameLinkNotification",
|
|
3520
|
+
emailSubject: "Retrieve your username",
|
|
3521
|
+
routeDescription: "Handles notification for username reminder recovery link",
|
|
3522
|
+
heading: "Retrieve your username",
|
|
3523
|
+
reason: "Someone asked for a reminder of the username for your\n {{applicationName}} account.",
|
|
3524
|
+
linkLabel: "Retrieve your username"
|
|
3525
|
+
}
|
|
3526
|
+
];
|
|
3527
|
+
var NOTIFICATION_CSV_ROWS = [
|
|
3528
|
+
`resetPasswordLinkNotification,The SMS message that is sent to a user containing a self-service password reset link,{{applicationName}}: reset your password using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : r\xE9initialisez votre mot de passe \xE0 l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`,
|
|
3529
|
+
`retrieveUsernameLinkNotification,The SMS message that is sent to a user containing a self-service username retrieval link,{{applicationName}}: retrieve your username using this link. It expires in 1 hour. {{{recoveryURL}}},{{applicationName}} : r\xE9cup\xE9rez votre nom d'utilisateur \xE0 l'aide de ce lien. Il expire dans 1 heure. {{{recoveryURL}}}`
|
|
3530
|
+
];
|
|
3531
|
+
var LOGIN_CSV_ROWS = [
|
|
3532
|
+
`buttons.backToLogin,"Label used to leave a screen that is waiting on an emailed link, where logging in is not yet possible",Back to login,Retour \xE0 la connexion`,
|
|
3533
|
+
`resetCredentials.recoveryInstructionsSent.body,"Body message for the recovery instructions sent page. Must not assert delivery, since the account may not exist.","If we found an account, you'll receive instructions for {forgottenItem, select, username {retrieving your username} other {resetting your password}}. The link expires in 1 hour.","Si nous trouvons un compte correspondant, vous recevrez les instructions pour {forgottenItem, select, username {r\xE9cup\xE9rer votre nom d'utilisateur} other {r\xE9initialiser votre mot de passe}}. Le lien expire dans 1 heure."`,
|
|
3534
|
+
`resetCredentials.recoveryInstructionsSent.title.email,Title for the recovery instructions sent page when notifications are delivered by email,Check your email,V\xE9rifiez votre e-mail`,
|
|
3535
|
+
`resetCredentials.recoveryInstructionsSent.title.phone,Title for the recovery instructions sent page when notifications are delivered by SMS,Check your phone,V\xE9rifiez votre t\xE9l\xE9phone`,
|
|
3536
|
+
`resetCredentials.recoveryLinkLanding.expired.body,"Body shown when a recovery link is invalid, expired, or already used. Must not reveal whether the underlying account exists.",This link is no longer valid. Request a new one to continue.,Ce lien n'est plus valide. Veuillez en demander un nouveau pour continuer.`,
|
|
3537
|
+
`resetCredentials.recoveryLinkLanding.expired.link,Link back to the forgotten item form shown on an expired/invalid recovery link,Start again,Recommencer`,
|
|
3538
|
+
`resetCredentials.recoveryLinkLanding.expired.title,"Title shown when a recovery link is invalid, expired, or already used",This link has expired,Ce lien a expir\xE9`
|
|
3539
|
+
];
|
|
3540
|
+
var skipped = [];
|
|
3541
|
+
function warnSkipped(message) {
|
|
3542
|
+
skipped.push(message);
|
|
3543
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3544
|
+
}
|
|
3545
|
+
function findObjectLiteral(declaration) {
|
|
3546
|
+
let expression = declaration?.getInitializer();
|
|
3547
|
+
while (expression && (import_ts_morph2.Node.isAsExpression(expression) || import_ts_morph2.Node.isSatisfiesExpression(expression))) {
|
|
3548
|
+
expression = expression.getExpression();
|
|
3549
|
+
}
|
|
3550
|
+
return expression && import_ts_morph2.Node.isObjectLiteralExpression(expression) ? expression : void 0;
|
|
3551
|
+
}
|
|
3552
|
+
function hasKeyFor(obj, key, constant) {
|
|
3553
|
+
const accepted = /* @__PURE__ */ new Set([
|
|
3554
|
+
`[TriggerEvent.${constant}]`,
|
|
3555
|
+
`['${key}']`,
|
|
3556
|
+
`["${key}"]`,
|
|
3557
|
+
`'${key}'`,
|
|
3558
|
+
`"${key}"`,
|
|
3559
|
+
key
|
|
3560
|
+
]);
|
|
3561
|
+
return obj.getProperties().some(
|
|
3562
|
+
(property) => import_ts_morph2.Node.isPropertyAssignment(property) && accepted.has(property.getName().trim())
|
|
3563
|
+
);
|
|
3564
|
+
}
|
|
3565
|
+
function renderKey(obj, key, constant) {
|
|
3566
|
+
const names = obj.getProperties().filter(import_ts_morph2.Node.isPropertyAssignment).map((property) => property.getName().trim());
|
|
3567
|
+
if (names.some((name) => name.startsWith("[TriggerEvent."))) {
|
|
3568
|
+
return `[TriggerEvent.${constant}]`;
|
|
3569
|
+
}
|
|
3570
|
+
if (names.some((name) => name.startsWith("["))) {
|
|
3571
|
+
return `['${key}']`;
|
|
3572
|
+
}
|
|
3573
|
+
return `'${key}'`;
|
|
3574
|
+
}
|
|
3575
|
+
function appendEntry(sourceFile, objectName, key, valueLines) {
|
|
3576
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3577
|
+
const properties = obj?.getProperties() ?? [];
|
|
3578
|
+
const lastProperty = properties[properties.length - 1];
|
|
3579
|
+
if (!lastProperty) return false;
|
|
3580
|
+
const indent = lastProperty.getIndentationText();
|
|
3581
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${key}: ${line2}` : line2}`).join("\n");
|
|
3582
|
+
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
3583
|
+
${entry}`);
|
|
3584
|
+
return true;
|
|
3585
|
+
}
|
|
3586
|
+
function objectHasKeyFor(sourceFile, objectName, key, constant) {
|
|
3587
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3588
|
+
return obj ? hasKeyFor(obj, key, constant) : false;
|
|
3589
|
+
}
|
|
3590
|
+
function renderKeyFor(sourceFile, objectName, key, constant) {
|
|
3591
|
+
const obj = findObjectLiteral(sourceFile.getVariableDeclaration(objectName));
|
|
3592
|
+
return obj ? renderKey(obj, key, constant) : `'${key}'`;
|
|
3593
|
+
}
|
|
3594
|
+
function updateEmailTemplates(project, cwd) {
|
|
3595
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, EMAIL_TEMPLATES_FILE));
|
|
3596
|
+
if (!sourceFile) {
|
|
3597
|
+
warnSkipped(`${EMAIL_TEMPLATES_FILE} not found; email templates not wired`);
|
|
3598
|
+
return;
|
|
3599
|
+
}
|
|
3600
|
+
const missingObject = [TRIGGER_VARIABLE_OBJECT, TEMPLATES_OBJECT].find(
|
|
3601
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3602
|
+
);
|
|
3603
|
+
if (missingObject) {
|
|
3604
|
+
warnSkipped(
|
|
3605
|
+
`Could not find '${missingObject}' in ${EMAIL_TEMPLATES_FILE}; email templates not wired`
|
|
3606
|
+
);
|
|
3607
|
+
return;
|
|
3608
|
+
}
|
|
3609
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3610
|
+
if (!objectHasKeyFor(
|
|
3611
|
+
sourceFile,
|
|
3612
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3613
|
+
event.id,
|
|
3614
|
+
event.constant
|
|
3615
|
+
) && appendEntry(
|
|
3616
|
+
sourceFile,
|
|
3617
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3618
|
+
renderKeyFor(
|
|
3619
|
+
sourceFile,
|
|
3620
|
+
TRIGGER_VARIABLE_OBJECT,
|
|
3621
|
+
event.id,
|
|
3622
|
+
event.constant
|
|
3623
|
+
),
|
|
3624
|
+
[
|
|
3625
|
+
"z.object({",
|
|
3626
|
+
" firstname: z.string(),",
|
|
3627
|
+
" applicationName: z.string(),",
|
|
3628
|
+
" countryLogo: z.string(),",
|
|
3629
|
+
" recoveryURL: z.string()",
|
|
3630
|
+
"})"
|
|
3631
|
+
]
|
|
3632
|
+
)) {
|
|
3633
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} variables`);
|
|
3634
|
+
}
|
|
3635
|
+
if (!objectHasKeyFor(
|
|
3636
|
+
sourceFile,
|
|
3637
|
+
TEMPLATES_OBJECT,
|
|
3638
|
+
event.id,
|
|
3639
|
+
event.constant
|
|
3640
|
+
) && appendEntry(
|
|
3641
|
+
sourceFile,
|
|
3642
|
+
TEMPLATES_OBJECT,
|
|
3643
|
+
renderKeyFor(sourceFile, TEMPLATES_OBJECT, event.id, event.constant),
|
|
3644
|
+
[
|
|
3645
|
+
"{",
|
|
3646
|
+
` type: '${event.id}',`,
|
|
3647
|
+
` subject: '${event.emailSubject}',`,
|
|
3648
|
+
` template: readOtherTemplate<TriggerVariable['${event.id}']>(`,
|
|
3649
|
+
` '${event.id}'`,
|
|
3650
|
+
" )",
|
|
3651
|
+
"}"
|
|
3652
|
+
]
|
|
3653
|
+
)) {
|
|
3654
|
+
console.log(` \u2713 ${EMAIL_TEMPLATES_FILE}: ${event.id} template`);
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
function updateSmsService(project, cwd) {
|
|
3659
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, SMS_SERVICE_FILE));
|
|
3660
|
+
if (!sourceFile) {
|
|
3661
|
+
warnSkipped(`${SMS_SERVICE_FILE} not found; SMS templates not wired`);
|
|
3662
|
+
return;
|
|
3663
|
+
}
|
|
3664
|
+
const missingObject = [
|
|
3665
|
+
OTHER_TEMPLATES_OBJECT,
|
|
3666
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT
|
|
3667
|
+
].find(
|
|
3668
|
+
(objectName) => !findObjectLiteral(sourceFile.getVariableDeclaration(objectName))
|
|
3669
|
+
);
|
|
3670
|
+
if (missingObject) {
|
|
3671
|
+
warnSkipped(
|
|
3672
|
+
`Could not find '${missingObject}' in ${SMS_SERVICE_FILE}; SMS templates not wired`
|
|
3673
|
+
);
|
|
3674
|
+
return;
|
|
3675
|
+
}
|
|
3676
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3677
|
+
if (!objectHasKeyFor(
|
|
3678
|
+
sourceFile,
|
|
3679
|
+
OTHER_TEMPLATES_OBJECT,
|
|
3680
|
+
event.smsTemplate,
|
|
3681
|
+
event.smsTemplate
|
|
3682
|
+
) && appendEntry(sourceFile, OTHER_TEMPLATES_OBJECT, event.smsTemplate, [
|
|
3683
|
+
`'${event.smsTemplate}'`
|
|
3684
|
+
])) {
|
|
3685
|
+
console.log(` \u2713 ${SMS_SERVICE_FILE}: ${event.smsTemplate}`);
|
|
3686
|
+
}
|
|
3687
|
+
if (!objectHasKeyFor(
|
|
3688
|
+
sourceFile,
|
|
3689
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3690
|
+
event.id,
|
|
3691
|
+
event.constant
|
|
3692
|
+
) && appendEntry(
|
|
3693
|
+
sourceFile,
|
|
3694
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3695
|
+
renderKeyFor(
|
|
3696
|
+
sourceFile,
|
|
3697
|
+
TRIGGER_TO_SMS_TEMPLATE_OBJECT,
|
|
3698
|
+
event.id,
|
|
3699
|
+
event.constant
|
|
3700
|
+
),
|
|
3701
|
+
[`'${event.smsTemplate}'`]
|
|
3702
|
+
)) {
|
|
3703
|
+
console.log(
|
|
3704
|
+
` \u2713 ${SMS_SERVICE_FILE}: ${event.id} -> ${event.smsTemplate}`
|
|
3705
|
+
);
|
|
3706
|
+
}
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
function updateHandler(project, cwd) {
|
|
3710
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, HANDLER_FILE));
|
|
3711
|
+
if (!sourceFile) {
|
|
3712
|
+
warnSkipped(`${HANDLER_FILE} not found; payload conversion not wired`);
|
|
3713
|
+
return;
|
|
3714
|
+
}
|
|
3715
|
+
const convertPayload = sourceFile.getFunction(CONVERT_PAYLOAD_FUNCTION);
|
|
3716
|
+
const caseBlock = convertPayload?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.SwitchStatement)?.getCaseBlock();
|
|
3717
|
+
if (!caseBlock) {
|
|
3718
|
+
warnSkipped(
|
|
3719
|
+
`Could not find a switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE}; payload conversion not wired`
|
|
3720
|
+
);
|
|
3721
|
+
return;
|
|
3722
|
+
}
|
|
3723
|
+
const missing = RECOVERY_EVENTS.filter(
|
|
3724
|
+
(event) => !caseBlock.getText().includes(`TriggerEvent.${event.constant}`) && !caseBlock.getText().includes(`'${event.id}'`)
|
|
3725
|
+
);
|
|
3726
|
+
if (missing.length === 0) return;
|
|
3727
|
+
const existingClauses = caseBlock.getClauses();
|
|
3728
|
+
if (existingClauses.length === 0) {
|
|
3729
|
+
warnSkipped(
|
|
3730
|
+
`The switch inside '${CONVERT_PAYLOAD_FUNCTION}' in ${HANDLER_FILE} has no cases; payload conversion not wired`
|
|
3731
|
+
);
|
|
3732
|
+
return;
|
|
3733
|
+
}
|
|
3734
|
+
const defaultClause = existingClauses.find(import_ts_morph2.Node.isDefaultClause);
|
|
3735
|
+
const anchor = defaultClause ?? existingClauses[existingClauses.length - 1];
|
|
3736
|
+
const indent = anchor.getIndentationText();
|
|
3737
|
+
const lines = [
|
|
3738
|
+
...missing.map((event) => `case TriggerEvent.${event.constant}:`),
|
|
3739
|
+
` return {`,
|
|
3740
|
+
` firstname,`,
|
|
3741
|
+
` applicationName: applicationConfig.APPLICATION_NAME,`,
|
|
3742
|
+
` countryLogo: COUNTRY_LOGO_URL,`,
|
|
3743
|
+
` recoveryURL: \`\${LOGIN_URL}recover?token=\${encodeURIComponent(payload.token)}\``,
|
|
3744
|
+
` }`
|
|
3745
|
+
];
|
|
3746
|
+
if (defaultClause) {
|
|
3747
|
+
caseBlock.insertText(
|
|
3748
|
+
anchor.getStart(),
|
|
3749
|
+
`${lines.map((line2, index) => index === 0 ? line2 : `${indent}${line2}`).join("\n")}
|
|
3750
|
+
${indent}`
|
|
3751
|
+
);
|
|
3752
|
+
} else {
|
|
3753
|
+
caseBlock.insertText(
|
|
3754
|
+
anchor.getEnd(),
|
|
3755
|
+
`
|
|
3756
|
+
${lines.map((line2) => `${indent}${line2}`).join("\n")}`
|
|
3757
|
+
);
|
|
3758
|
+
}
|
|
3759
|
+
for (const event of missing) {
|
|
3760
|
+
console.log(` \u2713 ${HANDLER_FILE}: ${event.id} case`);
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
function updateRoutes(project, cwd) {
|
|
3764
|
+
const sourceFile = project.getSourceFile(import_path2.default.join(cwd, ROUTES_FILE));
|
|
3765
|
+
if (!sourceFile) {
|
|
3766
|
+
warnSkipped(`${ROUTES_FILE} not found; trigger routes not registered`);
|
|
3767
|
+
return;
|
|
3768
|
+
}
|
|
3769
|
+
const routesFunction = sourceFile.getFunction(ROUTES_FUNCTION) ?? sourceFile.getFunctions().find((fn) => fn.isDefaultExport());
|
|
3770
|
+
const routesArray = routesFunction?.getFirstDescendantByKind(import_ts_morph2.SyntaxKind.ReturnStatement)?.getExpressionIfKind(import_ts_morph2.SyntaxKind.ArrayLiteralExpression);
|
|
3771
|
+
if (!routesArray) {
|
|
3772
|
+
warnSkipped(
|
|
3773
|
+
`Could not find the route array returned by '${ROUTES_FUNCTION}' in ${ROUTES_FILE}; trigger routes not registered`
|
|
3774
|
+
);
|
|
3775
|
+
return;
|
|
3776
|
+
}
|
|
3777
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3778
|
+
if (routesArray.getText().includes(`/trigger/user/${event.id}`)) continue;
|
|
3779
|
+
routesArray.addElement(`{
|
|
3780
|
+
method: 'POST',
|
|
3781
|
+
path: '/trigger/user/${event.id}',
|
|
3782
|
+
handler: makeNotificationHandler('${event.id}'),
|
|
3783
|
+
options: {
|
|
3784
|
+
auth: false,
|
|
3785
|
+
tags: ['api'],
|
|
3786
|
+
description: '${event.routeDescription}'
|
|
3787
|
+
}
|
|
3788
|
+
}`);
|
|
3789
|
+
console.log(` \u2713 ${ROUTES_FILE}: POST /trigger/user/${event.id}`);
|
|
3790
|
+
}
|
|
3791
|
+
}
|
|
3792
|
+
function renderEmailTemplate(event) {
|
|
3793
|
+
return `<!--
|
|
3794
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
3795
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3796
|
+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
3797
|
+
|
|
3798
|
+
OpenCRVS is also distributed under the terms of the Civil Registration
|
|
3799
|
+
& Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
3800
|
+
|
|
3801
|
+
Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
3802
|
+
-->
|
|
3803
|
+
<!doctype html>
|
|
3804
|
+
<html>
|
|
3805
|
+
<head>
|
|
3806
|
+
<link
|
|
3807
|
+
href="https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;700&display=swap"
|
|
3808
|
+
rel="stylesheet"
|
|
3809
|
+
/>
|
|
3810
|
+
<style type="text/css">
|
|
3811
|
+
body {
|
|
3812
|
+
font-family: 'Noto Sans', sans-serif;
|
|
3813
|
+
color: #222;
|
|
3814
|
+
padding: 16px 24px;
|
|
3815
|
+
}
|
|
3816
|
+
|
|
3817
|
+
h1 {
|
|
3818
|
+
font-size: 21px;
|
|
3819
|
+
margin-top: 32px;
|
|
3820
|
+
margin-bottom: 36px;
|
|
3821
|
+
font-weight: 700;
|
|
3822
|
+
}
|
|
3823
|
+
|
|
3824
|
+
p {
|
|
3825
|
+
font-weight: 400;
|
|
3826
|
+
font-size: 16px;
|
|
3827
|
+
line-height: 1.8;
|
|
3828
|
+
margin-bottom: 24px;
|
|
3829
|
+
}
|
|
3830
|
+
|
|
3831
|
+
i {
|
|
3832
|
+
color: #666;
|
|
3833
|
+
font-weight: 400;
|
|
3834
|
+
font-size: 16px;
|
|
3835
|
+
}
|
|
3836
|
+
</style>
|
|
3837
|
+
</head>
|
|
3838
|
+
|
|
3839
|
+
<body>
|
|
3840
|
+
<img
|
|
3841
|
+
src="{{countryLogo}}"
|
|
3842
|
+
alt="country_logo"
|
|
3843
|
+
style="max-height: 88px; max-width: 100%"
|
|
3844
|
+
/>
|
|
3845
|
+
<h1>${event.heading}</h1>
|
|
3846
|
+
<p>Hello {{firstname}},</p>
|
|
3847
|
+
<p>
|
|
3848
|
+
${event.reason}
|
|
3849
|
+
</p>
|
|
3850
|
+
|
|
3851
|
+
<div style="margin-top: 32px; margin-bottom: 32px">
|
|
3852
|
+
<a href="{{{recoveryURL}}}">${event.linkLabel}</a>
|
|
3853
|
+
</div>
|
|
3854
|
+
<br />
|
|
3855
|
+
<p>
|
|
3856
|
+
This link expires in 1 hour and can only be used once. If you did not
|
|
3857
|
+
request this, you can ignore this email.
|
|
3858
|
+
</p>
|
|
3859
|
+
<br />
|
|
3860
|
+
<p>
|
|
3861
|
+
Best regards, <br />
|
|
3862
|
+
{{applicationName}} Team
|
|
3863
|
+
</p>
|
|
3864
|
+
</body>
|
|
3865
|
+
</html>
|
|
3866
|
+
`;
|
|
3867
|
+
}
|
|
3868
|
+
function writeEmailTemplates(cwd) {
|
|
3869
|
+
const templateDir = import_path2.default.join(cwd, EMAIL_TEMPLATE_DIR);
|
|
3870
|
+
if (!(0, import_fs2.existsSync)(templateDir)) {
|
|
3871
|
+
warnSkipped(
|
|
3872
|
+
`${EMAIL_TEMPLATE_DIR} not found; recovery email bodies not written`
|
|
3873
|
+
);
|
|
3874
|
+
return;
|
|
3875
|
+
}
|
|
3876
|
+
for (const event of RECOVERY_EVENTS) {
|
|
3877
|
+
const templatePath = import_path2.default.join(templateDir, `${event.id}.html`);
|
|
3878
|
+
if ((0, import_fs2.existsSync)(templatePath)) continue;
|
|
3879
|
+
(0, import_fs2.writeFileSync)(templatePath, renderEmailTemplate(event));
|
|
3880
|
+
console.log(` \u2713 ${EMAIL_TEMPLATE_DIR}/${event.id}.html`);
|
|
3881
|
+
}
|
|
3882
|
+
}
|
|
3883
|
+
function addCsvRows(cwd, relativePath, rows) {
|
|
3884
|
+
const csvPath = import_path2.default.join(cwd, relativePath);
|
|
3885
|
+
const file = readCsvFile(csvPath);
|
|
3886
|
+
if (!file) {
|
|
3887
|
+
warnSkipped(`${relativePath} not found; translations not added`);
|
|
3888
|
+
return;
|
|
3889
|
+
}
|
|
3890
|
+
const added = addRows(file, rows);
|
|
3891
|
+
if (added.length === 0) return;
|
|
3892
|
+
for (const id of added) {
|
|
3893
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
3894
|
+
}
|
|
3895
|
+
writeCsvFile(csvPath, file);
|
|
3896
|
+
}
|
|
3897
|
+
async function main2() {
|
|
3898
|
+
const cwd = process.cwd();
|
|
3899
|
+
const tsConfigFilePath = import_path2.default.join(cwd, "tsconfig.json");
|
|
3900
|
+
console.log(
|
|
3901
|
+
"Registering the password-reset-link and username-reminder-link notifications...\n"
|
|
3902
|
+
);
|
|
3903
|
+
if (!(0, import_fs2.existsSync)(tsConfigFilePath)) {
|
|
3904
|
+
warnSkipped(
|
|
3905
|
+
`tsconfig.json not found in ${cwd}; notification wiring skipped entirely`
|
|
3906
|
+
);
|
|
3907
|
+
return;
|
|
3908
|
+
}
|
|
3909
|
+
const project = new import_ts_morph2.Project({
|
|
3910
|
+
tsConfigFilePath,
|
|
3911
|
+
skipAddingFilesFromTsConfig: false,
|
|
3912
|
+
// ts-morph indents inserted code with four spaces by default, which every
|
|
3913
|
+
// country config's prettier run would immediately undo.
|
|
3914
|
+
manipulationSettings: { indentationText: import_ts_morph2.IndentationText.TwoSpaces }
|
|
3915
|
+
});
|
|
3916
|
+
updateEmailTemplates(project, cwd);
|
|
3917
|
+
updateSmsService(project, cwd);
|
|
3918
|
+
updateHandler(project, cwd);
|
|
3919
|
+
updateRoutes(project, cwd);
|
|
3920
|
+
await project.save();
|
|
3921
|
+
writeEmailTemplates(cwd);
|
|
3922
|
+
addCsvRows(cwd, NOTIFICATION_CSV, NOTIFICATION_CSV_ROWS);
|
|
3923
|
+
addCsvRows(cwd, LOGIN_CSV, LOGIN_CSV_ROWS);
|
|
3924
|
+
if (skipped.length > 0) {
|
|
3925
|
+
console.warn(
|
|
3926
|
+
`
|
|
3927
|
+
\u26A0\uFE0F ${skipped.length} step(s) were skipped. Wire the following by hand before upgrading:`
|
|
3928
|
+
);
|
|
3929
|
+
for (const message of skipped) {
|
|
3930
|
+
console.warn(` - ${message}`);
|
|
3931
|
+
}
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
|
|
3935
|
+
// src/migrations/v2.1/add-translations.ts
|
|
3936
|
+
var import_path3 = __toESM(require("path"));
|
|
3937
|
+
|
|
3938
|
+
// src/translations/template.ts
|
|
3939
|
+
var REPOSITORY = "opencrvs/opencrvs-core";
|
|
3940
|
+
var TEMPLATE_TRANSLATIONS = "packages/countryconfig-template/src/translations";
|
|
3941
|
+
async function matchingRefs(namespace, prefix) {
|
|
3942
|
+
const url = `https://api.github.com/repos/${REPOSITORY}/git/matching-refs/${namespace}/${prefix}`;
|
|
3943
|
+
const response = await fetch(url, {
|
|
3944
|
+
headers: { accept: "application/vnd.github+json" }
|
|
3945
|
+
});
|
|
3946
|
+
if (!response.ok) {
|
|
3947
|
+
throw new Error(
|
|
3948
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3949
|
+
);
|
|
3950
|
+
}
|
|
3951
|
+
const refs = await response.json();
|
|
3952
|
+
const patchOf = (ref) => Number(ref.split(".").pop()) || 0;
|
|
3953
|
+
return refs.map(({ ref }) => ref.replace(/^refs\/(heads|tags)\//, "")).sort((a, b) => patchOf(b) - patchOf(a));
|
|
3954
|
+
}
|
|
3955
|
+
async function candidateRefs(version) {
|
|
3956
|
+
return [
|
|
3957
|
+
...await matchingRefs("heads", `release/${version}.`),
|
|
3958
|
+
...await matchingRefs("tags", `v${version}.`),
|
|
3959
|
+
"develop"
|
|
3960
|
+
];
|
|
3961
|
+
}
|
|
3962
|
+
async function fetchTemplate(refs, application) {
|
|
3963
|
+
for (const ref of refs) {
|
|
3964
|
+
const url = `https://raw.githubusercontent.com/${REPOSITORY}/${ref}/${TEMPLATE_TRANSLATIONS}/${application}.csv`;
|
|
3965
|
+
const response = await fetch(url);
|
|
3966
|
+
if (response.ok) {
|
|
3967
|
+
return { ref, contents: await response.text() };
|
|
3968
|
+
}
|
|
3969
|
+
if (response.status !== 404) {
|
|
3970
|
+
throw new Error(
|
|
3971
|
+
`GitHub answered ${response.status} ${response.statusText} for ${url}`
|
|
3972
|
+
);
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
return void 0;
|
|
3976
|
+
}
|
|
3977
|
+
|
|
3978
|
+
// src/migrations/v2.1/add-translations.ts
|
|
3979
|
+
var APPLICATIONS = ["client", "login"];
|
|
3980
|
+
var TARGET_VERSION = "2.1";
|
|
3981
|
+
var skipped2 = [];
|
|
3982
|
+
function warnSkipped2(message) {
|
|
3983
|
+
skipped2.push(message);
|
|
3984
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
3985
|
+
}
|
|
3986
|
+
function rowsToAdd(local, template) {
|
|
3987
|
+
const localColumns = parseCsvLine(local.header);
|
|
3988
|
+
const templateColumns = parseCsvLine(template.header);
|
|
3989
|
+
return template.body.filter((line2) => line2 !== "").map((line2) => {
|
|
3990
|
+
const values = parseCsvLine(line2);
|
|
3991
|
+
return toCsvLine(
|
|
3992
|
+
localColumns.map((column) => {
|
|
3993
|
+
const index = templateColumns.indexOf(column);
|
|
3994
|
+
return index === -1 ? "" : values[index] ?? "";
|
|
3995
|
+
})
|
|
3996
|
+
);
|
|
3997
|
+
});
|
|
3998
|
+
}
|
|
3999
|
+
async function updateApplication(cwd, refs, application) {
|
|
4000
|
+
const relativePath = `src/translations/${application}.csv`;
|
|
4001
|
+
const local = readCsvFile(import_path3.default.join(cwd, relativePath));
|
|
4002
|
+
if (!local) {
|
|
4003
|
+
warnSkipped2(`${relativePath} not found; translations not added`);
|
|
4004
|
+
return;
|
|
4005
|
+
}
|
|
4006
|
+
const fetched = await fetchTemplate(refs, application);
|
|
4007
|
+
if (!fetched) {
|
|
4008
|
+
warnSkipped2(
|
|
4009
|
+
`No ${application}.csv found in the ${TARGET_VERSION} country config template on GitHub; ${application}.csv not updated`
|
|
4010
|
+
);
|
|
4011
|
+
return;
|
|
4012
|
+
}
|
|
4013
|
+
const template = readTemplate(fetched.contents);
|
|
4014
|
+
const added = addRows(local, rowsToAdd(local, template));
|
|
4015
|
+
if (added.length === 0) {
|
|
4016
|
+
return;
|
|
4017
|
+
}
|
|
4018
|
+
try {
|
|
4019
|
+
writeCsvFile(import_path3.default.join(cwd, relativePath), local);
|
|
4020
|
+
} catch (error3) {
|
|
4021
|
+
warnSkipped2(
|
|
4022
|
+
`Could not write ${relativePath} (${error3.message}); translations not added`
|
|
4023
|
+
);
|
|
4024
|
+
return;
|
|
4025
|
+
}
|
|
4026
|
+
for (const id of added) {
|
|
4027
|
+
console.log(` \u2713 ${relativePath}: ${id}`);
|
|
4028
|
+
}
|
|
4029
|
+
}
|
|
4030
|
+
function readTemplate(contents) {
|
|
4031
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
4032
|
+
return {
|
|
4033
|
+
header: lines[0],
|
|
4034
|
+
body: lines.slice(1),
|
|
4035
|
+
newline: "\n",
|
|
4036
|
+
trailingNewline: true
|
|
4037
|
+
};
|
|
4038
|
+
}
|
|
4039
|
+
async function listRefs() {
|
|
4040
|
+
try {
|
|
4041
|
+
return await candidateRefs(TARGET_VERSION);
|
|
4042
|
+
} catch (error3) {
|
|
4043
|
+
warnSkipped2(
|
|
4044
|
+
`Could not list the ${TARGET_VERSION} refs on GitHub (${error3.message}); translations not added`
|
|
4045
|
+
);
|
|
4046
|
+
return void 0;
|
|
4047
|
+
}
|
|
4048
|
+
}
|
|
4049
|
+
async function main3() {
|
|
4050
|
+
const cwd = process.cwd();
|
|
4051
|
+
console.log("Adding the translation keys core gained this version...\n");
|
|
4052
|
+
const refs = await listRefs();
|
|
4053
|
+
if (refs) {
|
|
4054
|
+
for (const application of APPLICATIONS) {
|
|
4055
|
+
try {
|
|
4056
|
+
await updateApplication(cwd, refs, application);
|
|
4057
|
+
} catch (error3) {
|
|
4058
|
+
warnSkipped2(
|
|
4059
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${application}.csv not updated`
|
|
4060
|
+
);
|
|
4061
|
+
}
|
|
4062
|
+
}
|
|
4063
|
+
}
|
|
4064
|
+
if (skipped2.length > 0) {
|
|
4065
|
+
console.warn(
|
|
4066
|
+
`
|
|
4067
|
+
\u26A0\uFE0F ${skipped2.length} step(s) were skipped. Add the missing translations by hand before upgrading:`
|
|
4068
|
+
);
|
|
4069
|
+
for (const message of skipped2) {
|
|
4070
|
+
console.warn(` - ${message}`);
|
|
4071
|
+
}
|
|
4072
|
+
}
|
|
4073
|
+
}
|
|
4074
|
+
|
|
4075
|
+
// src/migrations/v2.1/enable-telemetry.ts
|
|
4076
|
+
var import_ts_morph3 = require("ts-morph");
|
|
4077
|
+
var import_fs3 = require("fs");
|
|
4078
|
+
var import_path4 = __toESM(require("path"));
|
|
4079
|
+
var HANDLER_FILE2 = "src/api/telemetry/handler.ts";
|
|
4080
|
+
var ENVIRONMENT_FILE = "src/environment.ts";
|
|
4081
|
+
var INDEX_FILE = "src/index.ts";
|
|
4082
|
+
var HANDLER_MODULE = "./api/telemetry/handler";
|
|
4083
|
+
var skipped3 = [];
|
|
4084
|
+
function warnSkipped3(message) {
|
|
4085
|
+
skipped3.push(message);
|
|
4086
|
+
console.warn(` \u26A0\uFE0F ${message}`);
|
|
4087
|
+
}
|
|
4088
|
+
var TELEMETRY_HANDLER_SOURCE = `/*
|
|
4089
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4090
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
4091
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
4092
|
+
*
|
|
4093
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
4094
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
4095
|
+
*
|
|
4096
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
4097
|
+
*/
|
|
4098
|
+
|
|
4099
|
+
import { Request, ResponseToolkit } from '@hapi/hapi'
|
|
4100
|
+
import * as Joi from 'joi'
|
|
4101
|
+
import { sendTelemetry, TelemetryReport } from '@opencrvs/toolkit/telemetry'
|
|
4102
|
+
import { env } from '@countryconfig/environment'
|
|
4103
|
+
import { logger } from '@countryconfig/logger'
|
|
4104
|
+
import { applicationConfig } from '@countryconfig/api/application/application-config'
|
|
4105
|
+
|
|
4106
|
+
/** Report the events service posts to \`/trigger/telemetry\`. */
|
|
4107
|
+
export const telemetrySchema = Joi.object({
|
|
4108
|
+
reported_at: Joi.string().isoDate().required(),
|
|
4109
|
+
app_version: Joi.string().optional(),
|
|
4110
|
+
metrics: Joi.object()
|
|
4111
|
+
.pattern(
|
|
4112
|
+
Joi.string(),
|
|
4113
|
+
Joi.alternatives(Joi.number(), Joi.string(), Joi.boolean())
|
|
4114
|
+
)
|
|
4115
|
+
.required()
|
|
4116
|
+
})
|
|
4117
|
+
|
|
4118
|
+
interface IncomingReport {
|
|
4119
|
+
reported_at: string
|
|
4120
|
+
app_version?: string
|
|
4121
|
+
metrics: Record<string, number | string | boolean>
|
|
4122
|
+
}
|
|
4123
|
+
|
|
4124
|
+
/** Logged once at countryconfig startup while telemetry is disabled. */
|
|
4125
|
+
export const TELEMETRY_DISABLED_NOTICE =
|
|
4126
|
+
'Telemetry is disabled. Help improve OpenCRVS by sharing anonymous, ' +
|
|
4127
|
+
'aggregate usage metrics (registration and certificate counts, active ' +
|
|
4128
|
+
'users, uptime) \u2014 no personal, health, or otherwise protected record data ' +
|
|
4129
|
+
'ever leaves your instance. Enable it by setting TELEMETRY_ENABLED=true on ' +
|
|
4130
|
+
'the countryconfig service.'
|
|
4131
|
+
|
|
4132
|
+
/**
|
|
4133
|
+
* Receives a usage report from the events service and, when telemetry is
|
|
4134
|
+
* enabled for this instance, stamps the instance identity onto it and forwards
|
|
4135
|
+
* it to the status service via the toolkit's \`sendTelemetry\` (which owns the
|
|
4136
|
+
* endpoint and payload schema). The events service is unaware of whether
|
|
4137
|
+
* telemetry is enabled or of the country code / domain / environment reported.
|
|
4138
|
+
*/
|
|
4139
|
+
export async function telemetryHandler(request: Request, h: ResponseToolkit) {
|
|
4140
|
+
// Only accept OpenCRVS *system* tokens (the events service's service
|
|
4141
|
+
// token has userType 'system'). A logged-in user's token is a 'user' token,
|
|
4142
|
+
// so a user cannot submit telemetry with their own credentials \u2014 and the
|
|
4143
|
+
// service-token endpoint is not reachable through the public gateway.
|
|
4144
|
+
const credentials = request.auth.credentials as
|
|
4145
|
+
| { userType?: string }
|
|
4146
|
+
| undefined
|
|
4147
|
+
if (credentials?.userType !== 'system') {
|
|
4148
|
+
logger.warn('Telemetry: rejected a request that is not from a system token')
|
|
4149
|
+
return h.response({ error: 'forbidden' }).code(403)
|
|
4150
|
+
}
|
|
4151
|
+
|
|
4152
|
+
if (!env.TELEMETRY_ENABLED) {
|
|
4153
|
+
// The encouraging notice is logged once at startup (see index.ts); keep the
|
|
4154
|
+
// per-report path quiet.
|
|
4155
|
+
return h.response({ status: 'skipped' }).code(200)
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
const incoming = request.payload as IncomingReport
|
|
4159
|
+
|
|
4160
|
+
// Only production instances report; staging, QA and local build the report
|
|
4161
|
+
// but never reach the status service. (This gate used to live in the
|
|
4162
|
+
// toolkit's sendTelemetry; each country config now owns it.)
|
|
4163
|
+
if (!env.isProduction) {
|
|
4164
|
+
logger.info(
|
|
4165
|
+
\`Telemetry: report for \${incoming.reported_at} was not sent \u2014 only production instances report\`
|
|
4166
|
+
)
|
|
4167
|
+
return h.response({ status: 'skipped' }).code(200)
|
|
4168
|
+
}
|
|
4169
|
+
|
|
4170
|
+
const report: TelemetryReport = {
|
|
4171
|
+
reported_at: incoming.reported_at,
|
|
4172
|
+
country_code: env.COUNTRY_CODE,
|
|
4173
|
+
organisation: env.ORGANISATION,
|
|
4174
|
+
// env.DOMAIN defaults to a wildcard for CORS in some setups; treat that as
|
|
4175
|
+
// "no domain" rather than reporting a literal "*".
|
|
4176
|
+
domain: env.DOMAIN && env.DOMAIN !== '*' ? env.DOMAIN : null,
|
|
4177
|
+
instance: {
|
|
4178
|
+
application_name: applicationConfig.APPLICATION_NAME,
|
|
4179
|
+
environment: env.ENVIRONMENT_NAME,
|
|
4180
|
+
app_version: incoming.app_version
|
|
4181
|
+
},
|
|
4182
|
+
metrics: incoming.metrics
|
|
4183
|
+
}
|
|
4184
|
+
|
|
4185
|
+
let result
|
|
4186
|
+
try {
|
|
4187
|
+
result = await sendTelemetry(report)
|
|
4188
|
+
} catch (error) {
|
|
4189
|
+
const message = error instanceof Error ? error.message : String(error)
|
|
4190
|
+
logger.error(\`Telemetry: forwarding to status service failed: \${message}\`)
|
|
4191
|
+
return h.response({ status: 'error' }).code(502)
|
|
4192
|
+
}
|
|
4193
|
+
|
|
4194
|
+
if (result.outcome === 'rejected') {
|
|
4195
|
+
logger.error(
|
|
4196
|
+
\`Telemetry: status service rejected report (HTTP \${result.status}): \${result.detail ?? ''}\`
|
|
4197
|
+
)
|
|
4198
|
+
return h.response({ status: 'error' }).code(502)
|
|
4199
|
+
}
|
|
4200
|
+
|
|
4201
|
+
logger.info(
|
|
4202
|
+
\`Telemetry: forwarded report for \${report.reported_at} to the status service\`
|
|
4203
|
+
)
|
|
4204
|
+
return h.response({ status: 'forwarded' }).code(202)
|
|
4205
|
+
}
|
|
4206
|
+
`;
|
|
4207
|
+
var TELEMETRY_DISABLED = {
|
|
4208
|
+
enabled: false,
|
|
4209
|
+
countryCode: "",
|
|
4210
|
+
organisation: ""
|
|
4211
|
+
};
|
|
4212
|
+
async function promptTelemetryConfig() {
|
|
4213
|
+
if (!process.stdin.isTTY) {
|
|
4214
|
+
return TELEMETRY_DISABLED;
|
|
4215
|
+
}
|
|
4216
|
+
const { confirm: confirm3, input: input4 } = await import("@inquirer/prompts");
|
|
4217
|
+
const enabled = await confirm3({
|
|
4218
|
+
message: "Enable anonymous usage telemetry to help improve OpenCRVS? Only aggregate metrics are shared \u2014 no personal or protected data.",
|
|
4219
|
+
default: true
|
|
4220
|
+
});
|
|
4221
|
+
if (!enabled) {
|
|
4222
|
+
return TELEMETRY_DISABLED;
|
|
4223
|
+
}
|
|
4224
|
+
const countryCode = (await input4({
|
|
4225
|
+
message: "Country code (ISO alpha-3, e.g. FAR):",
|
|
4226
|
+
validate: (value) => /^[A-Za-z]{3}$/.test(value.trim()) || "Enter a 3-letter ISO alpha-3 code."
|
|
4227
|
+
})).trim().toUpperCase();
|
|
4228
|
+
const organisation = (await input4({
|
|
4229
|
+
message: "Organisation running this instance:",
|
|
4230
|
+
validate: (value) => value.trim() !== "" || "Enter an organisation name."
|
|
4231
|
+
})).trim();
|
|
4232
|
+
return { enabled: true, countryCode, organisation };
|
|
4233
|
+
}
|
|
4234
|
+
function writeTelemetryHandler(cwd) {
|
|
4235
|
+
const handlerPath = import_path4.default.join(cwd, HANDLER_FILE2);
|
|
4236
|
+
if ((0, import_fs3.existsSync)(handlerPath)) {
|
|
4237
|
+
console.log(` ${HANDLER_FILE2} already present; left unchanged`);
|
|
4238
|
+
return;
|
|
4239
|
+
}
|
|
4240
|
+
(0, import_fs3.mkdirSync)(import_path4.default.dirname(handlerPath), { recursive: true });
|
|
4241
|
+
(0, import_fs3.writeFileSync)(handlerPath, TELEMETRY_HANDLER_SOURCE);
|
|
4242
|
+
console.log(` \u2713 ${HANDLER_FILE2}`);
|
|
4243
|
+
}
|
|
4244
|
+
function appendProperty(sourceFile, object2, name, valueLines) {
|
|
4245
|
+
const properties = object2.getProperties();
|
|
4246
|
+
const lastProperty = properties[properties.length - 1];
|
|
4247
|
+
if (!lastProperty) return false;
|
|
4248
|
+
const indent = lastProperty.getIndentationText();
|
|
4249
|
+
const entry = valueLines.map((line2, index) => `${indent}${index === 0 ? `${name}: ${line2}` : line2}`).join("\n");
|
|
4250
|
+
sourceFile.insertText(lastProperty.getEnd(), `,
|
|
4251
|
+
${entry}`);
|
|
4252
|
+
return true;
|
|
4253
|
+
}
|
|
4254
|
+
function ensureEnvalidNamedImports(sourceFile, names) {
|
|
4255
|
+
const importDeclaration = sourceFile.getImportDeclarations().find((declaration) => declaration.getModuleSpecifierValue() === "envalid");
|
|
4256
|
+
if (!importDeclaration) {
|
|
4257
|
+
warnSkipped3(
|
|
4258
|
+
`Could not find the 'envalid' import in ${ENVIRONMENT_FILE}; import { ${names.join(", ")} } by hand`
|
|
4259
|
+
);
|
|
4260
|
+
return;
|
|
4261
|
+
}
|
|
4262
|
+
const existing = new Set(
|
|
4263
|
+
importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4264
|
+
);
|
|
4265
|
+
for (const name of names) {
|
|
4266
|
+
if (!existing.has(name)) {
|
|
4267
|
+
importDeclaration.addNamedImport(name);
|
|
4268
|
+
}
|
|
4269
|
+
}
|
|
4270
|
+
}
|
|
4271
|
+
function getCleanEnvObject(sourceFile) {
|
|
4272
|
+
const options = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).find((call) => call.getExpression().getText() === "cleanEnv")?.getArguments()[1];
|
|
4273
|
+
return options && import_ts_morph3.Node.isObjectLiteralExpression(options) ? options : void 0;
|
|
4274
|
+
}
|
|
4275
|
+
function upsertEnvVar(sourceFile, name, kind, defaultExpr, desc, update) {
|
|
4276
|
+
const object2 = getCleanEnvObject(sourceFile);
|
|
4277
|
+
if (!object2) return;
|
|
4278
|
+
const existing = object2.getProperty(name);
|
|
4279
|
+
if (existing && import_ts_morph3.Node.isPropertyAssignment(existing)) {
|
|
4280
|
+
if (!update) return;
|
|
4281
|
+
const options = existing.getInitializerIfKind(import_ts_morph3.SyntaxKind.CallExpression)?.getArguments()[0];
|
|
4282
|
+
if (options && import_ts_morph3.Node.isObjectLiteralExpression(options)) {
|
|
4283
|
+
const defaultProperty = options.getProperty("default");
|
|
4284
|
+
if (defaultProperty && import_ts_morph3.Node.isPropertyAssignment(defaultProperty)) {
|
|
4285
|
+
defaultProperty.setInitializer(defaultExpr);
|
|
4286
|
+
} else {
|
|
4287
|
+
options.insertPropertyAssignment(0, {
|
|
4288
|
+
name: "default",
|
|
4289
|
+
initializer: defaultExpr
|
|
4290
|
+
});
|
|
4291
|
+
}
|
|
4292
|
+
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name} default set`);
|
|
4293
|
+
}
|
|
4294
|
+
return;
|
|
4295
|
+
}
|
|
4296
|
+
if (appendProperty(sourceFile, object2, name, [
|
|
4297
|
+
`${kind}({`,
|
|
4298
|
+
` default: ${defaultExpr},`,
|
|
4299
|
+
` desc: ${JSON.stringify(desc)}`,
|
|
4300
|
+
"})"
|
|
4301
|
+
])) {
|
|
4302
|
+
console.log(` \u2713 ${ENVIRONMENT_FILE}: ${name}`);
|
|
4303
|
+
}
|
|
4304
|
+
}
|
|
4305
|
+
function addEnvironmentVariables(project, cwd, config) {
|
|
4306
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4307
|
+
import_path4.default.join(cwd, ENVIRONMENT_FILE)
|
|
4308
|
+
);
|
|
4309
|
+
if (!sourceFile) {
|
|
4310
|
+
warnSkipped3(
|
|
4311
|
+
`${ENVIRONMENT_FILE} not found; add the telemetry env vars by hand`
|
|
4312
|
+
);
|
|
4313
|
+
return;
|
|
4314
|
+
}
|
|
4315
|
+
if (!getCleanEnvObject(sourceFile)) {
|
|
4316
|
+
warnSkipped3(
|
|
4317
|
+
`Could not find the cleanEnv(...) config object in ${ENVIRONMENT_FILE}; add the telemetry env vars by hand`
|
|
4318
|
+
);
|
|
4319
|
+
return;
|
|
4320
|
+
}
|
|
4321
|
+
ensureEnvalidNamedImports(sourceFile, ["bool", "str"]);
|
|
4322
|
+
upsertEnvVar(
|
|
4323
|
+
sourceFile,
|
|
4324
|
+
"TELEMETRY_ENABLED",
|
|
4325
|
+
"bool",
|
|
4326
|
+
config.enabled ? "true" : "false",
|
|
4327
|
+
"When true, usage telemetry received from the events service is forwarded to the OpenCRVS status service.",
|
|
4328
|
+
true
|
|
4329
|
+
);
|
|
4330
|
+
upsertEnvVar(
|
|
4331
|
+
sourceFile,
|
|
4332
|
+
"COUNTRY_CODE",
|
|
4333
|
+
"str",
|
|
4334
|
+
config.enabled ? JSON.stringify(config.countryCode) : `'FAR'`,
|
|
4335
|
+
"ISO-style country code of this instance, reported with telemetry.",
|
|
4336
|
+
config.enabled
|
|
4337
|
+
);
|
|
4338
|
+
upsertEnvVar(
|
|
4339
|
+
sourceFile,
|
|
4340
|
+
"ORGANISATION",
|
|
4341
|
+
"str",
|
|
4342
|
+
config.enabled ? JSON.stringify(config.organisation) : `''`,
|
|
4343
|
+
"Organisation running this instance, reported with telemetry. Empty by default.",
|
|
4344
|
+
config.enabled
|
|
4345
|
+
);
|
|
4346
|
+
upsertEnvVar(
|
|
4347
|
+
sourceFile,
|
|
4348
|
+
"ENVIRONMENT_NAME",
|
|
4349
|
+
"str",
|
|
4350
|
+
`'development'`,
|
|
4351
|
+
'Environment name (e.g. "production", "staging") reported as the telemetry environment.',
|
|
4352
|
+
false
|
|
4353
|
+
);
|
|
4354
|
+
}
|
|
4355
|
+
function ensureHandlerNamedImports(sourceFile, names) {
|
|
4356
|
+
const importDeclaration = sourceFile.getImportDeclarations().find(
|
|
4357
|
+
(declaration) => declaration.getModuleSpecifierValue() === HANDLER_MODULE
|
|
4358
|
+
);
|
|
4359
|
+
if (!importDeclaration) {
|
|
4360
|
+
sourceFile.addImportDeclaration({
|
|
4361
|
+
moduleSpecifier: HANDLER_MODULE,
|
|
4362
|
+
namedImports: names
|
|
4363
|
+
});
|
|
4364
|
+
console.log(` \u2713 ${INDEX_FILE}: import ${HANDLER_MODULE}`);
|
|
4365
|
+
return;
|
|
4366
|
+
}
|
|
4367
|
+
const existing = new Set(
|
|
4368
|
+
importDeclaration.getNamedImports().map((named) => named.getName())
|
|
4369
|
+
);
|
|
4370
|
+
const missing = names.filter((name) => !existing.has(name));
|
|
4371
|
+
for (const name of missing) {
|
|
4372
|
+
importDeclaration.addNamedImport(name);
|
|
4373
|
+
}
|
|
4374
|
+
if (missing.length > 0) {
|
|
4375
|
+
console.log(
|
|
4376
|
+
` \u2713 ${INDEX_FILE}: import ${missing.join(", ")} from ${HANDLER_MODULE}`
|
|
4377
|
+
);
|
|
4378
|
+
}
|
|
4379
|
+
}
|
|
4380
|
+
function wireIndex(project, cwd) {
|
|
4381
|
+
const sourceFile = project.addSourceFileAtPathIfExists(
|
|
4382
|
+
import_path4.default.join(cwd, INDEX_FILE)
|
|
4383
|
+
);
|
|
4384
|
+
if (!sourceFile) {
|
|
4385
|
+
warnSkipped3(
|
|
4386
|
+
`${INDEX_FILE} not found; register POST /trigger/telemetry and the startup notice by hand`
|
|
4387
|
+
);
|
|
4388
|
+
return;
|
|
4389
|
+
}
|
|
4390
|
+
ensureHandlerNamedImports(sourceFile, [
|
|
4391
|
+
"telemetryHandler",
|
|
4392
|
+
"telemetrySchema",
|
|
4393
|
+
"TELEMETRY_DISABLED_NOTICE"
|
|
4394
|
+
]);
|
|
4395
|
+
if (!sourceFile.getText().includes("path: '/trigger/telemetry'")) {
|
|
4396
|
+
const lastRouteStatement = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.CallExpression).filter((call) => call.getExpression().getText() === "server.route").map(
|
|
4397
|
+
(call) => call.getFirstAncestorByKind(import_ts_morph3.SyntaxKind.ExpressionStatement)
|
|
4398
|
+
).filter(
|
|
4399
|
+
(statement) => Boolean(statement)
|
|
4400
|
+
).pop();
|
|
4401
|
+
if (!lastRouteStatement) {
|
|
4402
|
+
warnSkipped3(
|
|
4403
|
+
`Could not find a server.route(...) call in ${INDEX_FILE}; register POST /trigger/telemetry by hand`
|
|
4404
|
+
);
|
|
4405
|
+
} else {
|
|
4406
|
+
const indent = lastRouteStatement.getIndentationText();
|
|
4407
|
+
const route = [
|
|
4408
|
+
`server.route({`,
|
|
4409
|
+
` method: 'POST',`,
|
|
4410
|
+
` path: '/trigger/telemetry',`,
|
|
4411
|
+
` handler: telemetryHandler,`,
|
|
4412
|
+
` options: {`,
|
|
4413
|
+
` tags: ['api', 'triggers'],`,
|
|
4414
|
+
` validate: {`,
|
|
4415
|
+
` payload: telemetrySchema`,
|
|
4416
|
+
` },`,
|
|
4417
|
+
` description:`,
|
|
4418
|
+
` 'Receives a usage report from the events service and forwards it to the status service when telemetry is enabled'`,
|
|
4419
|
+
` }`,
|
|
4420
|
+
`})`
|
|
4421
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4422
|
+
sourceFile.insertText(lastRouteStatement.getEnd(), `
|
|
4423
|
+
|
|
4424
|
+
${route}`);
|
|
4425
|
+
console.log(` \u2713 ${INDEX_FILE}: POST /trigger/telemetry`);
|
|
4426
|
+
}
|
|
4427
|
+
}
|
|
4428
|
+
if (!sourceFile.getText().includes("logger.info(TELEMETRY_DISABLED_NOTICE)")) {
|
|
4429
|
+
const startedLog = sourceFile.getDescendantsOfKind(import_ts_morph3.SyntaxKind.ExpressionStatement).find(
|
|
4430
|
+
(statement) => statement.getText().includes("Server successfully started")
|
|
4431
|
+
);
|
|
4432
|
+
if (!startedLog) {
|
|
4433
|
+
warnSkipped3(
|
|
4434
|
+
`Could not find the startup log in ${INDEX_FILE}; log TELEMETRY_DISABLED_NOTICE when TELEMETRY_ENABLED is false by hand`
|
|
4435
|
+
);
|
|
4436
|
+
} else {
|
|
4437
|
+
const indent = startedLog.getIndentationText();
|
|
4438
|
+
const notice = [
|
|
4439
|
+
`if (!env.TELEMETRY_ENABLED) {`,
|
|
4440
|
+
` logger.info(TELEMETRY_DISABLED_NOTICE)`,
|
|
4441
|
+
`}`
|
|
4442
|
+
].map((line2) => line2 ? `${indent}${line2}` : line2).join("\n");
|
|
4443
|
+
sourceFile.insertText(startedLog.getEnd(), `
|
|
4444
|
+
|
|
4445
|
+
${notice}`);
|
|
4446
|
+
console.log(` \u2713 ${INDEX_FILE}: telemetry-disabled startup notice`);
|
|
4447
|
+
if (!sourceFile.getImportDeclarations().some((d) => d.getModuleSpecifierValue() === "./environment")) {
|
|
4448
|
+
warnSkipped3(
|
|
4449
|
+
`The startup notice reads env.TELEMETRY_ENABLED but ${INDEX_FILE} does not import env from './environment'; import it by hand`
|
|
4450
|
+
);
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
}
|
|
3185
4454
|
}
|
|
3186
|
-
function
|
|
3187
|
-
const
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
4455
|
+
async function main4() {
|
|
4456
|
+
const cwd = process.cwd();
|
|
4457
|
+
const config = await promptTelemetryConfig();
|
|
4458
|
+
console.log(
|
|
4459
|
+
`
|
|
4460
|
+
Adding daily usage telemetry (${config.enabled ? `enabled for ${config.countryCode}` : "disabled"} by default)...
|
|
4461
|
+
`
|
|
3193
4462
|
);
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
4463
|
+
writeTelemetryHandler(cwd);
|
|
4464
|
+
const project = new import_ts_morph3.Project({
|
|
4465
|
+
// ts-morph indents inserted code with four spaces and double-quotes strings
|
|
4466
|
+
// by default, both of which the country config's prettier run would undo.
|
|
4467
|
+
manipulationSettings: {
|
|
4468
|
+
indentationText: import_ts_morph3.IndentationText.TwoSpaces,
|
|
4469
|
+
quoteKind: import_ts_morph3.QuoteKind.Single
|
|
3198
4470
|
}
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3205
|
-
|
|
3206
|
-
|
|
3207
|
-
if (!actionsInitializer || !import_ts_morph.Node.isArrayLiteralExpression(actionsInitializer))
|
|
3208
|
-
continue;
|
|
3209
|
-
const elements = actionsInitializer.getElements();
|
|
3210
|
-
const requestCorrectionIndex = elements.findIndex(
|
|
3211
|
-
(el) => import_ts_morph.Node.isObjectLiteralExpression(el) && isActionOfType(el, REQUEST_CORRECTION_TYPE)
|
|
3212
|
-
);
|
|
3213
|
-
if (requestCorrectionIndex === -1) continue;
|
|
3214
|
-
const requestCorrection = elements[requestCorrectionIndex];
|
|
3215
|
-
const flagsText = getNonEmptyArrayPropertyText(
|
|
3216
|
-
requestCorrection,
|
|
3217
|
-
FLAGS_PROPERTY_NAME
|
|
4471
|
+
});
|
|
4472
|
+
addEnvironmentVariables(project, cwd, config);
|
|
4473
|
+
wireIndex(project, cwd);
|
|
4474
|
+
await project.save();
|
|
4475
|
+
if (skipped3.length > 0) {
|
|
4476
|
+
console.warn(
|
|
4477
|
+
`
|
|
4478
|
+
\u26A0\uFE0F ${skipped3.length} telemetry step(s) were skipped. Wire the following by hand:`
|
|
3218
4479
|
);
|
|
3219
|
-
const
|
|
3220
|
-
|
|
3221
|
-
|
|
4480
|
+
for (const message of skipped3) {
|
|
4481
|
+
console.warn(` - ${message}`);
|
|
4482
|
+
}
|
|
4483
|
+
}
|
|
4484
|
+
}
|
|
4485
|
+
|
|
4486
|
+
// src/migrations/v2.1/rename-trigger-paths.ts
|
|
4487
|
+
var import_ts_morph4 = require("ts-morph");
|
|
4488
|
+
var import_path5 = __toESM(require("path"));
|
|
4489
|
+
var PATH_PREFIX_RENAMES = {
|
|
4490
|
+
"/triggers/user/": "/trigger/user/",
|
|
4491
|
+
"/triggers/system/": "/trigger/system/"
|
|
4492
|
+
};
|
|
4493
|
+
var STALE_PREFIX = "/triggers/";
|
|
4494
|
+
var METHOD_PROPERTY_NAME = "method";
|
|
4495
|
+
var PATH_PROPERTY_NAME = "path";
|
|
4496
|
+
var HTTP_VERBS = /* @__PURE__ */ new Set([
|
|
4497
|
+
"GET",
|
|
4498
|
+
"POST",
|
|
4499
|
+
"PUT",
|
|
4500
|
+
"PATCH",
|
|
4501
|
+
"DELETE",
|
|
4502
|
+
"OPTIONS",
|
|
4503
|
+
"HEAD",
|
|
4504
|
+
"*"
|
|
4505
|
+
]);
|
|
4506
|
+
function isRouteConfig(obj) {
|
|
4507
|
+
const methodProp = obj.getProperty(METHOD_PROPERTY_NAME);
|
|
4508
|
+
if (!methodProp || !import_ts_morph4.Node.isPropertyAssignment(methodProp)) return false;
|
|
4509
|
+
const methodInit = methodProp.getInitializer();
|
|
4510
|
+
if (!methodInit) return false;
|
|
4511
|
+
if (import_ts_morph4.Node.isStringLiteral(methodInit)) {
|
|
4512
|
+
if (!HTTP_VERBS.has(methodInit.getLiteralValue().toUpperCase()))
|
|
4513
|
+
return false;
|
|
4514
|
+
} else if (import_ts_morph4.Node.isArrayLiteralExpression(methodInit)) {
|
|
4515
|
+
const allVerbs = methodInit.getElements().every(
|
|
4516
|
+
(el) => import_ts_morph4.Node.isStringLiteral(el) && HTTP_VERBS.has(el.getLiteralValue().toUpperCase())
|
|
3222
4517
|
);
|
|
3223
|
-
if (!
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
4518
|
+
if (!allVerbs) return false;
|
|
4519
|
+
} else {
|
|
4520
|
+
return false;
|
|
4521
|
+
}
|
|
4522
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
4523
|
+
if (!pathProp || !import_ts_morph4.Node.isPropertyAssignment(pathProp)) return false;
|
|
4524
|
+
const pathInit = pathProp.getInitializer();
|
|
4525
|
+
return !!pathInit && import_ts_morph4.Node.isStringLiteral(pathInit);
|
|
4526
|
+
}
|
|
4527
|
+
function renameRoutePath(obj) {
|
|
4528
|
+
const pathProp = obj.getProperty(PATH_PROPERTY_NAME);
|
|
4529
|
+
if (!pathProp || !import_ts_morph4.Node.isPropertyAssignment(pathProp)) return null;
|
|
4530
|
+
const pathInit = pathProp.getInitializer();
|
|
4531
|
+
if (!pathInit || !import_ts_morph4.Node.isStringLiteral(pathInit)) return null;
|
|
4532
|
+
const oldPath = pathInit.getLiteralValue();
|
|
4533
|
+
const match = Object.entries(PATH_PREFIX_RENAMES).find(
|
|
4534
|
+
([from2]) => oldPath.startsWith(from2)
|
|
4535
|
+
);
|
|
4536
|
+
if (!match) return null;
|
|
4537
|
+
const [from, to] = match;
|
|
4538
|
+
const newPath = to + oldPath.slice(from.length);
|
|
4539
|
+
pathInit.replaceWithText(`'${newPath}'`);
|
|
4540
|
+
return newPath;
|
|
4541
|
+
}
|
|
4542
|
+
function processFile2(filePath, project) {
|
|
4543
|
+
const sourceFile = project.getSourceFile(filePath);
|
|
4544
|
+
if (!sourceFile) return 0;
|
|
4545
|
+
let renamedCount = 0;
|
|
4546
|
+
const relPath = import_path5.default.relative(process.cwd(), filePath);
|
|
4547
|
+
const candidates = sourceFile.getDescendantsOfKind(
|
|
4548
|
+
import_ts_morph4.SyntaxKind.ObjectLiteralExpression
|
|
4549
|
+
);
|
|
4550
|
+
for (const obj of candidates) {
|
|
4551
|
+
if (!isRouteConfig(obj)) continue;
|
|
4552
|
+
const newPath = renameRoutePath(obj);
|
|
4553
|
+
if (newPath) {
|
|
4554
|
+
renamedCount++;
|
|
4555
|
+
console.log(` [${relPath}] Renamed route path \u2192 '${newPath}'`);
|
|
3243
4556
|
}
|
|
3244
4557
|
}
|
|
3245
|
-
return
|
|
4558
|
+
return renamedCount;
|
|
3246
4559
|
}
|
|
3247
|
-
|
|
3248
|
-
const
|
|
3249
|
-
|
|
4560
|
+
function warnAboutStalePaths(sourceFiles) {
|
|
4561
|
+
const stale = [];
|
|
4562
|
+
for (const sourceFile of sourceFiles) {
|
|
4563
|
+
const relPath = import_path5.default.relative(process.cwd(), sourceFile.getFilePath());
|
|
4564
|
+
const lines = sourceFile.getFullText().split("\n");
|
|
4565
|
+
lines.forEach((line2, index) => {
|
|
4566
|
+
if (line2.includes(STALE_PREFIX)) {
|
|
4567
|
+
stale.push(` ${relPath}:${index + 1}: ${line2.trim()}`);
|
|
4568
|
+
}
|
|
4569
|
+
});
|
|
4570
|
+
}
|
|
4571
|
+
if (stale.length === 0) return;
|
|
4572
|
+
console.log(
|
|
4573
|
+
`
|
|
4574
|
+
WARNING: ${stale.length} remaining '${STALE_PREFIX}' reference(s) need to be renamed by hand:`
|
|
4575
|
+
);
|
|
4576
|
+
console.log(stale.join("\n"));
|
|
4577
|
+
}
|
|
4578
|
+
async function main5() {
|
|
4579
|
+
const srcDir = import_path5.default.join(process.cwd(), "src");
|
|
4580
|
+
console.log(`Scanning for Hapi route configs in: ${srcDir}
|
|
3250
4581
|
`);
|
|
3251
|
-
|
|
3252
|
-
|
|
4582
|
+
console.log("Active path renames:");
|
|
4583
|
+
for (const [from, to] of Object.entries(PATH_PREFIX_RENAMES)) {
|
|
4584
|
+
console.log(` '${from}*' \u2192 '${to}*'`);
|
|
4585
|
+
}
|
|
4586
|
+
console.log();
|
|
4587
|
+
const project = new import_ts_morph4.Project({
|
|
4588
|
+
tsConfigFilePath: import_path5.default.resolve(srcDir, "../tsconfig.json"),
|
|
3253
4589
|
skipAddingFilesFromTsConfig: false
|
|
3254
4590
|
});
|
|
3255
4591
|
const sourceFiles = project.getSourceFiles().filter((sf) => {
|
|
@@ -3258,43 +4594,45 @@ async function main() {
|
|
|
3258
4594
|
});
|
|
3259
4595
|
console.log(`Found ${sourceFiles.length} source file(s) to analyse.
|
|
3260
4596
|
`);
|
|
3261
|
-
let
|
|
4597
|
+
let totalRenamed = 0;
|
|
3262
4598
|
const modifiedFiles = [];
|
|
3263
4599
|
for (const sourceFile of sourceFiles) {
|
|
3264
4600
|
const filePath = sourceFile.getFilePath();
|
|
3265
|
-
const
|
|
3266
|
-
if (
|
|
3267
|
-
|
|
4601
|
+
const renamed = processFile2(filePath, project);
|
|
4602
|
+
if (renamed > 0) {
|
|
4603
|
+
totalRenamed += renamed;
|
|
3268
4604
|
modifiedFiles.push(filePath);
|
|
3269
4605
|
}
|
|
3270
4606
|
}
|
|
3271
4607
|
if (modifiedFiles.length === 0) {
|
|
3272
|
-
console.log(
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
return;
|
|
3276
|
-
}
|
|
3277
|
-
console.log(`
|
|
4608
|
+
console.log("No trigger route paths to rename.");
|
|
4609
|
+
} else {
|
|
4610
|
+
console.log(`
|
|
3278
4611
|
Saving ${modifiedFiles.length} modified file(s)...`);
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
4612
|
+
for (const filePath of modifiedFiles) {
|
|
4613
|
+
const sourceFile = project.getSourceFileOrThrow(filePath);
|
|
4614
|
+
await sourceFile.save();
|
|
4615
|
+
console.log(` Saved: ${import_path5.default.relative(process.cwd(), filePath)}`);
|
|
4616
|
+
}
|
|
4617
|
+
console.log(`
|
|
4618
|
+
Done. Renamed ${totalRenamed} route path(s).`);
|
|
3283
4619
|
}
|
|
3284
|
-
|
|
3285
|
-
`
|
|
3286
|
-
Done. Added ${totalChanges} correction action config(s) across ${modifiedFiles.length} file(s).`
|
|
3287
|
-
);
|
|
4620
|
+
warnAboutStalePaths(sourceFiles);
|
|
3288
4621
|
}
|
|
3289
4622
|
|
|
3290
4623
|
// src/migrations/v2.1/index.ts
|
|
3291
4624
|
async function runUpgrade(dockerSwarm) {
|
|
3292
4625
|
await main();
|
|
4626
|
+
await main5();
|
|
4627
|
+
await main2();
|
|
4628
|
+
await main3();
|
|
4629
|
+
await main4();
|
|
3293
4630
|
}
|
|
3294
4631
|
|
|
3295
4632
|
// src/environment/index.ts
|
|
3296
|
-
var
|
|
3297
|
-
var
|
|
4633
|
+
var import_fs8 = require("fs");
|
|
4634
|
+
var import_path10 = require("path");
|
|
4635
|
+
init_paths();
|
|
3298
4636
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
3299
4637
|
".github/workflows",
|
|
3300
4638
|
"environments",
|
|
@@ -3304,7 +4642,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3304
4642
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
3305
4643
|
(directory) => {
|
|
3306
4644
|
try {
|
|
3307
|
-
return !(0,
|
|
4645
|
+
return !(0, import_fs8.statSync)((0, import_path10.resolve)(repositoryRoot, directory)).isDirectory();
|
|
3308
4646
|
} catch {
|
|
3309
4647
|
return true;
|
|
3310
4648
|
}
|
|
@@ -3318,7 +4656,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3318
4656
|
}
|
|
3319
4657
|
async function runEnvironmentInit() {
|
|
3320
4658
|
validateRepositoryStructure();
|
|
3321
|
-
|
|
4659
|
+
assertNoOldInventoryLayout();
|
|
4660
|
+
const { runSetupEnvironment: runSetupEnvironment2 } = await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
4661
|
+
await runSetupEnvironment2();
|
|
4662
|
+
}
|
|
4663
|
+
async function runEnvironmentUpgrade() {
|
|
4664
|
+
validateRepositoryStructure();
|
|
4665
|
+
const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
4666
|
+
await upgradeEnvironmentLayout2();
|
|
3322
4667
|
}
|
|
3323
4668
|
async function runEnvironmentUpdateWorkflows() {
|
|
3324
4669
|
validateRepositoryStructure();
|
|
@@ -3335,6 +4680,396 @@ async function runEnvironmentSwarmToK8s() {
|
|
|
3335
4680
|
await Promise.resolve().then(() => (init_swarm_to_k8s(), swarm_to_k8s_exports));
|
|
3336
4681
|
}
|
|
3337
4682
|
|
|
4683
|
+
// src/verify/endpoints.ts
|
|
4684
|
+
var import_colors = require("kleur/colors");
|
|
4685
|
+
var z = __toESM(require("zod/v4"));
|
|
4686
|
+
var REQUEST_TIMEOUT_MS = 15e3;
|
|
4687
|
+
var DEFAULT_TARGET_URL = "http://localhost:3040";
|
|
4688
|
+
var REQUIRED_PUBLIC_ENDPOINTS = [
|
|
4689
|
+
{ method: "GET", path: "/client-config.js" },
|
|
4690
|
+
{ method: "GET", path: "/login-config.js" },
|
|
4691
|
+
{ method: "GET", path: "/handlebars.js" },
|
|
4692
|
+
{ method: "GET", path: "/content/client" },
|
|
4693
|
+
{ method: "GET", path: "/content/login" },
|
|
4694
|
+
{ method: "GET", path: "/content/map.geojson" },
|
|
4695
|
+
{ method: "GET", path: "/content/country-logo" },
|
|
4696
|
+
{ method: "GET", path: "/config/application" },
|
|
4697
|
+
{ method: "GET", path: "/config/workqueues" },
|
|
4698
|
+
{ method: "GET", path: "/config/locations" },
|
|
4699
|
+
{ method: "GET", path: "/config/roles" },
|
|
4700
|
+
{ method: "GET", path: "/config/events" }
|
|
4701
|
+
];
|
|
4702
|
+
var PROBE_SEGMENT = "verify-endpoints-probe";
|
|
4703
|
+
var SECURED_TRIGGER_USER_EVENTS = [
|
|
4704
|
+
"user-created",
|
|
4705
|
+
"user-updated",
|
|
4706
|
+
"username-reminder",
|
|
4707
|
+
"reset-password",
|
|
4708
|
+
"reset-password-by-admin",
|
|
4709
|
+
"password-reset-link",
|
|
4710
|
+
"username-reminder-link",
|
|
4711
|
+
"resend-invite",
|
|
4712
|
+
"2fa",
|
|
4713
|
+
"all-user-notification",
|
|
4714
|
+
"change-phone-number",
|
|
4715
|
+
"change-email-address"
|
|
4716
|
+
];
|
|
4717
|
+
var SECURED_ENDPOINTS = [
|
|
4718
|
+
...SECURED_TRIGGER_USER_EVENTS.map(
|
|
4719
|
+
(event) => ({
|
|
4720
|
+
method: "POST",
|
|
4721
|
+
path: `/trigger/user/${event}`
|
|
4722
|
+
})
|
|
4723
|
+
),
|
|
4724
|
+
{ method: "POST", path: "/trigger/telemetry" },
|
|
4725
|
+
{ method: "GET", path: "/trigger/system/ready" },
|
|
4726
|
+
{
|
|
4727
|
+
method: "GET",
|
|
4728
|
+
path: `/certificates/${PROBE_SEGMENT}`,
|
|
4729
|
+
label: "/certificates/{id}"
|
|
4730
|
+
},
|
|
4731
|
+
{ method: "GET", path: "/certificates" },
|
|
4732
|
+
{ method: "GET", path: "/config/users" }
|
|
4733
|
+
];
|
|
4734
|
+
var FALLBACK_EVENT_TRIGGERS = [
|
|
4735
|
+
{
|
|
4736
|
+
method: "POST",
|
|
4737
|
+
path: `/trigger/events/${PROBE_SEGMENT}/actions/${PROBE_SEGMENT}`,
|
|
4738
|
+
label: "/trigger/events/{event}/actions/{action}"
|
|
4739
|
+
},
|
|
4740
|
+
{
|
|
4741
|
+
method: "POST",
|
|
4742
|
+
path: `/trigger/events/birth/actions/${PROBE_SEGMENT}`,
|
|
4743
|
+
label: "/trigger/events/birth/actions/{action}"
|
|
4744
|
+
},
|
|
4745
|
+
{
|
|
4746
|
+
method: "POST",
|
|
4747
|
+
path: `/trigger/events/death/actions/${PROBE_SEGMENT}`,
|
|
4748
|
+
label: "/trigger/events/death/actions/{action}"
|
|
4749
|
+
}
|
|
4750
|
+
];
|
|
4751
|
+
var isSuccess = (status) => status !== "error" && status >= 200 && status < 300;
|
|
4752
|
+
var requiresAuthOrAbsent = (status) => status === 401 || status === 403 || status === 404;
|
|
4753
|
+
async function requestStatus(url, method) {
|
|
4754
|
+
try {
|
|
4755
|
+
const response = await fetch(url, {
|
|
4756
|
+
method,
|
|
4757
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS),
|
|
4758
|
+
// Sent without an Authorization header on purpose. A secured route
|
|
4759
|
+
// rejects with 401/403 before ever reading the body.
|
|
4760
|
+
headers: method === "POST" ? { "Content-Type": "application/json" } : void 0,
|
|
4761
|
+
body: method === "POST" ? "{}" : void 0
|
|
4762
|
+
});
|
|
4763
|
+
return response.status;
|
|
4764
|
+
} catch {
|
|
4765
|
+
return "error";
|
|
4766
|
+
}
|
|
4767
|
+
}
|
|
4768
|
+
function toEventTriggerConfig(value) {
|
|
4769
|
+
if (typeof value !== "object" || value === null) {
|
|
4770
|
+
return null;
|
|
4771
|
+
}
|
|
4772
|
+
const record2 = value;
|
|
4773
|
+
if (typeof record2.id !== "string") {
|
|
4774
|
+
return null;
|
|
4775
|
+
}
|
|
4776
|
+
const actions = Array.isArray(record2.actions) ? Array.from(
|
|
4777
|
+
new Set(
|
|
4778
|
+
record2.actions.map((action) => {
|
|
4779
|
+
if (typeof action !== "object" || action === null) {
|
|
4780
|
+
return null;
|
|
4781
|
+
}
|
|
4782
|
+
const type = action.type;
|
|
4783
|
+
return typeof type === "string" ? type : null;
|
|
4784
|
+
}).filter((type) => type !== null)
|
|
4785
|
+
)
|
|
4786
|
+
) : [];
|
|
4787
|
+
return { id: record2.id, actions };
|
|
4788
|
+
}
|
|
4789
|
+
async function fetchEventConfigs(baseUrl) {
|
|
4790
|
+
try {
|
|
4791
|
+
const response = await fetch(`${baseUrl}/config/events`, {
|
|
4792
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
4793
|
+
});
|
|
4794
|
+
if (!response.ok) {
|
|
4795
|
+
return null;
|
|
4796
|
+
}
|
|
4797
|
+
const body = await response.json();
|
|
4798
|
+
if (!Array.isArray(body)) {
|
|
4799
|
+
return null;
|
|
4800
|
+
}
|
|
4801
|
+
return body.map(toEventTriggerConfig).filter((config) => config !== null);
|
|
4802
|
+
} catch {
|
|
4803
|
+
return null;
|
|
4804
|
+
}
|
|
4805
|
+
}
|
|
4806
|
+
function resolveBaseUrl(input4) {
|
|
4807
|
+
const withProtocol = /^https?:\/\//i.test(input4) ? input4 : `https://${input4}`;
|
|
4808
|
+
return withProtocol.replace(/\/+$/, "");
|
|
4809
|
+
}
|
|
4810
|
+
function describeStatus(status) {
|
|
4811
|
+
return status === "error" ? "no response" : `HTTP ${status}`;
|
|
4812
|
+
}
|
|
4813
|
+
function endpointLabel(check) {
|
|
4814
|
+
const shown = check.label ?? check.path;
|
|
4815
|
+
const suffix = check.label ? (0, import_colors.dim)(` \u2192 ${check.path}`) : "";
|
|
4816
|
+
return `${check.method} ${shown}${suffix}`;
|
|
4817
|
+
}
|
|
4818
|
+
function line(ok, label, detail) {
|
|
4819
|
+
const mark = ok ? (0, import_colors.green)("\u2713") : (0, import_colors.red)("\u2717");
|
|
4820
|
+
return ` ${mark} ${label} ${(0, import_colors.dim)(`(${detail})`)}`;
|
|
4821
|
+
}
|
|
4822
|
+
function securedDetail(status) {
|
|
4823
|
+
if (status === 401 || status === 403) {
|
|
4824
|
+
return `${describeStatus(status)} \u2014 auth required`;
|
|
4825
|
+
}
|
|
4826
|
+
if (status === 404) {
|
|
4827
|
+
return `${describeStatus(status)} \u2014 not implemented`;
|
|
4828
|
+
}
|
|
4829
|
+
if (status === "error") {
|
|
4830
|
+
return `${describeStatus(status)} \u2014 request failed`;
|
|
4831
|
+
}
|
|
4832
|
+
return `${describeStatus(status)} \u2014 INSECURE: ensure this endpoint requires authentication!`;
|
|
4833
|
+
}
|
|
4834
|
+
var TEMPLATE_VERSION = "2.1";
|
|
4835
|
+
var TRANSLATED_APPLICATIONS = ["client", "login"];
|
|
4836
|
+
function readTemplateTranslations(contents) {
|
|
4837
|
+
const lines = contents.replace(/\r?\n$/, "").split(/\r?\n/);
|
|
4838
|
+
return {
|
|
4839
|
+
ids: lines.slice(1).filter((line2) => line2 !== "").map(idOf),
|
|
4840
|
+
languages: parseCsvLine(lines[0]).filter(
|
|
4841
|
+
(column) => column !== "id" && column !== "description"
|
|
4842
|
+
)
|
|
4843
|
+
};
|
|
4844
|
+
}
|
|
4845
|
+
var ServedTranslations = z.object({
|
|
4846
|
+
languages: z.array(
|
|
4847
|
+
z.object({
|
|
4848
|
+
lang: z.string(),
|
|
4849
|
+
messages: z.record(z.string(), z.string())
|
|
4850
|
+
})
|
|
4851
|
+
)
|
|
4852
|
+
});
|
|
4853
|
+
async function fetchServedTranslations(baseUrl, application) {
|
|
4854
|
+
try {
|
|
4855
|
+
const response = await fetch(`${baseUrl}/content/${application}`, {
|
|
4856
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
4857
|
+
});
|
|
4858
|
+
if (!response.ok) {
|
|
4859
|
+
return null;
|
|
4860
|
+
}
|
|
4861
|
+
const parsed = ServedTranslations.safeParse(await response.json());
|
|
4862
|
+
return parsed.success ? parsed.data.languages : null;
|
|
4863
|
+
} catch {
|
|
4864
|
+
return null;
|
|
4865
|
+
}
|
|
4866
|
+
}
|
|
4867
|
+
var MISSING_IDS_SHOWN = 10;
|
|
4868
|
+
async function verifyTranslations(baseUrl) {
|
|
4869
|
+
let refs;
|
|
4870
|
+
try {
|
|
4871
|
+
refs = await candidateRefs(TEMPLATE_VERSION);
|
|
4872
|
+
} catch (error3) {
|
|
4873
|
+
console.log(
|
|
4874
|
+
" " + (0, import_colors.yellow)(
|
|
4875
|
+
`Could not list the ${TEMPLATE_VERSION} refs on GitHub (${error3.message}); translations not checked.`
|
|
4876
|
+
)
|
|
4877
|
+
);
|
|
4878
|
+
return 0;
|
|
4879
|
+
}
|
|
4880
|
+
let failures = 0;
|
|
4881
|
+
for (const application of TRANSLATED_APPLICATIONS) {
|
|
4882
|
+
const endpoint = `GET /content/${application}`;
|
|
4883
|
+
let fetched;
|
|
4884
|
+
try {
|
|
4885
|
+
fetched = await fetchTemplate(refs, application);
|
|
4886
|
+
} catch (error3) {
|
|
4887
|
+
console.log(
|
|
4888
|
+
" " + (0, import_colors.yellow)(
|
|
4889
|
+
`Could not read ${application}.csv from the country config template on GitHub (${error3.message}); ${endpoint} not checked.`
|
|
4890
|
+
)
|
|
4891
|
+
);
|
|
4892
|
+
continue;
|
|
4893
|
+
}
|
|
4894
|
+
if (!fetched) {
|
|
4895
|
+
console.log(
|
|
4896
|
+
" " + (0, import_colors.yellow)(
|
|
4897
|
+
`No ${application}.csv in the ${TEMPLATE_VERSION} country config template on GitHub; ${endpoint} not checked.`
|
|
4898
|
+
)
|
|
4899
|
+
);
|
|
4900
|
+
continue;
|
|
4901
|
+
}
|
|
4902
|
+
const template = readTemplateTranslations(fetched.contents);
|
|
4903
|
+
const served = await fetchServedTranslations(baseUrl, application);
|
|
4904
|
+
if (!served) {
|
|
4905
|
+
console.log(
|
|
4906
|
+
" " + (0, import_colors.yellow)(`Could not read ${endpoint}; translations not checked.`)
|
|
4907
|
+
);
|
|
4908
|
+
continue;
|
|
4909
|
+
}
|
|
4910
|
+
const servedIds = new Set(
|
|
4911
|
+
served.flatMap(({ messages }) => Object.keys(messages))
|
|
4912
|
+
);
|
|
4913
|
+
const missing = template.ids.filter((id) => !servedIds.has(id));
|
|
4914
|
+
const servedLanguages = new Set(served.map(({ lang }) => lang));
|
|
4915
|
+
const absentLanguages = template.languages.filter(
|
|
4916
|
+
(lang) => !servedLanguages.has(lang)
|
|
4917
|
+
);
|
|
4918
|
+
if (missing.length === 0) {
|
|
4919
|
+
console.log(
|
|
4920
|
+
line(
|
|
4921
|
+
true,
|
|
4922
|
+
endpoint,
|
|
4923
|
+
`all ${template.ids.length} id(s) from the ${fetched.ref} template served`
|
|
4924
|
+
)
|
|
4925
|
+
);
|
|
4926
|
+
} else {
|
|
4927
|
+
failures++;
|
|
4928
|
+
console.log(
|
|
4929
|
+
line(
|
|
4930
|
+
false,
|
|
4931
|
+
endpoint,
|
|
4932
|
+
`${missing.length} of ${template.ids.length} id(s) from the ${fetched.ref} template not served`
|
|
4933
|
+
)
|
|
4934
|
+
);
|
|
4935
|
+
for (const id of missing.slice(0, MISSING_IDS_SHOWN)) {
|
|
4936
|
+
console.log(` ${(0, import_colors.dim)(id)}`);
|
|
4937
|
+
}
|
|
4938
|
+
if (missing.length > MISSING_IDS_SHOWN) {
|
|
4939
|
+
console.log(
|
|
4940
|
+
` ${(0, import_colors.dim)(`\u2026 and ${missing.length - MISSING_IDS_SHOWN} more`)}`
|
|
4941
|
+
);
|
|
4942
|
+
}
|
|
4943
|
+
}
|
|
4944
|
+
if (absentLanguages.length > 0) {
|
|
4945
|
+
console.log(
|
|
4946
|
+
" " + (0, import_colors.yellow)(
|
|
4947
|
+
`${application}: the template carries ${absentLanguages.join(
|
|
4948
|
+
", "
|
|
4949
|
+
)}, which this country config does not serve.`
|
|
4950
|
+
)
|
|
4951
|
+
);
|
|
4952
|
+
}
|
|
4953
|
+
}
|
|
4954
|
+
return failures;
|
|
4955
|
+
}
|
|
4956
|
+
async function runVerifyEndpoints(target = DEFAULT_TARGET_URL) {
|
|
4957
|
+
const baseUrl = resolveBaseUrl(target);
|
|
4958
|
+
console.log((0, import_colors.bold)(`Verifying country config endpoints at ${baseUrl}
|
|
4959
|
+
`));
|
|
4960
|
+
let failures = 0;
|
|
4961
|
+
console.log((0, import_colors.bold)("Required public endpoints (must respond 2xx):"));
|
|
4962
|
+
for (const check of REQUIRED_PUBLIC_ENDPOINTS) {
|
|
4963
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
4964
|
+
const ok = isSuccess(status);
|
|
4965
|
+
if (!ok) {
|
|
4966
|
+
failures++;
|
|
4967
|
+
}
|
|
4968
|
+
const detail = status === 404 ? `${describeStatus(status)} \u2014 missing` : ok ? describeStatus(status) : `${describeStatus(status)} \u2014 unexpected`;
|
|
4969
|
+
console.log(line(ok, endpointLabel(check), detail));
|
|
4970
|
+
}
|
|
4971
|
+
{
|
|
4972
|
+
const path10 = `/fonts/${PROBE_SEGMENT}.ttf`;
|
|
4973
|
+
const status = await requestStatus(`${baseUrl}${path10}`, "GET");
|
|
4974
|
+
const ok = status === 200 || status === 404;
|
|
4975
|
+
if (!ok) {
|
|
4976
|
+
failures++;
|
|
4977
|
+
}
|
|
4978
|
+
let detail;
|
|
4979
|
+
if (status === 404) {
|
|
4980
|
+
detail = `${describeStatus(status)} \u2014 reachable (made-up filename)`;
|
|
4981
|
+
} else if (status === 200) {
|
|
4982
|
+
detail = describeStatus(status);
|
|
4983
|
+
} else if (status === 401 || status === 403) {
|
|
4984
|
+
detail = `${describeStatus(status)} \u2014 must be public`;
|
|
4985
|
+
} else {
|
|
4986
|
+
detail = `${describeStatus(status)} \u2014 unexpected`;
|
|
4987
|
+
}
|
|
4988
|
+
console.log(line(ok, `GET /fonts/{filename}${(0, import_colors.dim)(` \u2192 ${path10}`)}`, detail));
|
|
4989
|
+
}
|
|
4990
|
+
console.log();
|
|
4991
|
+
console.log((0, import_colors.bold)("Secured endpoints (must be absent or require auth):"));
|
|
4992
|
+
for (const check of SECURED_ENDPOINTS) {
|
|
4993
|
+
const status = await requestStatus(`${baseUrl}${check.path}`, check.method);
|
|
4994
|
+
const ok = requiresAuthOrAbsent(status);
|
|
4995
|
+
if (!ok) {
|
|
4996
|
+
failures++;
|
|
4997
|
+
}
|
|
4998
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
4999
|
+
}
|
|
5000
|
+
console.log();
|
|
5001
|
+
console.log((0, import_colors.bold)("Event action triggers (must be absent or require auth):"));
|
|
5002
|
+
const events = await fetchEventConfigs(baseUrl);
|
|
5003
|
+
if (!events) {
|
|
5004
|
+
console.log(
|
|
5005
|
+
" " + (0, import_colors.yellow)(
|
|
5006
|
+
"Could not read /config/events; falling back to route-pattern checks."
|
|
5007
|
+
)
|
|
5008
|
+
);
|
|
5009
|
+
for (const check of FALLBACK_EVENT_TRIGGERS) {
|
|
5010
|
+
const status = await requestStatus(
|
|
5011
|
+
`${baseUrl}${check.path}`,
|
|
5012
|
+
check.method
|
|
5013
|
+
);
|
|
5014
|
+
const ok = requiresAuthOrAbsent(status);
|
|
5015
|
+
if (!ok) {
|
|
5016
|
+
failures++;
|
|
5017
|
+
}
|
|
5018
|
+
console.log(line(ok, endpointLabel(check), securedDetail(status)));
|
|
5019
|
+
}
|
|
5020
|
+
} else if (events.length === 0) {
|
|
5021
|
+
console.log(" " + (0, import_colors.yellow)("No events configured."));
|
|
5022
|
+
} else {
|
|
5023
|
+
for (const event of events) {
|
|
5024
|
+
const actions = event.actions.length ? event.actions : [PROBE_SEGMENT];
|
|
5025
|
+
const failed = [];
|
|
5026
|
+
for (const action of actions) {
|
|
5027
|
+
const status = await requestStatus(
|
|
5028
|
+
`${baseUrl}/trigger/events/${event.id}/actions/${action}`,
|
|
5029
|
+
"POST"
|
|
5030
|
+
);
|
|
5031
|
+
if (!requiresAuthOrAbsent(status)) {
|
|
5032
|
+
failed.push({ action, status });
|
|
5033
|
+
}
|
|
5034
|
+
}
|
|
5035
|
+
const pattern = `POST /trigger/events/${event.id}/actions/{action}`;
|
|
5036
|
+
if (failed.length === 0) {
|
|
5037
|
+
console.log(
|
|
5038
|
+
line(true, pattern, `${actions.length} action(s) \u2014 all require auth`)
|
|
5039
|
+
);
|
|
5040
|
+
} else {
|
|
5041
|
+
for (const failure of failed) {
|
|
5042
|
+
failures++;
|
|
5043
|
+
console.log(
|
|
5044
|
+
line(
|
|
5045
|
+
false,
|
|
5046
|
+
`POST /trigger/events/${event.id}/actions/${failure.action}`,
|
|
5047
|
+
securedDetail(failure.status)
|
|
5048
|
+
)
|
|
5049
|
+
);
|
|
5050
|
+
}
|
|
5051
|
+
const okCount = actions.length - failed.length;
|
|
5052
|
+
if (okCount > 0) {
|
|
5053
|
+
console.log(
|
|
5054
|
+
line(true, pattern, `${okCount} other action(s) require auth`)
|
|
5055
|
+
);
|
|
5056
|
+
}
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
5059
|
+
}
|
|
5060
|
+
console.log();
|
|
5061
|
+
console.log((0, import_colors.bold)("Translations served (must cover the copy core requires):"));
|
|
5062
|
+
failures += await verifyTranslations(baseUrl);
|
|
5063
|
+
console.log();
|
|
5064
|
+
if (failures > 0) {
|
|
5065
|
+
console.log(
|
|
5066
|
+
(0, import_colors.red)((0, import_colors.bold)(`\u2717 ${failures} check(s) failed.`)) + (0, import_colors.yellow)(" See the lines marked \u2717 above.")
|
|
5067
|
+
);
|
|
5068
|
+
process.exit(1);
|
|
5069
|
+
}
|
|
5070
|
+
console.log((0, import_colors.green)((0, import_colors.bold)("\u2713 All endpoint checks passed.")));
|
|
5071
|
+
}
|
|
5072
|
+
|
|
3338
5073
|
// src/cli.ts
|
|
3339
5074
|
var args = process.argv.slice(2);
|
|
3340
5075
|
var USAGE = `
|
|
@@ -3343,10 +5078,37 @@ Usage: opencrvs <command>
|
|
|
3343
5078
|
Commands:
|
|
3344
5079
|
environment Manage deployment environments
|
|
3345
5080
|
upgrade Upgrade an existing environment
|
|
3346
|
-
|
|
5081
|
+
verify-endpoints Verify the locally-running country config exposes the
|
|
5082
|
+
expected endpoints, keeps secured ones locked down and
|
|
5083
|
+
serves the translations core requires
|
|
3347
5084
|
|
|
3348
5085
|
Run 'opencrvs <command> --help' for more information on a command.
|
|
3349
5086
|
`.trim();
|
|
5087
|
+
var VERIFY_ENDPOINTS_USAGE = `
|
|
5088
|
+
Usage: opencrvs verify-endpoints [country-config-url]
|
|
5089
|
+
|
|
5090
|
+
Run this after 'opencrvs upgrade', with the upgraded country config running
|
|
5091
|
+
locally, to confirm it still behaves correctly. It checks over HTTP that:
|
|
5092
|
+
- required public endpoints exist (respond 2xx),
|
|
5093
|
+
- user-notification trigger endpoints are either absent or reject
|
|
5094
|
+
unauthenticated requests (never processed without a token), and
|
|
5095
|
+
- '/content/client' and '/content/login' serve every message id the country
|
|
5096
|
+
config template of this version carries.
|
|
5097
|
+
|
|
5098
|
+
Checking the translations reads the template off GitHub. When GitHub cannot be
|
|
5099
|
+
reached the other checks still run and that one is skipped with a warning.
|
|
5100
|
+
|
|
5101
|
+
Arguments:
|
|
5102
|
+
[country-config-url] Optional. Domain or URL of the country config
|
|
5103
|
+
service. Defaults to 'http://localhost:3040', the
|
|
5104
|
+
port country config listens on locally. A bare
|
|
5105
|
+
domain is assumed to use https.
|
|
5106
|
+
|
|
5107
|
+
Options:
|
|
5108
|
+
-h, --help Show this message.
|
|
5109
|
+
|
|
5110
|
+
Exits with a non-zero status if any check fails.
|
|
5111
|
+
`.trim();
|
|
3350
5112
|
var UPGRADE_USAGE = `
|
|
3351
5113
|
Usage: opencrvs upgrade [options]
|
|
3352
5114
|
|
|
@@ -3360,7 +5122,7 @@ Options:
|
|
|
3360
5122
|
'infrastructure/' directory is deleted (default).
|
|
3361
5123
|
-h, --help Show this message.
|
|
3362
5124
|
`.trim();
|
|
3363
|
-
function
|
|
5125
|
+
function main6() {
|
|
3364
5126
|
const command = args[0];
|
|
3365
5127
|
if (!command || command === "--help" || command === "-h") {
|
|
3366
5128
|
console.log(USAGE);
|
|
@@ -3371,8 +5133,8 @@ function main2() {
|
|
|
3371
5133
|
return handleEnvironment();
|
|
3372
5134
|
case "upgrade":
|
|
3373
5135
|
return handleUpgrade();
|
|
3374
|
-
case "
|
|
3375
|
-
return
|
|
5136
|
+
case "verify-endpoints":
|
|
5137
|
+
return handleVerifyEndpoints();
|
|
3376
5138
|
default:
|
|
3377
5139
|
console.error(`Unknown command: ${command}
|
|
3378
5140
|
`);
|
|
@@ -3389,6 +5151,7 @@ Usage: opencrvs environment <subcommand>
|
|
|
3389
5151
|
|
|
3390
5152
|
Subcommands:
|
|
3391
5153
|
init Initialise a new environment
|
|
5154
|
+
upgrade Upgrade existing environment configuration
|
|
3392
5155
|
update-workflows Update workflow environment options
|
|
3393
5156
|
users Manage environment users
|
|
3394
5157
|
swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
|
|
@@ -3399,6 +5162,8 @@ Subcommands:
|
|
|
3399
5162
|
switch (subcommand) {
|
|
3400
5163
|
case "init":
|
|
3401
5164
|
return runEnvironmentCommand("initialisation", runEnvironmentInit);
|
|
5165
|
+
case "upgrade":
|
|
5166
|
+
return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
|
|
3402
5167
|
case "update-workflows":
|
|
3403
5168
|
return runEnvironmentCommand(
|
|
3404
5169
|
"workflow update",
|
|
@@ -3419,10 +5184,10 @@ Subcommands:
|
|
|
3419
5184
|
async function runEnvironmentCommand(operation, command) {
|
|
3420
5185
|
try {
|
|
3421
5186
|
await command();
|
|
3422
|
-
} catch (
|
|
5187
|
+
} catch (error3) {
|
|
3423
5188
|
console.error(
|
|
3424
5189
|
`Environment ${operation} failed:`,
|
|
3425
|
-
|
|
5190
|
+
error3 instanceof Error ? error3.message : error3
|
|
3426
5191
|
);
|
|
3427
5192
|
process.exit(1);
|
|
3428
5193
|
}
|
|
@@ -3448,14 +5213,34 @@ async function handleUpgrade() {
|
|
|
3448
5213
|
try {
|
|
3449
5214
|
await runUpgrade(dockerSwarm);
|
|
3450
5215
|
console.log("Upgrade completed successfully!");
|
|
3451
|
-
} catch (
|
|
3452
|
-
console.error("Upgrade failed:",
|
|
5216
|
+
} catch (error3) {
|
|
5217
|
+
console.error("Upgrade failed:", error3);
|
|
3453
5218
|
process.exit(1);
|
|
3454
5219
|
}
|
|
3455
5220
|
}
|
|
3456
|
-
function
|
|
3457
|
-
|
|
3458
|
-
|
|
3459
|
-
|
|
5221
|
+
async function handleVerifyEndpoints() {
|
|
5222
|
+
const verifyArgs = args.slice(1);
|
|
5223
|
+
if (verifyArgs.includes("--help") || verifyArgs.includes("-h")) {
|
|
5224
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5225
|
+
process.exit(0);
|
|
5226
|
+
}
|
|
5227
|
+
const positional = verifyArgs.filter((arg) => !arg.startsWith("-"));
|
|
5228
|
+
if (positional.length > 1) {
|
|
5229
|
+
console.error(
|
|
5230
|
+
`Unexpected extra argument(s): ${positional.slice(1).join(", ")}
|
|
5231
|
+
`
|
|
5232
|
+
);
|
|
5233
|
+
console.log(VERIFY_ENDPOINTS_USAGE);
|
|
5234
|
+
process.exit(1);
|
|
5235
|
+
}
|
|
5236
|
+
try {
|
|
5237
|
+
await runVerifyEndpoints(positional[0]);
|
|
5238
|
+
} catch (error3) {
|
|
5239
|
+
console.error(
|
|
5240
|
+
"Endpoint verification failed:",
|
|
5241
|
+
error3 instanceof Error ? error3.message : error3
|
|
5242
|
+
);
|
|
5243
|
+
process.exit(1);
|
|
5244
|
+
}
|
|
3460
5245
|
}
|
|
3461
|
-
|
|
5246
|
+
main6();
|