Added getLoggings schema validation
ADD
src/assets/server/rest/v1/schemas/logging/loggings-get.json
+{
+ "title": "Get Loggings",
+ "description": "",
+ "type": "object",
+ "properties": {
+ "StartDateTime": {
+ "type": "string",
+ "format": "date-time",
+ "sanitize": "mongo"
+ },
+ "EndDateTime": {
+ "type": "string",
+ "format": "date-time",
+ "sanitize": "mongo"
+ },
+ "Level": {
+ "type": "string",
+ "sanitize": "mongo",
+ "pattern": "^((D|I|W|E|NONE|DEFAULT)(\\||D|I|W|E|NONE|DEFAULT)*)?$"
+ },
+ "Source": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "Host": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "Type": {
+ "type": "string",
+ "sanitize": "mongo",
+ "enum": [
+ "R", "S"
+ ]
+ },
+ "Action": {
+ "type": "string",
+ "sanitize": "mongo"
+ },
+ "UserID": {
+ "$ref": "user.json#/definitions/ids"
+ },
+ "Search": {
+ "$ref": "common.json#/definitions/search"
+ },
+ "SortFields": {
+ "$ref": "common.json#/definitions/sortFields"
+ },
+ "Limit": {
+ "$ref": "common.json#/definitions/limit"
+ },
+ "Skip": {
+ "$ref": "common.json#/definitions/skip"
+ },
+ "OnlyRecordCount": {
+ "$ref": "common.json#/definitions/onlyRecordCount"
+ },
+ "ProjectFields": {
+ "$ref": "common.json#/definitions/projectFields"
+ }
+ },
+ "required": []
+}

MODIFY
src/server/rest/v1/router/api/LoggingRouter.ts
src/server/rest/v1/router/api/LoggingRouter.ts
@@ -27,6 +27,7 @@ export default class LoggingRouter {
protected buildRouteLogging(): void {
this.router.get(`/${ServerRoute.REST_LOGGING}`, async (req: Request, res: Response, next: NextFunction) => {
+ req.query.ID = req.params.id;
await RouterUtils.handleServerAction(LoggingService.handleGetLog.bind(this), ServerAction.LOGGING, req, res, next);
});
}

MODIFY
src/server/rest/v1/service/LoggingService.ts
src/server/rest/v1/service/LoggingService.ts
@@ -10,6 +10,7 @@ import { HTTPAuthError } from '../../../../types/HTTPError';
import { Log } from '../../../../types/Log';
import LoggingSecurity from './security/LoggingSecurity';
import LoggingStorage from '../../../../storage/mongodb/LoggingStorage';
+import LoggingValidator from '../validator/LoggingValidator';
import { ServerAction } from '../../../../types/Server';
import TenantComponents from '../../../../types/TenantComponents';
import Utils from '../../../../utils/Utils';
@@ -101,7 +102,7 @@ export default class LoggingService {
});
}
// Filter
- const filteredRequest = LoggingSecurity.filterLogsRequest(req.query);
+ const filteredRequest = LoggingValidator.getInstance().validateLoggingsGetReq(req.query);
// Add filter for Site Admins
if (Utils.isComponentActiveFromToken(req.user, TenantComponents.ORGANIZATION) && Authorizations.isSiteAdmin(req.user)) {
// Optimization: Retrieve Charging Stations to get the logs only for the Site Admin user

ADD
src/server/rest/v1/validator/LoggingValidator.ts
+import { HttpLogsRequest } from '../../../../types/requests/HttpLoggingRequest';
+import Schema from '../../../../types/validator/Schema';
+import SchemaValidator from './SchemaValidator';
+import fs from 'fs';
+import global from '../../../../types/GlobalType';
+
+export default class LoggingValidator extends SchemaValidator {
+ private static instance: LoggingValidator|null = null;
+ private loggingsGet: Schema;
+
+ private constructor() {
+ super('LoggingValidator');
+ this.loggingsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/loggings/loggings-get.json`, 'utf8'));
+ }
+
+ public static getInstance(): LoggingValidator {
+ if (!LoggingValidator.instance) {
+ LoggingValidator.instance = new LoggingValidator();
+ }
+ return LoggingValidator.instance;
+ }
+
+ public validateLoggingsGetReq(data: any): HttpLogsRequest {
+ // Validate schema
+ this.validate(this.loggingsGet, data);
+ return data;
+ }
+}

Added getLoggings schema validation