@opencrvs/toolkit 2.1.0-rc.f383722 → 2.1.0-rc.f5f3da9
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 +1 -0
- package/dist/application-config/index.js +0 -1
- package/dist/cli.js +217 -77
- package/dist/commons/api/router.d.ts +0 -85
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/AdvancedSearchConfig.d.ts +0 -6
- package/dist/commons/events/AuditLog.d.ts +0 -37
- package/dist/commons/events/EventIndex.d.ts +2 -2
- package/dist/commons/events/FieldConfig.d.ts +1 -6
- package/dist/commons/events/index.d.ts +0 -1
- package/dist/commons/events/locations.d.ts +0 -7
- package/dist/conditionals/index.js +0 -1
- package/dist/environment/index.d.ts +1 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +10 -0
- package/dist/environment/logger.d.ts +3 -12
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/paths.d.ts +13 -0
- package/dist/environment/paths.d.ts.map +1 -0
- package/dist/environment/paths.js +94 -0
- package/dist/environment/setup-environment.js +2 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +2 -1
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +4 -3
- package/dist/environment/upgrade.d.ts +2 -0
- package/dist/environment/upgrade.d.ts.map +1 -0
- package/dist/environment/upgrade.js +100 -0
- package/dist/environment/users.js +11 -13
- package/dist/events/index.js +0 -88
- package/dist/notification/index.js +25 -99
- package/dist/scopes/index.d.ts +26 -28
- package/dist/scopes/index.js +0 -1
- package/opencrvs-toolkit-2.1.0-rc.f5f3da9.tgz +0 -0
- package/package.json +3 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/.nx/cache/file-map.json +0 -360
- package/.nx/cache/project-graph.json +0 -6
- package/dist/commons/events/locationPayloads.d.ts +0 -95
- package/opencrvs-toolkit-2.1.0-rc.f383722.tgz +0 -0
package/README.md
CHANGED
package/dist/cli.js
CHANGED
|
@@ -30,6 +30,53 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
+
// src/environment/paths.ts
|
|
34
|
+
function getEnvironmentDir(environment) {
|
|
35
|
+
return (0, import_path2.join)("environments", environment);
|
|
36
|
+
}
|
|
37
|
+
function getEnvironmentInventoryPath(environment) {
|
|
38
|
+
return (0, import_path2.join)(getEnvironmentDir(environment), INVENTORY_FILE_NAME);
|
|
39
|
+
}
|
|
40
|
+
function getEnvironmentInventoryVarsPath(environment) {
|
|
41
|
+
return (0, import_path2.join)(getEnvironmentDir(environment), INVENTORY_VARS_FILE_NAME);
|
|
42
|
+
}
|
|
43
|
+
function findOldInventoryFiles() {
|
|
44
|
+
return glob.sync((0, import_path2.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
45
|
+
}
|
|
46
|
+
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
47
|
+
return (0, import_path2.basename)(filePath, ".yml");
|
|
48
|
+
}
|
|
49
|
+
function hasOldInventoryLayout() {
|
|
50
|
+
return findOldInventoryFiles().length > 0;
|
|
51
|
+
}
|
|
52
|
+
function assertNoOldInventoryLayout() {
|
|
53
|
+
if (!hasOldInventoryLayout()) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
throw new Error(
|
|
57
|
+
[
|
|
58
|
+
`Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
|
|
59
|
+
"Please run `yarn environment:upgrade` before running `yarn environment:init`."
|
|
60
|
+
].join(" ")
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
var import_fs, import_path2, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME, INVENTORY_VARS_FILE_NAME;
|
|
64
|
+
var init_paths = __esm({
|
|
65
|
+
"src/environment/paths.ts"() {
|
|
66
|
+
"use strict";
|
|
67
|
+
import_fs = require("fs");
|
|
68
|
+
import_path2 = require("path");
|
|
69
|
+
glob = __toESM(require("glob"));
|
|
70
|
+
OLD_INVENTORY_DIR = (0, import_path2.join)(
|
|
71
|
+
"infrastructure",
|
|
72
|
+
"server-setup",
|
|
73
|
+
"inventory"
|
|
74
|
+
);
|
|
75
|
+
INVENTORY_FILE_NAME = "inventory.yml";
|
|
76
|
+
INVENTORY_VARS_FILE_NAME = "inventory-vars.yml";
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
33
80
|
// src/environment/logger.ts
|
|
34
81
|
var import_kleur, log, warn, success, info, error;
|
|
35
82
|
var init_logger = __esm({
|
|
@@ -471,9 +518,9 @@ function storeSecrets(environment, answers) {
|
|
|
471
518
|
let envConfig = {};
|
|
472
519
|
try {
|
|
473
520
|
envConfig = import_dotenv.default.parse(
|
|
474
|
-
(0,
|
|
521
|
+
(0, import_fs2.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
475
522
|
);
|
|
476
|
-
} catch (
|
|
523
|
+
} catch (error3) {
|
|
477
524
|
envConfig = {};
|
|
478
525
|
}
|
|
479
526
|
const linesFromAnswers = answers.map(
|
|
@@ -481,10 +528,10 @@ function storeSecrets(environment, answers) {
|
|
|
481
528
|
);
|
|
482
529
|
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
483
530
|
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
484
|
-
(0,
|
|
531
|
+
(0, import_fs2.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
485
532
|
}
|
|
486
533
|
function readYamlFile(filePath) {
|
|
487
|
-
const fileContent =
|
|
534
|
+
const fileContent = import_fs2.default.readFileSync(filePath, "utf8");
|
|
488
535
|
return yaml.load(fileContent);
|
|
489
536
|
}
|
|
490
537
|
function writeYamlFile(filePath, data) {
|
|
@@ -497,16 +544,16 @@ function writeYamlFile(filePath, data) {
|
|
|
497
544
|
noRefs: true,
|
|
498
545
|
sortKeys: false
|
|
499
546
|
});
|
|
500
|
-
|
|
501
|
-
} catch (
|
|
502
|
-
throw new Error(`Failed to write inventory file: ${
|
|
547
|
+
import_fs2.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
548
|
+
} catch (error3) {
|
|
549
|
+
throw new Error(`Failed to write inventory file: ${error3}`);
|
|
503
550
|
}
|
|
504
551
|
}
|
|
505
|
-
var
|
|
552
|
+
var import_fs2, yaml, import_dotenv;
|
|
506
553
|
var init_utils = __esm({
|
|
507
554
|
"src/environment/utils.ts"() {
|
|
508
555
|
"use strict";
|
|
509
|
-
|
|
556
|
+
import_fs2 = __toESM(require("fs"));
|
|
510
557
|
yaml = __toESM(require("js-yaml"));
|
|
511
558
|
import_dotenv = __toESM(require("dotenv"));
|
|
512
559
|
}
|
|
@@ -559,29 +606,29 @@ function extractWorkerNodes(data) {
|
|
|
559
606
|
return worker_hosts;
|
|
560
607
|
}
|
|
561
608
|
function copyChartsValues(env, values) {
|
|
562
|
-
const srcDir =
|
|
563
|
-
const destDir =
|
|
564
|
-
|
|
609
|
+
const srcDir = import_path3.default.resolve(__dirname, "templates", "charts-values");
|
|
610
|
+
const destDir = import_path3.default.resolve(process.cwd(), "environments", env);
|
|
611
|
+
import_fs3.default.mkdirSync(destDir, { recursive: true });
|
|
565
612
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
566
613
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
567
614
|
values["opencrvs_environment"] = env;
|
|
568
615
|
function copyRecursive(src, dest) {
|
|
569
|
-
const stat =
|
|
616
|
+
const stat = import_fs3.default.statSync(src);
|
|
570
617
|
if (stat.isDirectory()) {
|
|
571
|
-
|
|
572
|
-
for (const item of
|
|
573
|
-
copyRecursive(
|
|
618
|
+
import_fs3.default.mkdirSync(dest, { recursive: true });
|
|
619
|
+
for (const item of import_fs3.default.readdirSync(src)) {
|
|
620
|
+
copyRecursive(import_path3.default.join(src, item), import_path3.default.join(dest, item));
|
|
574
621
|
}
|
|
575
622
|
} else {
|
|
576
|
-
const content =
|
|
623
|
+
const content = import_fs3.default.readFileSync(src, "utf8");
|
|
577
624
|
const template = import_handlebars.default.compile(content);
|
|
578
625
|
const updated = template(values);
|
|
579
626
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
580
|
-
if (isOverridesFile &&
|
|
627
|
+
if (isOverridesFile && import_fs3.default.existsSync(dest)) {
|
|
581
628
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
582
629
|
return;
|
|
583
630
|
}
|
|
584
|
-
|
|
631
|
+
import_fs3.default.writeFileSync(dest, updated, "utf8");
|
|
585
632
|
log(` \u2713 Created: ${dest}`);
|
|
586
633
|
}
|
|
587
634
|
}
|
|
@@ -592,36 +639,31 @@ function copyChartsValues(env, values) {
|
|
|
592
639
|
`);
|
|
593
640
|
}
|
|
594
641
|
function generateInventory(env, values) {
|
|
595
|
-
const templatePath =
|
|
642
|
+
const templatePath = import_path3.default.join(
|
|
596
643
|
__dirname,
|
|
597
644
|
"templates",
|
|
598
645
|
"inventory",
|
|
599
646
|
"inventory.template.yml"
|
|
600
647
|
);
|
|
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");
|
|
648
|
+
const outputPath = import_path3.default.resolve(process.cwd(), getEnvironmentInventoryPath(env));
|
|
649
|
+
const templateFile = import_fs3.default.readFileSync(templatePath, "utf-8");
|
|
609
650
|
const template = import_handlebars.default.compile(templateFile);
|
|
610
651
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
611
652
|
const updated = template(values);
|
|
612
|
-
|
|
613
|
-
|
|
653
|
+
import_fs3.default.mkdirSync(import_path3.default.dirname(outputPath), { recursive: true });
|
|
654
|
+
import_fs3.default.writeFileSync(outputPath, updated);
|
|
614
655
|
log(`
|
|
615
656
|
\u2705 Generated inventory file at ${outputPath}
|
|
616
657
|
`);
|
|
617
658
|
}
|
|
618
|
-
var
|
|
659
|
+
var import_fs3, import_path3, import_handlebars;
|
|
619
660
|
var init_templates = __esm({
|
|
620
661
|
"src/environment/templates.ts"() {
|
|
621
662
|
"use strict";
|
|
622
|
-
|
|
623
|
-
|
|
663
|
+
import_fs3 = __toESM(require("fs"));
|
|
664
|
+
import_path3 = __toESM(require("path"));
|
|
624
665
|
init_logger();
|
|
666
|
+
init_paths();
|
|
625
667
|
import_handlebars = __toESM(require("handlebars"));
|
|
626
668
|
import_handlebars.default.registerHelper("data_label_idx", function(value) {
|
|
627
669
|
return parseInt(value) + 2;
|
|
@@ -1237,7 +1279,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1237
1279
|
keys.push(keyContent);
|
|
1238
1280
|
}
|
|
1239
1281
|
}
|
|
1240
|
-
} catch (
|
|
1282
|
+
} catch (error3) {
|
|
1241
1283
|
continue;
|
|
1242
1284
|
}
|
|
1243
1285
|
}
|
|
@@ -1773,6 +1815,7 @@ var init_setup_environment = __esm({
|
|
|
1773
1815
|
init_editor_questions();
|
|
1774
1816
|
init_questions_helper();
|
|
1775
1817
|
init_manage_users();
|
|
1818
|
+
init_paths();
|
|
1776
1819
|
ALL_QUESTIONS = [];
|
|
1777
1820
|
ALL_ANSWERS = [];
|
|
1778
1821
|
ALL_QUESTIONS.push(
|
|
@@ -1936,9 +1979,7 @@ var init_setup_environment = __esm({
|
|
|
1936
1979
|
);
|
|
1937
1980
|
const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
|
|
1938
1981
|
log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
|
|
1939
|
-
const users = await manageUsers(
|
|
1940
|
-
`infrastructure/server-setup/inventory/${environment}.yml`
|
|
1941
|
-
);
|
|
1982
|
+
const users = await manageUsers(getEnvironmentInventoryPath(environment));
|
|
1942
1983
|
log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
|
|
1943
1984
|
const sslCertExists = findExistingValue(
|
|
1944
1985
|
"SSL_CRT",
|
|
@@ -2752,11 +2793,11 @@ __export(update_workflows_exports, {
|
|
|
2752
2793
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
2753
2794
|
});
|
|
2754
2795
|
async function extractInfrastructureNames() {
|
|
2755
|
-
const files =
|
|
2756
|
-
const infraEnvironments = files.map((file) => (0,
|
|
2796
|
+
const files = glob2.sync((0, import_path4.join)("environments", "*", INVENTORY_FILE_NAME));
|
|
2797
|
+
const infraEnvironments = files.map((file) => (0, import_path4.basename)((0, import_path4.dirname)(file)));
|
|
2757
2798
|
if (infraEnvironments.length === 0) {
|
|
2758
2799
|
console.log(
|
|
2759
|
-
|
|
2800
|
+
`\u26A0\uFE0F Warning: No environment inventory files found at environments/*/${INVENTORY_FILE_NAME}`
|
|
2760
2801
|
);
|
|
2761
2802
|
return [];
|
|
2762
2803
|
}
|
|
@@ -2766,8 +2807,8 @@ async function extractInfrastructureNames() {
|
|
|
2766
2807
|
async function extractEnvironmentNames() {
|
|
2767
2808
|
const entries = await (0, import_promises.readdir)("environments");
|
|
2768
2809
|
const environments = entries.filter((entry) => {
|
|
2769
|
-
const fullPath = (0,
|
|
2770
|
-
return (0,
|
|
2810
|
+
const fullPath = (0, import_path4.join)("environments", entry);
|
|
2811
|
+
return (0, import_fs4.statSync)(fullPath).isDirectory();
|
|
2771
2812
|
});
|
|
2772
2813
|
if (environments.length === 0) {
|
|
2773
2814
|
console.log(
|
|
@@ -2793,7 +2834,7 @@ async function updateWorkflows(envList, config) {
|
|
|
2793
2834
|
const { workflows } = config;
|
|
2794
2835
|
for (const workflowPath of workflows) {
|
|
2795
2836
|
try {
|
|
2796
|
-
const fileContents = (0,
|
|
2837
|
+
const fileContents = (0, import_fs4.readFileSync)(workflowPath, "utf8");
|
|
2797
2838
|
const workflowData = yaml2.load(fileContents);
|
|
2798
2839
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2799
2840
|
throw new Error(
|
|
@@ -2801,15 +2842,15 @@ async function updateWorkflows(envList, config) {
|
|
|
2801
2842
|
);
|
|
2802
2843
|
}
|
|
2803
2844
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2804
|
-
(0,
|
|
2845
|
+
(0, import_fs4.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2805
2846
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2806
|
-
} catch (
|
|
2847
|
+
} catch (error3) {
|
|
2807
2848
|
console.error(
|
|
2808
2849
|
`
|
|
2809
2850
|
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2810
2851
|
);
|
|
2811
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`,
|
|
2812
|
-
throw
|
|
2852
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error3);
|
|
2853
|
+
throw error3;
|
|
2813
2854
|
}
|
|
2814
2855
|
}
|
|
2815
2856
|
}
|
|
@@ -2850,21 +2891,111 @@ async function updateWorkflowEnvironments() {
|
|
|
2850
2891
|
} else {
|
|
2851
2892
|
log("\u2139\uFE0F No workflows were updated.");
|
|
2852
2893
|
}
|
|
2853
|
-
} catch (
|
|
2854
|
-
console.error("\n\u274C Error updating workflows:",
|
|
2894
|
+
} catch (error3) {
|
|
2895
|
+
console.error("\n\u274C Error updating workflows:", error3);
|
|
2855
2896
|
process.exit(1);
|
|
2856
2897
|
}
|
|
2857
2898
|
}
|
|
2858
|
-
var import_promises,
|
|
2899
|
+
var import_promises, import_fs4, import_path4, glob2, yaml2;
|
|
2859
2900
|
var init_update_workflows = __esm({
|
|
2860
2901
|
"src/environment/update-workflows.ts"() {
|
|
2861
2902
|
"use strict";
|
|
2862
2903
|
import_promises = require("fs/promises");
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2904
|
+
import_fs4 = require("fs");
|
|
2905
|
+
import_path4 = require("path");
|
|
2906
|
+
glob2 = __toESM(require("glob"));
|
|
2866
2907
|
yaml2 = __toESM(require("js-yaml"));
|
|
2867
2908
|
init_logger();
|
|
2909
|
+
init_paths();
|
|
2910
|
+
}
|
|
2911
|
+
});
|
|
2912
|
+
|
|
2913
|
+
// src/environment/upgrade.ts
|
|
2914
|
+
var upgrade_exports = {};
|
|
2915
|
+
__export(upgrade_exports, {
|
|
2916
|
+
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2917
|
+
});
|
|
2918
|
+
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2919
|
+
if (!(0, import_fs5.existsSync)(sourcePath)) {
|
|
2920
|
+
return false;
|
|
2921
|
+
}
|
|
2922
|
+
if ((0, import_fs5.existsSync)(destinationPath)) {
|
|
2923
|
+
warn(
|
|
2924
|
+
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2925
|
+
);
|
|
2926
|
+
return false;
|
|
2927
|
+
}
|
|
2928
|
+
(0, import_fs5.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
|
|
2929
|
+
(0, import_fs5.renameSync)(sourcePath, destinationPath);
|
|
2930
|
+
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2931
|
+
return true;
|
|
2932
|
+
}
|
|
2933
|
+
function migrateInventoryFiles() {
|
|
2934
|
+
const oldInventoryFiles = findOldInventoryFiles();
|
|
2935
|
+
if (oldInventoryFiles.length === 0) {
|
|
2936
|
+
log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
|
|
2937
|
+
return false;
|
|
2938
|
+
}
|
|
2939
|
+
log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
|
|
2940
|
+
let didMoveInventory = false;
|
|
2941
|
+
for (const oldInventoryFile of oldInventoryFiles) {
|
|
2942
|
+
const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
|
|
2943
|
+
didMoveInventory = moveFileIfDestinationMissing(
|
|
2944
|
+
oldInventoryFile,
|
|
2945
|
+
getEnvironmentInventoryPath(environment)
|
|
2946
|
+
) || didMoveInventory;
|
|
2947
|
+
}
|
|
2948
|
+
try {
|
|
2949
|
+
if ((0, import_fs5.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs5.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
2950
|
+
(0, import_fs5.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2951
|
+
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2952
|
+
}
|
|
2953
|
+
} catch {
|
|
2954
|
+
warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
|
|
2955
|
+
}
|
|
2956
|
+
return didMoveInventory;
|
|
2957
|
+
}
|
|
2958
|
+
function migrateInventoryVarsFiles() {
|
|
2959
|
+
if (!(0, import_fs5.existsSync)("environments")) {
|
|
2960
|
+
return false;
|
|
2961
|
+
}
|
|
2962
|
+
log(import_kleur5.default.bold("\nMigrating optional inventory variable files"));
|
|
2963
|
+
let didMoveVars = false;
|
|
2964
|
+
for (const entry of (0, import_fs5.readdirSync)("environments")) {
|
|
2965
|
+
const environmentDir = (0, import_path5.join)("environments", entry);
|
|
2966
|
+
if (!(0, import_fs5.statSync)(environmentDir).isDirectory()) {
|
|
2967
|
+
continue;
|
|
2968
|
+
}
|
|
2969
|
+
didMoveVars = moveFileIfDestinationMissing(
|
|
2970
|
+
(0, import_path5.join)(environmentDir, "inventory.override.yml"),
|
|
2971
|
+
getEnvironmentInventoryVarsPath(entry)
|
|
2972
|
+
) || didMoveVars;
|
|
2973
|
+
}
|
|
2974
|
+
if (!didMoveVars) {
|
|
2975
|
+
log(`\u2139\uFE0F No inventory override files found to rename to ${INVENTORY_VARS_FILE_NAME}`);
|
|
2976
|
+
}
|
|
2977
|
+
return didMoveVars;
|
|
2978
|
+
}
|
|
2979
|
+
async function upgradeEnvironmentLayout() {
|
|
2980
|
+
const didMoveInventory = migrateInventoryFiles();
|
|
2981
|
+
const didMoveVars = migrateInventoryVarsFiles();
|
|
2982
|
+
await updateWorkflowEnvironments();
|
|
2983
|
+
if (didMoveInventory || didMoveVars) {
|
|
2984
|
+
success("\n\u2705 Environment layout upgrade completed successfully.");
|
|
2985
|
+
return;
|
|
2986
|
+
}
|
|
2987
|
+
success("\n\u2705 Environment layout already uses the current structure.");
|
|
2988
|
+
}
|
|
2989
|
+
var import_fs5, import_path5, import_kleur5;
|
|
2990
|
+
var init_upgrade = __esm({
|
|
2991
|
+
"src/environment/upgrade.ts"() {
|
|
2992
|
+
"use strict";
|
|
2993
|
+
import_fs5 = require("fs");
|
|
2994
|
+
import_path5 = require("path");
|
|
2995
|
+
import_kleur5 = __toESM(require("kleur"));
|
|
2996
|
+
init_logger();
|
|
2997
|
+
init_paths();
|
|
2998
|
+
init_update_workflows();
|
|
2868
2999
|
}
|
|
2869
3000
|
});
|
|
2870
3001
|
|
|
@@ -2877,7 +3008,7 @@ async function select4(options) {
|
|
|
2877
3008
|
const inquirer = await import("@inquirer/prompts");
|
|
2878
3009
|
return inquirer.select(options);
|
|
2879
3010
|
}
|
|
2880
|
-
async function selectInventoryFile(dirPath = "./
|
|
3011
|
+
async function selectInventoryFile(dirPath = "./environments") {
|
|
2881
3012
|
if (!fs4.existsSync(dirPath)) {
|
|
2882
3013
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
2883
3014
|
warn(
|
|
@@ -2885,22 +3016,20 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2885
3016
|
);
|
|
2886
3017
|
return null;
|
|
2887
3018
|
}
|
|
2888
|
-
const
|
|
2889
|
-
const filePath = path4.join(dirPath,
|
|
2890
|
-
|
|
2891
|
-
const ext = path4.extname(file).slice(1).toLowerCase();
|
|
2892
|
-
return isFile && (ext === "yml" || ext === "yaml");
|
|
3019
|
+
const environments = fs4.readdirSync(dirPath).filter((entry) => {
|
|
3020
|
+
const filePath = path4.join(dirPath, entry);
|
|
3021
|
+
return fs4.statSync(filePath).isDirectory() && fs4.existsSync(getEnvironmentInventoryPath(entry));
|
|
2893
3022
|
}).sort();
|
|
2894
|
-
if (
|
|
3023
|
+
if (environments.length === 0) {
|
|
2895
3024
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
2896
3025
|
warn(
|
|
2897
3026
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
2898
3027
|
);
|
|
2899
3028
|
return null;
|
|
2900
3029
|
}
|
|
2901
|
-
const choices =
|
|
2902
|
-
name:
|
|
2903
|
-
value:
|
|
3030
|
+
const choices = environments.map((environment) => ({
|
|
3031
|
+
name: environment,
|
|
3032
|
+
value: getEnvironmentInventoryPath(environment)
|
|
2904
3033
|
}));
|
|
2905
3034
|
const selectedFile = await select4({
|
|
2906
3035
|
message: "Select environment (inventory file) to load users:",
|
|
@@ -2909,33 +3038,34 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2909
3038
|
return selectedFile;
|
|
2910
3039
|
}
|
|
2911
3040
|
async function manageEnvironmentUsers() {
|
|
2912
|
-
console.log("\n",
|
|
3041
|
+
console.log("\n", import_kleur6.default.bold().underline("Manage users"), "\n");
|
|
2913
3042
|
const inventory_file = await selectInventoryFile();
|
|
2914
3043
|
if (!inventory_file) {
|
|
2915
3044
|
return;
|
|
2916
3045
|
}
|
|
2917
3046
|
await manageUsers(inventory_file);
|
|
2918
3047
|
}
|
|
2919
|
-
var fs4, path4,
|
|
3048
|
+
var fs4, path4, import_kleur6;
|
|
2920
3049
|
var init_users = __esm({
|
|
2921
3050
|
"src/environment/users.ts"() {
|
|
2922
3051
|
"use strict";
|
|
2923
3052
|
fs4 = __toESM(require("fs"));
|
|
2924
3053
|
path4 = __toESM(require("path"));
|
|
2925
|
-
|
|
3054
|
+
import_kleur6 = __toESM(require("kleur"));
|
|
2926
3055
|
init_manage_users();
|
|
2927
3056
|
init_logger();
|
|
3057
|
+
init_paths();
|
|
2928
3058
|
}
|
|
2929
3059
|
});
|
|
2930
3060
|
|
|
2931
3061
|
// src/environment/swarm-to-k8s.ts
|
|
2932
3062
|
var swarm_to_k8s_exports = {};
|
|
2933
|
-
var path5,
|
|
3063
|
+
var path5, import_kleur7, import_core2;
|
|
2934
3064
|
var init_swarm_to_k8s = __esm({
|
|
2935
3065
|
"src/environment/swarm-to-k8s.ts"() {
|
|
2936
3066
|
"use strict";
|
|
2937
3067
|
path5 = __toESM(require("path"));
|
|
2938
|
-
|
|
3068
|
+
import_kleur7 = __toESM(require("kleur"));
|
|
2939
3069
|
init_logger();
|
|
2940
3070
|
init_utils();
|
|
2941
3071
|
init_templates();
|
|
@@ -2944,7 +3074,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2944
3074
|
init_github();
|
|
2945
3075
|
(async () => {
|
|
2946
3076
|
log(
|
|
2947
|
-
|
|
3077
|
+
import_kleur7.default.bold(
|
|
2948
3078
|
"------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
|
|
2949
3079
|
)
|
|
2950
3080
|
);
|
|
@@ -2975,7 +3105,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
2975
3105
|
);
|
|
2976
3106
|
process.exit(0);
|
|
2977
3107
|
}
|
|
2978
|
-
log(
|
|
3108
|
+
log(import_kleur7.default.bold().underline("Migration properties:"));
|
|
2979
3109
|
log(` \u2713 Environment: ${environment}`);
|
|
2980
3110
|
const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
|
|
2981
3111
|
if (!old_inventory_path) {
|
|
@@ -3293,8 +3423,9 @@ async function runUpgrade(dockerSwarm) {
|
|
|
3293
3423
|
}
|
|
3294
3424
|
|
|
3295
3425
|
// src/environment/index.ts
|
|
3296
|
-
var
|
|
3297
|
-
var
|
|
3426
|
+
var import_fs6 = require("fs");
|
|
3427
|
+
var import_path6 = require("path");
|
|
3428
|
+
init_paths();
|
|
3298
3429
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
3299
3430
|
".github/workflows",
|
|
3300
3431
|
"environments",
|
|
@@ -3304,7 +3435,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3304
3435
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
3305
3436
|
(directory) => {
|
|
3306
3437
|
try {
|
|
3307
|
-
return !(0,
|
|
3438
|
+
return !(0, import_fs6.statSync)((0, import_path6.resolve)(repositoryRoot, directory)).isDirectory();
|
|
3308
3439
|
} catch {
|
|
3309
3440
|
return true;
|
|
3310
3441
|
}
|
|
@@ -3318,8 +3449,14 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3318
3449
|
}
|
|
3319
3450
|
async function runEnvironmentInit() {
|
|
3320
3451
|
validateRepositoryStructure();
|
|
3452
|
+
assertNoOldInventoryLayout();
|
|
3321
3453
|
await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
3322
3454
|
}
|
|
3455
|
+
async function runEnvironmentUpgrade() {
|
|
3456
|
+
validateRepositoryStructure();
|
|
3457
|
+
const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
3458
|
+
await upgradeEnvironmentLayout2();
|
|
3459
|
+
}
|
|
3323
3460
|
async function runEnvironmentUpdateWorkflows() {
|
|
3324
3461
|
validateRepositoryStructure();
|
|
3325
3462
|
const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
|
|
@@ -3389,6 +3526,7 @@ Usage: opencrvs environment <subcommand>
|
|
|
3389
3526
|
|
|
3390
3527
|
Subcommands:
|
|
3391
3528
|
init Initialise a new environment
|
|
3529
|
+
upgrade Upgrade existing environment configuration layout
|
|
3392
3530
|
update-workflows Update workflow environment options
|
|
3393
3531
|
users Manage environment users
|
|
3394
3532
|
swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
|
|
@@ -3399,6 +3537,8 @@ Subcommands:
|
|
|
3399
3537
|
switch (subcommand) {
|
|
3400
3538
|
case "init":
|
|
3401
3539
|
return runEnvironmentCommand("initialisation", runEnvironmentInit);
|
|
3540
|
+
case "upgrade":
|
|
3541
|
+
return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
|
|
3402
3542
|
case "update-workflows":
|
|
3403
3543
|
return runEnvironmentCommand(
|
|
3404
3544
|
"workflow update",
|
|
@@ -3419,10 +3559,10 @@ Subcommands:
|
|
|
3419
3559
|
async function runEnvironmentCommand(operation, command) {
|
|
3420
3560
|
try {
|
|
3421
3561
|
await command();
|
|
3422
|
-
} catch (
|
|
3562
|
+
} catch (error3) {
|
|
3423
3563
|
console.error(
|
|
3424
3564
|
`Environment ${operation} failed:`,
|
|
3425
|
-
|
|
3565
|
+
error3 instanceof Error ? error3.message : error3
|
|
3426
3566
|
);
|
|
3427
3567
|
process.exit(1);
|
|
3428
3568
|
}
|
|
@@ -3448,8 +3588,8 @@ async function handleUpgrade() {
|
|
|
3448
3588
|
try {
|
|
3449
3589
|
await runUpgrade(dockerSwarm);
|
|
3450
3590
|
console.log("Upgrade completed successfully!");
|
|
3451
|
-
} catch (
|
|
3452
|
-
console.error("Upgrade failed:",
|
|
3591
|
+
} catch (error3) {
|
|
3592
|
+
console.error("Upgrade failed:", error3);
|
|
3453
3593
|
process.exit(1);
|
|
3454
3594
|
}
|
|
3455
3595
|
}
|
|
@@ -8242,37 +8242,6 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
8242
8242
|
responseSummary: {
|
|
8243
8243
|
clientId: string;
|
|
8244
8244
|
};
|
|
8245
|
-
} | {
|
|
8246
|
-
id: string;
|
|
8247
|
-
clientId: string;
|
|
8248
|
-
clientType: "system" | "user";
|
|
8249
|
-
createdAt: string;
|
|
8250
|
-
operation: "locations.create";
|
|
8251
|
-
requestData: {
|
|
8252
|
-
id: string;
|
|
8253
|
-
versionId: string;
|
|
8254
|
-
name: string;
|
|
8255
|
-
externalId?: string | null | undefined;
|
|
8256
|
-
effectiveFrom: string;
|
|
8257
|
-
status: string;
|
|
8258
|
-
administrativeAreaId?: string | null | undefined;
|
|
8259
|
-
locationType?: string | null | undefined;
|
|
8260
|
-
};
|
|
8261
|
-
} | {
|
|
8262
|
-
id: string;
|
|
8263
|
-
clientId: string;
|
|
8264
|
-
clientType: "system" | "user";
|
|
8265
|
-
createdAt: string;
|
|
8266
|
-
operation: "administrativeAreas.create";
|
|
8267
|
-
requestData: {
|
|
8268
|
-
id: string;
|
|
8269
|
-
versionId: string;
|
|
8270
|
-
name: string;
|
|
8271
|
-
externalId?: string | null | undefined;
|
|
8272
|
-
effectiveFrom: string;
|
|
8273
|
-
status: string;
|
|
8274
|
-
parentId?: string | null | undefined;
|
|
8275
|
-
};
|
|
8276
8245
|
} | {
|
|
8277
8246
|
id: string;
|
|
8278
8247
|
clientId: string;
|
|
@@ -8405,34 +8374,6 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
8405
8374
|
output: void;
|
|
8406
8375
|
meta: object;
|
|
8407
8376
|
}>;
|
|
8408
|
-
create: import("@trpc/server").TRPCMutationProcedure<{
|
|
8409
|
-
input: {
|
|
8410
|
-
id?: string | undefined;
|
|
8411
|
-
versionId?: string | undefined;
|
|
8412
|
-
name: string;
|
|
8413
|
-
externalId?: string | null | undefined;
|
|
8414
|
-
administrativeAreaId: string | null;
|
|
8415
|
-
locationType: string | null;
|
|
8416
|
-
effectiveFrom?: string | undefined;
|
|
8417
|
-
status?: "active" | "inactive" | undefined;
|
|
8418
|
-
};
|
|
8419
|
-
output: {
|
|
8420
|
-
id: string & import("zod").$brand<"UUID">;
|
|
8421
|
-
name: string;
|
|
8422
|
-
externalId?: string | null | undefined;
|
|
8423
|
-
administrativeAreaId: (string & import("zod").$brand<"UUID">) | null;
|
|
8424
|
-
locationType: string | null;
|
|
8425
|
-
status: "active" | "inactive";
|
|
8426
|
-
versions: {
|
|
8427
|
-
versionId: string & import("zod").$brand<"UUID">;
|
|
8428
|
-
effectiveFrom: string;
|
|
8429
|
-
name: string;
|
|
8430
|
-
externalId?: string | null | undefined;
|
|
8431
|
-
status: "active" | "inactive";
|
|
8432
|
-
}[];
|
|
8433
|
-
};
|
|
8434
|
-
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
8435
|
-
}>;
|
|
8436
8377
|
get: import("@trpc/server").TRPCQueryProcedure<{
|
|
8437
8378
|
input: {
|
|
8438
8379
|
id: string;
|
|
@@ -8879,32 +8820,6 @@ export declare const appRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
8879
8820
|
output: void;
|
|
8880
8821
|
meta: object;
|
|
8881
8822
|
}>;
|
|
8882
|
-
create: import("@trpc/server").TRPCMutationProcedure<{
|
|
8883
|
-
input: {
|
|
8884
|
-
id?: string | undefined;
|
|
8885
|
-
versionId?: string | undefined;
|
|
8886
|
-
name: string;
|
|
8887
|
-
externalId?: string | null | undefined;
|
|
8888
|
-
parentId: string | null;
|
|
8889
|
-
effectiveFrom?: string | undefined;
|
|
8890
|
-
status?: "active" | "inactive" | undefined;
|
|
8891
|
-
};
|
|
8892
|
-
output: {
|
|
8893
|
-
id: string & import("zod").$brand<"UUID">;
|
|
8894
|
-
name: string;
|
|
8895
|
-
externalId?: string | null | undefined;
|
|
8896
|
-
parentId: (string & import("zod").$brand<"UUID">) | null;
|
|
8897
|
-
status: "active" | "inactive";
|
|
8898
|
-
versions: {
|
|
8899
|
-
versionId: string & import("zod").$brand<"UUID">;
|
|
8900
|
-
effectiveFrom: string;
|
|
8901
|
-
name: string;
|
|
8902
|
-
externalId?: string | null | undefined;
|
|
8903
|
-
status: "active" | "inactive";
|
|
8904
|
-
}[];
|
|
8905
|
-
};
|
|
8906
|
-
meta: import("trpc-to-openapi").OpenApiMeta;
|
|
8907
|
-
}>;
|
|
8908
8823
|
}>>;
|
|
8909
8824
|
integrations: import("@trpc/server").TRPCBuiltRouter<{
|
|
8910
8825
|
ctx: Partial<{
|