@bmfk/api 0.0.0-stage → 1.0.0
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/CHANGELOG.md +83 -0
- package/LICENSE +21 -0
- package/README.md +1293 -2
- package/dist/apiServer/APIService.d.ts +125 -0
- package/dist/apiServer/APIService.js +769 -0
- package/dist/apiServer/BaseEndpoint.d.ts +90 -0
- package/dist/apiServer/BaseEndpoint.js +314 -0
- package/dist/apiServer/BaseService.d.ts +17 -0
- package/dist/apiServer/BaseService.js +39 -0
- package/dist/apiServer/DBService.d.ts +131 -0
- package/dist/apiServer/DBService.js +290 -0
- package/dist/apiServer/DocumentService.d.ts +9 -0
- package/dist/apiServer/DocumentService.js +65 -0
- package/dist/apiServer/LocalRequest.d.ts +3 -0
- package/dist/apiServer/LocalRequest.js +6 -0
- package/dist/apiServer/LogService.d.ts +78 -0
- package/dist/apiServer/LogService.js +349 -0
- package/dist/apiServer/MonitorService.d.ts +102 -0
- package/dist/apiServer/MonitorService.js +615 -0
- package/dist/apiServer/StatService.d.ts +4 -0
- package/dist/apiServer/StatService.js +10 -0
- package/dist/apiServer/TimeframeService.d.ts +28 -0
- package/dist/apiServer/TimeframeService.js +97 -0
- package/dist/apiServer/WebSocketServer.d.ts +39 -0
- package/dist/apiServer/WebSocketServer.js +173 -0
- package/dist/apiServer/db/IDBAdapter.d.ts +14 -0
- package/dist/apiServer/db/IDBAdapter.js +2 -0
- package/dist/apiServer/db/MysqlAdapter.d.ts +72 -0
- package/dist/apiServer/db/MysqlAdapter.js +869 -0
- package/dist/apiServer/db/PostgresAdapter.d.ts +41 -0
- package/dist/apiServer/db/PostgresAdapter.js +73 -0
- package/dist/apiServer/deployment/AccessConfigWizard.d.ts +5 -0
- package/dist/apiServer/deployment/AccessConfigWizard.js +254 -0
- package/dist/apiServer/deployment/Activate.d.ts +4 -0
- package/dist/apiServer/deployment/Activate.js +124 -0
- package/dist/apiServer/deployment/BackupManager.d.ts +33 -0
- package/dist/apiServer/deployment/BackupManager.js +174 -0
- package/dist/apiServer/deployment/Backups.d.ts +2 -0
- package/dist/apiServer/deployment/Backups.js +44 -0
- package/dist/apiServer/deployment/BlueGreenState.d.ts +31 -0
- package/dist/apiServer/deployment/BlueGreenState.js +150 -0
- package/dist/apiServer/deployment/Bundler.d.ts +12 -0
- package/dist/apiServer/deployment/Bundler.js +178 -0
- package/dist/apiServer/deployment/ConfigService.d.ts +203 -0
- package/dist/apiServer/deployment/ConfigService.js +195 -0
- package/dist/apiServer/deployment/Deploy.d.ts +4 -0
- package/dist/apiServer/deployment/Deploy.js +404 -0
- package/dist/apiServer/deployment/DeployKeyWizard.d.ts +2 -0
- package/dist/apiServer/deployment/DeployKeyWizard.js +84 -0
- package/dist/apiServer/deployment/Deployer.d.ts +13 -0
- package/dist/apiServer/deployment/Deployer.js +96 -0
- package/dist/apiServer/deployment/DeployerInit.d.ts +25 -0
- package/dist/apiServer/deployment/DeployerInit.js +214 -0
- package/dist/apiServer/deployment/DeployerService.d.ts +378 -0
- package/dist/apiServer/deployment/DeployerService.js +1553 -0
- package/dist/apiServer/deployment/HashPassword.d.ts +3 -0
- package/dist/apiServer/deployment/HashPassword.js +126 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.d.ts +1 -0
- package/dist/apiServer/deployment/MigrateConfigsWizard.js +202 -0
- package/dist/apiServer/deployment/MigrateProject.d.ts +31 -0
- package/dist/apiServer/deployment/MigrateProject.js +335 -0
- package/dist/apiServer/deployment/NginxHelper.d.ts +10 -0
- package/dist/apiServer/deployment/NginxHelper.js +111 -0
- package/dist/apiServer/deployment/Notifier.d.ts +30 -0
- package/dist/apiServer/deployment/Notifier.js +82 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/ProjectConfigWizard.js +148 -0
- package/dist/apiServer/deployment/Restore.d.ts +2 -0
- package/dist/apiServer/deployment/Restore.js +89 -0
- package/dist/apiServer/deployment/ReviewStore.d.ts +62 -0
- package/dist/apiServer/deployment/ReviewStore.js +186 -0
- package/dist/apiServer/deployment/SecretsInjector.d.ts +21 -0
- package/dist/apiServer/deployment/SecretsInjector.js +189 -0
- package/dist/apiServer/deployment/SetupConfigWizard.d.ts +1 -0
- package/dist/apiServer/deployment/SetupConfigWizard.js +238 -0
- package/dist/apiServer/deployment/Status.d.ts +2 -0
- package/dist/apiServer/deployment/Status.js +83 -0
- package/dist/apiServer/deployment/TelegramNotifier.d.ts +8 -0
- package/dist/apiServer/deployment/TelegramNotifier.js +23 -0
- package/dist/apiServer/deployment/Watchdog.d.ts +15 -0
- package/dist/apiServer/deployment/Watchdog.js +65 -0
- package/dist/apiServer/deployment/Wizards.d.ts +1 -0
- package/dist/apiServer/deployment/Wizards.js +83 -0
- package/dist/apiServer/deployment/cli.d.ts +2 -0
- package/dist/apiServer/deployment/cli.js +224 -0
- package/dist/apiServer/deployment/cliCommon.d.ts +27 -0
- package/dist/apiServer/deployment/cliCommon.js +110 -0
- package/dist/apiServer/deployment/cliPrompt.d.ts +5 -0
- package/dist/apiServer/deployment/cliPrompt.js +38 -0
- package/dist/apiServer/deployment/resolveConfig.d.ts +19 -0
- package/dist/apiServer/deployment/resolveConfig.js +139 -0
- package/dist/apiServer/documentation/Documentation.d.ts +18 -0
- package/dist/apiServer/documentation/Documentation.js +143 -0
- package/dist/apiServer/documentation/index.html +460 -0
- package/dist/apiServer/external/MicroserviceClient.d.ts +28 -0
- package/dist/apiServer/external/MicroserviceClient.js +144 -0
- package/dist/apiServer/external/MicroserviceHost.d.ts +52 -0
- package/dist/apiServer/external/MicroserviceHost.js +183 -0
- package/dist/apiServer/external/MicroserviceHostController.d.ts +6 -0
- package/dist/apiServer/external/MicroserviceHostController.js +65 -0
- package/dist/apiServer/helper/AppDataPath.d.ts +9 -0
- package/dist/apiServer/helper/AppDataPath.js +81 -0
- package/dist/apiServer/helper/ClientIp.d.ts +3 -0
- package/dist/apiServer/helper/ClientIp.js +33 -0
- package/dist/apiServer/helper/DataProvider.d.ts +18 -0
- package/dist/apiServer/helper/DataProvider.js +57 -0
- package/dist/apiServer/helper/IpAllowList.d.ts +8 -0
- package/dist/apiServer/helper/IpAllowList.js +40 -0
- package/dist/apiServer/helper/JSONStableStringify.d.ts +1 -0
- package/dist/apiServer/helper/JSONStableStringify.js +15 -0
- package/dist/apiServer/helper/PasswordHash.d.ts +5 -0
- package/dist/apiServer/helper/PasswordHash.js +52 -0
- package/dist/apiServer/helper/Sleep.d.ts +1 -0
- package/dist/apiServer/helper/Sleep.js +5 -0
- package/dist/apiServer/helper/Trace.d.ts +8 -0
- package/dist/apiServer/helper/Trace.js +30 -0
- package/dist/apiServer/helper/UID.d.ts +16 -0
- package/dist/apiServer/helper/UID.js +98 -0
- package/dist/apiServer/helper/Validator.d.ts +86 -0
- package/dist/apiServer/helper/Validator.js +560 -0
- package/dist/apiServer/helper/YYYYMMDDHH.d.ts +2 -0
- package/dist/apiServer/helper/YYYYMMDDHH.js +31 -0
- package/dist/apiServer/helper/ZipUtils.d.ts +6 -0
- package/dist/apiServer/helper/ZipUtils.js +28 -0
- package/dist/apiServer/http/Http.d.ts +183 -0
- package/dist/apiServer/http/Http.js +627 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.d.ts +19 -0
- package/dist/apiServer/interceptors/InterceptorPayAuth.js +124 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.d.ts +40 -0
- package/dist/apiServer/interceptors/InterceptorSignedAuth.js +150 -0
- package/dist/apiServer/monitor/AccessStore.d.ts +27 -0
- package/dist/apiServer/monitor/AccessStore.js +163 -0
- package/dist/apiServer/monitor/LogFiles.d.ts +34 -0
- package/dist/apiServer/monitor/LogFiles.js +109 -0
- package/dist/apiServer/monitor/Monitor.d.ts +54 -0
- package/dist/apiServer/monitor/Monitor.js +447 -0
- package/dist/apiServer/monitor/MonitorAuth.d.ts +87 -0
- package/dist/apiServer/monitor/MonitorAuth.js +474 -0
- package/dist/apiServer/monitor/ProcessMonitor.d.ts +177 -0
- package/dist/apiServer/monitor/ProcessMonitor.js +468 -0
- package/dist/apiServer/monitor/SystemInfo.d.ts +70 -0
- package/dist/apiServer/monitor/SystemInfo.js +217 -0
- package/dist/apiServer/monitor/ThreatMonitor.d.ts +73 -0
- package/dist/apiServer/monitor/ThreatMonitor.js +239 -0
- package/dist/apiServer/monitor/index.html +591 -0
- package/dist/apiServer/review/Review.d.ts +23 -0
- package/dist/apiServer/review/Review.js +149 -0
- package/dist/apiServer/review/ReviewAuth.d.ts +56 -0
- package/dist/apiServer/review/ReviewAuth.js +147 -0
- package/dist/apiServer/review/ReviewDiff.d.ts +43 -0
- package/dist/apiServer/review/ReviewDiff.js +175 -0
- package/dist/apiServer/review/index.html +501 -0
- package/dist/apiServer/routes/Liveness.d.ts +7 -0
- package/dist/apiServer/routes/Liveness.js +27 -0
- package/dist/apiServer/routes/Readiness.d.ts +13 -0
- package/dist/apiServer/routes/Readiness.js +20 -0
- package/dist/apiServer/security/BlockedIps.d.ts +46 -0
- package/dist/apiServer/security/BlockedIps.js +185 -0
- package/dist/apiServer/structures/DefaultErrors.d.ts +36 -0
- package/dist/apiServer/structures/DefaultErrors.js +52 -0
- package/dist/apiServer/structures/HTTPStatus.d.ts +7 -0
- package/dist/apiServer/structures/HTTPStatus.js +11 -0
- package/dist/apiServer/structures/Interfaces.d.ts +55 -0
- package/dist/apiServer/structures/Interfaces.js +2 -0
- package/dist/index.d.ts +45 -0
- package/dist/index.js +110 -0
- package/dist/signal/Signal.d.ts +23 -0
- package/dist/signal/Signal.js +85 -0
- package/package.json +88 -4
|
@@ -0,0 +1,189 @@
|
|
|
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.SecretsInjector = void 0;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const AppDataPath_1 = require("../helper/AppDataPath");
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const vm_1 = __importDefault(require("vm"));
|
|
11
|
+
const PLACEHOLDER = /_\{\{([A-Za-z0-9_]+)\}\}_/g;
|
|
12
|
+
class SecretsInjector {
|
|
13
|
+
static resolvePath(project, slot, settings, defaultDir, destinationRoot) {
|
|
14
|
+
const file = settings?.file?.trim(), dir = (settings?.dir?.trim() || defaultDir?.trim() || "");
|
|
15
|
+
let target;
|
|
16
|
+
if (file) {
|
|
17
|
+
if (!path_1.default.isAbsolute(file))
|
|
18
|
+
return { error: `secrets.file must be an absolute path ("${file}")` };
|
|
19
|
+
const ext = path_1.default.extname(file) || ".json";
|
|
20
|
+
target = slot ? path_1.default.join(path_1.default.dirname(file), `${path_1.default.basename(file, path_1.default.extname(file))}-${slot}${ext}`) : file;
|
|
21
|
+
}
|
|
22
|
+
else if (dir) {
|
|
23
|
+
if (!path_1.default.isAbsolute(dir))
|
|
24
|
+
return { error: `the secrets directory must be an absolute path ("${dir}")` };
|
|
25
|
+
target = path_1.default.join(dir, `${project}${slot ? "-" + slot : ""}.json`);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
target = path_1.default.join(AppDataPath_1.AppData.projectDir(project), `secrets${slot ? "-" + slot : ""}.json`);
|
|
29
|
+
}
|
|
30
|
+
target = path_1.default.resolve(target);
|
|
31
|
+
const root = path_1.default.resolve(destinationRoot);
|
|
32
|
+
if (target === root || target.startsWith(root + path_1.default.sep))
|
|
33
|
+
return { error: `the secrets file must live outside the deploy folder ("${target}" is inside "${root}")` };
|
|
34
|
+
return { path: target };
|
|
35
|
+
}
|
|
36
|
+
static write(file, values) {
|
|
37
|
+
fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true, mode: 0o700 });
|
|
38
|
+
const tmp = file + ".tmp";
|
|
39
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(values, null, 2), { encoding: "utf-8", mode: 0o600 });
|
|
40
|
+
fs_1.default.chmodSync(tmp, 0o600);
|
|
41
|
+
fs_1.default.renameSync(tmp, file);
|
|
42
|
+
}
|
|
43
|
+
static verify(file, values) {
|
|
44
|
+
try {
|
|
45
|
+
fs_1.default.accessSync(file, fs_1.default.constants.R_OK);
|
|
46
|
+
const back = JSON.parse(fs_1.default.readFileSync(file, "utf-8"));
|
|
47
|
+
const missing = Object.keys(values).filter(k => !Object.prototype.hasOwnProperty.call(back, k));
|
|
48
|
+
return missing.length ? `${file} lacks ${missing.join(", ")}` : null;
|
|
49
|
+
}
|
|
50
|
+
catch (e) {
|
|
51
|
+
return `${file} is not readable: ${e?.message ?? e}`;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static expression(file, key) {
|
|
55
|
+
const p = JSON.stringify(file);
|
|
56
|
+
return `(function(k){var s=globalThis.__bmfkSecrets||(globalThis.__bmfkSecrets=JSON.parse(require("fs").readFileSync(${p},"utf8")));`
|
|
57
|
+
+ `if(!Object.prototype.hasOwnProperty.call(s,k))throw new Error("secret \\""+k+"\\" is missing in "+${p});return String(s[k]);})(${JSON.stringify(key)})`;
|
|
58
|
+
}
|
|
59
|
+
static transform(source, keys, file) {
|
|
60
|
+
let rewritten = 0, inBlockComment = false;
|
|
61
|
+
const lines = source.split("\n");
|
|
62
|
+
for (let n = 0; n < lines.length; n++) {
|
|
63
|
+
const line = lines[n];
|
|
64
|
+
if (!inBlockComment && line.indexOf("_{{") === -1) {
|
|
65
|
+
inBlockComment = SecretsInjector.endsInBlockComment(line, false);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const defuse = (text) => text.replace(/_\{\{/g, "_{ {");
|
|
69
|
+
let out = "", i = 0;
|
|
70
|
+
while (i < line.length) {
|
|
71
|
+
if (inBlockComment) {
|
|
72
|
+
const end = line.indexOf("*/", i);
|
|
73
|
+
if (end === -1) {
|
|
74
|
+
out += defuse(line.slice(i));
|
|
75
|
+
i = line.length;
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
out += defuse(line.slice(i, end + 2));
|
|
79
|
+
i = end + 2;
|
|
80
|
+
inBlockComment = false;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const c = line[i];
|
|
84
|
+
if (c === "/" && line[i + 1] === "/") {
|
|
85
|
+
out += defuse(line.slice(i));
|
|
86
|
+
i = line.length;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (c === "/" && line[i + 1] === "*") {
|
|
90
|
+
inBlockComment = true;
|
|
91
|
+
out += "/*";
|
|
92
|
+
i += 2;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
96
|
+
let j = i + 1;
|
|
97
|
+
while (j < line.length && line[j] !== c)
|
|
98
|
+
j += line[j] === "\\" ? 2 : 1;
|
|
99
|
+
if (j >= line.length) {
|
|
100
|
+
out += line.slice(i);
|
|
101
|
+
i = line.length;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
const literal = line.slice(i, j + 1);
|
|
105
|
+
const rep = SecretsInjector.rewriteLiteral(literal, c, keys, file);
|
|
106
|
+
if (rep !== literal)
|
|
107
|
+
rewritten++;
|
|
108
|
+
out += rep;
|
|
109
|
+
i = j + 1;
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
out += c;
|
|
113
|
+
i++;
|
|
114
|
+
}
|
|
115
|
+
lines[n] = out;
|
|
116
|
+
}
|
|
117
|
+
const content = lines.join("\n");
|
|
118
|
+
let leftover = false;
|
|
119
|
+
for (const m of content.matchAll(PLACEHOLDER))
|
|
120
|
+
if (keys.has(m[1])) {
|
|
121
|
+
leftover = true;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
return { content, rewritten, leftover };
|
|
125
|
+
}
|
|
126
|
+
static endsInBlockComment(line, open) {
|
|
127
|
+
let i = 0;
|
|
128
|
+
while (i < line.length) {
|
|
129
|
+
if (open) {
|
|
130
|
+
const e = line.indexOf("*/", i);
|
|
131
|
+
if (e === -1)
|
|
132
|
+
return true;
|
|
133
|
+
open = false;
|
|
134
|
+
i = e + 2;
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const c = line[i];
|
|
138
|
+
if (c === "/" && line[i + 1] === "/")
|
|
139
|
+
return false;
|
|
140
|
+
if (c === "/" && line[i + 1] === "*") {
|
|
141
|
+
open = true;
|
|
142
|
+
i += 2;
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
146
|
+
let j = i + 1;
|
|
147
|
+
while (j < line.length && line[j] !== c)
|
|
148
|
+
j += line[j] === "\\" ? 2 : 1;
|
|
149
|
+
i = j + 1;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
i++;
|
|
153
|
+
}
|
|
154
|
+
return open;
|
|
155
|
+
}
|
|
156
|
+
static rewriteLiteral(literal, quote, keys, file) {
|
|
157
|
+
const body = literal.slice(1, -1);
|
|
158
|
+
if (quote === "`" && body.includes("${"))
|
|
159
|
+
return literal;
|
|
160
|
+
const parts = [];
|
|
161
|
+
let last = 0, found = false;
|
|
162
|
+
for (const m of body.matchAll(PLACEHOLDER)) {
|
|
163
|
+
if (!keys.has(m[1]))
|
|
164
|
+
continue;
|
|
165
|
+
found = true;
|
|
166
|
+
const before = body.slice(last, m.index);
|
|
167
|
+
if (before)
|
|
168
|
+
parts.push(quote + before + quote);
|
|
169
|
+
parts.push(SecretsInjector.expression(file, m[1]));
|
|
170
|
+
last = m.index + m[0].length;
|
|
171
|
+
}
|
|
172
|
+
if (!found)
|
|
173
|
+
return literal;
|
|
174
|
+
const after = body.slice(last);
|
|
175
|
+
if (after)
|
|
176
|
+
parts.push(quote + after + quote);
|
|
177
|
+
return "(" + (parts.length === 1 ? parts[0] : `""+` + parts.join("+")) + ")";
|
|
178
|
+
}
|
|
179
|
+
static parses(source) {
|
|
180
|
+
try {
|
|
181
|
+
new vm_1.default.Script(`(function (exports, require, module, __filename, __dirname) {${source}\n})`);
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
exports.SecretsInjector = SecretsInjector;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function SetupConfigWizard(target?: string): Promise<void>;
|
|
@@ -0,0 +1,238 @@
|
|
|
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.SetupConfigWizard = SetupConfigWizard;
|
|
7
|
+
const fs_1 = __importDefault(require("fs"));
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
10
|
+
const process_1 = require("process");
|
|
11
|
+
const PasswordHash_1 = require("../helper/PasswordHash");
|
|
12
|
+
const IpAllowList_1 = require("../helper/IpAllowList");
|
|
13
|
+
const Validator_1 = require("../helper/Validator");
|
|
14
|
+
const MonitorAuth_1 = require("../monitor/MonitorAuth");
|
|
15
|
+
const DeployerService_1 = require("./DeployerService");
|
|
16
|
+
const HashPassword_1 = require("./HashPassword");
|
|
17
|
+
const cliCommon_1 = require("./cliCommon");
|
|
18
|
+
const cliPrompt_1 = require("./cliPrompt");
|
|
19
|
+
async function SetupConfigWizard(target) {
|
|
20
|
+
const { red, green, yellow, dim, bold } = (0, cliCommon_1.palette)();
|
|
21
|
+
if (!process_1.stdin.isTTY) {
|
|
22
|
+
console.error(red("✗ setup-config needs an interactive terminal — it asks for passwords."));
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
let file = target ?? (["setup.json", "projects/setup.json"].find(f => fs_1.default.existsSync(f)) ?? "");
|
|
26
|
+
if (target && fs_1.default.existsSync(target) && fs_1.default.statSync(target).isDirectory())
|
|
27
|
+
file = path_1.default.join(target, "setup.json");
|
|
28
|
+
console.log(bold("\nDeployer setup.json") + dim(" (the deployer re-reads it on change)"));
|
|
29
|
+
file = path_1.default.resolve(file || await (0, cliPrompt_1.ask)("File", "setup.json"));
|
|
30
|
+
let doc = { users: [] };
|
|
31
|
+
if (fs_1.default.existsSync(file)) {
|
|
32
|
+
try {
|
|
33
|
+
doc = JSON.parse(fs_1.default.readFileSync(file, "utf-8") || "{}");
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(red(`✗ ${file} is not valid JSON (${e?.message ?? e}).`));
|
|
37
|
+
process.exit(1);
|
|
38
|
+
}
|
|
39
|
+
console.log(dim(` Loaded ${file}`));
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
console.log(dim(` New file: ${file}`));
|
|
43
|
+
}
|
|
44
|
+
doc.users = Array.isArray(doc.users) ? doc.users : [];
|
|
45
|
+
for (const u of doc.users)
|
|
46
|
+
if (u && u.login === undefined && typeof u.username === "string") {
|
|
47
|
+
u.login = u.username;
|
|
48
|
+
delete u.username;
|
|
49
|
+
console.log(yellow(` ⚠ "${u.login}": old field "username" renamed to "login" — saved with the next save`));
|
|
50
|
+
}
|
|
51
|
+
let changed = false;
|
|
52
|
+
const clientsToUpdate = new Set();
|
|
53
|
+
const show = () => {
|
|
54
|
+
console.log("\n" + bold("Deployer users") + dim(" (in deploy.json: username + password)"));
|
|
55
|
+
if (!doc.users.length)
|
|
56
|
+
console.log(red(" none — nobody can deploy"));
|
|
57
|
+
for (const u of doc.users) {
|
|
58
|
+
const state = u.publicKey ? green("signing key")
|
|
59
|
+
: !u.password ? red("no password or key — can't sign in")
|
|
60
|
+
: doc.require_signature !== false ? yellow("password — refused, only signed requests are accepted")
|
|
61
|
+
: PasswordHash_1.PasswordHash.isHash(u.password) ? dim("hashed password")
|
|
62
|
+
: red("PLAIN-TEXT password — refused, set a new one or run migrate-configs");
|
|
63
|
+
console.log(` ${String(u.login).padEnd(20)} ${state}`);
|
|
64
|
+
}
|
|
65
|
+
console.log(bold("Signed requests only") + " " + (doc.require_signature !== false ? green("yes") : yellow("no — password users still accepted")));
|
|
66
|
+
console.log(bold("Reviewers"));
|
|
67
|
+
if (!doc.reviewers?.length)
|
|
68
|
+
console.log(dim(" none"));
|
|
69
|
+
for (const r of doc.reviewers ?? [])
|
|
70
|
+
console.log(` ${String(r.login).padEnd(20)} ${String(r.email ?? "").padEnd(28)} ${PasswordHash_1.PasswordHash.isHash(r.password) ? dim("hashed password") : red("PLAIN-TEXT password")}`);
|
|
71
|
+
console.log(bold("Allowed addresses") + " " + (doc.allowed_ips?.length ? doc.allowed_ips.join(", ") : dim("any address")));
|
|
72
|
+
console.log(bold("Review page URL") + " " + (doc.review_url || dim("not set")));
|
|
73
|
+
};
|
|
74
|
+
const user = (login) => doc.users.find((u) => u.login === login);
|
|
75
|
+
const reviewer = (login) => (doc.reviewers ?? []).find((r) => r.login === login);
|
|
76
|
+
async function password(question) {
|
|
77
|
+
for (;;) {
|
|
78
|
+
const p1 = await (0, HashPassword_1.askHidden)(` ${question} (hidden, 12+ characters): `);
|
|
79
|
+
const policy = MonitorAuth_1.MonitorAuth.passwordPolicyError(p1);
|
|
80
|
+
if (policy) {
|
|
81
|
+
console.log(red(` ✗ ${policy}`));
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const p2 = await (0, HashPassword_1.askHidden)(" repeat: ");
|
|
85
|
+
if (p1 !== p2) {
|
|
86
|
+
console.log(red(" ✗ passwords do not match"));
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
return p1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const deployerHash = (login, pw) => PasswordHash_1.PasswordHash.hash(crypto_1.default.createHash("sha256").update(login + ":" + pw).digest("hex"));
|
|
93
|
+
const validLogin = (v) => /^[A-Za-z0-9._@-]+$/.test(v) ? null : "letters, digits, '.', '_', '-', '@' only";
|
|
94
|
+
const actions = {
|
|
95
|
+
"1": { title: "add a deployer user", run: async () => {
|
|
96
|
+
const login = await (0, cliPrompt_1.askValid)(" login", "", v => !v ? "required" : user(v) ? "already exists" : validLogin(v));
|
|
97
|
+
doc.users.push({ login, password: await deployerHash(login, await password(`password for ${login}`)) });
|
|
98
|
+
clientsToUpdate.add(login);
|
|
99
|
+
console.log(green(` ✓ ${login} added`));
|
|
100
|
+
changed = true;
|
|
101
|
+
} },
|
|
102
|
+
"2": { title: "change a deployer user's password", run: async () => {
|
|
103
|
+
const u = user(await (0, cliPrompt_1.askValid)(" login", "", v => user(v) ? null : "no such user"));
|
|
104
|
+
u.password = await deployerHash(u.login, await password(`new password for ${u.login}`));
|
|
105
|
+
clientsToUpdate.add(u.login);
|
|
106
|
+
console.log(green(` ✓ password of ${u.login} changed`));
|
|
107
|
+
changed = true;
|
|
108
|
+
} },
|
|
109
|
+
"3": { title: "rename a deployer user", run: async () => {
|
|
110
|
+
const u = user(await (0, cliPrompt_1.askValid)(" current login", "", v => user(v) ? null : "no such user"));
|
|
111
|
+
const login = await (0, cliPrompt_1.askValid)(" new login", "", v => !v ? "required" : user(v) ? "already exists" : validLogin(v));
|
|
112
|
+
u.password = await deployerHash(login, await password(`password for ${login} (the same or a new one)`));
|
|
113
|
+
clientsToUpdate.delete(u.login);
|
|
114
|
+
u.login = login;
|
|
115
|
+
clientsToUpdate.add(login);
|
|
116
|
+
console.log(green(` ✓ renamed to ${login}`));
|
|
117
|
+
changed = true;
|
|
118
|
+
} },
|
|
119
|
+
"4": { title: "remove a deployer user", run: async () => {
|
|
120
|
+
const login = await (0, cliPrompt_1.askValid)(" login", "", v => user(v) ? null : "no such user");
|
|
121
|
+
if (doc.users.length === 1)
|
|
122
|
+
console.log(yellow(" ⚠ This is the last user — nobody will be able to deploy."));
|
|
123
|
+
if (!(await (0, cliPrompt_1.yes)(` remove ${login}?`, false)))
|
|
124
|
+
return;
|
|
125
|
+
doc.users = doc.users.filter((u) => u.login !== login);
|
|
126
|
+
clientsToUpdate.delete(login);
|
|
127
|
+
console.log(green(` ✓ ${login} removed`));
|
|
128
|
+
changed = true;
|
|
129
|
+
} },
|
|
130
|
+
"k": { title: "set a deployer user's public key (signed deploys)", run: async () => {
|
|
131
|
+
const u = user(await (0, cliPrompt_1.askValid)(" login", "", v => user(v) ? null : "no such user — add the user first"));
|
|
132
|
+
const key = await (0, cliPrompt_1.askValid)(" public key from `npx bmfk deploy-key` (base64)", "", v => {
|
|
133
|
+
try {
|
|
134
|
+
crypto_1.default.createPublicKey({ key: Buffer.from(v, "base64"), format: "der", type: "spki" });
|
|
135
|
+
return /^MCowBQYDK2VwAyEA/.test(v) ? null : "not an Ed25519 public key";
|
|
136
|
+
}
|
|
137
|
+
catch {
|
|
138
|
+
return "not a public key (base64 SPKI)";
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
u.publicKey = key;
|
|
142
|
+
if (u.password) {
|
|
143
|
+
delete u.password;
|
|
144
|
+
console.log(dim(" password removed — the user signs in with the key only"));
|
|
145
|
+
}
|
|
146
|
+
clientsToUpdate.delete(u.login);
|
|
147
|
+
console.log(green(` ✓ ${u.login} signs requests with their key`));
|
|
148
|
+
changed = true;
|
|
149
|
+
} },
|
|
150
|
+
"r": { title: "require signed requests from everyone (on/off)", run: async () => {
|
|
151
|
+
const passwordUsers = doc.users.filter((x) => !x.publicKey).map((x) => x.login);
|
|
152
|
+
const on = doc.require_signature !== false;
|
|
153
|
+
if (!on && passwordUsers.length)
|
|
154
|
+
console.log(yellow(` ⚠ ${passwordUsers.join(", ")} have no key yet — they can't deploy once this is on.`));
|
|
155
|
+
if (await (0, cliPrompt_1.yes)(" only signed requests?", !on))
|
|
156
|
+
delete doc.require_signature;
|
|
157
|
+
else
|
|
158
|
+
doc.require_signature = false;
|
|
159
|
+
changed = true;
|
|
160
|
+
} },
|
|
161
|
+
"5": { title: "add a reviewer", run: async () => {
|
|
162
|
+
const login = await (0, cliPrompt_1.askValid)(" login", "", v => !v ? "required" : reviewer(v) ? "already exists" : validLogin(v));
|
|
163
|
+
const email = await (0, cliPrompt_1.askValid)(" email (gets the review links)", "", v => /^[^\s@]+@[^\s@]+$/.test(v) ? null : "an email address");
|
|
164
|
+
doc.reviewers = [...(doc.reviewers ?? []), { login, password: await PasswordHash_1.PasswordHash.hash(await password(`password for ${login}`)), email }];
|
|
165
|
+
console.log(green(` ✓ reviewer ${login} added`) + dim(" — 2FA is set up at the first sign-in on the review page"));
|
|
166
|
+
changed = true;
|
|
167
|
+
} },
|
|
168
|
+
"6": { title: "change a reviewer's password or email", run: async () => {
|
|
169
|
+
const r = reviewer(await (0, cliPrompt_1.askValid)(" login", "", v => reviewer(v) ? null : "no such reviewer"));
|
|
170
|
+
r.email = await (0, cliPrompt_1.askValid)(" email", r.email ?? "", v => /^[^\s@]+@[^\s@]+$/.test(v) ? null : "an email address");
|
|
171
|
+
if (await (0, cliPrompt_1.yes)(" set a new password?", false))
|
|
172
|
+
r.password = await PasswordHash_1.PasswordHash.hash(await password(`new password for ${r.login}`));
|
|
173
|
+
console.log(green(` ✓ ${r.login} updated`));
|
|
174
|
+
changed = true;
|
|
175
|
+
} },
|
|
176
|
+
"7": { title: "remove a reviewer", run: async () => {
|
|
177
|
+
const login = await (0, cliPrompt_1.askValid)(" login", "", v => reviewer(v) ? null : "no such reviewer");
|
|
178
|
+
if (!(await (0, cliPrompt_1.yes)(` remove ${login}? Projects that list them can't be uploaded until their config is changed`, false)))
|
|
179
|
+
return;
|
|
180
|
+
doc.reviewers = doc.reviewers.filter((r) => r.login !== login);
|
|
181
|
+
if (!doc.reviewers.length)
|
|
182
|
+
delete doc.reviewers;
|
|
183
|
+
console.log(green(` ✓ ${login} removed`));
|
|
184
|
+
changed = true;
|
|
185
|
+
} },
|
|
186
|
+
"8": { title: "set allowed addresses", run: async () => {
|
|
187
|
+
const v = await (0, cliPrompt_1.askValid)(" IPs and subnets, comma-separated (empty = any address)", (doc.allowed_ips ?? []).join(", "), x => IpAllowList_1.IpAllowList.build((0, cliPrompt_1.list)(x)).error ?? null);
|
|
188
|
+
const ips = (0, cliPrompt_1.list)(v);
|
|
189
|
+
if (ips.length)
|
|
190
|
+
doc.allowed_ips = ips;
|
|
191
|
+
else
|
|
192
|
+
delete doc.allowed_ips;
|
|
193
|
+
if (ips.includes("127.0.0.1") || ips.includes("::1"))
|
|
194
|
+
console.log(yellow(" ⚠ Behind a proxy on this host, loopback lets every request through — use the clients' real addresses."));
|
|
195
|
+
changed = true;
|
|
196
|
+
} },
|
|
197
|
+
"9": { title: "set the review page URL", run: async () => {
|
|
198
|
+
const v = await (0, cliPrompt_1.askValid)(" URL (empty = none)", doc.review_url ?? "", x => !x || /^https?:\/\/\S+$/.test(x) ? null : "an http(s) URL");
|
|
199
|
+
if (v)
|
|
200
|
+
doc.review_url = v;
|
|
201
|
+
else
|
|
202
|
+
delete doc.review_url;
|
|
203
|
+
changed = true;
|
|
204
|
+
} },
|
|
205
|
+
};
|
|
206
|
+
for (;;) {
|
|
207
|
+
show();
|
|
208
|
+
console.log("\n" + Object.entries(actions).map(([k, a]) => ` ${k}) ${a.title}`).join("\n") + `\n s) save and exit\n q) quit without saving`);
|
|
209
|
+
const choice = (await (0, cliPrompt_1.ask)("Choose", "")).toLowerCase();
|
|
210
|
+
if (choice === "q") {
|
|
211
|
+
if (changed && !(await (0, cliPrompt_1.yes)("Discard the changes?", false)))
|
|
212
|
+
continue;
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
if (choice === "s") {
|
|
216
|
+
const errors = await Validator_1.Validator.validateStructure(DeployerService_1.SETUP_MODEL, doc);
|
|
217
|
+
if (errors && errors.length) {
|
|
218
|
+
console.log(red(` ✗ Not saved — the deployer would refuse it: ${errors.join("; ")}`));
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
fs_1.default.mkdirSync(path_1.default.dirname(file), { recursive: true });
|
|
222
|
+
const tmp = file + ".tmp";
|
|
223
|
+
fs_1.default.writeFileSync(tmp, JSON.stringify(doc, null, 4) + "\n", { encoding: "utf-8", mode: 0o600 });
|
|
224
|
+
fs_1.default.chmodSync(tmp, 0o600);
|
|
225
|
+
fs_1.default.renameSync(tmp, file);
|
|
226
|
+
console.log(green(`✓ Saved ${file}`) + dim(" (0600) — a running deployer picks it up within a second"));
|
|
227
|
+
if (clientsToUpdate.size)
|
|
228
|
+
console.log(yellow(` Update deploy.json wherever these users deploy from (username + password): ${[...clientsToUpdate].join(", ")}`));
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const action = actions[choice];
|
|
232
|
+
if (!action) {
|
|
233
|
+
console.log(red(" ✗ choose a number, s or q"));
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
await action.run();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Status = Status;
|
|
4
|
+
const Http_1 = require("../http/Http");
|
|
5
|
+
const DefaultErrors_1 = require("../structures/DefaultErrors");
|
|
6
|
+
const resolveConfig_1 = require("./resolveConfig");
|
|
7
|
+
const cliCommon_1 = require("./cliCommon");
|
|
8
|
+
async function Status(opt) {
|
|
9
|
+
opt = await (0, resolveConfig_1.resolveConfig)(opt);
|
|
10
|
+
let statusUrl;
|
|
11
|
+
if (/\/add\/?$/.test(opt.host))
|
|
12
|
+
statusUrl = opt.host.replace(/\/add\/?$/, "/status");
|
|
13
|
+
else if (opt.switch_host && /\/switch\/?$/.test(opt.switch_host))
|
|
14
|
+
statusUrl = opt.switch_host.replace(/\/switch\/?$/, "/status");
|
|
15
|
+
else
|
|
16
|
+
throw new Error(`Cannot derive status URL from host "${opt.host}" — make sure "host" ends with /add.`);
|
|
17
|
+
const requestBody = { name: opt.name };
|
|
18
|
+
const response = await Http_1.Http.post(statusUrl, requestBody, {
|
|
19
|
+
headers: (0, cliCommon_1.deployerHeaders)(opt, statusUrl, requestBody),
|
|
20
|
+
timeoutMs: 15 * 1000,
|
|
21
|
+
retry: { enabled: false },
|
|
22
|
+
});
|
|
23
|
+
const useColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
24
|
+
const c = (code, t) => useColor ? `\x1b[${code}m${t}\x1b[0m` : t;
|
|
25
|
+
const red = (t) => c("31", t), green = (t) => c("32", t), yellow = (t) => c("33", t);
|
|
26
|
+
const blue = (t) => c("34", t), dim = (t) => c("2", t), bold = (t) => c("1", t);
|
|
27
|
+
const slotColor = (s) => s === "blue" ? blue(bold("BLUE")) : s === "green" ? green(bold("GREEN")) : dim("—");
|
|
28
|
+
const line = dim("─".repeat(60));
|
|
29
|
+
console.log("");
|
|
30
|
+
if (!response.ok) {
|
|
31
|
+
console.error(red(bold("✗ STATUS FAILED — transport error")));
|
|
32
|
+
console.error(line);
|
|
33
|
+
console.error(` ${dim("host: ")} ${statusUrl}`);
|
|
34
|
+
console.error(` ${dim("status:")} ${response.status !== undefined ? `HTTP ${response.status}` : "network error (no response)"}`);
|
|
35
|
+
if (response.error !== undefined) {
|
|
36
|
+
const t = typeof response.error === "string" ? response.error : JSON.stringify(response.error);
|
|
37
|
+
console.error(` ${dim("error: ")} ${t.length > 400 ? t.slice(0, 400) + "…" : t}`);
|
|
38
|
+
}
|
|
39
|
+
console.error(line);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
const body = response.data;
|
|
43
|
+
const appError = DefaultErrors_1.ErrorUtils.isError(body?.error) ? body.error : DefaultErrors_1.ErrorUtils.isError(body?.data) ? body.data : null;
|
|
44
|
+
if (appError) {
|
|
45
|
+
console.error(red(bold("✗ STATUS REJECTED BY SERVER")));
|
|
46
|
+
console.error(line);
|
|
47
|
+
console.error(` ${dim("code: ")} ${appError.code}`);
|
|
48
|
+
console.error(` ${dim("message:")} ${appError.message}`);
|
|
49
|
+
console.error(line);
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
const entry = body?.data?.[opt.name];
|
|
53
|
+
if (!entry) {
|
|
54
|
+
console.error(red(bold(`✗ Project "${opt.name}" is not configured on the deployer`)));
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
const state = entry.state;
|
|
58
|
+
console.log(`${bold("●")} ${bold(opt.name)}`);
|
|
59
|
+
console.log(line);
|
|
60
|
+
if (!entry.hasBlueGreen) {
|
|
61
|
+
console.log(` ${dim("mode: ")} single slot ${dim("(no blue-green configured)")}`);
|
|
62
|
+
}
|
|
63
|
+
else if (!state) {
|
|
64
|
+
console.log(` ${dim("mode: ")} blue-green`);
|
|
65
|
+
console.log(` ${dim("state: ")} ${yellow("never deployed")}`);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
console.log(` ${dim("active: ")} ${slotColor(state.active)}`);
|
|
69
|
+
console.log(` ${dim("lastDeployed:")} ${slotColor(state.lastDeployed)}`);
|
|
70
|
+
if (entry.readyToSwitch)
|
|
71
|
+
console.log(` ${yellow("⚠ " + state.lastDeployed + " is deployed but NOT switched")} ${dim("→ bmfk activate")}`);
|
|
72
|
+
const last = Array.isArray(state.history) && state.history.length ? state.history[state.history.length - 1] : null;
|
|
73
|
+
if (last) {
|
|
74
|
+
const d = new Date(last.at);
|
|
75
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
76
|
+
const when = `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
|
77
|
+
console.log(` ${dim("last action: ")} ${last.action} ${last.slot} ${dim("by")} ${last.user} ${dim("·")} ${when}`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
console.log(line);
|
|
81
|
+
console.log("");
|
|
82
|
+
return state?.active ?? null;
|
|
83
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface ITelegramOptions {
|
|
2
|
+
bot: string;
|
|
3
|
+
chat: string;
|
|
4
|
+
topic?: number;
|
|
5
|
+
api?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function telegramText(project: string, status: string, user: string, host?: string): string;
|
|
8
|
+
export declare function sendTelegram(opt: ITelegramOptions, text: string): Promise<boolean>;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.telegramText = telegramText;
|
|
7
|
+
exports.sendTelegram = sendTelegram;
|
|
8
|
+
const os_1 = __importDefault(require("os"));
|
|
9
|
+
const LogService_1 = require("../LogService");
|
|
10
|
+
const Http_1 = require("../http/Http");
|
|
11
|
+
const esc = (v) => String(v).replace(/[&<>]/g, c => ({ "&": "&", "<": "<", ">": ">" }[c]));
|
|
12
|
+
function telegramText(project, status, user, host = os_1.default.hostname()) {
|
|
13
|
+
const icon = /error|fail|declined/.test(status) ? "❌" : /review/.test(status) ? "👀" : /roll|restor|switch/.test(status) ? "🔄" : "✅";
|
|
14
|
+
return `${icon} <b>${esc(project)}</b> — ${esc(status)}\nby <b>${esc(user)}</b> · ${esc(host)} · ${new Date().toISOString().slice(0, 19).replace("T", " ")} UTC`;
|
|
15
|
+
}
|
|
16
|
+
async function sendTelegram(opt, text) {
|
|
17
|
+
const resp = await Http_1.Http.post(`${opt.api ?? "https://api.telegram.org"}/bot${opt.bot}/sendMessage`, { chat_id: opt.chat, text, parse_mode: "HTML", disable_web_page_preview: true, ...(opt.topic ? { message_thread_id: opt.topic } : {}) }, { skipLogging: true, timeoutMs: 10_000, retry: { enabled: false } });
|
|
18
|
+
if (resp.ok)
|
|
19
|
+
return true;
|
|
20
|
+
const description = resp.error?.description;
|
|
21
|
+
(0, LogService_1.logWarn)(`Telegram: message to chat ${opt.chat} not sent — ${resp.status ? `HTTP ${resp.status}` : "network error"}${description ? ": " + description : ""}`);
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BaseService } from "../BaseService";
|
|
2
|
+
import { IConfig } from "./ConfigService";
|
|
3
|
+
import { IDeploymentNotifier } from "./Notifier";
|
|
4
|
+
export declare class Watchdog extends BaseService {
|
|
5
|
+
config: Map<string, IConfig>;
|
|
6
|
+
lastStatuses: Map<string, boolean>;
|
|
7
|
+
notifier: IDeploymentNotifier | null;
|
|
8
|
+
private onStatus;
|
|
9
|
+
constructor(notifier?: IDeploymentNotifier | null, onStatus?: (project: string, status: string) => void);
|
|
10
|
+
applicationReady(): void;
|
|
11
|
+
setup(): Promise<void>;
|
|
12
|
+
checkReadiness(config: IConfig): Promise<void>;
|
|
13
|
+
statusPassed(config: IConfig): void;
|
|
14
|
+
statusFailed(config: IConfig): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Watchdog = void 0;
|
|
4
|
+
const Http_1 = require("../http/Http");
|
|
5
|
+
const BaseService_1 = require("../BaseService");
|
|
6
|
+
const ConfigService_1 = require("./ConfigService");
|
|
7
|
+
class Watchdog extends BaseService_1.BaseService {
|
|
8
|
+
config = new Map();
|
|
9
|
+
lastStatuses = new Map();
|
|
10
|
+
notifier = null;
|
|
11
|
+
onStatus;
|
|
12
|
+
constructor(notifier, onStatus) {
|
|
13
|
+
super("Watchdog");
|
|
14
|
+
this.notifier = notifier || null;
|
|
15
|
+
this.onStatus = onStatus ?? (() => { });
|
|
16
|
+
}
|
|
17
|
+
applicationReady() {
|
|
18
|
+
this.setup();
|
|
19
|
+
ConfigService_1.S_CONFIG_UPDATED.subscribe(async () => { this.config = await ConfigService_1.REQ_DEPLOYMENT_CONFIG.request(); });
|
|
20
|
+
}
|
|
21
|
+
async setup() {
|
|
22
|
+
this.config = await ConfigService_1.REQ_DEPLOYMENT_CONFIG.request();
|
|
23
|
+
setInterval(() => {
|
|
24
|
+
for (let i of this.config) {
|
|
25
|
+
if (i[1].readiness) {
|
|
26
|
+
this.checkReadiness(i[1]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}, 10000);
|
|
30
|
+
}
|
|
31
|
+
async checkReadiness(config) {
|
|
32
|
+
if (!config.readiness)
|
|
33
|
+
return;
|
|
34
|
+
const resp = await Http_1.Http.get(config.readiness, { retry: { enabled: true } });
|
|
35
|
+
if (resp.ok) {
|
|
36
|
+
this.statusPassed(config);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
this.statusFailed(config);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
statusPassed(config) {
|
|
43
|
+
if (this.lastStatuses.get(config.name) === false) {
|
|
44
|
+
this.onStatus(config.name, "readiness-ok");
|
|
45
|
+
if (config.email && config.email.length > 0) {
|
|
46
|
+
for (let email of config.email) {
|
|
47
|
+
this.notifier?.notifyEmailStatus(email, "readiness-ok", config.name, "watchdog");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
this.lastStatuses.set(config.name, true);
|
|
52
|
+
}
|
|
53
|
+
statusFailed(config) {
|
|
54
|
+
if (this.lastStatuses.get(config.name) !== false) {
|
|
55
|
+
this.onStatus(config.name, "readiness-error");
|
|
56
|
+
if (config.email && config.email.length > 0) {
|
|
57
|
+
for (let email of config.email) {
|
|
58
|
+
this.notifier?.notifyEmailStatus(email, "readiness-error", config.name, "watchdog");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
this.lastStatuses.set(config.name, false);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.Watchdog = Watchdog;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Wizards(): Promise<void>;
|