@opencrvs/toolkit 2.1.0-rc.d7bd264 → 2.1.0-rc.d987aec
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 +9 -1
- package/create-countryconfig/index.js +412 -59
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +266 -212
- package/dist/authentication/index.d.ts +67 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +750 -0
- package/dist/cli.js +1786 -120
- package/dist/commons/api/router.d.ts +691 -76
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +15 -5
- package/dist/commons/events/ActionConfig.d.ts +0 -21
- package/dist/commons/events/ActionDocument.d.ts +4 -4
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/AdvancedSearchConfig.d.ts +18 -0
- package/dist/commons/events/AuditLog.d.ts +147 -0
- package/dist/commons/events/CountryConfigQueryInput.d.ts +0 -18
- package/dist/commons/events/EventConfig.d.ts +3 -0
- package/dist/commons/events/EventDocument.d.ts +470 -2
- package/dist/commons/events/EventIndex.d.ts +2 -6
- package/dist/commons/events/EventMetadata.d.ts +1 -12
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +84 -53
- package/dist/commons/events/FieldTypeMapping.d.ts +15 -15
- package/dist/commons/events/FieldValue.d.ts +2 -2
- package/dist/commons/events/Flag.d.ts +0 -6
- 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 +5 -17
- package/dist/commons/events/event.d.ts +12 -0
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locationPayloads.d.ts +95 -0
- package/dist/commons/events/locations.d.ts +169 -26
- package/dist/commons/events/mocks.test.utils.d.ts +30 -0
- package/dist/commons/events/test.utils.d.ts +25 -4
- package/dist/commons/events/utils.d.ts +13 -2
- 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 +81 -59
- 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 +10 -0
- 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.js +28 -7
- 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 +17 -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/events/index.js +2905 -2463
- 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.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 +213 -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 +438 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1058 -0
- package/dist/notification/index.js +1317 -1475
- package/dist/scopes/index.d.ts +104 -59
- package/dist/scopes/index.js +81 -59
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +39 -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 +95 -0
- package/dist/templates/charts-values/traefik/values.yaml +23 -9
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/dist/translations/check.d.ts +21 -0
- package/dist/translations/check.d.ts.map +1 -0
- package/dist/translations/check.js +132 -0
- package/dist/verify/endpoints.d.ts +2 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +345 -0
- package/opencrvs-toolkit-2.1.0-rc.d987aec.tgz +0 -0
- package/package.json +12 -6
- 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.d7bd264.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -166,11 +166,28 @@ exports.infrastructureQuestions = [
|
|
|
166
166
|
scope: 'ENVIRONMENT'
|
|
167
167
|
},
|
|
168
168
|
{
|
|
169
|
-
name: '
|
|
169
|
+
name: 'kubeMasterNode',
|
|
170
170
|
type: 'text',
|
|
171
|
-
message: `Kubernetes
|
|
171
|
+
message: `Kubernetes master node hostnames or IP (default: auto-detect)`,
|
|
172
|
+
valueType: 'VARIABLE',
|
|
173
|
+
valueLabel: 'KUBE_MASTER_NODE',
|
|
174
|
+
initial: process.env.KUBE_MASTER_NODE,
|
|
175
|
+
scope: 'ENVIRONMENT'
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'kubeWorkerNodes',
|
|
179
|
+
type: 'text',
|
|
180
|
+
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
181
|
+
valueType: 'VARIABLE',
|
|
182
|
+
valueLabel: 'KUBE_WORKER_NODES',
|
|
183
|
+
initial: process.env.KUBE_WORKER_NODES || '',
|
|
184
|
+
scope: 'ENVIRONMENT'
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: 'kubeApiHost',
|
|
188
|
+
type: 'text',
|
|
189
|
+
message: `Kubernetes API endpoint IP (default: KUBE_MASTER_NODE)`,
|
|
172
190
|
valueType: 'VARIABLE',
|
|
173
|
-
// validate: notEmpty,
|
|
174
191
|
valueLabel: 'KUBE_API_HOST',
|
|
175
192
|
initial: process.env.KUBE_API_HOST,
|
|
176
193
|
scope: 'ENVIRONMENT'
|
|
@@ -185,16 +202,6 @@ exports.infrastructureQuestions = [
|
|
|
185
202
|
initial: process.env.KUBE_API_ALLOWED_CIDRS || '',
|
|
186
203
|
scope: 'ENVIRONMENT'
|
|
187
204
|
},
|
|
188
|
-
{
|
|
189
|
-
name: 'kubeWorkerNodes',
|
|
190
|
-
type: 'text',
|
|
191
|
-
message: `Kubernetes worker node hostnames or IPs (comma-separated, default: no worker nodes)`,
|
|
192
|
-
valueType: 'VARIABLE',
|
|
193
|
-
// validate: notEmpty,
|
|
194
|
-
valueLabel: 'KUBE_WORKER_NODES',
|
|
195
|
-
initial: process.env.KUBE_WORKER_NODES || '',
|
|
196
|
-
scope: 'ENVIRONMENT'
|
|
197
|
-
}
|
|
198
205
|
];
|
|
199
206
|
exports.staticSSLCertQuestions = [
|
|
200
207
|
{
|
|
@@ -224,7 +231,6 @@ exports.backupQuestions = [
|
|
|
224
231
|
type: 'text',
|
|
225
232
|
message: `Please enter backup server host/IP address, (default: no backup):`,
|
|
226
233
|
valueType: 'VARIABLE',
|
|
227
|
-
// validate: notEmpty,
|
|
228
234
|
valueLabel: 'BACKUP_HOST',
|
|
229
235
|
initial: process.env.BACKUP_HOST || '',
|
|
230
236
|
scope: 'ENVIRONMENT'
|
|
@@ -49,6 +49,12 @@ function select(options) {
|
|
|
49
49
|
return inquirer.select(options);
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
|
+
function input(options) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const inquirer = yield import('@inquirer/prompts');
|
|
55
|
+
return inquirer.input(options);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
52
58
|
const github_1 = require("./github");
|
|
53
59
|
const derived_variables_1 = require("./derived-variables");
|
|
54
60
|
const utils_1 = require("./utils");
|
|
@@ -59,6 +65,7 @@ const questions_1 = require("./questions");
|
|
|
59
65
|
const editor_questions_1 = require("./editor-questions");
|
|
60
66
|
const questions_helper_1 = require("./questions-helper");
|
|
61
67
|
const manage_users_1 = require("./manage-users");
|
|
68
|
+
const paths_1 = require("./paths");
|
|
62
69
|
function questionToPrompt(_a) {
|
|
63
70
|
var { valueType, valueLabel, scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "scope"]);
|
|
64
71
|
return promptOptions;
|
|
@@ -170,7 +177,7 @@ function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
170
177
|
}
|
|
171
178
|
ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOtherQuestions, ...questions_1.dockerhubQuestions, ...questions_1.diskQuestions, ...questions_1.infrastructureQuestions, ...questions_1.backupQuestions, ...questions_1.countryQuestions, ...questions_1.databaseAndMonitoringQuestions, ...questions_1.emailQuestions, ...questions_1.sentryQuestions, ...derived_variables_1.derivedVariables, ...questions_1.metabaseAdminQuestions);
|
|
172
179
|
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
173
|
-
var _a, _b, _c;
|
|
180
|
+
var _a, _b, _c, _d;
|
|
174
181
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Github'), '\n');
|
|
175
182
|
const { githubOrganisation, githubRepository } = yield (0, prompts_1.default)(questions_1.githubQuestions.map(questionToPrompt), {
|
|
176
183
|
onCancel: () => {
|
|
@@ -271,7 +278,7 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
|
|
|
271
278
|
? infrastructure.kubeWorkerNodes.split(',').map((ip) => ip.trim())
|
|
272
279
|
: [];
|
|
273
280
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('SSH Users'), '\n');
|
|
274
|
-
const users = yield (0, manage_users_1.manageUsers)(
|
|
281
|
+
const users = yield (0, manage_users_1.manageUsers)((0, paths_1.getEnvironmentInventoryPath)(environment));
|
|
275
282
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Traefik SSL Certificate'), '\n');
|
|
276
283
|
const sslCertExists = (0, utils_1.findExistingValue)('SSL_CRT', 'SECRET', 'ENVIRONMENT', existingValues);
|
|
277
284
|
let ssl_answers = [];
|
|
@@ -330,7 +337,8 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
|
|
|
330
337
|
let backupHost = ((_a = (0, utils_1.findExistingValue)('BACKUP_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _a === void 0 ? void 0 : _a.value) || '';
|
|
331
338
|
let backupType = '';
|
|
332
339
|
let restoreEnvironmentName = (_b = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _b === void 0 ? void 0 : _b.value;
|
|
333
|
-
let
|
|
340
|
+
let restoreHost = ((_c = (0, utils_1.findExistingValue)('RESTORE_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _c === void 0 ? void 0 : _c.value) || '';
|
|
341
|
+
let restoreType = ((_d = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_MODE', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _d === void 0 ? void 0 : _d.value) ||
|
|
334
342
|
process.env.RESTORE_ENVIRONMENT_MODE ||
|
|
335
343
|
'dump';
|
|
336
344
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Backup'));
|
|
@@ -392,6 +400,10 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
|
|
|
392
400
|
}
|
|
393
401
|
]
|
|
394
402
|
});
|
|
403
|
+
restoreHost = yield input({
|
|
404
|
+
message: 'What is the host/IP address of the restore backup server?',
|
|
405
|
+
default: restoreHost
|
|
406
|
+
});
|
|
395
407
|
}
|
|
396
408
|
else {
|
|
397
409
|
(0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Restore is disabled'));
|
|
@@ -556,6 +568,13 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
|
|
|
556
568
|
value: answerOrExisting(restoreEnvironmentName, (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => val || ''),
|
|
557
569
|
didExist: (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues),
|
|
558
570
|
scope: 'ENVIRONMENT'
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
type: 'VARIABLE',
|
|
574
|
+
name: 'RESTORE_HOST',
|
|
575
|
+
value: answerOrExisting(restoreHost, (0, utils_1.findExistingValue)('RESTORE_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => val || ''),
|
|
576
|
+
didExist: (0, utils_1.findExistingValue)('RESTORE_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
|
|
577
|
+
scope: 'ENVIRONMENT'
|
|
559
578
|
}
|
|
560
579
|
];
|
|
561
580
|
if (enableEncryption) {
|
|
@@ -716,7 +735,7 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
|
|
|
716
735
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Running configuration files updates'));
|
|
717
736
|
(0, templates_1.generateInventory)(environment, {
|
|
718
737
|
kube_worker_nodes: kubeWorkerNodes,
|
|
719
|
-
kube_api_host: infrastructure.
|
|
738
|
+
kube_api_host: infrastructure.kubeApiHost || '',
|
|
720
739
|
backup_host: backupHost || '',
|
|
721
740
|
users: users
|
|
722
741
|
});
|
|
@@ -727,12 +746,14 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
|
|
|
727
746
|
// Hardcode like this blocks us from being generic:
|
|
728
747
|
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
729
748
|
two_fa_enabled: environment !== 'production' ? false : true,
|
|
730
|
-
|
|
749
|
+
traefik_mode: traefikConfOption,
|
|
731
750
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
732
751
|
restore_environment_name: restoreEnvironmentName || '',
|
|
733
752
|
restore_type: restoreType,
|
|
734
|
-
|
|
735
|
-
|
|
753
|
+
restore_host: restoreHost || '',
|
|
754
|
+
backup_enabled: configureBackup ? true : false,
|
|
755
|
+
backup_type: backupType,
|
|
756
|
+
backup_host: backupHost || ''
|
|
736
757
|
});
|
|
737
758
|
let addon_message = kubeWorkerNodes.length > 0 || configureBackup
|
|
738
759
|
? '--------------------------------------------------------------------------------------------\n' +
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/environment/templates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/environment/templates.ts"],"names":[],"mappings":"AA0BA,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAepD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAWpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASnD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,CAStD;AAGD;;;;GAIG;AACH;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QA0CzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAsBzE"}
|
|
@@ -24,7 +24,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
24
24
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.getUsers = getUsers;
|
|
28
27
|
exports.extractAndModifyUsers = extractAndModifyUsers;
|
|
29
28
|
exports.dockerManagerFirst = dockerManagerFirst;
|
|
30
29
|
exports.extractBackupNode = extractBackupNode;
|
|
@@ -34,18 +33,12 @@ exports.generateInventory = generateInventory;
|
|
|
34
33
|
const fs_1 = __importDefault(require("fs"));
|
|
35
34
|
const path_1 = __importDefault(require("path"));
|
|
36
35
|
const logger_1 = require("./logger");
|
|
36
|
+
const paths_1 = require("./paths");
|
|
37
37
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
38
38
|
// Register a helper to increment numbers
|
|
39
39
|
handlebars_1.default.registerHelper('data_label_idx', function (value) {
|
|
40
40
|
return parseInt(value) + 2;
|
|
41
41
|
});
|
|
42
|
-
function getUsers(data) {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
if (!((_b = (_a = data === null || data === void 0 ? void 0 : data.all) === null || _a === void 0 ? void 0 : _a.vars) === null || _b === void 0 ? void 0 : _b.users)) {
|
|
45
|
-
return { users: [] };
|
|
46
|
-
}
|
|
47
|
-
return data.all.vars.users;
|
|
48
|
-
}
|
|
49
42
|
// START: TEMPORAL SECTION FOR TRANSITION FROM DOCKER SWARM TO K8s
|
|
50
43
|
// Extract users from the old inventory
|
|
51
44
|
// Docker swarm format to new
|
|
@@ -55,6 +48,9 @@ function extractAndModifyUsers(data) {
|
|
|
55
48
|
return { users: [] };
|
|
56
49
|
}
|
|
57
50
|
const users = data.all.vars.users.map((user) => {
|
|
51
|
+
if (user.role) {
|
|
52
|
+
return user;
|
|
53
|
+
}
|
|
58
54
|
const { sudoer } = user, rest = __rest(user, ["sudoer"]);
|
|
59
55
|
return Object.assign(Object.assign({}, rest), { role: sudoer ? 'admin' : 'operator' });
|
|
60
56
|
});
|
|
@@ -149,7 +145,7 @@ function copyChartsValues(env, values) {
|
|
|
149
145
|
function generateInventory(env, values) {
|
|
150
146
|
// Template and output paths
|
|
151
147
|
const templatePath = path_1.default.join(__dirname, 'templates', 'inventory', 'inventory.template.yml');
|
|
152
|
-
const outputPath = path_1.default.
|
|
148
|
+
const outputPath = path_1.default.resolve(process.cwd(), (0, paths_1.getEnvironmentInventoryPath)(env));
|
|
153
149
|
const templateFile = fs_1.default.readFileSync(templatePath, 'utf-8');
|
|
154
150
|
const template = handlebars_1.default.compile(templateFile);
|
|
155
151
|
values['single_node'] =
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-workflows.d.ts","sourceRoot":"","sources":["../../src/environment/update-workflows.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"update-workflows.d.ts","sourceRoot":"","sources":["../../src/environment/update-workflows.ts"],"names":[],"mappings":"AA+HA,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAgDhE"}
|
|
@@ -60,12 +60,21 @@ const path_1 = require("path");
|
|
|
60
60
|
const glob = __importStar(require("glob"));
|
|
61
61
|
const yaml = __importStar(require("js-yaml"));
|
|
62
62
|
const logger_1 = require("./logger");
|
|
63
|
+
const paths_1 = require("./paths");
|
|
64
|
+
function isDirectory(path) {
|
|
65
|
+
try {
|
|
66
|
+
return (0, fs_1.statSync)(path).isDirectory();
|
|
67
|
+
}
|
|
68
|
+
catch (_a) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
63
72
|
function extractInfrastructureNames() {
|
|
64
73
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const files = glob.sync('
|
|
66
|
-
const infraEnvironments = files.map((file) => (0, path_1.basename)(
|
|
74
|
+
const files = glob.sync((0, path_1.join)('environments', '*', paths_1.INVENTORY_FILE_NAME));
|
|
75
|
+
const infraEnvironments = files.map((file) => (0, path_1.basename)((0, path_1.dirname)(file)));
|
|
67
76
|
if (infraEnvironments.length === 0) {
|
|
68
|
-
console.log(
|
|
77
|
+
console.log(`⚠️ Warning: No environment inventory files found at environments/*/${paths_1.INVENTORY_FILE_NAME}`);
|
|
69
78
|
return [];
|
|
70
79
|
}
|
|
71
80
|
(0, logger_1.log)('🔍 Found infrastructure configurations:', infraEnvironments.join(', '));
|
|
@@ -77,8 +86,11 @@ function extractEnvironmentNames() {
|
|
|
77
86
|
const entries = yield (0, promises_1.readdir)('environments');
|
|
78
87
|
// Filter only directories
|
|
79
88
|
const environments = entries.filter((entry) => {
|
|
80
|
-
const
|
|
81
|
-
|
|
89
|
+
const environmentPath = (0, path_1.join)('environments', entry);
|
|
90
|
+
const opencrvsServicesPath = (0, path_1.join)(environmentPath, 'opencrvs-services');
|
|
91
|
+
return (isDirectory(environmentPath) &&
|
|
92
|
+
(0, fs_1.existsSync)(opencrvsServicesPath) &&
|
|
93
|
+
isDirectory(opencrvsServicesPath));
|
|
82
94
|
});
|
|
83
95
|
if (environments.length === 0) {
|
|
84
96
|
console.log('⚠️ Warning: No environment directories found in environments/');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../src/environment/upgrade.ts"],"names":[],"mappings":"AAkFA,wBAAsB,wBAAwB,kBAY7C"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.upgradeEnvironmentLayout = upgradeEnvironmentLayout;
|
|
26
|
+
const fs_1 = require("fs");
|
|
27
|
+
const path_1 = require("path");
|
|
28
|
+
const kleur_1 = __importDefault(require("kleur"));
|
|
29
|
+
const logger_1 = require("./logger");
|
|
30
|
+
const paths_1 = require("./paths");
|
|
31
|
+
const update_workflows_1 = require("./update-workflows");
|
|
32
|
+
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
33
|
+
if (!(0, fs_1.existsSync)(sourcePath)) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if ((0, fs_1.existsSync)(destinationPath)) {
|
|
37
|
+
(0, logger_1.warn)(`⚠️ Skipped ${sourcePath}; destination already exists at ${destinationPath}`);
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(destinationPath), { recursive: true });
|
|
41
|
+
(0, fs_1.renameSync)(sourcePath, destinationPath);
|
|
42
|
+
(0, logger_1.log)(` ✓ Moved ${sourcePath} -> ${destinationPath}`);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
function migrateInventoryFiles() {
|
|
46
|
+
const oldInventoryFiles = (0, paths_1.findOldInventoryFiles)();
|
|
47
|
+
if (oldInventoryFiles.length === 0) {
|
|
48
|
+
(0, logger_1.log)(`ℹ️ No old inventory files found at ${paths_1.OLD_INVENTORY_DIR}`);
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
(0, logger_1.log)(kleur_1.default.bold('\nMigrating Ansible inventory files'));
|
|
52
|
+
let didMoveInventory = false;
|
|
53
|
+
for (const oldInventoryFile of oldInventoryFiles) {
|
|
54
|
+
const environment = (0, paths_1.getEnvironmentNameFromOldInventoryPath)(oldInventoryFile);
|
|
55
|
+
didMoveInventory =
|
|
56
|
+
moveFileIfDestinationMissing(oldInventoryFile, (0, paths_1.getEnvironmentInventoryPath)(environment)) || didMoveInventory;
|
|
57
|
+
}
|
|
58
|
+
try {
|
|
59
|
+
if ((0, fs_1.existsSync)(paths_1.OLD_INVENTORY_DIR) &&
|
|
60
|
+
(0, fs_1.readdirSync)(paths_1.OLD_INVENTORY_DIR).length === 0) {
|
|
61
|
+
(0, fs_1.rmdirSync)(paths_1.OLD_INVENTORY_DIR);
|
|
62
|
+
(0, logger_1.log)(` ✓ Removed empty ${paths_1.OLD_INVENTORY_DIR}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
catch (_a) {
|
|
66
|
+
(0, logger_1.warn)(`⚠️ Could not remove ${paths_1.OLD_INVENTORY_DIR}; please review it manually`);
|
|
67
|
+
}
|
|
68
|
+
return didMoveInventory;
|
|
69
|
+
}
|
|
70
|
+
function upgradeEnvironmentLayout() {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
const didMoveInventory = migrateInventoryFiles();
|
|
73
|
+
yield (0, update_workflows_1.updateWorkflowEnvironments)();
|
|
74
|
+
if (didMoveInventory) {
|
|
75
|
+
(0, logger_1.success)('\n✅ Environment layout upgrade completed successfully.');
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
(0, logger_1.success)('\n✅ Environment layout already uses the current structure.');
|
|
79
|
+
}
|
|
80
|
+
(0, logger_1.log)('\nCommit changes into git after upgrade');
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -62,6 +62,7 @@ const path = __importStar(require("path"));
|
|
|
62
62
|
const kleur_1 = __importDefault(require("kleur"));
|
|
63
63
|
const manage_users_1 = require("./manage-users");
|
|
64
64
|
const logger_1 = require("./logger");
|
|
65
|
+
const paths_1 = require("./paths");
|
|
65
66
|
function select(options) {
|
|
66
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
67
68
|
const inquirer = yield import('@inquirer/prompts');
|
|
@@ -76,32 +77,29 @@ function select(options) {
|
|
|
76
77
|
* * @returns {string} Inventory file
|
|
77
78
|
*/
|
|
78
79
|
function selectInventoryFile() {
|
|
79
|
-
return __awaiter(this, arguments, void 0, function* (dirPath = './
|
|
80
|
+
return __awaiter(this, arguments, void 0, function* (dirPath = './environments') {
|
|
80
81
|
// Check if directory exists
|
|
81
82
|
if (!fs.existsSync(dirPath)) {
|
|
82
83
|
(0, logger_1.warn)(`⚠️ No environment configuration directory found at ${dirPath}`);
|
|
83
84
|
(0, logger_1.warn)('Hint: If this is a new infrastructure repository, run `opencrvs environment init` first.');
|
|
84
85
|
return null;
|
|
85
86
|
}
|
|
86
|
-
|
|
87
|
-
const files = fs
|
|
87
|
+
const environments = fs
|
|
88
88
|
.readdirSync(dirPath)
|
|
89
|
-
.filter((
|
|
90
|
-
const filePath = path.join(dirPath,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return isFile && (ext === 'yml' || ext === 'yaml');
|
|
89
|
+
.filter((entry) => {
|
|
90
|
+
const filePath = path.join(dirPath, entry);
|
|
91
|
+
return (fs.statSync(filePath).isDirectory() &&
|
|
92
|
+
fs.existsSync((0, paths_1.getEnvironmentInventoryPath)(entry)));
|
|
94
93
|
})
|
|
95
94
|
.sort();
|
|
96
|
-
if (
|
|
95
|
+
if (environments.length === 0) {
|
|
97
96
|
(0, logger_1.warn)(`⚠️ No environment configuration files found at ${dirPath}`);
|
|
98
97
|
(0, logger_1.warn)('Hint: If this is a new infrastructure repository, run `opencrvs environment init` first.');
|
|
99
98
|
return null;
|
|
100
99
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
value: path.join(dirPath, file)
|
|
100
|
+
const choices = environments.map((environment) => ({
|
|
101
|
+
name: environment,
|
|
102
|
+
value: (0, paths_1.getEnvironmentInventoryPath)(environment)
|
|
105
103
|
}));
|
|
106
104
|
const selectedFile = yield select({
|
|
107
105
|
message: 'Select environment (inventory file) to load users:',
|