@opencrvs/toolkit 2.2.0-rc.9042a13 → 2.2.0-rc.9dfc125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build.sh +2 -12
- package/dist/application-config/index.js +12 -7
- package/dist/authentication/index.d.ts +1 -0
- package/dist/authentication/index.js +16 -5
- package/dist/cli.js +875 -193
- package/dist/commons/api/router.d.ts +252 -246
- package/dist/commons/application-config/index.d.ts +2 -2
- package/dist/commons/conditionals/index.d.ts +1 -0
- package/dist/commons/conditionals/validate.d.ts +5 -0
- package/dist/commons/events/ActionConfig.d.ts +16 -23
- package/dist/commons/events/ActionDocument.d.ts +1 -0
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
- package/dist/commons/events/CountryConfigQueryInput.d.ts +60 -18
- package/dist/commons/events/EventConfig.d.ts +12 -2
- package/dist/commons/events/EventIndex.d.ts +23 -6
- package/dist/commons/events/EventMetadata.d.ts +0 -1
- package/dist/commons/events/FieldConfig.d.ts +1 -1
- package/dist/commons/events/FieldTypeMapping.d.ts +6 -6
- package/dist/commons/events/Flag.d.ts +1 -7
- package/dist/commons/events/PlainDate.d.ts +1 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +74 -27
- package/dist/commons/events/eventConfigValidation.d.ts +9 -0
- package/dist/commons/events/index.d.ts +2 -0
- package/dist/commons/events/notificationFormFallback.d.ts +10 -0
- package/dist/commons/events/state/flags.d.ts +1 -1
- package/dist/commons/events/test.utils.d.ts +3 -0
- package/dist/commons/events/utils.d.ts +85 -56
- package/dist/conditionals/index.js +2 -3
- package/dist/environment/custom-types.d.ts +1 -0
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/derived-variables.d.ts +12 -4
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +13 -4
- package/dist/environment/questions.d.ts +14 -2
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +40 -19
- package/dist/environment/registry.d.ts +15 -0
- package/dist/environment/registry.d.ts.map +1 -0
- package/dist/environment/registry.js +112 -0
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +111 -24
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/events/index.js +251 -67
- package/dist/migrations/index.d.ts +9 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +847 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
- package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
- package/dist/migrations/move-declaration-to-declare-action.js +377 -0
- package/dist/migrations/{add-translations.d.ts → persistent/add-translations.d.ts} +1 -1
- package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
- package/dist/migrations/{add-translations.js → persistent/add-translations.js} +2 -2
- package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
- package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
- package/dist/migrations/persistent/check-upgrade-path.js +105 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
- package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
- package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
- package/dist/migrations/{v2.2/read-declaration-through-helper.d.ts → read-declaration-through-helper.d.ts} +1 -1
- package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
- package/dist/migrations/{v2.2/read-declaration-through-helper.js → read-declaration-through-helper.js} +1 -1
- package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
- package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
- package/dist/migrations/replace-incomplete-flag.js +126 -0
- package/dist/notification/index.js +151 -21
- package/dist/scopes/index.d.ts +54 -84
- package/dist/scopes/index.js +12 -5
- package/dist/templates/charts-values/dependencies/values.yaml +1 -1
- package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -6
- package/dist/templates/charts-values/traefik/values.yaml +2 -0
- package/opencrvs-toolkit-2.2.0-rc.9dfc125.tgz +0 -0
- package/package.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/dist/migrations/add-translations.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
- package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
- package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
- package/dist/migrations/v2.1/enable-telemetry.js +0 -455
- package/dist/migrations/v2.1/index.d.ts +0 -6
- package/dist/migrations/v2.1/index.d.ts.map +0 -1
- package/dist/migrations/v2.1/index.js +0 -50
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -17
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
- package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
- package/dist/migrations/v2.1/remove-sentry.js +0 -354
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
- package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
- package/dist/migrations/v2.1/template-files.d.ts +0 -8
- package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
- package/dist/migrations/v2.1/template-files.js +0 -49
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -11
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
- package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
- package/dist/migrations/v2.2/index.d.ts +0 -6
- package/dist/migrations/v2.2/index.d.ts.map +0 -1
- package/dist/migrations/v2.2/index.js +0 -456
- package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +0 -1
- package/dist/templates/countryconfig-template/.tiltignore +0 -1
- package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
- package/dist/templates/countryconfig-template/Tiltfile +0 -112
- package/dist/templates/countryconfig-template/assets/README.md +0 -1
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
- package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
- package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
- package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
- package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
- package/opencrvs-toolkit-2.2.0-rc.9042a13.tgz +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.validateRegistryCredentials = validateRegistryCredentials;
|
|
23
|
+
const REQUEST_TIMEOUT_MS = 10000;
|
|
24
|
+
// Docker Hub serves its registry API from registry-1.docker.io, docker.io is the website
|
|
25
|
+
function registryApiHost(registry) {
|
|
26
|
+
const host = registry.trim().toLowerCase();
|
|
27
|
+
return host === 'docker.io' || host === 'index.docker.io'
|
|
28
|
+
? 'registry-1.docker.io'
|
|
29
|
+
: host;
|
|
30
|
+
}
|
|
31
|
+
function request(url, authorization) {
|
|
32
|
+
return fetch(url, {
|
|
33
|
+
headers: authorization ? { Authorization: authorization } : {},
|
|
34
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function failure(registry, step, response) {
|
|
38
|
+
const reason = `${registry} ${step} responded with HTTP ${response.status}`;
|
|
39
|
+
switch (response.status) {
|
|
40
|
+
case 401:
|
|
41
|
+
case 403:
|
|
42
|
+
return {
|
|
43
|
+
status: 'invalid-credentials',
|
|
44
|
+
reason: `${reason}. Check REGISTRY_USERNAME, REGISTRY_TOKEN, REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
45
|
+
};
|
|
46
|
+
case 404:
|
|
47
|
+
// The API cannot tell an empty repository from one that does not exist
|
|
48
|
+
return {
|
|
49
|
+
status: 'repository-not-found',
|
|
50
|
+
reason: `${reason}. This is also the answer for an empty repository. Check REGISTRY_ORGANISATION and REGISTRY_REPOSITORY`
|
|
51
|
+
};
|
|
52
|
+
default:
|
|
53
|
+
return { status: 'unreachable', reason };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Checks, using the OCI Distribution (Docker Registry HTTP API v2) that every
|
|
58
|
+
* registry implements, that the username/token pair is accepted by the registry
|
|
59
|
+
* and that the organisation/repository is visible to that account.
|
|
60
|
+
*
|
|
61
|
+
* Existing GitHub secrets cannot be read back, so when any value is missing
|
|
62
|
+
* (kept from an existing secret) the check is skipped.
|
|
63
|
+
*/
|
|
64
|
+
function validateRegistryCredentials(registry, organisation, repository, username, token) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a, _b;
|
|
67
|
+
var _c, _d;
|
|
68
|
+
if (!registry || !organisation || !repository || !username || !token) {
|
|
69
|
+
return {
|
|
70
|
+
status: 'skipped',
|
|
71
|
+
reason: 'Some values are kept from existing GitHub secrets, which cannot be read back'
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const host = registryApiHost(registry);
|
|
75
|
+
const name = `${organisation}/${repository}`;
|
|
76
|
+
const basic = `Basic ${Buffer.from(`${username}:${token}`).toString('base64')}`;
|
|
77
|
+
try {
|
|
78
|
+
// A registry that wants a token names its token service in the challenge.
|
|
79
|
+
// For any other answer the credentials are sent as they are.
|
|
80
|
+
const challenge = (_c = (yield request(`https://${host}/v2/`, undefined)).headers.get('www-authenticate')) !== null && _c !== void 0 ? _c : '';
|
|
81
|
+
const realm = (_a = challenge.match(/realm="([^"]*)"/i)) === null || _a === void 0 ? void 0 : _a[1];
|
|
82
|
+
const service = (_b = challenge.match(/service="([^"]*)"/i)) === null || _b === void 0 ? void 0 : _b[1];
|
|
83
|
+
let authorization = basic;
|
|
84
|
+
if (/^\s*bearer/i.test(challenge) && realm) {
|
|
85
|
+
const tokenUrl = new URL(realm);
|
|
86
|
+
if (service) {
|
|
87
|
+
tokenUrl.searchParams.set('service', service);
|
|
88
|
+
}
|
|
89
|
+
tokenUrl.searchParams.set('scope', `repository:${name}:pull`);
|
|
90
|
+
const login = yield request(tokenUrl, basic);
|
|
91
|
+
if (!login.ok) {
|
|
92
|
+
return failure(registry, 'login', login);
|
|
93
|
+
}
|
|
94
|
+
const body = (yield login.json());
|
|
95
|
+
authorization = `Bearer ${(_d = body.token) !== null && _d !== void 0 ? _d : body.access_token}`;
|
|
96
|
+
}
|
|
97
|
+
const path = name.split('/').map(encodeURIComponent).join('/');
|
|
98
|
+
const response = yield request(`https://${host}/v2/${path}/tags/list?n=1`, authorization);
|
|
99
|
+
return response.ok
|
|
100
|
+
? { status: 'valid' }
|
|
101
|
+
: failure(registry, `lookup of repository ${name}`, response);
|
|
102
|
+
}
|
|
103
|
+
catch (err) {
|
|
104
|
+
if (!(err instanceof Error)) {
|
|
105
|
+
return { status: 'unreachable', reason: String(err) };
|
|
106
|
+
}
|
|
107
|
+
// fetch only reports "fetch failed", the real error (e.g. ENOTFOUND) is its cause
|
|
108
|
+
const cause = err.cause instanceof Error ? `: ${err.cause.message}` : '';
|
|
109
|
+
return { status: 'unreachable', reason: `${err.message}${cause}` };
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-environment.d.ts","sourceRoot":"","sources":["../../src/environment/setup-environment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup-environment.d.ts","sourceRoot":"","sources":["../../src/environment/setup-environment.ts"],"names":[],"mappings":"AA4aA,wBAAsB,mBAAmB,kBAwpCxC"}
|
|
@@ -65,10 +65,11 @@ const update_workflows_1 = require("./update-workflows");
|
|
|
65
65
|
const questions_1 = require("./questions");
|
|
66
66
|
const editor_questions_1 = require("./editor-questions");
|
|
67
67
|
const questions_helper_1 = require("./questions-helper");
|
|
68
|
+
const registry_1 = require("./registry");
|
|
68
69
|
const manage_users_1 = require("./manage-users");
|
|
69
70
|
const paths_1 = require("./paths");
|
|
70
71
|
function questionToPrompt(_a) {
|
|
71
|
-
var { valueType, valueLabel, scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "scope"]);
|
|
72
|
+
var { valueType, valueLabel, legacyValueLabel, scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "legacyValueLabel", "scope"]);
|
|
72
73
|
return promptOptions;
|
|
73
74
|
}
|
|
74
75
|
const ALL_QUESTIONS = [];
|
|
@@ -112,6 +113,14 @@ function getAnswers(existingValues) {
|
|
|
112
113
|
});
|
|
113
114
|
});
|
|
114
115
|
}
|
|
116
|
+
// The value of a variable that exists, as the initial value of its question.
|
|
117
|
+
// A select question takes the index of the choice.
|
|
118
|
+
function getInitialValue(question, variable) {
|
|
119
|
+
if (question.type === 'select' && Array.isArray(question.choices)) {
|
|
120
|
+
return (0, questions_helper_1.getIndexFromChoices)(question.choices, variable.value);
|
|
121
|
+
}
|
|
122
|
+
return variable.value;
|
|
123
|
+
}
|
|
115
124
|
function promptAndStoreAnswer(questions, existingValues) {
|
|
116
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
117
126
|
(0, logger_1.log)('');
|
|
@@ -122,13 +131,15 @@ function promptAndStoreAnswer(questions, existingValues) {
|
|
|
122
131
|
}
|
|
123
132
|
if (questionWithVariableLabel.valueType === 'VARIABLE') {
|
|
124
133
|
const existingVariable = (0, utils_1.findExistingValue)(questionWithVariableLabel.valueLabel, 'VARIABLE', questionWithVariableLabel.scope, existingValues);
|
|
134
|
+
// Unlike a secret, the value of a variable can be read, so one that only exists
|
|
135
|
+
// under its previous name is the default of the question
|
|
136
|
+
const legacyVariable = !existingVariable && questionWithVariableLabel.legacyValueLabel
|
|
137
|
+
? (0, utils_1.findExistingValue)(questionWithVariableLabel.legacyValueLabel, 'VARIABLE', questionWithVariableLabel.scope, existingValues)
|
|
138
|
+
: undefined;
|
|
139
|
+
if (legacyVariable) {
|
|
140
|
+
return Object.assign(Object.assign({}, questionWithVariableLabel), { message: `${questionWithVariableLabel.message} ${kleur_1.default.gray(`(default taken from ${legacyVariable.name}, the previous name of this variable)`)}`, initial: getInitialValue(questionWithVariableLabel, legacyVariable) });
|
|
141
|
+
}
|
|
125
142
|
if (existingVariable) {
|
|
126
|
-
let initial_value = existingVariable.value;
|
|
127
|
-
// Get correct initial value for select questions
|
|
128
|
-
if (questionWithVariableLabel.type === 'select' &&
|
|
129
|
-
Array.isArray(questionWithVariableLabel.choices)) {
|
|
130
|
-
initial_value = (0, questions_helper_1.getIndexFromChoices)(questionWithVariableLabel.choices, existingVariable.value);
|
|
131
|
-
}
|
|
132
143
|
return [
|
|
133
144
|
{
|
|
134
145
|
name: 'overWrite' + questionWithVariableLabel.name,
|
|
@@ -136,12 +147,30 @@ function promptAndStoreAnswer(questions, existingValues) {
|
|
|
136
147
|
scope: questionWithVariableLabel.scope,
|
|
137
148
|
message: `${kleur_1.default.yellow(`Variable ${kleur_1.default.cyan(existingVariable.name)} already exists in Github. Do you want to update it?`)}`
|
|
138
149
|
},
|
|
139
|
-
Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null), initial:
|
|
150
|
+
Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null), initial: getInitialValue(questionWithVariableLabel, existingVariable) })
|
|
140
151
|
];
|
|
141
152
|
}
|
|
142
153
|
}
|
|
143
154
|
if (questionWithVariableLabel.valueType === 'SECRET') {
|
|
144
155
|
const existingSecret = (0, utils_1.findExistingValue)(questionWithVariableLabel.valueLabel, 'SECRET', questionWithVariableLabel.scope, existingValues);
|
|
156
|
+
// The value of a secret that only exists under its previous name can't be read, so
|
|
157
|
+
// it is left to the secrets migration workflow, unless a new value is entered here
|
|
158
|
+
const legacySecret = !existingSecret && questionWithVariableLabel.legacyValueLabel
|
|
159
|
+
? (0, utils_1.findExistingValue)(questionWithVariableLabel.legacyValueLabel, 'SECRET', questionWithVariableLabel.scope, existingValues)
|
|
160
|
+
: undefined;
|
|
161
|
+
if (legacySecret) {
|
|
162
|
+
return [
|
|
163
|
+
{
|
|
164
|
+
name: 'overWrite' + questionWithVariableLabel.name,
|
|
165
|
+
type: 'confirm',
|
|
166
|
+
scope: questionWithVariableLabel.scope,
|
|
167
|
+
message: `${kleur_1.default.yellow(`${legacySecret.scope === 'REPOSITORY'
|
|
168
|
+
? 'Repository secret'
|
|
169
|
+
: 'Secret'} ${kleur_1.default.cyan(legacySecret.name)} already exists in Github under the previous name of ${kleur_1.default.cyan(questionWithVariableLabel.valueLabel)}. The secrets migration workflow copies it. Do you want to enter a new value instead?`)}`
|
|
170
|
+
},
|
|
171
|
+
Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null) })
|
|
172
|
+
];
|
|
173
|
+
}
|
|
145
174
|
if (existingSecret) {
|
|
146
175
|
return [
|
|
147
176
|
{
|
|
@@ -175,7 +204,47 @@ function promptAndStoreAnswer(questions, existingValues) {
|
|
|
175
204
|
return Object.assign(Object.assign({}, Object.fromEntries(existingValuesForQuestions)), result);
|
|
176
205
|
});
|
|
177
206
|
}
|
|
178
|
-
|
|
207
|
+
/**
|
|
208
|
+
* The value of a secret or variable that is generated rather than asked for, or
|
|
209
|
+
* null when it exists. One that only exists under its previous name counts as
|
|
210
|
+
* existing: the secrets migration workflow copies it, and a generated value
|
|
211
|
+
* would replace the credential that is in use.
|
|
212
|
+
*/
|
|
213
|
+
function defineIfMissing(existingValues, name, type, scope, newValue) {
|
|
214
|
+
var _a;
|
|
215
|
+
if ((0, utils_1.findExistingValue)(name, type, scope, existingValues)) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
const legacyName = (_a = ALL_QUESTIONS.find((question) => question.valueLabel === name &&
|
|
219
|
+
question.valueType === type &&
|
|
220
|
+
question.scope === scope)) === null || _a === void 0 ? void 0 : _a.legacyValueLabel;
|
|
221
|
+
if (legacyName &&
|
|
222
|
+
(0, utils_1.findExistingValue)(legacyName, type, scope, existingValues)) {
|
|
223
|
+
(0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default
|
|
224
|
+
.bold()
|
|
225
|
+
.yellow(`${legacyName} exists, the secrets migration workflow copies it to ${name}`));
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
return process.env[name] || newValue;
|
|
229
|
+
}
|
|
230
|
+
function promptAndValidateRegistry(existingValues) {
|
|
231
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
232
|
+
const answers = yield promptAndStoreAnswer(questions_1.registryQuestions, existingValues);
|
|
233
|
+
const result = yield (0, registry_1.validateRegistryCredentials)(answers.registryHost, answers.registryOrganisation, answers.registryRepository, answers.registryUsername, answers.registryToken);
|
|
234
|
+
if (result.status === 'valid' || result.status === 'skipped') {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
(0, logger_1.error)(`\n${result.status}: ${result.reason || 'Generic error'}\n`);
|
|
238
|
+
const continueNotValidated = yield confirm({
|
|
239
|
+
message: 'Container registry credentials are not validated. Continue anyway?',
|
|
240
|
+
default: false
|
|
241
|
+
});
|
|
242
|
+
if (!continueNotValidated) {
|
|
243
|
+
process.exit(1);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOtherQuestions, ...questions_1.registryQuestions, ...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);
|
|
179
248
|
function runSetupEnvironment() {
|
|
180
249
|
return __awaiter(this, void 0, void 0, function* () {
|
|
181
250
|
var _a, _b, _c, _d;
|
|
@@ -279,8 +348,8 @@ function runSetupEnvironment() {
|
|
|
279
348
|
if (!two_fa_enabled && ['production', 'staging'].includes(environment_type)) {
|
|
280
349
|
(0, logger_1.warn)('2FA is disabled on a production-like environment. Logins will accept the fixed test code 000000, exposing real citizen data. Only do this if you know what you are doing.');
|
|
281
350
|
}
|
|
282
|
-
(0, logger_1.log)('\n', kleur_1.default.bold().underline('
|
|
283
|
-
yield
|
|
351
|
+
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Container registry'));
|
|
352
|
+
yield promptAndValidateRegistry(existingValues);
|
|
284
353
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Kubernetes & Runtime'));
|
|
285
354
|
const infrastructure = yield promptAndStoreAnswer(questions_1.infrastructureQuestions, existingValues);
|
|
286
355
|
const kubeWorkerNodes = infrastructure.kubeWorkerNodes
|
|
@@ -419,7 +488,18 @@ function runSetupEnvironment() {
|
|
|
419
488
|
(0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Restore is disabled'));
|
|
420
489
|
}
|
|
421
490
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Monitoring'));
|
|
422
|
-
|
|
491
|
+
const existingMonitoringEnabled = (0, utils_1.findExistingValue)('MONITORING_ENABLED', 'VARIABLE', 'ENVIRONMENT', existingValues);
|
|
492
|
+
const monitoringDefault = process.env.MONITORING_ENABLED || (existingMonitoringEnabled === null || existingMonitoringEnabled === void 0 ? void 0 : existingMonitoringEnabled.value);
|
|
493
|
+
const monitoring_enabled = yield confirm({
|
|
494
|
+
message: 'Enable monitoring (Kibana, APM, Filebeat, Metricbeat, Elastalert, OpenTelemetry Collector and tracing)? Disable it if this environment does not need its own monitoring stack.',
|
|
495
|
+
default: monitoringDefault ? monitoringDefault === 'true' : true
|
|
496
|
+
});
|
|
497
|
+
if (monitoring_enabled) {
|
|
498
|
+
yield promptAndStoreAnswer(questions_1.databaseAndMonitoringQuestions, existingValues);
|
|
499
|
+
}
|
|
500
|
+
else {
|
|
501
|
+
(0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Monitoring is disabled'));
|
|
502
|
+
}
|
|
423
503
|
const sentryDSNExists = (0, utils_1.findExistingValue)('SENTRY_DSN', 'SECRET', 'ENVIRONMENT', existingValues);
|
|
424
504
|
(0, logger_1.log)('\n', kleur_1.default.bold().underline('Sentry'));
|
|
425
505
|
if (sentryDSNExists) {
|
|
@@ -449,11 +529,7 @@ function runSetupEnvironment() {
|
|
|
449
529
|
* Variables the user doesn't need to set manually
|
|
450
530
|
*/
|
|
451
531
|
const answerOrExisting = (variable, existingValue, fn) => fn(variable || (existingValue === null || existingValue === void 0 ? void 0 : existingValue.value)) || '';
|
|
452
|
-
|
|
453
|
-
return (0, utils_1.findExistingValue)(name, type, scope, existingValues)
|
|
454
|
-
? null
|
|
455
|
-
: process.env[name] || newValue;
|
|
456
|
-
}
|
|
532
|
+
const findExistingOrDefine = (name, type, scope, newValue) => defineIfMissing(existingValues, name, type, scope, newValue);
|
|
457
533
|
const derivedUpdates = [
|
|
458
534
|
{
|
|
459
535
|
name: 'GH_ENCRYPTION_PASSWORD',
|
|
@@ -478,6 +554,15 @@ function runSetupEnvironment() {
|
|
|
478
554
|
value: two_fa_enabled ? 'true' : 'false',
|
|
479
555
|
scope: 'ENVIRONMENT'
|
|
480
556
|
});
|
|
557
|
+
// Read by the deployment workflows (vars.MONITORING_ENABLED) to decide
|
|
558
|
+
// whether the OpenTelemetry Collector is installed
|
|
559
|
+
derivedUpdates.push({
|
|
560
|
+
name: 'MONITORING_ENABLED',
|
|
561
|
+
type: 'VARIABLE',
|
|
562
|
+
didExist: existingMonitoringEnabled,
|
|
563
|
+
value: monitoring_enabled ? 'true' : 'false',
|
|
564
|
+
scope: 'ENVIRONMENT'
|
|
565
|
+
});
|
|
481
566
|
derivedUpdates.push(...ssl_answers);
|
|
482
567
|
if (configureBackup) {
|
|
483
568
|
derivedUpdates.push({
|
|
@@ -504,17 +589,17 @@ function runSetupEnvironment() {
|
|
|
504
589
|
scope: 'ENVIRONMENT'
|
|
505
590
|
},
|
|
506
591
|
{
|
|
507
|
-
name: '
|
|
592
|
+
name: 'S3_ADMIN_ACCESS_KEY',
|
|
508
593
|
type: 'SECRET',
|
|
509
|
-
didExist: (0, utils_1.findExistingValue)('
|
|
510
|
-
value: findExistingOrDefine('
|
|
594
|
+
didExist: (0, utils_1.findExistingValue)('S3_ADMIN_ACCESS_KEY', 'SECRET', 'ENVIRONMENT', existingValues),
|
|
595
|
+
value: findExistingOrDefine('S3_ADMIN_ACCESS_KEY', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
|
|
511
596
|
scope: 'ENVIRONMENT'
|
|
512
597
|
},
|
|
513
598
|
{
|
|
514
|
-
name: '
|
|
599
|
+
name: 'S3_ADMIN_SECRET_KEY',
|
|
515
600
|
type: 'SECRET',
|
|
516
|
-
didExist: (0, utils_1.findExistingValue)('
|
|
517
|
-
value: findExistingOrDefine('
|
|
601
|
+
didExist: (0, utils_1.findExistingValue)('S3_ADMIN_SECRET_KEY', 'SECRET', 'ENVIRONMENT', existingValues),
|
|
602
|
+
value: findExistingOrDefine('S3_ADMIN_SECRET_KEY', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
|
|
518
603
|
scope: 'ENVIRONMENT'
|
|
519
604
|
},
|
|
520
605
|
{
|
|
@@ -643,7 +728,8 @@ function runSetupEnvironment() {
|
|
|
643
728
|
const newVariables = updates.filter((update) => update.type === 'VARIABLE' && !update.didExist);
|
|
644
729
|
const updatedVariables = updates.filter((update) => update.type === 'VARIABLE' && Boolean(update.didExist));
|
|
645
730
|
const unknownVariables = existingValues.filter((value) => {
|
|
646
|
-
return !ALL_QUESTIONS.find((question) => question.valueLabel === value.name
|
|
731
|
+
return !ALL_QUESTIONS.find((question) => (question.valueLabel === value.name ||
|
|
732
|
+
question.legacyValueLabel === value.name) &&
|
|
647
733
|
question.valueType === value.type &&
|
|
648
734
|
question.scope === value.scope);
|
|
649
735
|
});
|
|
@@ -772,6 +858,7 @@ function runSetupEnvironment() {
|
|
|
772
858
|
env: environment,
|
|
773
859
|
environment_type: environment_type,
|
|
774
860
|
two_fa_enabled,
|
|
861
|
+
monitoring_enabled,
|
|
775
862
|
traefik_mode: traefikConfOption,
|
|
776
863
|
restore_enabled: restoreEnvironmentName ? true : false,
|
|
777
864
|
restore_environment_name: restoreEnvironmentName || '',
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,QAyBzE"}
|