badmfck-api-server 4.1.28 → 4.1.30
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/dist/apiServer/APIService.d.ts +5 -0
- package/dist/apiServer/APIService.js +13 -1
- package/dist/apiServer/deployment/ConfigService.d.ts +162 -0
- package/dist/apiServer/deployment/ConfigService.js +234 -0
- package/dist/apiServer/deployment/Deployer.d.ts +9 -0
- package/dist/apiServer/deployment/Deployer.js +60 -0
- package/dist/apiServer/deployment/DeployerService.d.ts +119 -0
- package/dist/apiServer/deployment/DeployerService.js +579 -0
- package/dist/apiServer/deployment/NginxHelper.d.ts +9 -0
- package/dist/apiServer/deployment/NginxHelper.js +80 -0
- package/dist/apiServer/deployment/Notifier.d.ts +16 -0
- package/dist/apiServer/deployment/Notifier.js +59 -0
- package/dist/apiServer/deployment/Watchdog.d.ts +14 -0
- package/dist/apiServer/deployment/Watchdog.js +61 -0
- package/dist/apiServer/routes/Liveness.js +1 -1
- package/dist/apiServer/routes/Readiness.d.ts +1 -1
- package/dist/apiServer/routes/Readiness.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Notifier = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const BaseService_1 = require("../BaseService");
|
|
6
|
+
const __1 = require("../..");
|
|
7
|
+
class Notifier extends BaseService_1.BaseService {
|
|
8
|
+
SMS_URL;
|
|
9
|
+
SMS_KEY;
|
|
10
|
+
constructor({ URL, KEY }) {
|
|
11
|
+
super("Notifier");
|
|
12
|
+
this.SMS_URL = URL;
|
|
13
|
+
this.SMS_KEY = KEY;
|
|
14
|
+
}
|
|
15
|
+
async init() {
|
|
16
|
+
super.init();
|
|
17
|
+
}
|
|
18
|
+
async notifyEmailStatus(email, status, project, user) {
|
|
19
|
+
const text = `${project} deployment <b>${status}</b> by <b>${user}</b> ${new Date().toISOString()}`;
|
|
20
|
+
const title = `Deployment: ${project} - ${status} (${user})`;
|
|
21
|
+
const token = (0, crypto_1.createHash)("sha256").update(this.SMS_KEY + email + title + text).digest("base64");
|
|
22
|
+
let response = null;
|
|
23
|
+
try {
|
|
24
|
+
response = await __1.Http.post(this.SMS_URL + "/api/mail/send", {
|
|
25
|
+
to: email,
|
|
26
|
+
text: title,
|
|
27
|
+
html: text
|
|
28
|
+
}, {
|
|
29
|
+
headers: {
|
|
30
|
+
"authorization": token,
|
|
31
|
+
"Content-Type": "application/json"
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
console.error(e);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async notifySMSStatus(phone, text, user) {
|
|
40
|
+
const finalText = `${text} (by ${user})`;
|
|
41
|
+
const token = (0, crypto_1.createHash)("sha256").update(this.SMS_KEY + phone + finalText + "").digest("base64");
|
|
42
|
+
let response = null;
|
|
43
|
+
try {
|
|
44
|
+
response = await __1.Http.post(this.SMS_URL + "/api/sms", {
|
|
45
|
+
to: phone,
|
|
46
|
+
content: finalText
|
|
47
|
+
}, {
|
|
48
|
+
headers: {
|
|
49
|
+
"authorization": token,
|
|
50
|
+
"Content-Type": "application/json"
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
console.error(e);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Notifier = Notifier;
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
+
constructor(notifier?: IDeploymentNotifier | null);
|
|
9
|
+
applicationReady(): void;
|
|
10
|
+
setup(): Promise<void>;
|
|
11
|
+
checkReadiness(config: IConfig): Promise<void>;
|
|
12
|
+
statusPassed(config: IConfig): void;
|
|
13
|
+
statusFailed(config: IConfig): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Watchdog = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
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
|
+
constructor(notifier) {
|
|
12
|
+
super("Watchdog");
|
|
13
|
+
this.notifier = notifier || null;
|
|
14
|
+
}
|
|
15
|
+
applicationReady() {
|
|
16
|
+
this.setup();
|
|
17
|
+
ConfigService_1.S_CONFIG_UPDATED.subscribe(async () => { this.config = await ConfigService_1.REQ_DEPLOYMENT_CONFIG.request(); });
|
|
18
|
+
}
|
|
19
|
+
async setup() {
|
|
20
|
+
this.config = await ConfigService_1.REQ_DEPLOYMENT_CONFIG.request();
|
|
21
|
+
setInterval(() => {
|
|
22
|
+
for (let i of this.config) {
|
|
23
|
+
if (i[1].readiness) {
|
|
24
|
+
this.checkReadiness(i[1]);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, 10000);
|
|
28
|
+
}
|
|
29
|
+
async checkReadiness(config) {
|
|
30
|
+
if (!config.readiness)
|
|
31
|
+
return;
|
|
32
|
+
const resp = await __1.Http.get(config.readiness);
|
|
33
|
+
if (resp.ok) {
|
|
34
|
+
this.statusPassed(config);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
this.statusFailed(config);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
statusPassed(config) {
|
|
41
|
+
if (this.lastStatuses.get(config.name) === false) {
|
|
42
|
+
if (config.email && config.email.length > 0) {
|
|
43
|
+
for (let email of config.email) {
|
|
44
|
+
this.notifier?.notifyEmailStatus(email, "readiness-ok", config.name, "watchdog");
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
this.lastStatuses.set(config.name, true);
|
|
49
|
+
}
|
|
50
|
+
statusFailed(config) {
|
|
51
|
+
if (this.lastStatuses.get(config.name) !== false) {
|
|
52
|
+
if (config.email && config.email.length > 0) {
|
|
53
|
+
for (let email of config.email) {
|
|
54
|
+
this.notifier?.notifyEmailStatus(email, "readiness-error", config.name, "watchdog");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
this.lastStatuses.set(config.name, false);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Watchdog = Watchdog;
|
|
@@ -13,7 +13,7 @@ class Readiness extends BaseEndpoint_1.BaseEndpoint {
|
|
|
13
13
|
this.registerEndpoints([{ endpoint: "", handler: this.checkReadiness, ignoreInterceptor: true }]);
|
|
14
14
|
}
|
|
15
15
|
async checkReadiness(req) {
|
|
16
|
-
const request = APIService_1.REQ_HTTP_REQUESTS_COUNT.request();
|
|
16
|
+
const request = await APIService_1.REQ_HTTP_REQUESTS_COUNT.request();
|
|
17
17
|
return { data: { liveness: true, wakeTime: (+new Date()) - (+this.started), request: request } };
|
|
18
18
|
}
|
|
19
19
|
}
|