itlab-internal-services 2.2.0 → 2.2.2
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/env.d.ts +4 -0
- package/dist/env.js +5 -1
- package/dist/favicon.controller.d.ts +5 -0
- package/dist/favicon.controller.js +54 -0
- package/dist/http.logger.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/liveness.probe.d.ts +1 -5
- package/dist/liveness.probe.js +4 -22
- package/dist/modules/database/database.module.js +29 -17
- package/package.json +1 -1
package/dist/env.d.ts
CHANGED
|
@@ -3,3 +3,7 @@ export declare const ENV_JWT_SECRET = "JWT_SECRET";
|
|
|
3
3
|
export declare const ENV_MONGO_SRV = "MONGO_SRV";
|
|
4
4
|
export declare const ENV_MONGO_USERNAME = "MONGO_USERNAME";
|
|
5
5
|
export declare const ENV_MONGO_PASSWORD = "MONGO_PASSWORD";
|
|
6
|
+
export declare const ENV_MONGO_CERT_DIR = "MONGO_CERT_DIR";
|
|
7
|
+
export declare const ENV_MONGO_TLS_CA_CRT = "MONGO_TLS_CA_CRT";
|
|
8
|
+
export declare const ENV_MONGO_TLS_TLS_CRT = "MONGO_TLS_TLS_CRT";
|
|
9
|
+
export declare const ENV_MONGO_TLS_TLS_KEY = "MONGO_TLS_TLS_KEY";
|
package/dist/env.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ENV_MONGO_PASSWORD = exports.ENV_MONGO_USERNAME = exports.ENV_MONGO_SRV = exports.ENV_JWT_SECRET = exports.ENV_K8S_TOKEN = void 0;
|
|
3
|
+
exports.ENV_MONGO_TLS_TLS_KEY = exports.ENV_MONGO_TLS_TLS_CRT = exports.ENV_MONGO_TLS_CA_CRT = exports.ENV_MONGO_CERT_DIR = exports.ENV_MONGO_PASSWORD = exports.ENV_MONGO_USERNAME = exports.ENV_MONGO_SRV = exports.ENV_JWT_SECRET = exports.ENV_K8S_TOKEN = void 0;
|
|
4
4
|
exports.ENV_K8S_TOKEN = 'K8S_TOKEN';
|
|
5
5
|
exports.ENV_JWT_SECRET = 'JWT_SECRET';
|
|
6
6
|
exports.ENV_MONGO_SRV = 'MONGO_SRV';
|
|
7
7
|
exports.ENV_MONGO_USERNAME = 'MONGO_USERNAME';
|
|
8
8
|
exports.ENV_MONGO_PASSWORD = 'MONGO_PASSWORD';
|
|
9
|
+
exports.ENV_MONGO_CERT_DIR = 'MONGO_CERT_DIR';
|
|
10
|
+
exports.ENV_MONGO_TLS_CA_CRT = 'MONGO_TLS_CA_CRT';
|
|
11
|
+
exports.ENV_MONGO_TLS_TLS_CRT = 'MONGO_TLS_TLS_CRT';
|
|
12
|
+
exports.ENV_MONGO_TLS_TLS_KEY = 'MONGO_TLS_TLS_KEY';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
15
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
16
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
17
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
18
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
19
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
20
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
+
};
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.FaviconController = void 0;
|
|
28
|
+
const common_1 = require("@nestjs/common");
|
|
29
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
30
|
+
const axios_1 = __importDefault(require("axios"));
|
|
31
|
+
const favicon = 'https://file.svi-itlab.com/650d514c58cbe60df3494bc0';
|
|
32
|
+
let FaviconController = class FaviconController {
|
|
33
|
+
constructor() {
|
|
34
|
+
this.axios = axios_1.default.create();
|
|
35
|
+
}
|
|
36
|
+
getFavicon(res) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const { data } = yield this.axios.get(favicon, { responseType: 'stream' });
|
|
39
|
+
data.pipe(res);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__decorate([
|
|
44
|
+
(0, common_1.Get)('favicon.ico'),
|
|
45
|
+
__param(0, (0, common_1.Res)()),
|
|
46
|
+
__metadata("design:type", Function),
|
|
47
|
+
__metadata("design:paramtypes", [Object]),
|
|
48
|
+
__metadata("design:returntype", Promise)
|
|
49
|
+
], FaviconController.prototype, "getFavicon", null);
|
|
50
|
+
FaviconController = __decorate([
|
|
51
|
+
(0, swagger_1.ApiTags)('Favicon'),
|
|
52
|
+
(0, common_1.Controller)()
|
|
53
|
+
], FaviconController);
|
|
54
|
+
exports.FaviconController = FaviconController;
|
package/dist/http.logger.js
CHANGED
|
@@ -5,7 +5,7 @@ const common_1 = require("@nestjs/common");
|
|
|
5
5
|
function useHttpLogger(app) {
|
|
6
6
|
app.use((req, res, next) => {
|
|
7
7
|
const { method, url } = req;
|
|
8
|
-
const ignore = ['/alive', '/
|
|
8
|
+
const ignore = ['/alive', '/favicon.ico'];
|
|
9
9
|
if (url.includes('swagger') || url.startsWith('/api') || ignore.includes(url)) {
|
|
10
10
|
next();
|
|
11
11
|
return;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./exceptions"), exports);
|
|
18
|
+
__exportStar(require("./favicon.controller"), exports);
|
|
18
19
|
__exportStar(require("./guards"), exports);
|
|
19
20
|
__exportStar(require("./http.logger"), exports);
|
|
20
21
|
__exportStar(require("./interceptors"), exports);
|
package/dist/liveness.probe.d.ts
CHANGED
package/dist/liveness.probe.js
CHANGED
|
@@ -20,42 +20,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
20
20
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
21
21
|
});
|
|
22
22
|
};
|
|
23
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
|
-
};
|
|
26
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
24
|
exports.LivenessProbe = void 0;
|
|
28
25
|
const common_1 = require("@nestjs/common");
|
|
29
26
|
const swagger_1 = require("@nestjs/swagger");
|
|
30
|
-
const axios_1 = __importDefault(require("axios"));
|
|
31
|
-
const favicon = 'https://file.svi-itlab.com/650d514c58cbe60df3494bc0';
|
|
32
27
|
let LivenessProbe = class LivenessProbe {
|
|
33
|
-
|
|
34
|
-
this.axios = axios_1.default.create();
|
|
35
|
-
}
|
|
36
|
-
getAlive() {
|
|
37
|
-
return { ok: 1 };
|
|
38
|
-
}
|
|
39
|
-
getFavicon(res) {
|
|
28
|
+
getAlive(response) {
|
|
40
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
|
|
42
|
-
data.pipe(res);
|
|
30
|
+
response.status(200).send({ ok: 1 });
|
|
43
31
|
});
|
|
44
32
|
}
|
|
45
33
|
};
|
|
46
34
|
__decorate([
|
|
47
|
-
(0, common_1.Get)('alive'),
|
|
48
|
-
__metadata("design:type", Function),
|
|
49
|
-
__metadata("design:paramtypes", []),
|
|
50
|
-
__metadata("design:returntype", void 0)
|
|
51
|
-
], LivenessProbe.prototype, "getAlive", null);
|
|
52
|
-
__decorate([
|
|
53
|
-
(0, common_1.Get)('favicon.ico'),
|
|
35
|
+
(0, common_1.Get)('/alive'),
|
|
54
36
|
__param(0, (0, common_1.Res)()),
|
|
55
37
|
__metadata("design:type", Function),
|
|
56
38
|
__metadata("design:paramtypes", [Object]),
|
|
57
39
|
__metadata("design:returntype", Promise)
|
|
58
|
-
], LivenessProbe.prototype, "
|
|
40
|
+
], LivenessProbe.prototype, "getAlive", null);
|
|
59
41
|
LivenessProbe = __decorate([
|
|
60
42
|
(0, swagger_1.ApiTags)('Kubernetes Liveness Probe'),
|
|
61
43
|
(0, common_1.Controller)()
|
|
@@ -53,7 +53,7 @@ const swagger_1 = require("@nestjs/swagger");
|
|
|
53
53
|
const fs_1 = require("fs");
|
|
54
54
|
const mongoose_2 = __importStar(require("mongoose"));
|
|
55
55
|
const path_1 = require("path");
|
|
56
|
-
const
|
|
56
|
+
const env_1 = require("../../env");
|
|
57
57
|
const model_service_1 = require("./model-service/model.service");
|
|
58
58
|
const populate_service_1 = require("./populate-service/populate.service");
|
|
59
59
|
const service_mapper_service_1 = require("./service-mapper-service/service-mapper.service");
|
|
@@ -69,19 +69,19 @@ let DatabaseModule = DatabaseModule_1 = class DatabaseModule {
|
|
|
69
69
|
inject: [config_1.ConfigService],
|
|
70
70
|
useFactory: (configService) => {
|
|
71
71
|
mongoose_2.default.set('strictQuery', true);
|
|
72
|
-
const mongoSrv = configService.getOrThrow(
|
|
73
|
-
const username = configService.getOrThrow(
|
|
74
|
-
const password = configService.getOrThrow(
|
|
72
|
+
const mongoSrv = configService.getOrThrow(env_1.ENV_MONGO_SRV);
|
|
73
|
+
const username = configService.getOrThrow(env_1.ENV_MONGO_USERNAME);
|
|
74
|
+
const password = configService.getOrThrow(env_1.ENV_MONGO_PASSWORD);
|
|
75
75
|
const production = configService.getOrThrow('NODE_ENV', 'development') === 'production';
|
|
76
|
-
const tlsDir = (0, path_1.join)(process.cwd(), configService.get(
|
|
76
|
+
const tlsDir = (0, path_1.join)(process.cwd(), configService.get(env_1.ENV_MONGO_CERT_DIR, 'mongo-tls'));
|
|
77
77
|
const tlsCAFile = (0, path_1.join)(tlsDir, 'hub-services-mongodb.ca.pem');
|
|
78
78
|
const tlsCertificateKeyFile = (0, path_1.join)(tlsDir, 'hub-services-mongodb.cert-key.pem');
|
|
79
79
|
if (production) {
|
|
80
80
|
this.logger.log('Running in production mode... Creating certificates');
|
|
81
81
|
(0, fs_1.mkdirSync)(tlsDir, { recursive: true });
|
|
82
|
-
const caCrt = configService.getOrThrow(
|
|
83
|
-
const tlsCrt = configService.getOrThrow(
|
|
84
|
-
const tlsKey = configService.getOrThrow(
|
|
82
|
+
const caCrt = configService.getOrThrow(env_1.ENV_MONGO_TLS_CA_CRT);
|
|
83
|
+
const tlsCrt = configService.getOrThrow(env_1.ENV_MONGO_TLS_TLS_CRT);
|
|
84
|
+
const tlsKey = configService.getOrThrow(env_1.ENV_MONGO_TLS_TLS_KEY);
|
|
85
85
|
(0, fs_1.rmSync)(tlsCAFile, { force: true, recursive: true });
|
|
86
86
|
(0, fs_1.writeFileSync)(tlsCAFile, caCrt);
|
|
87
87
|
this.logger.log('Created Certificate Authority (.pem)');
|
|
@@ -126,23 +126,35 @@ let DatabaseLivenessProbe = class DatabaseLivenessProbe {
|
|
|
126
126
|
constructor(connection) {
|
|
127
127
|
this.connection = connection;
|
|
128
128
|
}
|
|
129
|
-
|
|
129
|
+
getAlive(response) {
|
|
130
130
|
return __awaiter(this, void 0, void 0, function* () {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return
|
|
134
|
-
|
|
131
|
+
if (!this.connection || this.connection.readyState !== 1) {
|
|
132
|
+
response.status(500).send('Not connected to MongoDB');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const result = yield this.connection.db.admin().ping();
|
|
137
|
+
if (!!((result === null || result === void 0 ? void 0 : result.ok) === 1)) {
|
|
138
|
+
response.status(200).send({ ok: 1, db: 1 });
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
throw new Error('Could not connect to MongoDB');
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
response.status(500).send("Couldn't connect to MongoDB");
|
|
145
|
+
}
|
|
135
146
|
});
|
|
136
147
|
}
|
|
137
148
|
};
|
|
138
149
|
__decorate([
|
|
139
|
-
(0, common_1.Get)('/alive
|
|
150
|
+
(0, common_1.Get)('/alive'),
|
|
151
|
+
__param(0, (0, common_1.Res)()),
|
|
140
152
|
__metadata("design:type", Function),
|
|
141
|
-
__metadata("design:paramtypes", []),
|
|
153
|
+
__metadata("design:paramtypes", [Object]),
|
|
142
154
|
__metadata("design:returntype", Promise)
|
|
143
|
-
], DatabaseLivenessProbe.prototype, "
|
|
155
|
+
], DatabaseLivenessProbe.prototype, "getAlive", null);
|
|
144
156
|
DatabaseLivenessProbe = __decorate([
|
|
145
|
-
(0, swagger_1.ApiTags)('Kubernetes
|
|
157
|
+
(0, swagger_1.ApiTags)('Kubernetes Liveness Probe'),
|
|
146
158
|
(0, common_1.Controller)(),
|
|
147
159
|
__param(0, (0, mongoose_1.InjectConnection)()),
|
|
148
160
|
__metadata("design:paramtypes", [mongoose_2.Connection])
|