@opencrvs/toolkit 2.0.0-rc.bd45274 → 2.0.0-rc.bd55713

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 (79) hide show
  1. package/README.md +14 -0
  2. package/build.sh +1 -0
  3. package/dist/application-config/index.js +7 -1
  4. package/dist/cli.js +3191 -42
  5. package/dist/commons/api/router.d.ts +11 -2
  6. package/dist/commons/events/ActionConfig.d.ts +28 -2
  7. package/dist/commons/events/FieldConfig.d.ts +1 -0
  8. package/dist/commons/events/FieldType.d.ts +1 -0
  9. package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
  10. package/dist/environment/custom-types.d.ts +33 -0
  11. package/dist/environment/custom-types.d.ts.map +1 -0
  12. package/dist/environment/custom-types.js +2 -0
  13. package/dist/environment/derived-variables.d.ts +134 -0
  14. package/dist/environment/derived-variables.d.ts.map +1 -0
  15. package/dist/environment/derived-variables.js +159 -0
  16. package/dist/environment/editor-questions.d.ts +5 -0
  17. package/dist/environment/editor-questions.d.ts.map +1 -0
  18. package/dist/environment/editor-questions.js +56 -0
  19. package/dist/environment/git.d.ts +5 -0
  20. package/dist/environment/git.d.ts.map +1 -0
  21. package/dist/environment/git.js +28 -0
  22. package/dist/environment/github.d.ts +26 -0
  23. package/dist/environment/github.d.ts.map +1 -0
  24. package/dist/environment/github.js +234 -0
  25. package/dist/environment/index.d.ts +6 -0
  26. package/dist/environment/index.d.ts.map +1 -0
  27. package/dist/environment/index.js +61 -0
  28. package/dist/environment/logger.d.ts +15 -0
  29. package/dist/environment/logger.d.ts.map +1 -0
  30. package/dist/environment/logger.js +15 -0
  31. package/dist/environment/manage-users.d.ts +11 -0
  32. package/dist/environment/manage-users.d.ts.map +1 -0
  33. package/dist/environment/manage-users.js +484 -0
  34. package/dist/environment/questions-helper.d.ts +15 -0
  35. package/dist/environment/questions-helper.d.ts.map +1 -0
  36. package/dist/environment/questions-helper.js +60 -0
  37. package/dist/environment/questions.d.ts +222 -0
  38. package/dist/environment/questions.d.ts.map +1 -0
  39. package/dist/environment/questions.js +455 -0
  40. package/dist/environment/setup-environment.d.ts +2 -0
  41. package/dist/environment/setup-environment.d.ts.map +1 -0
  42. package/dist/environment/setup-environment.js +763 -0
  43. package/dist/environment/ssh-keygen.d.ts +5 -0
  44. package/dist/environment/ssh-keygen.d.ts.map +1 -0
  45. package/dist/environment/ssh-keygen.js +8 -0
  46. package/dist/environment/swarm-to-k8s.d.ts +2 -0
  47. package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
  48. package/dist/environment/swarm-to-k8s.js +162 -0
  49. package/dist/environment/templates/charts-values/dependencies/values.override.yaml +4 -0
  50. package/dist/environment/templates/charts-values/dependencies/values.yaml +82 -0
  51. package/dist/environment/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  52. package/dist/environment/templates/charts-values/opencrvs-services/values.yaml +79 -0
  53. package/dist/environment/templates/charts-values/traefik/values.override.yaml +4 -0
  54. package/dist/environment/templates/charts-values/traefik/values.yaml +116 -0
  55. package/dist/environment/templates/inventory/inventory.template.yml +100 -0
  56. package/dist/environment/templates/inventory/production.example.yml +77 -0
  57. package/dist/environment/templates/inventory/qa.example.yml +48 -0
  58. package/dist/environment/templates.d.ts +27 -0
  59. package/dist/environment/templates.d.ts.map +1 -0
  60. package/dist/environment/templates.js +149 -0
  61. package/dist/environment/update-workflows.d.ts +2 -0
  62. package/dist/environment/update-workflows.d.ts.map +1 -0
  63. package/dist/environment/update-workflows.js +151 -0
  64. package/dist/environment/users.d.ts +2 -0
  65. package/dist/environment/users.d.ts.map +1 -0
  66. package/dist/environment/users.js +92 -0
  67. package/dist/environment/utils.d.ts +18 -0
  68. package/dist/environment/utils.d.ts.map +1 -0
  69. package/dist/environment/utils.js +90 -0
  70. package/dist/events/index.js +153 -62
  71. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  72. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  73. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -1
  74. package/dist/migrations/v2.0/index.js +1 -1
  75. package/dist/notification/index.js +96 -3
  76. package/opencrvs-toolkit-2.0.0-rc.bd55713.tgz +0 -0
  77. package/package.json +15 -1
  78. package/tsconfig.tsbuildinfo +1 -1
  79. package/opencrvs-toolkit-2.0.0-rc.bd45274.tgz +0 -0
@@ -0,0 +1,234 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createEnvironmentVariable = createEnvironmentVariable;
13
+ exports.updateEnvironmentVariable = updateEnvironmentVariable;
14
+ exports.createRepositoryVariable = createRepositoryVariable;
15
+ exports.updateRepositoryVariable = updateRepositoryVariable;
16
+ exports.getRepositoryId = getRepositoryId;
17
+ exports.createEnvironmentSecret = createEnvironmentSecret;
18
+ exports.createRepositorySecret = createRepositorySecret;
19
+ exports.getRepositoryEnvironments = getRepositoryEnvironments;
20
+ exports.createEnvironment = createEnvironment;
21
+ exports.listEnvironmentSecrets = listEnvironmentSecrets;
22
+ exports.listRepositorySecrets = listRepositorySecrets;
23
+ exports.listEnvironmentVariables = listEnvironmentVariables;
24
+ exports.listRepositoryVariables = listRepositoryVariables;
25
+ const sodium = require('libsodium-wrappers');
26
+ const logger_1 = require("./logger");
27
+ function createEnvironmentVariable(octokit, repositoryId, environment, name, value) {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ yield octokit.request(`POST /repositories/${repositoryId}/environments/${environment}/variables`, {
30
+ repository_id: repositoryId,
31
+ environment_name: environment,
32
+ name: name,
33
+ value: value,
34
+ headers: {
35
+ 'X-GitHub-Api-Version': '2022-11-28'
36
+ }
37
+ });
38
+ });
39
+ }
40
+ function updateEnvironmentVariable(octokit, repositoryId, environment, name, value) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ yield octokit.request(`PATCH /repositories/${repositoryId}/environments/${environment}/variables/${name}`, {
43
+ repository_id: repositoryId,
44
+ environment_name: environment,
45
+ name: name,
46
+ value: value,
47
+ headers: {
48
+ 'X-GitHub-Api-Version': '2022-11-28'
49
+ }
50
+ });
51
+ });
52
+ }
53
+ // Create repository variable
54
+ function createRepositoryVariable(octokit, repositoryId, name, value) {
55
+ return __awaiter(this, void 0, void 0, function* () {
56
+ yield octokit.request(`POST /repositories/${repositoryId}/actions/variables`, {
57
+ repository_id: repositoryId,
58
+ name: name,
59
+ value: value,
60
+ headers: {
61
+ 'X-GitHub-Api-Version': '2022-11-28'
62
+ }
63
+ });
64
+ });
65
+ }
66
+ // Update repository variable
67
+ function updateRepositoryVariable(octokit, repositoryId, name, value) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ yield octokit.request(`PATCH /repositories/${repositoryId}/actions/variables/${name}`, {
70
+ repository_id: repositoryId,
71
+ name: name,
72
+ value: value,
73
+ headers: {
74
+ 'X-GitHub-Api-Version': '2022-11-28'
75
+ }
76
+ });
77
+ });
78
+ }
79
+ function getRepositoryId(octokit, owner, repo) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const response = yield octokit.request('GET /repos/{owner}/{repo}', {
82
+ owner: owner,
83
+ repo: repo
84
+ });
85
+ return response.data.id;
86
+ });
87
+ }
88
+ function getRepositoryPublicKey(octokit, owner, repo) {
89
+ return __awaiter(this, void 0, void 0, function* () {
90
+ const res = yield octokit.request('GET /repos/{owner}/{repo}/actions/secrets/public-key', {
91
+ owner: owner,
92
+ repo: repo
93
+ });
94
+ return res.data;
95
+ });
96
+ }
97
+ function getPublicKey(octokit, environment, ORGANISATION, REPOSITORY_NAME) {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const repositoryId = yield getRepositoryId(octokit, ORGANISATION, REPOSITORY_NAME);
100
+ yield octokit.request(`PUT /repos/${ORGANISATION}/${REPOSITORY_NAME}/environments/${environment}`, {
101
+ headers: {
102
+ 'X-GitHub-Api-Version': '2022-11-28'
103
+ }
104
+ });
105
+ const res = yield octokit.request(`GET /repositories/${repositoryId}/environments/${environment}/secrets/public-key`, {
106
+ owner: ORGANISATION,
107
+ repo: REPOSITORY_NAME,
108
+ headers: {
109
+ 'X-GitHub-Api-Version': '2022-11-28'
110
+ }
111
+ });
112
+ return res.data;
113
+ });
114
+ }
115
+ function createEnvironmentSecret(octokit, repositoryId, environment, name, secret, organisationName, repositoryName) {
116
+ return __awaiter(this, void 0, void 0, function* () {
117
+ //Check if libsodium is ready and then proceed.
118
+ yield sodium.ready;
119
+ const { key, key_id } = yield getPublicKey(octokit, environment, organisationName, repositoryName);
120
+ // Convert Secret & Base64 key to Uint8Array.
121
+ const binkey = sodium.from_base64(key, sodium.base64_variants.ORIGINAL);
122
+ const binsec = sodium.from_string(secret);
123
+ //Encrypt the secret using LibSodium
124
+ const encBytes = sodium.crypto_box_seal(binsec, binkey);
125
+ // Convert encrypted Uint8Array to Base64
126
+ const encryptedValue = sodium.to_base64(encBytes, sodium.base64_variants.ORIGINAL);
127
+ yield octokit.request(`PUT /repositories/${repositoryId}/environments/${environment}/secrets/${name}`, {
128
+ repository_id: repositoryId,
129
+ environment_name: environment,
130
+ secret_name: name,
131
+ encrypted_value: encryptedValue,
132
+ key_id,
133
+ headers: {
134
+ 'X-GitHub-Api-Version': '2022-11-28'
135
+ }
136
+ });
137
+ });
138
+ }
139
+ function createRepositorySecret(octokit, repositoryId, name, secret, organisationName, repositoryName) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ //Check if libsodium is ready and then proceed.
142
+ yield sodium.ready;
143
+ const { key, key_id } = yield getRepositoryPublicKey(octokit, organisationName, repositoryName);
144
+ // Convert Secret & Base64 key to Uint8Array.
145
+ const binkey = sodium.from_base64(key, sodium.base64_variants.ORIGINAL);
146
+ const binsec = sodium.from_string(secret);
147
+ //Encrypt the secret using LibSodium
148
+ const encBytes = sodium.crypto_box_seal(binsec, binkey);
149
+ // Convert encrypted Uint8Array to Base64
150
+ const encryptedValue = sodium.to_base64(encBytes, sodium.base64_variants.ORIGINAL);
151
+ yield octokit.request(`PUT /repositories/${repositoryId}/actions/secrets/${name}`, {
152
+ encrypted_value: encryptedValue,
153
+ key_id,
154
+ headers: {
155
+ 'X-GitHub-Api-Version': '2022-11-28'
156
+ }
157
+ });
158
+ });
159
+ }
160
+ function getRepositoryEnvironments(octokit, githubOrganisation, repository) {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ var _a;
163
+ const response = yield octokit.request('GET /repos/{githubOrganisation}/{repository}/environments', {
164
+ githubOrganisation,
165
+ repository,
166
+ });
167
+ // Safe access with fallback to empty array if undefined
168
+ const environments = ((_a = response.data.environments) !== null && _a !== void 0 ? _a : []).map((env) => env.name);
169
+ return environments;
170
+ });
171
+ }
172
+ function createEnvironment(octokit, environment, ORGANISATION, REPOSITORY_NAME) {
173
+ return __awaiter(this, void 0, void 0, function* () {
174
+ var _a, _b, _c, _d;
175
+ try {
176
+ yield octokit.request(`PUT /repos/${ORGANISATION}/${REPOSITORY_NAME}/environments/${environment}`, {
177
+ headers: {
178
+ 'X-GitHub-Api-Version': '2022-11-28'
179
+ }
180
+ });
181
+ return true;
182
+ }
183
+ catch (err) {
184
+ (0, logger_1.error)(`Cannot create environment: [${err.status}] ${(_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.message}`);
185
+ throw new Error(`Cannot create environment: [${err.status}] ${(_d = (_c = err.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message}`);
186
+ }
187
+ });
188
+ }
189
+ function listEnvironmentSecrets(octokit, owner, repositoryId, environmentName) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const response = yield octokit.request('GET /repositories/{repository_id}/environments/{environment_name}/secrets', {
192
+ owner: owner,
193
+ repository_id: repositoryId,
194
+ environment_name: environmentName,
195
+ per_page: 100
196
+ });
197
+ return response.data.secrets.map((secret) => (Object.assign(Object.assign({}, secret), { type: 'SECRET', scope: 'ENVIRONMENT' })));
198
+ });
199
+ }
200
+ function listRepositorySecrets(octokit, owner, repositoryName) {
201
+ return __awaiter(this, void 0, void 0, function* () {
202
+ const response = yield octokit.request('GET /repos/{owner}/{repo}/actions/secrets', {
203
+ owner: owner,
204
+ repo: repositoryName,
205
+ per_page: 100
206
+ });
207
+ return response.data.secrets.map((secret) => (Object.assign(Object.assign({}, secret), { type: 'SECRET', scope: 'REPOSITORY' })));
208
+ });
209
+ }
210
+ function listEnvironmentVariables(octokit, repositoryId, environmentName) {
211
+ return __awaiter(this, void 0, void 0, function* () {
212
+ const response = yield octokit.request('GET /repositories/{repository_id}/environments/{environment_name}/variables', {
213
+ repository_id: repositoryId,
214
+ environment_name: environmentName,
215
+ per_page: 100,
216
+ headers: {
217
+ 'X-GitHub-Api-Version': '2022-11-28'
218
+ }
219
+ });
220
+ return response.data.variables
221
+ .map((variable) => (Object.assign(Object.assign({}, variable), { type: 'VARIABLE', scope: 'ENVIRONMENT' })))
222
+ .filter((variable) => variable.name !== 'ACTIONS_RUNNER_DEBUG');
223
+ });
224
+ }
225
+ function listRepositoryVariables(octokit, owner, repositoryName) {
226
+ return __awaiter(this, void 0, void 0, function* () {
227
+ const response = yield octokit.request('GET /repos/{owner}/{repo}/actions/variables', {
228
+ owner: owner,
229
+ repo: repositoryName,
230
+ per_page: 100
231
+ });
232
+ return response.data.variables.map((variable) => (Object.assign(Object.assign({}, variable), { type: 'VARIABLE', scope: 'REPOSITORY' })));
233
+ });
234
+ }
@@ -0,0 +1,6 @@
1
+ export declare function validateRepositoryStructure(repositoryRoot?: string): void;
2
+ export declare function runEnvironmentInit(): Promise<void>;
3
+ export declare function runEnvironmentUpdateWorkflows(): Promise<void>;
4
+ export declare function runEnvironmentUsers(): Promise<void>;
5
+ export declare function runEnvironmentSwarmToK8s(): Promise<void>;
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/environment/index.ts"],"names":[],"mappings":"AASA,wBAAgB,2BAA2B,CAAC,cAAc,SAAgB,QAkBzE;AAED,wBAAsB,kBAAkB,kBAGvC;AAED,wBAAsB,6BAA6B,kBAIlD;AAED,wBAAsB,mBAAmB,kBAGxC;AAED,wBAAsB,wBAAwB,kBAG7C"}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validateRepositoryStructure = validateRepositoryStructure;
13
+ exports.runEnvironmentInit = runEnvironmentInit;
14
+ exports.runEnvironmentUpdateWorkflows = runEnvironmentUpdateWorkflows;
15
+ exports.runEnvironmentUsers = runEnvironmentUsers;
16
+ exports.runEnvironmentSwarmToK8s = runEnvironmentSwarmToK8s;
17
+ const fs_1 = require("fs");
18
+ const path_1 = require("path");
19
+ const REQUIRED_REPOSITORY_DIRECTORIES = [
20
+ '.github/workflows',
21
+ 'environments',
22
+ 'infrastructure'
23
+ ];
24
+ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
25
+ const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter((directory) => {
26
+ try {
27
+ return !(0, fs_1.statSync)((0, path_1.resolve)(repositoryRoot, directory)).isDirectory();
28
+ }
29
+ catch (_a) {
30
+ return true;
31
+ }
32
+ });
33
+ if (missingDirectories.length > 0) {
34
+ throw new Error(`The current directory is not a valid OpenCRVS country configuration repository. Missing required director${missingDirectories.length === 1 ? 'y' : 'ies'}: ${missingDirectories.join(', ')}`);
35
+ }
36
+ }
37
+ function runEnvironmentInit() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ validateRepositoryStructure();
40
+ yield import('./setup-environment.js');
41
+ });
42
+ }
43
+ function runEnvironmentUpdateWorkflows() {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ validateRepositoryStructure();
46
+ const { updateWorkflowEnvironments } = yield import('./update-workflows.js');
47
+ yield updateWorkflowEnvironments();
48
+ });
49
+ }
50
+ function runEnvironmentUsers() {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ validateRepositoryStructure();
53
+ yield import('./users.js');
54
+ });
55
+ }
56
+ function runEnvironmentSwarmToK8s() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ validateRepositoryStructure();
59
+ yield import('./swarm-to-k8s.js');
60
+ });
61
+ }
@@ -0,0 +1,15 @@
1
+ export declare const log: {
2
+ (...data: any[]): void;
3
+ (message?: any, ...optionalParams: any[]): void;
4
+ };
5
+ export declare const warn: {
6
+ (...data: any[]): void;
7
+ (message?: any, ...optionalParams: any[]): void;
8
+ };
9
+ export declare const success: (...args: any[]) => void;
10
+ export declare const info: {
11
+ (...data: any[]): void;
12
+ (message?: any, ...optionalParams: any[]): void;
13
+ };
14
+ export declare const error: (...args: any[]) => void;
15
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/environment/logger.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,GAAG;;;CAAc,CAAA;AAC9B,eAAO,MAAM,IAAI;;;CAAe,CAAA;AAChC,eAAO,MAAM,OAAO,YAAa,GAAG,EAAE,SACI,CAAA;AAC1C,eAAO,MAAM,IAAI;;;CAAe,CAAA;AAChC,eAAO,MAAM,KAAK,YAAa,GAAG,EAAE,SAA2C,CAAA"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.error = exports.info = exports.success = exports.warn = exports.log = void 0;
7
+ const kleur_1 = __importDefault(require("kleur"));
8
+ /* eslint-disable no-console */
9
+ exports.log = console.log;
10
+ exports.warn = console.warn;
11
+ const success = (...args) => console.log(kleur_1.default.green(args.join(' ')));
12
+ exports.success = success;
13
+ exports.info = console.info;
14
+ const error = (...args) => console.log(kleur_1.default.red(args.join(' ')));
15
+ exports.error = error;
@@ -0,0 +1,11 @@
1
+ export interface User {
2
+ name: string;
3
+ ssh_keys: string[];
4
+ state: 'present' | 'absent';
5
+ role: 'admin' | 'operator';
6
+ }
7
+ /**
8
+ * Main function to manage users
9
+ */
10
+ export declare function manageUsers(inventoryPath: string): Promise<User[]>;
11
+ //# sourceMappingURL=manage-users.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manage-users.d.ts","sourceRoot":"","sources":["../../src/environment/manage-users.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC5B,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;CAC5B;AA2VD;;GAEG;AACH,wBAAsB,WAAW,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAoIxE"}