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/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 { 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; 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 {