@opencrvs/toolkit 2.2.0-rc.3af310b → 2.2.0-rc.3de6f63

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.
Files changed (64) hide show
  1. package/dist/application-config/index.js +5 -5
  2. package/dist/authentication/index.d.ts +1 -0
  3. package/dist/authentication/index.js +16 -4
  4. package/dist/cli.js +586 -303
  5. package/dist/commons/api/router.d.ts +246 -246
  6. package/dist/commons/application-config/index.d.ts +2 -2
  7. package/dist/commons/conditionals/index.d.ts +1 -0
  8. package/dist/commons/conditionals/validate.d.ts +5 -0
  9. package/dist/commons/events/ActionConfig.d.ts +2 -2
  10. package/dist/commons/events/ActionDocument.d.ts +1 -0
  11. package/dist/commons/events/ActionInput.d.ts +4 -4
  12. package/dist/commons/events/AdvancedSearchConfig.d.ts +3 -0
  13. package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
  14. package/dist/commons/events/EventConfig.d.ts +1 -10
  15. package/dist/commons/events/EventIndex.d.ts +2 -2
  16. package/dist/commons/events/FieldConfig.d.ts +1 -1
  17. package/dist/commons/events/FieldTypeMapping.d.ts +6 -6
  18. package/dist/commons/events/Flag.d.ts +1 -1
  19. package/dist/commons/events/PlainDate.d.ts +1 -0
  20. package/dist/commons/events/eventConfigValidation.d.ts +1 -1
  21. package/dist/commons/events/field.d.ts +5 -0
  22. package/dist/commons/events/index.d.ts +3 -0
  23. package/dist/commons/events/test.utils.d.ts +2 -3
  24. package/dist/commons/events/toNotificationForm.d.ts +17 -0
  25. package/dist/commons/events/utils.d.ts +26 -5
  26. package/dist/conditionals/index.js +2 -2
  27. package/dist/environment/custom-types.d.ts +1 -0
  28. package/dist/environment/custom-types.d.ts.map +1 -1
  29. package/dist/environment/derived-variables.d.ts +6 -4
  30. package/dist/environment/derived-variables.d.ts.map +1 -1
  31. package/dist/environment/derived-variables.js +6 -4
  32. package/dist/environment/questions.d.ts +14 -2
  33. package/dist/environment/questions.d.ts.map +1 -1
  34. package/dist/environment/questions.js +39 -18
  35. package/dist/environment/registry.d.ts +15 -0
  36. package/dist/environment/registry.d.ts.map +1 -0
  37. package/dist/environment/registry.js +112 -0
  38. package/dist/environment/setup-environment.d.ts.map +1 -1
  39. package/dist/environment/setup-environment.js +76 -28
  40. package/dist/events/index.js +197 -143
  41. package/dist/migrations/add-notify-config.d.ts +40 -0
  42. package/dist/migrations/add-notify-config.d.ts.map +1 -0
  43. package/dist/migrations/add-notify-config.js +249 -0
  44. package/dist/migrations/index.d.ts.map +1 -1
  45. package/dist/migrations/index.js +345 -143
  46. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -1
  47. package/dist/migrations/move-declaration-to-declare-action.js +27 -144
  48. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -1
  49. package/dist/migrations/read-declaration-through-helper.js +3 -61
  50. package/dist/migrations/utils.d.ts +61 -0
  51. package/dist/migrations/utils.d.ts.map +1 -0
  52. package/dist/migrations/utils.js +218 -0
  53. package/dist/notification/index.js +267 -81
  54. package/dist/scopes/index.d.ts +54 -51
  55. package/dist/scopes/index.js +12 -4
  56. package/dist/templates/charts-values/opencrvs-services/values.yaml +3 -4
  57. package/opencrvs-toolkit-2.2.0-rc.3de6f63.tgz +0 -0
  58. package/package.json +3 -2
  59. package/tsconfig.build.tsbuildinfo +1 -1
  60. package/dist/commons/events/notificationFormFallback.d.ts +0 -10
  61. package/dist/environment/dockerhub.d.ts +0 -15
  62. package/dist/environment/dockerhub.d.ts.map +0 -1
  63. package/dist/environment/dockerhub.js +0 -104
  64. package/opencrvs-toolkit-2.2.0-rc.3af310b.tgz +0 -0
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.metabaseAdminQuestions = exports.sentryQuestions = exports.emailQuestions = exports.databaseAndMonitoringQuestions = exports.diskQuestions = exports.backupQuestions = exports.staticSSLCertQuestions = exports.infrastructureQuestions = exports.countryQuestions = exports.githubTokenQuestion = exports.githubOtherQuestions = exports.githubQuestions = exports.dockerhubQuestions = void 0;
16
+ exports.metabaseAdminQuestions = exports.sentryQuestions = exports.emailQuestions = exports.databaseAndMonitoringQuestions = exports.diskQuestions = exports.backupQuestions = exports.staticSSLCertQuestions = exports.infrastructureQuestions = exports.countryQuestions = exports.githubTokenQuestion = exports.githubOtherQuestions = exports.githubQuestions = exports.registryQuestions = void 0;
17
17
  const kleur_1 = __importDefault(require("kleur"));
18
18
  const utils_1 = require("./utils");
19
19
  const git_1 = require("./git");
@@ -40,45 +40,66 @@ function validateCIDRs(input) {
40
40
  }
41
41
  return true;
42
42
  }
43
- exports.dockerhubQuestions = [
43
+ // A host with an optional port, without protocol or path (e.g. docker.io, ghcr.io, registry.example.org:5000)
44
+ function validateRegistryHost(input) {
45
+ return /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?(:[0-9]+)?$/i.test(input)
46
+ ? true
47
+ : 'Please enter a registry host without protocol or path (e.g. docker.io, ghcr.io)';
48
+ }
49
+ // The DOCKER_* and DOCKERHUB_* secrets are the previous names of the REGISTRY_* secrets
50
+ exports.registryQuestions = [
51
+ {
52
+ name: 'registryHost',
53
+ type: 'text',
54
+ message: 'What is the host of your container registry? (e.g. docker.io, ghcr.io)',
55
+ valueType: 'VARIABLE',
56
+ valueLabel: 'REGISTRY_HOST',
57
+ validate: validateRegistryHost,
58
+ initial: process.env.REGISTRY_HOST || 'docker.io',
59
+ scope: 'REPOSITORY'
60
+ },
44
61
  {
45
- name: 'dockerhubOrganisation',
62
+ name: 'registryOrganisation',
46
63
  type: 'text',
47
- message: 'What is the name of your Docker Hub organisation?',
64
+ message: 'What is the name of your organisation (or user) in the container registry?',
48
65
  valueType: 'SECRET',
49
- valueLabel: 'DOCKERHUB_ACCOUNT',
66
+ valueLabel: 'REGISTRY_ORGANISATION',
67
+ legacyValueLabel: 'DOCKERHUB_ACCOUNT',
50
68
  validate: notEmpty,
51
- initial: process.env.DOCKER_ORGANISATION,
69
+ initial: process.env.REGISTRY_ORGANISATION,
52
70
  scope: 'REPOSITORY'
53
71
  },
54
72
  {
55
- name: 'dockerhubRepository',
73
+ name: 'registryRepository',
56
74
  type: 'text',
57
- message: 'What is the name of your private Docker Hub repository?',
75
+ message: 'What is the name of your private container repository?',
58
76
  valueType: 'SECRET',
59
- valueLabel: 'DOCKERHUB_REPO',
77
+ valueLabel: 'REGISTRY_REPOSITORY',
78
+ legacyValueLabel: 'DOCKERHUB_REPO',
60
79
  validate: notEmpty,
61
- initial: process.env.DOCKER_REPO,
80
+ initial: process.env.REGISTRY_REPOSITORY,
62
81
  scope: 'REPOSITORY'
63
82
  },
64
83
  {
65
- name: 'dockerhubUsername',
84
+ name: 'registryUsername',
66
85
  type: 'text',
67
- message: 'What is the Docker Hub username the the target server should be using?',
86
+ message: 'What is the container registry username the target server should be using?',
68
87
  valueType: 'SECRET',
69
- valueLabel: 'DOCKER_USERNAME',
88
+ valueLabel: 'REGISTRY_USERNAME',
89
+ legacyValueLabel: 'DOCKER_USERNAME',
70
90
  validate: notEmpty,
71
- initial: process.env.DOCKER_USERNAME,
91
+ initial: process.env.REGISTRY_USERNAME,
72
92
  scope: 'REPOSITORY'
73
93
  },
74
94
  {
75
- name: 'dockerhubToken',
95
+ name: 'registryToken',
76
96
  type: 'text',
77
- message: 'What is the token of this Docker Hub account?',
97
+ message: 'What is the token of this container registry account?',
78
98
  valueType: 'SECRET',
79
- valueLabel: 'DOCKER_TOKEN',
99
+ valueLabel: 'REGISTRY_TOKEN',
100
+ legacyValueLabel: 'DOCKER_TOKEN',
80
101
  validate: notEmpty,
81
- initial: process.env.DOCKER_TOKEN,
102
+ initial: process.env.REGISTRY_TOKEN,
82
103
  scope: 'REPOSITORY'
83
104
  }
84
105
  ];
@@ -0,0 +1,15 @@
1
+ type RegistryValidationResult = {
2
+ status: 'valid' | 'skipped' | 'invalid-credentials' | 'repository-not-found' | 'unreachable';
3
+ reason?: string;
4
+ };
5
+ /**
6
+ * Checks, using the OCI Distribution (Docker Registry HTTP API v2) that every
7
+ * registry implements, that the username/token pair is accepted by the registry
8
+ * and that the organisation/repository is visible to that account.
9
+ *
10
+ * Existing GitHub secrets cannot be read back, so when any value is missing
11
+ * (kept from an existing secret) the check is skipped.
12
+ */
13
+ export declare function validateRegistryCredentials(registry: string | undefined, organisation: string | undefined, repository: string | undefined, username: string | undefined, token: string | undefined): Promise<RegistryValidationResult>;
14
+ export {};
15
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/environment/registry.ts"],"names":[],"mappings":"AAaA,KAAK,wBAAwB,GAAG;IAC9B,MAAM,EACF,OAAO,GAEP,SAAS,GACT,qBAAqB,GACrB,sBAAsB,GAEtB,aAAa,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAyCD;;;;;;;GAOG;AACH,wBAAsB,2BAA2B,CAC/C,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,OAAO,CAAC,wBAAwB,CAAC,CA0DnC"}
@@ -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":"AAiUA,wBAAsB,mBAAmB,kBA2pCxC"}
1
+ {"version":3,"file":"setup-environment.d.ts","sourceRoot":"","sources":["../../src/environment/setup-environment.ts"],"names":[],"mappings":"AA4aA,wBAAsB,mBAAmB,kBAwpCxC"}
@@ -65,11 +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 dockerhub_1 = require("./dockerhub");
68
+ const registry_1 = require("./registry");
69
69
  const manage_users_1 = require("./manage-users");
70
70
  const paths_1 = require("./paths");
71
71
  function questionToPrompt(_a) {
72
- 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"]);
73
73
  return promptOptions;
74
74
  }
75
75
  const ALL_QUESTIONS = [];
@@ -113,6 +113,14 @@ function getAnswers(existingValues) {
113
113
  });
114
114
  });
115
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
+ }
116
124
  function promptAndStoreAnswer(questions, existingValues) {
117
125
  return __awaiter(this, void 0, void 0, function* () {
118
126
  (0, logger_1.log)('');
@@ -123,13 +131,15 @@ function promptAndStoreAnswer(questions, existingValues) {
123
131
  }
124
132
  if (questionWithVariableLabel.valueType === 'VARIABLE') {
125
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
+ }
126
142
  if (existingVariable) {
127
- let initial_value = existingVariable.value;
128
- // Get correct initial value for select questions
129
- if (questionWithVariableLabel.type === 'select' &&
130
- Array.isArray(questionWithVariableLabel.choices)) {
131
- initial_value = (0, questions_helper_1.getIndexFromChoices)(questionWithVariableLabel.choices, existingVariable.value);
132
- }
133
143
  return [
134
144
  {
135
145
  name: 'overWrite' + questionWithVariableLabel.name,
@@ -137,12 +147,30 @@ function promptAndStoreAnswer(questions, existingValues) {
137
147
  scope: questionWithVariableLabel.scope,
138
148
  message: `${kleur_1.default.yellow(`Variable ${kleur_1.default.cyan(existingVariable.name)} already exists in Github. Do you want to update it?`)}`
139
149
  },
140
- Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null), initial: initial_value })
150
+ Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null), initial: getInitialValue(questionWithVariableLabel, existingVariable) })
141
151
  ];
142
152
  }
143
153
  }
144
154
  if (questionWithVariableLabel.valueType === 'SECRET') {
145
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
+ }
146
174
  if (existingSecret) {
147
175
  return [
148
176
  {
@@ -176,16 +204,39 @@ function promptAndStoreAnswer(questions, existingValues) {
176
204
  return Object.assign(Object.assign({}, Object.fromEntries(existingValuesForQuestions)), result);
177
205
  });
178
206
  }
179
- function promptAndValidateDockerhub(existingValues) {
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) {
180
231
  return __awaiter(this, void 0, void 0, function* () {
181
- const answers = yield promptAndStoreAnswer(questions_1.dockerhubQuestions, existingValues);
182
- const result = yield (0, dockerhub_1.validateDockerHubCredentials)(answers.dockerhubOrganisation, answers.dockerhubRepository, answers.dockerhubUsername, answers.dockerhubToken);
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);
183
234
  if (result.status === 'valid' || result.status === 'skipped') {
184
235
  return;
185
236
  }
186
237
  (0, logger_1.error)(`\n${result.status}: ${result.reason || 'Generic error'}\n`);
187
238
  const continueNotValidated = yield confirm({
188
- message: 'Docker Hub credentials are not validated. Continue anyway?',
239
+ message: 'Container registry credentials are not validated. Continue anyway?',
189
240
  default: false
190
241
  });
191
242
  if (!continueNotValidated) {
@@ -193,7 +244,7 @@ function promptAndValidateDockerhub(existingValues) {
193
244
  }
194
245
  });
195
246
  }
196
- 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);
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);
197
248
  function runSetupEnvironment() {
198
249
  return __awaiter(this, void 0, void 0, function* () {
199
250
  var _a, _b, _c, _d;
@@ -297,8 +348,8 @@ function runSetupEnvironment() {
297
348
  if (!two_fa_enabled && ['production', 'staging'].includes(environment_type)) {
298
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.');
299
350
  }
300
- (0, logger_1.log)('\n', kleur_1.default.bold().underline('Docker Hub'));
301
- yield promptAndValidateDockerhub(existingValues);
351
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Container registry'));
352
+ yield promptAndValidateRegistry(existingValues);
302
353
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('Kubernetes & Runtime'));
303
354
  const infrastructure = yield promptAndStoreAnswer(questions_1.infrastructureQuestions, existingValues);
304
355
  const kubeWorkerNodes = infrastructure.kubeWorkerNodes
@@ -478,11 +529,7 @@ function runSetupEnvironment() {
478
529
  * Variables the user doesn't need to set manually
479
530
  */
480
531
  const answerOrExisting = (variable, existingValue, fn) => fn(variable || (existingValue === null || existingValue === void 0 ? void 0 : existingValue.value)) || '';
481
- function findExistingOrDefine(name, type, scope, newValue) {
482
- return (0, utils_1.findExistingValue)(name, type, scope, existingValues)
483
- ? null
484
- : process.env[name] || newValue;
485
- }
532
+ const findExistingOrDefine = (name, type, scope, newValue) => defineIfMissing(existingValues, name, type, scope, newValue);
486
533
  const derivedUpdates = [
487
534
  {
488
535
  name: 'GH_ENCRYPTION_PASSWORD',
@@ -542,17 +589,17 @@ function runSetupEnvironment() {
542
589
  scope: 'ENVIRONMENT'
543
590
  },
544
591
  {
545
- name: 'MINIO_ROOT_USER',
592
+ name: 'S3_ADMIN_ACCESS_KEY',
546
593
  type: 'SECRET',
547
- didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', existingValues),
548
- value: findExistingOrDefine('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
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)()),
549
596
  scope: 'ENVIRONMENT'
550
597
  },
551
598
  {
552
- name: 'MINIO_ROOT_PASSWORD',
599
+ name: 'S3_ADMIN_SECRET_KEY',
553
600
  type: 'SECRET',
554
- didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
555
- value: findExistingOrDefine('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
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)()),
556
603
  scope: 'ENVIRONMENT'
557
604
  },
558
605
  {
@@ -681,7 +728,8 @@ function runSetupEnvironment() {
681
728
  const newVariables = updates.filter((update) => update.type === 'VARIABLE' && !update.didExist);
682
729
  const updatedVariables = updates.filter((update) => update.type === 'VARIABLE' && Boolean(update.didExist));
683
730
  const unknownVariables = existingValues.filter((value) => {
684
- return !ALL_QUESTIONS.find((question) => question.valueLabel === value.name &&
731
+ return !ALL_QUESTIONS.find((question) => (question.valueLabel === value.name ||
732
+ question.legacyValueLabel === value.name) &&
685
733
  question.valueType === value.type &&
686
734
  question.scope === value.scope);
687
735
  });