diff options
author | Chocobozzz <me@florianbigard.com> | 2022-07-15 15:30:14 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2022-07-18 11:37:18 +0200 |
commit | 42b40636991b97fe818007fab19091764fc5db73 (patch) | |
tree | db431787c06ce898d22e91ff771f795219274fc6 /server/middlewares/validators/logs.ts | |
parent | 654d4ede7fa4d0faa71e49bcfab6b65a686397b2 (diff) | |
download | PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.gz PeerTube-42b40636991b97fe818007fab19091764fc5db73.tar.zst PeerTube-42b40636991b97fe818007fab19091764fc5db73.zip |
Add ability for client to create server logs
Diffstat (limited to 'server/middlewares/validators/logs.ts')
-rw-r--r-- | server/middlewares/validators/logs.ts | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/server/middlewares/validators/logs.ts b/server/middlewares/validators/logs.ts index 901d8ca64..324ba6915 100644 --- a/server/middlewares/validators/logs.ts +++ b/server/middlewares/validators/logs.ts | |||
@@ -1,11 +1,56 @@ | |||
1 | import express from 'express' | 1 | import express from 'express' |
2 | import { query } from 'express-validator' | 2 | import { body, query } from 'express-validator' |
3 | import { isUrlValid } from '@server/helpers/custom-validators/activitypub/misc' | ||
3 | import { isStringArray } from '@server/helpers/custom-validators/search' | 4 | import { isStringArray } from '@server/helpers/custom-validators/search' |
4 | import { isValidLogLevel } from '../../helpers/custom-validators/logs' | 5 | import { CONFIG } from '@server/initializers/config' |
6 | import { HttpStatusCode } from '@shared/models' | ||
7 | import { | ||
8 | isValidClientLogLevel, | ||
9 | isValidClientLogMessage, | ||
10 | isValidClientLogMeta, | ||
11 | isValidClientLogStackTrace, | ||
12 | isValidClientLogUserAgent, | ||
13 | isValidLogLevel | ||
14 | } from '../../helpers/custom-validators/logs' | ||
5 | import { isDateValid, toArray } from '../../helpers/custom-validators/misc' | 15 | import { isDateValid, toArray } from '../../helpers/custom-validators/misc' |
6 | import { logger } from '../../helpers/logger' | 16 | import { logger } from '../../helpers/logger' |
7 | import { areValidationErrors } from './shared' | 17 | import { areValidationErrors } from './shared' |
8 | 18 | ||
19 | const createClientLogValidator = [ | ||
20 | body('message') | ||
21 | .custom(isValidClientLogMessage).withMessage('Should have a valid log message'), | ||
22 | |||
23 | body('url') | ||
24 | .custom(isUrlValid).withMessage('Should have a valid log url'), | ||
25 | |||
26 | body('level') | ||
27 | .custom(isValidClientLogLevel).withMessage('Should have a valid log message'), | ||
28 | |||
29 | body('stackTrace') | ||
30 | .optional() | ||
31 | .custom(isValidClientLogStackTrace).withMessage('Should have a valid log stack trace'), | ||
32 | |||
33 | body('meta') | ||
34 | .optional() | ||
35 | .custom(isValidClientLogMeta).withMessage('Should have a valid log meta'), | ||
36 | |||
37 | body('userAgent') | ||
38 | .optional() | ||
39 | .custom(isValidClientLogUserAgent).withMessage('Should have a valid log user agent'), | ||
40 | |||
41 | (req: express.Request, res: express.Response, next: express.NextFunction) => { | ||
42 | logger.debug('Checking createClientLogValidator parameters.', { parameters: req.query }) | ||
43 | |||
44 | if (CONFIG.LOG.ACCEPT_CLIENT_LOG !== true) { | ||
45 | return res.sendStatus(HttpStatusCode.FORBIDDEN_403) | ||
46 | } | ||
47 | |||
48 | if (areValidationErrors(req, res)) return | ||
49 | |||
50 | return next() | ||
51 | } | ||
52 | ] | ||
53 | |||
9 | const getLogsValidator = [ | 54 | const getLogsValidator = [ |
10 | query('startDate') | 55 | query('startDate') |
11 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), | 56 | .custom(isDateValid).withMessage('Should have a start date that conforms to ISO 8601'), |
@@ -49,5 +94,6 @@ const getAuditLogsValidator = [ | |||
49 | 94 | ||
50 | export { | 95 | export { |
51 | getLogsValidator, | 96 | getLogsValidator, |
52 | getAuditLogsValidator | 97 | getAuditLogsValidator, |
98 | createClientLogValidator | ||
53 | } | 99 | } |