Fixed OCPI local token cannot be generated
DELETE
src/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-local-token-generate.json
-{
- "title": "Generate OCPI Endpoint local token Request",
- "description": "",
- "type": "object",
- "properties": {
- "id": {
- "$ref": "ocpi-endpoint.json#/definitions/id"
- },
- "name": {
- "$ref": "ocpi-endpoint.json#/definitions/name"
- }
- },
- "required": [
- "id",
- "name"
- ]
-}

MODIFY
src/server/rest/v1/service/OCPIEndpointService.ts
src/server/rest/v1/service/OCPIEndpointService.ts
@@ -308,9 +308,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handlePullSessionsEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the lock
- const pullSessionsLock = await LockingHelper.createOCPIPullSessionsLock(tenant.id, ocpiEndpoint);
+ const pullSessionsLock = await LockingHelper.createOCPIPullSessionsLock(req.tenant.id, ocpiEndpoint);
if (!pullSessionsLock) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -360,9 +359,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handlePullTokensEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the lock
- const pullTokensLock = await LockingHelper.createOCPIPullTokensLock(tenant.id, ocpiEndpoint, false);
+ const pullTokensLock = await LockingHelper.createOCPIPullTokensLock(req.tenant.id, ocpiEndpoint, false);
if (!pullTokensLock) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -412,9 +410,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handlePullCdrsEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the lock
- const pullCdrsLock = await LockingHelper.createOCPIPullCdrsLock(tenant.id, ocpiEndpoint);
+ const pullCdrsLock = await LockingHelper.createOCPIPullCdrsLock(req.tenant.id, ocpiEndpoint);
if (!pullCdrsLock) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -464,9 +461,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleCheckCdrsEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the lock
- const checkCdrsLock = await LockingHelper.createOCPICheckCdrsLock(tenant.id, ocpiEndpoint);
+ const checkCdrsLock = await LockingHelper.createOCPICheckCdrsLock(req.tenant.id, ocpiEndpoint);
if (!checkCdrsLock) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -516,9 +512,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleCheckSessionsEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the lock
- const checkSessionsLock = await LockingHelper.createOCPICheckSessionsLock(tenant.id, ocpiEndpoint);
+ const checkSessionsLock = await LockingHelper.createOCPICheckSessionsLock(req.tenant.id, ocpiEndpoint);
if (!checkSessionsLock) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -568,9 +563,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleCheckLocationsEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the lock
- const checkLocationsLock = await LockingHelper.createOCPICheckLocationsLock(tenant.id, ocpiEndpoint);
+ const checkLocationsLock = await LockingHelper.createOCPICheckLocationsLock(req.tenant.id, ocpiEndpoint);
if (!checkLocationsLock) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -620,9 +614,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handlePushEVSEStatusesOcpiEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Get the lock
- const patchStatusesLock = await LockingHelper.createOCPIPatchEVSEStatusesLock(tenant.id, ocpiEndpoint);
+ const patchStatusesLock = await LockingHelper.createOCPIPatchEVSEStatusesLock(req.tenant.id, ocpiEndpoint);
if (!patchStatusesLock) {
throw new AppError({
source: Constants.CENTRAL_SERVER,
@@ -724,9 +717,8 @@ export default class OCPIEndpointService {
const ocpiEndpoint = await OCPIEndpointStorage.getOcpiEndpoint(req.tenant, filteredRequest.id);
UtilsService.assertObjectExists(action, ocpiEndpoint, `OCPI Endpoint ID '${filteredRequest.id}' does not exist`,
MODULE_NAME, 'handleUnregisterOcpiEndpoint', req.user);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
// Build OCPI Client
- const ocpiClient = await OCPIClientFactory.getOcpiClient(tenant, ocpiEndpoint);
+ const ocpiClient = await OCPIClientFactory.getOcpiClient(req.tenant, ocpiEndpoint);
// Try to register
const result = await ocpiClient.unregister();
// Check ping result
@@ -829,19 +821,16 @@ export default class OCPIEndpointService {
module: MODULE_NAME, method: 'handleGenerateLocalTokenOcpiEndpoint'
});
}
- // Filter
- const filteredRequest = OCPIEndpointValidator.getInstance().validateOCPIEndpointLocalTokenGenerateGetReq(req.body);
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
- const localToken = OCPIUtils.generateLocalToken(tenant.subdomain);
+ // Generate endpoint
+ const localToken = OCPIUtils.generateLocalToken(req.tenant.subdomain);
await Logging.logSecurityInfo({
tenantID: req.user.tenantID,
user: req.user, module: MODULE_NAME, method: 'handleGenerateLocalTokenOcpiEndpoint',
- message: `Local Token for Ocpi Endpoint '${filteredRequest.name}' has been generated successfully`,
+ message: 'Local Token for Ocpi Endpoint has been generated successfully',
action,
- detailedMessages: { token: filteredRequest }
+ detailedMessages: { token: localToken }
});
res.json(Object.assign({
- id: filteredRequest.id,
localToken: localToken
}, Constants.REST_RESPONSE_SUCCESS));
next();

MODIFY
src/server/rest/v1/service/TransactionService.ts
src/server/rest/v1/service/TransactionService.ts
@@ -66,11 +66,8 @@ export default class TransactionService {
module: MODULE_NAME, method: 'handleSynchronizeRefundedTransactions'
});
}
-
- const tenant = await TenantStorage.getTenant(req.user.tenantID);
const task = new SynchronizeRefundTransactionsTask();
- await task.processTenant(tenant, null);
-
+ await task.processTenant(req.tenant, null);
const response: any = {
...Constants.REST_RESPONSE_SUCCESS,
};
@@ -1002,7 +999,7 @@ export default class TransactionService {
const billingImpl = await BillingFactory.getBillingImpl(tenant);
for (const transactionID of transactionsIDs) {
// Get
- const transaction = await TransactionStorage.getTransaction(await TenantStorage.getTenant(loggedUser.tenantID), transactionID);
+ const transaction = await TransactionStorage.getTransaction(tenant, transactionID);
// Not Found
if (!transaction) {
result.inError++;
@@ -1045,7 +1042,7 @@ export default class TransactionService {
const foundConnector = Utils.getConnectorFromID(transaction.chargeBox, transaction.connectorId);
if (foundConnector && transaction.id === foundConnector.currentTransactionID) {
OCPPUtils.clearChargingStationConnectorRuntimeData(transaction.chargeBox, transaction.connectorId);
- await ChargingStationStorage.saveChargingStationConnectors(await TenantStorage.getTenant(loggedUser.tenantID),
+ await ChargingStationStorage.saveChargingStationConnectors(tenant,
transaction.chargeBox.id, transaction.chargeBox.connectors);
}
// To Delete
@@ -1057,7 +1054,7 @@ export default class TransactionService {
}
}
// Delete All Transactions
- result.inSuccess = await TransactionStorage.deleteTransactions(await TenantStorage.getTenant(loggedUser.tenantID), transactionsIDsToDelete);
+ result.inSuccess = await TransactionStorage.deleteTransactions(tenant, transactionsIDsToDelete);
// Log
await Logging.logActionsResponse(loggedUser.tenantID,
ServerAction.TRANSACTIONS_DELETE,

MODIFY
src/server/rest/v1/validator/OCPIEndpointValidator.ts
src/server/rest/v1/validator/OCPIEndpointValidator.ts
-import { HttpOCPIEndpointByIdRequest, HttpOCPIEndpointGenerateLocalTokenRequest, HttpOCPIEndpointRequest, HttpOCPIEndpointsRequest } from '../../../../types/requests/HttpOCPIEndpointRequest';
+import { HttpOCPIEndpointByIdRequest, HttpOCPIEndpointRequest, HttpOCPIEndpointsRequest } from '../../../../types/requests/HttpOCPIEndpointRequest';
import OCPIEndpoint from '../../../../types/ocpi/OCPIEndpoint';
import Schema from '../../../../types/validator/Schema';
@@ -11,7 +11,6 @@ export default class OCPIEndpointValidator extends SchemaValidator {
private ocpiEndpointCreate: Schema;
private ocpiEndpointPing: Schema;
private ocpiEndpointById: Schema;
- private ocpiEndpointLocalTokenGenerate: Schema;
private ocpiEndpointGet: Schema;
private ocpiEndpointsGet: Schema;
private ocpiEndpointUpdate: Schema;
@@ -22,7 +21,6 @@ export default class OCPIEndpointValidator extends SchemaValidator {
this.ocpiEndpointCreate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-create.json`, 'utf8'));
this.ocpiEndpointPing = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-ping.json`, 'utf8'));
this.ocpiEndpointById = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-by-id.json`, 'utf8'));
- this.ocpiEndpointLocalTokenGenerate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-local-token-generate.json`, 'utf8'));
this.ocpiEndpointGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-get.json`, 'utf8'));
this.ocpiEndpointsGet = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoints-get.json`, 'utf8'));
this.ocpiEndpointUpdate = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/ocpi/ocpi-endpoint-update.json`, 'utf8'));
@@ -47,10 +45,6 @@ export default class OCPIEndpointValidator extends SchemaValidator {
return this.validate('validateOCPIEndpointByIdReq', this.ocpiEndpointById, data);
}
- public validateOCPIEndpointLocalTokenGenerateGetReq(data: unknown): HttpOCPIEndpointGenerateLocalTokenRequest {
- return this.validate('validateOCPIEndpointLocalTokenGenerateGetReq', this.ocpiEndpointLocalTokenGenerate, data);
- }
-
public validateOCPIEndpointGetReq(data: unknown): HttpOCPIEndpointRequest {
return this.validate('validateOCPIEndpointGetReq', this.ocpiEndpointGet, data);
}

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -585,7 +585,7 @@ export enum ServerRoute {
REST_OCPI_ENDPOINT_PULL_TOKENS = 'ocpi/endpoints/:id/tokens/pull',
REST_OCPI_ENDPOINT_SEND_EVSE_STATUSES = 'ocpi/endpoints/:id/evses/statuses/send',
REST_OCPI_ENDPOINT_SEND_TOKENS = 'ocpi/endpoints/:id/tokens/send',
- REST_OCPI_ENDPOINT_GENERATE_LOCAL_TOKEN = 'ocpi/endpoints/:id/tokens/generate',
+ REST_OCPI_ENDPOINT_GENERATE_LOCAL_TOKEN = 'ocpi/endpoints/tokens/generate',
REST_OCPI_ENDPOINTS = 'ocpi/endpoints',
REST_OCPI_ENDPOINT = 'ocpi/endpoints/:id',
REST_OCPI_ENDPOINT_REGISTER = 'ocpi/endpoints/:id/register',

MODIFY
src/types/requests/HttpOCPIEndpointRequest.ts
src/types/requests/HttpOCPIEndpointRequest.ts
@@ -10,10 +10,6 @@ export interface HttpOCPIEndpointByIdRequest {
id: string;
}
-export interface HttpOCPIEndpointGenerateLocalTokenRequest extends HttpOCPIEndpointByIdRequest {
- name: string;
-}
-
export interface HttpOCPIEndpointRequest extends HttpByIDRequest {
ID: string;
}

Fixed OCPI local token cannot be generated