itlab-internal-services 1.0.4 → 1.1.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.
|
@@ -17,13 +17,15 @@ const common_1 = require("@nestjs/common");
|
|
|
17
17
|
const swagger_1 = require("@nestjs/swagger");
|
|
18
18
|
const internal_constants_1 = require("../internal.constants");
|
|
19
19
|
exports.INTERNAL_HEADER_KEY = 'X-itlab-k8s-auth';
|
|
20
|
+
const description = 'Application unauthorized';
|
|
21
|
+
const status = common_1.HttpStatus.FORBIDDEN;
|
|
20
22
|
let InternalGuard = class InternalGuard {
|
|
21
23
|
constructor(headerToken = '') {
|
|
22
24
|
this.headerToken = headerToken;
|
|
23
25
|
}
|
|
24
26
|
canActivate(ctx) {
|
|
25
27
|
if (this.headerToken.length === 0)
|
|
26
|
-
|
|
28
|
+
throw new UnauthorizedApplicationException();
|
|
27
29
|
if (this.headerToken === ctx.switchToHttp().getRequest().header(exports.INTERNAL_HEADER_KEY))
|
|
28
30
|
return true;
|
|
29
31
|
throw new UnauthorizedApplicationException();
|
|
@@ -37,7 +39,7 @@ InternalGuard = __decorate([
|
|
|
37
39
|
exports.InternalGuard = InternalGuard;
|
|
38
40
|
let UnauthorizedApplicationException = class UnauthorizedApplicationException extends common_1.HttpException {
|
|
39
41
|
constructor() {
|
|
40
|
-
super(
|
|
42
|
+
super(description, status);
|
|
41
43
|
}
|
|
42
44
|
};
|
|
43
45
|
UnauthorizedApplicationException = __decorate([
|
|
@@ -45,5 +47,5 @@ UnauthorizedApplicationException = __decorate([
|
|
|
45
47
|
__metadata("design:paramtypes", [])
|
|
46
48
|
], UnauthorizedApplicationException);
|
|
47
49
|
exports.UnauthorizedApplicationException = UnauthorizedApplicationException;
|
|
48
|
-
const Internal = () => (0, common_1.applyDecorators)((0, swagger_1.ApiBasicAuth)(exports.INTERNAL_HEADER_KEY), (0, common_1.UseGuards)(new InternalGuard()), (0, swagger_1.
|
|
50
|
+
const Internal = () => (0, common_1.applyDecorators)((0, swagger_1.ApiBasicAuth)(exports.INTERNAL_HEADER_KEY), (0, common_1.UseGuards)(new InternalGuard()), (0, swagger_1.ApiResponse)({ description, status }));
|
|
49
51
|
exports.Internal = Internal;
|
|
@@ -14,11 +14,11 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const swagger_1 = require("@nestjs/swagger");
|
|
16
16
|
const jwt_guard_1 = require("./jwt.guard");
|
|
17
|
-
const
|
|
17
|
+
const META = 'itlab-internal-perms-guard';
|
|
18
|
+
const description = 'Insufficient permissions';
|
|
19
|
+
const status = common_1.HttpStatus.FORBIDDEN;
|
|
18
20
|
function transformPermissions(permissions) {
|
|
19
|
-
const mapped = permissions.map((p) =>
|
|
20
|
-
return [p, p.split('.').slice(0, -1).join('.') + '.*'];
|
|
21
|
-
});
|
|
21
|
+
const mapped = permissions.map((p) => [p, p.split('.').slice(0, -1).join('.') + '.*']);
|
|
22
22
|
return [...new Set(mapped.flat())];
|
|
23
23
|
}
|
|
24
24
|
let PermsGuard = class PermsGuard {
|
|
@@ -26,10 +26,9 @@ let PermsGuard = class PermsGuard {
|
|
|
26
26
|
this.reflector = reflector;
|
|
27
27
|
}
|
|
28
28
|
canActivate(ctx) {
|
|
29
|
-
let perms = this.reflector.get(
|
|
30
|
-
if (!perms || !perms.length || perms.length === 0)
|
|
29
|
+
let perms = this.reflector.get(META, ctx.getHandler());
|
|
30
|
+
if (!perms || !perms.length || perms.length === 0)
|
|
31
31
|
return true;
|
|
32
|
-
}
|
|
33
32
|
perms = transformPermissions(perms);
|
|
34
33
|
const { user } = ctx.switchToHttp().getRequest();
|
|
35
34
|
let userPerms = user.perms;
|
|
@@ -48,7 +47,7 @@ PermsGuard = __decorate([
|
|
|
48
47
|
exports.PermsGuard = PermsGuard;
|
|
49
48
|
let InsufficientPermissionsException = class InsufficientPermissionsException extends common_1.HttpException {
|
|
50
49
|
constructor() {
|
|
51
|
-
super(
|
|
50
|
+
super(description, status);
|
|
52
51
|
}
|
|
53
52
|
};
|
|
54
53
|
InsufficientPermissionsException = __decorate([
|
|
@@ -56,7 +55,5 @@ InsufficientPermissionsException = __decorate([
|
|
|
56
55
|
__metadata("design:paramtypes", [])
|
|
57
56
|
], InsufficientPermissionsException);
|
|
58
57
|
exports.InsufficientPermissionsException = InsufficientPermissionsException;
|
|
59
|
-
const Perms = (...perms) => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(
|
|
60
|
-
description: 'Unauthorized or insufficient permissions',
|
|
61
|
-
}));
|
|
58
|
+
const Perms = (...perms) => (0, common_1.applyDecorators)((0, common_1.SetMetadata)(META, perms), (0, common_1.UseGuards)(jwt_guard_1.JwtGuard, PermsGuard), (0, swagger_1.ApiBearerAuth)(), (0, swagger_1.ApiOperation)({ summary: 'Perms: ' + perms.join(', ') }), (0, swagger_1.ApiResponse)({ description, status }));
|
|
62
59
|
exports.Perms = Perms;
|
package/dist/pipes/hid.pipe.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.ApiHid = exports.Hid = exports.InvalidHidException = void 0;
|
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
6
|
const itlab_functions_1 = require("itlab-functions");
|
|
7
|
+
const description = 'Invalid parameter';
|
|
8
|
+
const status = common_1.HttpStatus.BAD_REQUEST;
|
|
7
9
|
class ParseHidPipe {
|
|
8
10
|
constructor(param) {
|
|
9
11
|
this.param = param;
|
|
@@ -17,7 +19,7 @@ class ParseHidPipe {
|
|
|
17
19
|
}
|
|
18
20
|
class InvalidHidException extends common_1.HttpException {
|
|
19
21
|
constructor(param) {
|
|
20
|
-
super(
|
|
22
|
+
super(`${description} '${param}'`, status);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
exports.InvalidHidException = InvalidHidException;
|
|
@@ -30,5 +32,5 @@ const ApiHid = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)(
|
|
|
30
32
|
'Hallo Welt': { value: 'hallo-welt' },
|
|
31
33
|
'Heute ist ein toller Tag': { value: 'heute-ist-ein-toller-tag' },
|
|
32
34
|
},
|
|
33
|
-
}), (0, swagger_1.
|
|
35
|
+
}), (0, swagger_1.ApiResponse)({ description, status }));
|
|
34
36
|
exports.ApiHid = ApiHid;
|
package/dist/pipes/id.pipe.js
CHANGED
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ApiId = exports.Id = exports.InvalidIdException = void 0;
|
|
4
4
|
const common_1 = require("@nestjs/common");
|
|
5
5
|
const swagger_1 = require("@nestjs/swagger");
|
|
6
|
+
const description = 'Invalid parameter';
|
|
7
|
+
const status = common_1.HttpStatus.BAD_REQUEST;
|
|
6
8
|
class ParseIdPipe {
|
|
7
9
|
constructor(param) {
|
|
8
10
|
this.param = param;
|
|
@@ -17,11 +19,11 @@ class ParseIdPipe {
|
|
|
17
19
|
}
|
|
18
20
|
class InvalidIdException extends common_1.HttpException {
|
|
19
21
|
constructor(param) {
|
|
20
|
-
super(
|
|
22
|
+
super(`${description} '${param}'`, status);
|
|
21
23
|
}
|
|
22
24
|
}
|
|
23
25
|
exports.InvalidIdException = InvalidIdException;
|
|
24
26
|
const Id = (param) => (0, common_1.Param)(param, new ParseIdPipe(param));
|
|
25
27
|
exports.Id = Id;
|
|
26
|
-
const ApiId = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({ name: param, example: ''.padEnd(24, '0') }), (0, swagger_1.
|
|
28
|
+
const ApiId = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({ name: param, example: ''.padEnd(24, '0') }), (0, swagger_1.ApiResponse)({ description, status }));
|
|
27
29
|
exports.ApiId = ApiId;
|
|
@@ -19,6 +19,8 @@ function generateExamples() {
|
|
|
19
19
|
Object.entries(Targets).forEach(([value, key]) => (map[key] = { value }));
|
|
20
20
|
return map;
|
|
21
21
|
}
|
|
22
|
+
const description = 'Invalid parameter';
|
|
23
|
+
const status = common_1.HttpStatus.BAD_REQUEST;
|
|
22
24
|
class ParseTargetPipe {
|
|
23
25
|
constructor(param) {
|
|
24
26
|
this.param = param;
|
|
@@ -31,15 +33,11 @@ class ParseTargetPipe {
|
|
|
31
33
|
}
|
|
32
34
|
class InvalidTargetException extends common_1.HttpException {
|
|
33
35
|
constructor(param) {
|
|
34
|
-
super(
|
|
36
|
+
super(`${description} '${param}'`, status);
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
exports.InvalidTargetException = InvalidTargetException;
|
|
38
40
|
const Target = (param) => (0, common_1.Param)(param, new ParseTargetPipe(param));
|
|
39
41
|
exports.Target = Target;
|
|
40
|
-
const ApiTarget = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({
|
|
41
|
-
name: param,
|
|
42
|
-
example: Targets.NEWSROOM,
|
|
43
|
-
examples: generateExamples(),
|
|
44
|
-
}), (0, swagger_1.ApiBadRequestResponse)({ description: 'Invalid parameter' }));
|
|
42
|
+
const ApiTarget = (param) => (0, common_1.applyDecorators)((0, swagger_1.ApiParam)({ name: param, example: Targets.NEWSROOM, examples: generateExamples() }), (0, swagger_1.ApiResponse)({ description, status }));
|
|
45
43
|
exports.ApiTarget = ApiTarget;
|