From 8449f924ab5c1199836b828661ac254cedd9e3af Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Sun, 26 Mar 2023 09:14:52 +0200 Subject: [PATCH 1/3] tenant - optional cpmsDomainName --- src/types/Tenant.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/Tenant.ts b/src/types/Tenant.ts index d2e2e7cfc7..b144281351 100644 --- a/src/types/Tenant.ts +++ b/src/types/Tenant.ts @@ -9,9 +9,10 @@ export default interface Tenant extends CreatedUpdatedProps { address: Address; logo: string; components: TenantComponent; + cpmsDomainName?: string; // Optional - domain name used to connect chargers redirectDomain?: string; idleMode?: boolean // Prevents batch and async tasks executions when moving the tenant to a different cloud infrastructure provider - taskExecutionEnv?: string; // Environement on which tasks should be executed + taskExecutionEnv?: string; // Environment on which tasks should be executed } export interface TenantComponent { From ca3b761f80eda8ae64585473d4ab46f294e7b384 Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Sun, 26 Mar 2023 11:10:45 +0200 Subject: [PATCH 2/3] tenant - cpms domain name --- .../rest/v1/service/AuthorizationService.ts | 6 +++--- src/utils/Utils.ts | 20 +++++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/server/rest/v1/service/AuthorizationService.ts b/src/server/rest/v1/service/AuthorizationService.ts index 5bd652ce66..662355b388 100644 --- a/src/server/rest/v1/service/AuthorizationService.ts +++ b/src/server/rest/v1/service/AuthorizationService.ts @@ -482,9 +482,9 @@ export default class AuthorizationService { // Optimize data over the net Utils.removeCanPropertiesWithFalseValue(registrationToken); // Build OCPP URLs - registrationToken.ocpp15SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant.id, OCPPVersion.VERSION_15, OCPPProtocol.SOAP, registrationToken.id); - registrationToken.ocpp16SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant.id, OCPPVersion.VERSION_16, OCPPProtocol.SOAP, registrationToken.id); - registrationToken.ocpp16JSONSecureUrl = Utils.buildOCPPServerSecureURL(tenant.id, OCPPVersion.VERSION_16, OCPPProtocol.JSON, registrationToken.id); + registrationToken.ocpp15SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant, OCPPVersion.VERSION_15, OCPPProtocol.SOAP, registrationToken.id); + registrationToken.ocpp16SOAPSecureUrl = Utils.buildOCPPServerSecureURL(tenant, OCPPVersion.VERSION_16, OCPPProtocol.SOAP, registrationToken.id); + registrationToken.ocpp16JSONSecureUrl = Utils.buildOCPPServerSecureURL(tenant, OCPPVersion.VERSION_16, OCPPProtocol.JSON, registrationToken.id); } public static async checkAndGetChargingStationTemplateAuthorizations(tenant: Tenant, userToken: UserToken, diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index b76aefa553..28e453b1f2 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -927,13 +927,21 @@ export default class Utils { return `${centralSystemFrontEndConfig.protocol}://${centralSystemFrontEndConfig.host}:${centralSystemFrontEndConfig.port}`; } - public static buildOCPPServerSecureURL(tenantID: string, ocppVersion: OCPPVersion, ocppProtocol: OCPPProtocol, token?: string): string { - switch (ocppProtocol) { - case OCPPProtocol.JSON: - return `${Configuration.getJsonEndpointConfig().baseSecureUrl}/${Utils.getOCPPServerVersionURLPath(ocppVersion)}/${tenantID}/${token}`; - case OCPPProtocol.SOAP: - return `${Configuration.getWSDLEndpointConfig().baseSecureUrl}/${Utils.getOCPPServerVersionURLPath(ocppVersion)}?TenantID=${tenantID}%26Token=${token}`; + public static buildOCPPServerSecureURL(tenant: Tenant, ocppVersion: OCPPVersion, ocppProtocol: OCPPProtocol, token?: string): string { + if (ocppProtocol === OCPPProtocol.SOAP) { + const baseSecureUrl = Utils.alterBaseURL(tenant, Configuration.getWSDLEndpointConfig().baseSecureUrl); + return `${baseSecureUrl}/${Utils.getOCPPServerVersionURLPath(ocppVersion)}?TenantID=${tenant.id}%26Token=${token}`; } + const baseSecureUrl = Utils.alterBaseURL(tenant, Configuration.getJsonEndpointConfig().baseSecureUrl); + return `${baseSecureUrl}/${Utils.getOCPPServerVersionURLPath(ocppVersion)}/${tenant.id}/${token}`; + } + + public static alterBaseURL(tenant: Tenant, baseUrl: string) : string { + if (tenant.cpmsDomainName) { + const protocol = baseUrl.split(':').shift(); + baseUrl = `${protocol}://${tenant.cpmsDomainName}`; + } + return baseUrl; } public static getOCPPServerVersionURLPath(ocppVersion: OCPPVersion): string { From 6f73ef8de7119c00b3ae21f027e07431bf1f5b8d Mon Sep 17 00:00:00 2001 From: ClaudeROSSI Date: Mon, 27 Mar 2023 08:33:24 +0200 Subject: [PATCH 3/3] config - cosmetic change --- src/utils/Configuration.ts | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 7f7bfc07b3..50927188dc 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -295,21 +295,15 @@ export default class Configuration { private static getConfig(): ConfigurationData { if (!Configuration.config) { - let configuration: ConfigurationData; + let configurationPath: string; if (process.env.SERVER_ROLE) { - configuration = JSON.parse( - fs.readFileSync(`${global.appRoot}/assets/config_` + process.env.SERVER_ROLE + '.json', 'utf8')) as ConfigurationData; + configurationPath = `${global.appRoot}/assets/config_` + process.env.SERVER_ROLE + '.json'; // Dev environment only + } else if (fs.existsSync('/config/config.json')) { + configurationPath = '/config/config.json'; // K8s Environment } else { - // K8s - if (fs.existsSync('/config/config.json')) { - configuration = JSON.parse( - fs.readFileSync('/config/config.json', 'utf8')) as ConfigurationData; - // AWS - } else { - configuration = JSON.parse( - fs.readFileSync(`${global.appRoot}/assets/config.json`, 'utf8')) as ConfigurationData; - } + configurationPath = `${global.appRoot}/assets/config.json`; // AWS ECS environment only } + const configuration = JSON.parse(fs.readFileSync(configurationPath, 'utf8')) as ConfigurationData; Configuration.config = ConfigurationValidatorStorage.getInstance().validateConfigurationSave(configuration); } return Configuration.config;