Changed getHttpsAgent due to async Cypher.decrypt
MODIFY
src/client/oicp/CpoOICPClient.ts
src/client/oicp/CpoOICPClient.ts
@@ -477,6 +477,7 @@ export default class CpoOICPClient extends OICPClient {
* Push EVSE
*/
public async pushEvseData(evses: OICPEvseDataRecord[], actionType: OICPActionType): Promise<OICPAcknowledgment> {
+ this.axiosInstance.defaults.httpsAgent = await this.getHttpsAgent(ServerAction.OICP_CREATE_AXIOS_INSTANCE);
let pushEvseDataResponse: OICPAcknowledgment;
let requestError: any;
// Check for input parameter
@@ -535,6 +536,7 @@ export default class CpoOICPClient extends OICPClient {
* Push EVSE Status
*/
public async pushEvseStatus(evseStatuses: OICPEvseStatusRecord[], actionType: OICPActionType): Promise<OICPAcknowledgment> {
+ this.axiosInstance.defaults.httpsAgent = await this.getHttpsAgent(ServerAction.OICP_CREATE_AXIOS_INSTANCE);
let pushEvseStatusResponse: OICPAcknowledgment;
let requestError: any;
// Check for input parameter
@@ -593,6 +595,7 @@ export default class CpoOICPClient extends OICPClient {
* ERoaming Authorize Start
*/
public async authorizeStart(tagID: string, transactionId?: number): Promise<OICPAuthorizeStartCpoReceive> {
+ this.axiosInstance.defaults.httpsAgent = await this.getHttpsAgent(ServerAction.OICP_CREATE_AXIOS_INSTANCE);
let authorizeResponse: OICPAuthorizeStartCpoReceive;
let requestError: any;
if (!tagID) {

MODIFY
src/client/oicp/OICPClient.ts
src/client/oicp/OICPClient.ts
@@ -40,10 +40,7 @@ export default abstract class OICPClient {
this.oicpEndpoint = oicpEndpoint;
this.role = role.toLowerCase();
this.oicpConfig = Configuration.getOICPServiceConfig();
- void (async () => {
- this.axiosConfig = await this.getAxiosConfig(ServerAction.OICP_CREATE_AXIOS_INSTANCE);
- this.axiosInstance = AxiosFactory.getAxiosInstance(tenant.id, { axiosConfig: this.axiosConfig }, true); // FIXME: set noInterceptors = true to avoid 'Converting circular structure to JSON' Error
- })();
+ this.axiosInstance = AxiosFactory.getAxiosInstance(tenant.id, { axiosConfig: this.getAxiosConfig(ServerAction.OICP_CREATE_AXIOS_INSTANCE) }, true); // FIXME: set noInterceptors = true to avoid 'Converting circular structure to JSON' Error
}
public getLocalCountryCode(action: ServerAction): string {
@@ -132,6 +129,18 @@ export default abstract class OICPClient {
});
}
+ protected async getHttpsAgent(action: ServerAction): Promise<https.Agent> {
+ const publicCert = await this.getClientCertificate(action);
+ const privateKey = await this.getPrivateKey(action);
+ const httpsAgent = new https.Agent({
+ rejectUnauthorized: false,
+ cert: publicCert,
+ key: privateKey,
+ passphrase: ''
+ });
+ return httpsAgent;
+ }
+
private async getPrivateKey(action: ServerAction): Promise<string> {
if (!this.settings[this.role]) {
throw new BackendError({
@@ -164,26 +173,14 @@ export default abstract class OICPClient {
return await Cypher.decrypt(this.tenant.id, this.settings[this.role].cert);
}
- private async getAxiosConfig(action: ServerAction): Promise<AxiosRequestConfig> {
+ private getAxiosConfig(action: ServerAction): AxiosRequestConfig {
const axiosConfig: AxiosRequestConfig = {} as AxiosRequestConfig;
- axiosConfig.httpsAgent = await this.getHttpsAgent(action);
+ // AxiosConfig.httpsAgent = await this.getHttpsAgent(action);
axiosConfig.headers = {
'Content-Type': 'application/json'
};
return axiosConfig;
}
- private async getHttpsAgent(action: ServerAction): Promise<https.Agent> {
- const publicCert = await this.getClientCertificate(action);
- const privateKey = await this.getPrivateKey(action);
- const httpsAgent = new https.Agent({
- rejectUnauthorized: false,
- cert: publicCert,
- key: privateKey,
- passphrase: ''
- });
- return httpsAgent;
- }
-
public abstract ping();
}

Changed getHttpsAgent due to async Cypher.decrypt