Added Org IDs in logs
MODIFY
src/server/rest/v1/service/UtilsService.ts
src/server/rest/v1/service/UtilsService.ts
@@ -23,6 +23,7 @@ import { DataResult } from '../../../../types/DataResult';
import { EntityData } from '../../../../types/GlobalType';
import { Log } from '../../../../types/Log';
import Logging from '../../../../utils/Logging';
+import LoggingHelper from '../../../../utils/LoggingHelper';
import LoggingStorage from '../../../../storage/mongodb/LoggingStorage';
import OCPIEndpoint from '../../../../types/ocpi/OCPIEndpoint';
import OICPEndpoint from '../../../../types/oicp/OICPEndpoint';
@@ -93,7 +94,8 @@ export default class UtilsService {
message: `ChargingStation Id '${chargingStation.id}' not issued by the organization`,
module: MODULE_NAME, method: 'checkAndGetChargingStationAuthorization',
user: userToken,
- action: action
+ action: action,
+ ...LoggingHelper.getChargingStationProperties(chargingStation)
});
}
// Deleted?
@@ -103,7 +105,8 @@ export default class UtilsService {
message: `ChargingStation with ID '${chargingStation.id}' is logically deleted`,
module: MODULE_NAME,
method: 'checkAndGetChargingStationAuthorization',
- user: userToken
+ user: userToken,
+ ...LoggingHelper.getChargingStationProperties(chargingStation)
});
}
return chargingStation;
@@ -362,7 +365,7 @@ export default class UtilsService {
action: authAction, entity: Entity.SITE,
module: MODULE_NAME, method: 'checkAndGetSiteAuthorization',
value: siteID,
- siteID: siteID,
+ ...LoggingHelper.getSiteProperties(site)
});
}
return site;
@@ -373,7 +376,8 @@ export default class UtilsService {
// Check mandatory fields failsafe, should already be done in the json schema validation for each request
UtilsService.assertIdIsProvided(action, assetID, MODULE_NAME, 'checkAndGetAssetAuthorization', userToken);
// Retrieve authorization for action
- const authorizationFilter = await AuthorizationService.checkAndGetAssetAuthorizations(tenant, userToken, authAction, { ID: assetID }, entityData);
+ const authorizationFilter = await AuthorizationService.checkAndGetAssetAuthorizations(
+ tenant, userToken, authAction, { ID: assetID }, entityData);
// In certain cases the authorization filter will pass
if (!authorizationFilter.authorized) {
throw new AppAuthError({
@@ -396,7 +400,6 @@ export default class UtilsService {
// Check object not empty
UtilsService.assertObjectExists(action, asset, `Asset ID '${assetID}' cannot be retrieved`,
MODULE_NAME, 'checkAndGetAssetAuthorization', userToken);
-
// Assign projected fields
if (authorizationFilter.projectFields) {
asset.projectFields = authorizationFilter.projectFields;
@@ -416,6 +419,7 @@ export default class UtilsService {
action: authAction, entity: Entity.ASSET,
module: MODULE_NAME, method: 'checkAndGetAssetAuthorization',
value: assetID,
+ ...LoggingHelper.getAssetProperties(asset)
});
}
return asset;
@@ -751,7 +755,7 @@ export default class UtilsService {
action: authAction, entity: Entity.SITE_AREA,
module: MODULE_NAME, method: 'checkAndGetSiteAreaAuthorization',
value: siteAreaID,
- siteAreaID: siteAreaID,
+ ...LoggingHelper.getSiteAreaProperties(siteArea)
});
}
return siteArea;

MODIFY
src/utils/LoggingHelper.ts
src/utils/LoggingHelper.ts
import Asset from '../types/Asset';
import ChargingStation from '../types/ChargingStation';
import { Log } from '../types/Log';
+import Site from '../types/Site';
+import SiteArea from '../types/SiteArea';
import Transaction from '../types/Transaction';
export default class LoggingHelper {
@@ -30,4 +32,18 @@ export default class LoggingHelper {
siteAreaID: asset.siteAreaID,
};
}
+
+ public static getSiteProperties(site: Site): { siteID: string; companyID: string; } {
+ return {
+ siteID: site.id,
+ companyID: site.companyID,
+ };
+ }
+
+ public static getSiteAreaProperties(siteArea: SiteArea): { siteID: string; siteAreaID: string; } {
+ return {
+ siteAreaID: siteArea.id,
+ siteID: siteArea.siteID,
+ };
+ }
}

Added Org IDs in logs