Skip to content

Commit

Permalink
Merge pull request #4157 from sap-labs-france/tenant-cpmsDomainName
Browse files Browse the repository at this point in the history
Tenant - CPMS - domain name per tenant
  • Loading branch information
Claude ROSSI authored Mar 27, 2023
2 parents d27f9b8 + 6f73ef8 commit b1554f3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/server/rest/v1/service/AuthorizationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/types/Tenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 6 additions & 12 deletions src/utils/Configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 14 additions & 6 deletions src/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit b1554f3

Please sign in to comment.