@opencrvs/toolkit 2.0.0-rc.bd420ee → 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 (103) hide show
  1. package/README.md +14 -0
  2. package/build.sh +1 -0
  3. package/create-countryconfig/index.js +50 -20
  4. package/create-countryconfig/package.json +12 -2
  5. package/dist/application-config/index.js +258 -94
  6. package/dist/cli.js +3294 -48
  7. package/dist/commons/api/router.d.ts +445 -20
  8. package/dist/commons/application-config/index.d.ts +1 -0
  9. package/dist/commons/conditionals/conditionals.d.ts +354 -4
  10. package/dist/commons/conditionals/validate.d.ts +51 -2
  11. package/dist/commons/events/ActionConfig.d.ts +28 -2
  12. package/dist/commons/events/ActionDocument.d.ts +6 -0
  13. package/dist/commons/events/ActionInput.d.ts +42 -36
  14. package/dist/commons/events/AdvancedSearchConfig.d.ts +342 -0
  15. package/dist/commons/events/Draft.d.ts +2 -3
  16. package/dist/commons/events/EventDocument.d.ts +3 -0
  17. package/dist/commons/events/FieldConfig.d.ts +378 -50
  18. package/dist/commons/events/FieldType.d.ts +1 -0
  19. package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
  20. package/dist/commons/events/FieldValue.d.ts +6 -0
  21. package/dist/commons/events/WorkqueueConfig.d.ts +150 -150
  22. package/dist/commons/events/field.d.ts +53 -1
  23. package/dist/commons/events/index.d.ts +2 -0
  24. package/dist/commons/events/state/flags.d.ts +16 -0
  25. package/dist/commons/events/state/utils.d.ts +12 -287
  26. package/dist/commons/events/utils.d.ts +12 -1
  27. package/dist/conditionals/index.js +55 -2
  28. package/dist/environment/custom-types.d.ts +33 -0
  29. package/dist/environment/custom-types.d.ts.map +1 -0
  30. package/dist/environment/custom-types.js +2 -0
  31. package/dist/environment/derived-variables.d.ts +134 -0
  32. package/dist/environment/derived-variables.d.ts.map +1 -0
  33. package/dist/environment/derived-variables.js +159 -0
  34. package/dist/environment/editor-questions.d.ts +5 -0
  35. package/dist/environment/editor-questions.d.ts.map +1 -0
  36. package/dist/environment/editor-questions.js +56 -0
  37. package/dist/environment/git.d.ts +5 -0
  38. package/dist/environment/git.d.ts.map +1 -0
  39. package/dist/environment/git.js +28 -0
  40. package/dist/environment/github.d.ts +26 -0
  41. package/dist/environment/github.d.ts.map +1 -0
  42. package/dist/environment/github.js +234 -0
  43. package/dist/environment/index.d.ts +6 -0
  44. package/dist/environment/index.d.ts.map +1 -0
  45. package/dist/environment/index.js +61 -0
  46. package/dist/environment/logger.d.ts +15 -0
  47. package/dist/environment/logger.d.ts.map +1 -0
  48. package/dist/environment/logger.js +15 -0
  49. package/dist/environment/manage-users.d.ts +11 -0
  50. package/dist/environment/manage-users.d.ts.map +1 -0
  51. package/dist/environment/manage-users.js +484 -0
  52. package/dist/environment/questions-helper.d.ts +15 -0
  53. package/dist/environment/questions-helper.d.ts.map +1 -0
  54. package/dist/environment/questions-helper.js +60 -0
  55. package/dist/environment/questions.d.ts +222 -0
  56. package/dist/environment/questions.d.ts.map +1 -0
  57. package/dist/environment/questions.js +455 -0
  58. package/dist/environment/setup-environment.d.ts +2 -0
  59. package/dist/environment/setup-environment.d.ts.map +1 -0
  60. package/dist/environment/setup-environment.js +763 -0
  61. package/dist/environment/ssh-keygen.d.ts +5 -0
  62. package/dist/environment/ssh-keygen.d.ts.map +1 -0
  63. package/dist/environment/ssh-keygen.js +8 -0
  64. package/dist/environment/swarm-to-k8s.d.ts +2 -0
  65. package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
  66. package/dist/environment/swarm-to-k8s.js +162 -0
  67. package/dist/environment/templates/charts-values/dependencies/values.override.yaml +4 -0
  68. package/dist/environment/templates/charts-values/dependencies/values.yaml +82 -0
  69. package/dist/environment/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  70. package/dist/environment/templates/charts-values/opencrvs-services/values.yaml +79 -0
  71. package/dist/environment/templates/charts-values/traefik/values.override.yaml +4 -0
  72. package/dist/environment/templates/charts-values/traefik/values.yaml +116 -0
  73. package/dist/environment/templates/inventory/inventory.template.yml +100 -0
  74. package/dist/environment/templates/inventory/production.example.yml +77 -0
  75. package/dist/environment/templates/inventory/qa.example.yml +48 -0
  76. package/dist/environment/templates.d.ts +27 -0
  77. package/dist/environment/templates.d.ts.map +1 -0
  78. package/dist/environment/templates.js +149 -0
  79. package/dist/environment/update-workflows.d.ts +2 -0
  80. package/dist/environment/update-workflows.d.ts.map +1 -0
  81. package/dist/environment/update-workflows.js +151 -0
  82. package/dist/environment/users.d.ts +2 -0
  83. package/dist/environment/users.d.ts.map +1 -0
  84. package/dist/environment/users.js +92 -0
  85. package/dist/environment/utils.d.ts +18 -0
  86. package/dist/environment/utils.d.ts.map +1 -0
  87. package/dist/environment/utils.js +90 -0
  88. package/dist/events/index.js +1050 -233
  89. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  90. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  91. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -1
  92. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +3 -0
  93. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +1 -0
  94. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +110 -0
  95. package/dist/migrations/v2.0/index.d.ts.map +1 -1
  96. package/dist/migrations/v2.0/index.js +106 -9
  97. package/dist/notification/index.js +884 -131
  98. package/dist/scopes/index.d.ts +4 -6
  99. package/dist/scopes/index.js +12 -4
  100. package/opencrvs-toolkit-2.0.0-rc.bd55713.tgz +0 -0
  101. package/package.json +20 -2
  102. package/tsconfig.tsbuildinfo +1 -1
  103. package/opencrvs-toolkit-2.0.0-rc.bd420ee.tgz +0 -0
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.derivedVariables = void 0;
4
+ exports.derivedVariables = [
5
+ {
6
+ name: 'ACTIVATE_USERS',
7
+ valueLabel: 'ACTIVATE_USERS',
8
+ valueType: 'VARIABLE',
9
+ type: 'disabled',
10
+ scope: 'ENVIRONMENT'
11
+ },
12
+ {
13
+ name: 'COUNTRY_CONFIG_HOST',
14
+ valueLabel: 'COUNTRY_CONFIG_HOST',
15
+ valueType: 'VARIABLE',
16
+ type: 'disabled',
17
+ scope: 'ENVIRONMENT'
18
+ },
19
+ {
20
+ name: 'GATEWAY_HOST',
21
+ valueLabel: 'GATEWAY_HOST',
22
+ valueType: 'VARIABLE',
23
+ type: 'disabled',
24
+ scope: 'ENVIRONMENT'
25
+ },
26
+ {
27
+ name: 'CONTENT_SECURITY_POLICY_WILDCARD',
28
+ valueLabel: 'CONTENT_SECURITY_POLICY_WILDCARD',
29
+ valueType: 'VARIABLE',
30
+ type: 'disabled',
31
+ scope: 'ENVIRONMENT'
32
+ },
33
+ {
34
+ name: 'CLIENT_APP_URL',
35
+ valueLabel: 'CLIENT_APP_URL',
36
+ valueType: 'VARIABLE',
37
+ type: 'disabled',
38
+ scope: 'ENVIRONMENT'
39
+ },
40
+ {
41
+ name: 'LOGIN_URL',
42
+ valueLabel: 'LOGIN_URL',
43
+ valueType: 'VARIABLE',
44
+ type: 'disabled',
45
+ scope: 'ENVIRONMENT'
46
+ },
47
+ {
48
+ name: 'ELASTICSEARCH_SUPERUSER_PASSWORD',
49
+ valueLabel: 'ELASTICSEARCH_SUPERUSER_PASSWORD',
50
+ valueType: 'SECRET',
51
+ type: 'disabled',
52
+ scope: 'ENVIRONMENT'
53
+ },
54
+ {
55
+ name: 'KIBANA_SYSTEM_PASSWORD',
56
+ valueLabel: 'KIBANA_SYSTEM_PASSWORD',
57
+ valueType: 'SECRET',
58
+ type: 'disabled',
59
+ scope: 'ENVIRONMENT'
60
+ },
61
+ {
62
+ name: 'MINIO_ROOT_USER',
63
+ valueLabel: 'MINIO_ROOT_USER',
64
+ valueType: 'SECRET',
65
+ type: 'disabled',
66
+ scope: 'ENVIRONMENT'
67
+ },
68
+ {
69
+ name: 'MINIO_ROOT_PASSWORD',
70
+ valueLabel: 'MINIO_ROOT_PASSWORD',
71
+ valueType: 'SECRET',
72
+ type: 'disabled',
73
+ scope: 'ENVIRONMENT'
74
+ },
75
+ {
76
+ name: 'MONGODB_ADMIN_USER',
77
+ valueLabel: 'MONGODB_ADMIN_USER',
78
+ valueType: 'SECRET',
79
+ type: 'disabled',
80
+ scope: 'ENVIRONMENT'
81
+ },
82
+ {
83
+ name: 'MONGODB_ADMIN_PASSWORD',
84
+ valueLabel: 'MONGODB_ADMIN_PASSWORD',
85
+ valueType: 'SECRET',
86
+ type: 'disabled',
87
+ scope: 'ENVIRONMENT'
88
+ },
89
+ {
90
+ name: 'POSTGRES_USER',
91
+ valueLabel: 'POSTGRES_USER',
92
+ valueType: 'SECRET',
93
+ type: 'disabled',
94
+ scope: 'ENVIRONMENT'
95
+ },
96
+ {
97
+ name: 'POSTGRES_PASSWORD',
98
+ valueLabel: 'POSTGRES_PASSWORD',
99
+ valueType: 'SECRET',
100
+ type: 'disabled',
101
+ scope: 'ENVIRONMENT'
102
+ },
103
+ {
104
+ name: 'SUPER_USER_PASSWORD',
105
+ valueLabel: 'SUPER_USER_PASSWORD',
106
+ valueType: 'SECRET',
107
+ type: 'disabled',
108
+ scope: 'ENVIRONMENT'
109
+ },
110
+ {
111
+ name: 'ENCRYPTION_KEY',
112
+ valueLabel: 'ENCRYPTION_KEY',
113
+ valueType: 'SECRET',
114
+ type: 'disabled',
115
+ scope: 'ENVIRONMENT'
116
+ },
117
+ {
118
+ name: 'GH_ENCRYPTION_PASSWORD',
119
+ valueLabel: 'GH_ENCRYPTION_PASSWORD',
120
+ valueType: 'SECRET',
121
+ type: 'disabled',
122
+ scope: 'REPOSITORY'
123
+ },
124
+ {
125
+ name: 'BACKUP_ENCRYPTION_PASSPHRASE',
126
+ valueLabel: 'BACKUP_ENCRYPTION_PASSPHRASE',
127
+ valueType: 'SECRET',
128
+ type: 'disabled',
129
+ scope: 'ENVIRONMENT'
130
+ },
131
+ {
132
+ name: 'BACKUP_HOST_PRIVATE_KEY',
133
+ valueLabel: 'BACKUP_HOST_PRIVATE_KEY',
134
+ valueType: 'SECRET',
135
+ type: 'disabled',
136
+ scope: 'ENVIRONMENT'
137
+ },
138
+ {
139
+ name: 'BACKUP_HOST_PUBLIC_KEY',
140
+ valueLabel: 'BACKUP_HOST_PUBLIC_KEY',
141
+ valueType: 'SECRET',
142
+ type: 'disabled',
143
+ scope: 'ENVIRONMENT'
144
+ },
145
+ {
146
+ name: 'RESTORE_ENVIRONMENT_NAME',
147
+ valueLabel: 'RESTORE_ENVIRONMENT_NAME',
148
+ valueType: 'VARIABLE',
149
+ type: 'disabled',
150
+ scope: 'ENVIRONMENT'
151
+ },
152
+ {
153
+ name: 'NOTIFICATION_TRANSPORT',
154
+ valueLabel: 'NOTIFICATION_TRANSPORT',
155
+ valueType: 'VARIABLE',
156
+ type: 'disabled',
157
+ scope: 'ENVIRONMENT'
158
+ },
159
+ ];
@@ -0,0 +1,5 @@
1
+ import { Secret, Variable } from './github';
2
+ import { AnswerWithNullValue, QuestionDescriptor } from './custom-types';
3
+ export declare function editorQuestion(question: string): Promise<string>;
4
+ export declare function askQuestionWithEditor(questions: Array<QuestionDescriptor<any>>, existingValues: Array<Secret | Variable>): Promise<AnswerWithNullValue[]>;
5
+ //# sourceMappingURL=editor-questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-questions.d.ts","sourceRoot":"","sources":["../../src/environment/editor-questions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,mBAAmB,EAAW,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAKlF,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAIhE;AAED,wBAAsB,qBAAqB,CACvC,SAAS,EAAE,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,EACzC,cAAc,EAAE,KAAK,CAAC,MAAM,GAAG,QAAQ,CAAC,GACzC,OAAO,CAAC,mBAAmB,EAAE,CAAC,CA6ChC"}
@@ -0,0 +1,56 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.editorQuestion = editorQuestion;
16
+ exports.askQuestionWithEditor = askQuestionWithEditor;
17
+ const utils_1 = require("./utils");
18
+ const kleur_1 = __importDefault(require("kleur"));
19
+ const prompts_1 = __importDefault(require("prompts"));
20
+ function editorQuestion(question) {
21
+ return import('@inquirer/prompts').then(({ editor }) => editor({ message: question }));
22
+ }
23
+ function askQuestionWithEditor(questions, existingValues) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ let answers = [];
26
+ for (const question of questions) {
27
+ const questionWithVariableLabel = Object.assign(Object.assign({}, question), { message: `${kleur_1.default.cyan(question.valueLabel || '')}: ${question.message}` });
28
+ if (!questionWithVariableLabel.valueLabel) {
29
+ throw Error("Undefined Label");
30
+ }
31
+ const existingSecret = (0, utils_1.findExistingValue)(questionWithVariableLabel.valueLabel, 'SECRET', questionWithVariableLabel.scope, existingValues);
32
+ let updateSecret = true;
33
+ if (existingSecret) {
34
+ updateSecret = (yield (0, prompts_1.default)([{
35
+ name: 'overWrite',
36
+ type: 'confirm',
37
+ message: `${kleur_1.default.yellow(`${existingSecret.scope === 'REPOSITORY'
38
+ ? 'Repository secret'
39
+ : 'Secret'} ${kleur_1.default.cyan(existingSecret.name)} already exists in Github. Do you want to update it?`)}`
40
+ }])).overWrite;
41
+ }
42
+ if (!existingSecret || updateSecret === true) {
43
+ const question_answer = yield editorQuestion(questionWithVariableLabel.message);
44
+ const answer = {
45
+ type: 'SECRET',
46
+ scope: 'ENVIRONMENT',
47
+ name: questionWithVariableLabel.valueLabel,
48
+ value: question_answer,
49
+ didExist: existingSecret
50
+ };
51
+ answers.push(answer);
52
+ }
53
+ }
54
+ return answers;
55
+ });
56
+ }
@@ -0,0 +1,5 @@
1
+ export declare function getRepoInfo(): {
2
+ organization: string;
3
+ repository: string;
4
+ };
5
+ //# sourceMappingURL=git.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../src/environment/git.ts"],"names":[],"mappings":"AAEA,wBAAgB,WAAW;;;EAyB1B"}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRepoInfo = getRepoInfo;
4
+ const child_process_1 = require("child_process");
5
+ function getRepoInfo() {
6
+ try {
7
+ const remoteUrl = (0, child_process_1.execSync)("git config --get remote.origin.url", {
8
+ stdio: ["ignore", "pipe", "ignore"]
9
+ })
10
+ .toString()
11
+ .trim();
12
+ // Handle both SSH and HTTPS formats
13
+ const match = remoteUrl.match(/github\.com[:/](.+?)\/(.+?)(\.git)?$/);
14
+ if (!match) {
15
+ return { organization: "", repository: "" };
16
+ }
17
+ return {
18
+ organization: match[1],
19
+ repository: match[2]
20
+ };
21
+ }
22
+ catch (_a) {
23
+ return {
24
+ organization: "",
25
+ repository: ""
26
+ };
27
+ }
28
+ }
@@ -0,0 +1,26 @@
1
+ import { Octokit } from '@octokit/core';
2
+ export declare function createEnvironmentVariable(octokit: Octokit, repositoryId: number, environment: string, name: string, value: string): Promise<void>;
3
+ export declare function updateEnvironmentVariable(octokit: Octokit, repositoryId: number, environment: string, name: string, value: string): Promise<void>;
4
+ export declare function createRepositoryVariable(octokit: Octokit, repositoryId: number, name: string, value: string): Promise<void>;
5
+ export declare function updateRepositoryVariable(octokit: Octokit, repositoryId: number, name: string, value: string): Promise<void>;
6
+ export declare function getRepositoryId(octokit: Octokit, owner: string, repo: string): Promise<number>;
7
+ export declare function createEnvironmentSecret(octokit: Octokit, repositoryId: number, environment: string, name: string, secret: string, organisationName: string, repositoryName: string): Promise<void>;
8
+ export declare function createRepositorySecret(octokit: Octokit, repositoryId: number, name: string, secret: string, organisationName: string, repositoryName: string): Promise<void>;
9
+ export declare function getRepositoryEnvironments(octokit: Octokit, githubOrganisation: string, repository: string): Promise<string[]>;
10
+ export declare function createEnvironment(octokit: Octokit, environment: string, ORGANISATION: string, REPOSITORY_NAME: string): Promise<boolean>;
11
+ export type Secret = {
12
+ type: 'SECRET';
13
+ name: string;
14
+ scope: 'ENVIRONMENT' | 'REPOSITORY';
15
+ };
16
+ export type Variable = {
17
+ type: 'VARIABLE';
18
+ name: string;
19
+ value: string;
20
+ scope: 'ENVIRONMENT' | 'REPOSITORY';
21
+ };
22
+ export declare function listEnvironmentSecrets(octokit: Octokit, owner: string, repositoryId: number, environmentName: string): Promise<Secret[]>;
23
+ export declare function listRepositorySecrets(octokit: Octokit, owner: string, repositoryName: string): Promise<Secret[]>;
24
+ export declare function listEnvironmentVariables(octokit: Octokit, repositoryId: number, environmentName: string): Promise<Variable[]>;
25
+ export declare function listRepositoryVariables(octokit: Octokit, owner: string, repositoryName: string): Promise<Variable[]>;
26
+ //# sourceMappingURL=github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/environment/github.ts"],"names":[],"mappings":"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"}
@@ -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"}