From: Jérôme Benoit Date: Sun, 26 Mar 2023 14:41:19 +0000 (+0200) Subject: refactor: rename a template key to a more sensible name X-Git-Tag: v1.2.0-0~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e302df1d4573ef07df7c44a210a34e429f571814;p=e-mobility-charging-stations-simulator.git refactor: rename a template key to a more sensible name Signed-off-by: Jérôme Benoit --- diff --git a/.cfignore b/.cfignore index 4b19c682..30ad46d7 100644 --- a/.cfignore +++ b/.cfignore @@ -47,7 +47,7 @@ *_REMOTE_*.txt *.md *.db -*tags-template.* +*idtags-template.* *config-template.* *cf-template.* manifest-*.yml diff --git a/.gitignore b/.gitignore index 47cb73ef..5bf56abf 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,8 @@ src/assets/config*.json !src/assets/config-template.json src/scripts/scriptConfig.json -src/assets/*tags*.json -!src/assets/authorization-tags-template.json +src/assets/*idtags*.json +!src/assets/idtags-template.json mikro-orm.config*.ts !mikro-orm.config-template.ts manifest*.yml diff --git a/README.md b/README.md index 8ce209e5..969b8ef4 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ pnpm install ## Initial configuration Copy the configuration template file [src/assets/config-template.json](src/assets/config-template.json) to [src/assets/config.json](src/assets/config.json). -Copy the authorization RFID tags template file [src/assets/authorization-tags-template.json](src/assets/authorization-tags-template.json) to [src/assets/authorization-tags.json](src/assets/authorization-tags.json). +Copy the RFID tags template file [src/assets/idtags-template.json](src/assets/idtags-template.json) to [src/assets/idtags.json](src/assets/idtags.json). Tweak them to your needs by following the section [configuration files syntax](README.md#configuration-files-syntax). @@ -76,7 +76,7 @@ The charging stations simulator's configuration parameters must be within the `s All charging station configuration templates are in the directory [src/assets/station-templates](src/assets/station-templates). -A list of RFID tags must be defined for the automatic transaction generator with a default location and name: `src/assets/authorization-tags.json`. A template file is available at [src/assets/authorization-tags-template.json](src/assets/authorization-tags-template.json). +A list of RFID tags must be defined for the automatic transaction generator in a file with a default location and name: `src/assets/idtags.json`. A template file is available at [src/assets/idtags-template.json](src/assets/idtags-template.json). **Configuration files hierarchy and priority**: @@ -142,7 +142,7 @@ But the modifications to test have to be done to the files in the build target d | ocppPersistentConfiguration | true/false | true | boolean | enable persistent OCPP parameters storage by charging stations 'hashId'. The persistency is ensured by the charging stations configuration files in [dist/assets/configurations](dist/assets/configurations) | | stationInfoPersistentConfiguration | true/false | true | boolean | enable persistent station information and specifications storage by charging stations 'hashId'. The persistency is ensured by the charging stations configuration files in [dist/assets/configurations](dist/assets/configurations) | | wsOptions | | {} | ClientOptions & ClientRequestArgs | [ws](https://github.com/websockets/ws) and node.js [http](https://nodejs.org/api/http.html) clients options intersection | -| authorizationFile | | undefined | string | RFID tags list file relative to src/assets path | +| idTagsFile | | undefined | string | RFID tags list file relative to src/assets path | | baseName | | undefined | string | base name to build charging stations id | | nameSuffix | | undefined | string | name suffix to build charging stations id | | fixedName | true/false | false | boolean | use the baseName as the charging stations unique name | diff --git a/docker/Dockerfile b/docker/Dockerfile index 5177c03a..58885688 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -5,7 +5,7 @@ WORKDIR /usr/builder COPY .npmrc package.json pnpm-lock.yaml tsconfig.json rollup.config.mjs build-requirements.mjs skip-preinstall.cjs prepare.cjs ./ COPY src ./src COPY docker/config.json ./src/assets/config.json -COPY docker/authorization-tags.json ./src/assets/authorization-tags.json +COPY docker/idtags.json ./src/assets/idtags.json RUN set -ex \ && apk add --no-cache --virtual .gyp build-base python3 \ && corepack enable \ diff --git a/docker/autoconfig.sh b/docker/autoconfig.sh index 7b35536c..11815905 100755 --- a/docker/autoconfig.sh +++ b/docker/autoconfig.sh @@ -8,7 +8,7 @@ then [ -z $emobility_service_type ] && { echo "emobility env service type variable not found, exiting"; exit 1; } cp $emobility_install_dir/dist/assets/configs-aws/$emobility_server_type-$emobility_service_type-$emobility_landscape.json $emobility_install_dir/dist/assets/config.json - cp $emobility_install_dir/dist/assets/configs-aws/$emobility_server_type-$emobility_service_type-$emobility_landscape-tags.json $emobility_install_dir/dist/assets/authorization-tags.json + cp $emobility_install_dir/dist/assets/configs-aws/$emobility_server_type-$emobility_service_type-$emobility_landscape-idtags.json $emobility_install_dir/dist/assets/idtags.json else echo "no emobility env defined, start with default configuration" fi diff --git a/docker/authorization-tags.json b/docker/idtags.json similarity index 100% rename from docker/authorization-tags.json rename to docker/idtags.json diff --git a/src/assets/authorization-tags-template.json b/src/assets/idtags-template.json similarity index 100% rename from src/assets/authorization-tags-template.json rename to src/assets/idtags-template.json diff --git a/src/assets/station-templates/abb-atg.station-template.json b/src/assets/station-templates/abb-atg.station-template.json index cda5806e..9414a19e 100644 --- a/src/assets/station-templates/abb-atg.station-template.json +++ b/src/assets/station-templates/abb-atg.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-ABB", "chargePointModel": "MD_TERRA_53", "chargePointVendor": "ABB", diff --git a/src/assets/station-templates/abb.station-template.json b/src/assets/station-templates/abb.station-template.json index 2aef581a..0c6b233a 100644 --- a/src/assets/station-templates/abb.station-template.json +++ b/src/assets/station-templates/abb.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-ABB", "chargePointModel": "MD_TERRA_53", "chargePointVendor": "ABB", diff --git a/src/assets/station-templates/chargex.station-template.json b/src/assets/station-templates/chargex.station-template.json index 3f4a6be1..6ff7562d 100644 --- a/src/assets/station-templates/chargex.station-template.json +++ b/src/assets/station-templates/chargex.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-CHARGEX", "chargePointModel": "Aqueduct 1.0", "chargePointVendor": "ChargeX GmbH", diff --git a/src/assets/station-templates/evlink.station-template.json b/src/assets/station-templates/evlink.station-template.json index 307db670..fda88bfb 100644 --- a/src/assets/station-templates/evlink.station-template.json +++ b/src/assets/station-templates/evlink.station-template.json @@ -1,7 +1,7 @@ { "supervisionUrlOcppConfiguration": true, "supervisionUrlOcppKey": "ocppcentraladdress", - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-EVLINK", "chargePointModel": "MONOBLOCK", "chargePointVendor": "Schneider Electric", diff --git a/src/assets/station-templates/keba.station-template.json b/src/assets/station-templates/keba.station-template.json index a76741d9..f91c22e9 100644 --- a/src/assets/station-templates/keba.station-template.json +++ b/src/assets/station-templates/keba.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-KEBA", "chargePointModel": "KC-P30-ESS400C2-E0R", "chargePointVendor": "Keba AG", diff --git a/src/assets/station-templates/schneider-imredd.station-template.json b/src/assets/station-templates/schneider-imredd.station-template.json index 18c6ea47..0369d0ac 100644 --- a/src/assets/station-templates/schneider-imredd.station-template.json +++ b/src/assets/station-templates/schneider-imredd.station-template.json @@ -1,7 +1,7 @@ { "supervisionUrlOcppConfiguration": true, "supervisionUrlOcppKey": "ocppcentraladdress", - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-SCHNEIDER", "chargePointModel": "MONOBLOCK", "chargePointVendor": "Schneider Electric", diff --git a/src/assets/station-templates/schneider.station-template.json b/src/assets/station-templates/schneider.station-template.json index 65f7f304..4dd71473 100644 --- a/src/assets/station-templates/schneider.station-template.json +++ b/src/assets/station-templates/schneider.station-template.json @@ -1,7 +1,7 @@ { "supervisionUrlOcppConfiguration": true, "supervisionUrlOcppKey": "ocppcentraladdress", - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-SCHNEIDER", "chargePointModel": "MONOBLOCK", "chargePointVendor": "Schneider Electric", diff --git a/src/assets/station-templates/siemens.station-template.json b/src/assets/station-templates/siemens.station-template.json index 74341ca5..aca529ac 100644 --- a/src/assets/station-templates/siemens.station-template.json +++ b/src/assets/station-templates/siemens.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-SIEMENS", "fixedName": true, "chargePointModel": "SIEMENSXX213", diff --git a/src/assets/station-templates/virtual-simple-atg.station-template.json b/src/assets/station-templates/virtual-simple-atg.station-template.json index 666be37b..0dbd6782 100644 --- a/src/assets/station-templates/virtual-simple-atg.station-template.json +++ b/src/assets/station-templates/virtual-simple-atg.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-BASIC", "chargePointModel": "Simulator simple", "chargePointVendor": "Ovomaltin", diff --git a/src/assets/station-templates/virtual-simple.station-template.json b/src/assets/station-templates/virtual-simple.station-template.json index ccec3ee5..d94b5d39 100644 --- a/src/assets/station-templates/virtual-simple.station-template.json +++ b/src/assets/station-templates/virtual-simple.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-BASIC", "chargePointModel": "Simulator simple", "chargePointVendor": "Ovomaltin", diff --git a/src/assets/station-templates/virtual.station-template.json b/src/assets/station-templates/virtual.station-template.json index 1ecf8875..3980cba6 100644 --- a/src/assets/station-templates/virtual.station-template.json +++ b/src/assets/station-templates/virtual.station-template.json @@ -1,5 +1,5 @@ { - "authorizationFile": "authorization-tags.json", + "idTagsFile": "idtags.json", "baseName": "CS-SIMU", "chargePointModel": "Simulator connectors", "chargePointVendor": "Ovomaltin", diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index cc717711..831c662e 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -164,16 +164,16 @@ export class ChargingStation { public logPrefix = (): string => { return Utils.logPrefix( ` ${ - (Utils.isNotEmptyString(this?.stationInfo?.chargingStationId) && - this?.stationInfo?.chargingStationId) ?? - ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile()) ?? - '' + (Utils.isNotEmptyString(this?.stationInfo?.chargingStationId) + ? this?.stationInfo?.chargingStationId + : ChargingStationUtils.getChargingStationId(this.index, this.getTemplateFromFile())) ?? + 'Error at building log prefix' } |` ); }; public hasIdTags(): boolean { - const idTagsFile = ChargingStationUtils.getAuthorizationFile(this.stationInfo); + const idTagsFile = ChargingStationUtils.getIdTagsFile(this.stationInfo); return Utils.isNotEmptyArray(this.idTagsCache.getIdTags(idTagsFile)); } @@ -879,6 +879,18 @@ export class ChargingStation { 'supervisionUrl', 'supervisionUrls' ); + ChargingStationUtils.warnDeprecatedTemplateKey( + stationTemplate, + 'authorizationFile', + this.templateFile, + this.logPrefix(), + "Use 'idTagsFile' instead" + ); + ChargingStationUtils.convertDeprecatedTemplateKey( + stationTemplate, + 'authorizationFile', + 'idTagsFile' + ); const stationInfo: ChargingStationInfo = ChargingStationUtils.stationTemplateToStationInfo(stationTemplate); stationInfo.hashId = ChargingStationUtils.getHashId(this.index, stationTemplate); diff --git a/src/charging-station/ChargingStationUtils.ts b/src/charging-station/ChargingStationUtils.ts index ca9a93bc..bca8c088 100644 --- a/src/charging-station/ChargingStationUtils.ts +++ b/src/charging-station/ChargingStationUtils.ts @@ -2,6 +2,7 @@ import crypto from 'node:crypto'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; +import chalk from 'chalk'; import moment from 'moment'; import type { ChargingStation } from './internal'; @@ -219,11 +220,11 @@ export class ChargingStationUtils { logMsgToAppend = '' ): void { if (!Utils.isUndefined(template[key])) { - logger.warn( - `${logPrefix} Deprecated template key '${key}' usage in file '${templateFile}'${ - Utils.isNotEmptyString(logMsgToAppend) && `. ${logMsgToAppend}` - }` - ); + const logMsg = `Deprecated template key '${key}' usage in file '${templateFile}'${ + Utils.isNotEmptyString(logMsgToAppend) ? `. ${logMsgToAppend}` : '' + }`; + logger.warn(`${logPrefix} ${logMsg}`); + console.warn(chalk.yellow(`${logMsg}`)); } } @@ -413,13 +414,13 @@ export class ChargingStationUtils { return defaultVoltageOut; } - public static getAuthorizationFile(stationInfo: ChargingStationInfo): string | undefined { + public static getIdTagsFile(stationInfo: ChargingStationInfo): string | undefined { return ( - stationInfo.authorizationFile && + stationInfo.idTagsFile && path.join( path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../'), 'assets', - path.basename(stationInfo.authorizationFile) + path.basename(stationInfo.idTagsFile) ) ); } diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index 7b49b590..48ecb552 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -32,7 +32,7 @@ export class IdTagsCache { connectorId: number ): string { const hashId = chargingStation.stationInfo.hashId; - const idTagsFile = ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo); + const idTagsFile = ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo); switch (distribution) { case IdTagDistribution.RANDOM: return this.getRandomIdTag(hashId, idTagsFile); @@ -79,7 +79,7 @@ export class IdTagsCache { } private getConnectorAffinityIdTag(chargingStation: ChargingStation, connectorId: number): string { - const file = ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo); + const file = ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo); const idTags = this.getIdTags(file); const hashId = chargingStation.stationInfo.hashId; const addressableKey = file + hashId; diff --git a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts index 12a64b6c..cad78436 100644 --- a/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts +++ b/src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts @@ -742,7 +742,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService { chargingStation.hasIdTags() === true && Utils.isNotEmptyString( chargingStation.idTagsCache - .getIdTags(ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo)) + .getIdTags(ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo)) ?.find((idTag) => idTag === commandPayload.idTag) ) ) { diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 32402da5..2d15ce5d 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -91,7 +91,7 @@ export abstract class OCPPIncomingRequestService extends AsyncResource { protected handleRequestClearCache(chargingStation: ChargingStation): ClearCacheResponse { chargingStation.idTagsCache.deleteIdTags( - ChargingStationUtils.getAuthorizationFile(chargingStation.stationInfo) + ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo) ); return OCPPConstants.OCPP_RESPONSE_ACCEPTED; } diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 0cd0e45f..8060a937 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -67,8 +67,7 @@ export type ChargingStationTemplate = { ocppPersistentConfiguration?: boolean; stationInfoPersistentConfiguration?: boolean; wsOptions?: WsOptions; - // FIXME: rename to idTagFile - authorizationFile?: string; + idTagsFile?: string; baseName: string; nameSuffix?: string; fixedName?: boolean; diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 7d5b217d..8c3d15cc 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -322,13 +322,13 @@ export class Configuration { ) { console.error( chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage in section '${sectionName}'${ - logMsgToAppend.trim().length > 0 && `. ${logMsgToAppend}` + logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : '' }}` ); } else if (!Utils.isUndefined(Configuration.getConfig()[key])) { console.error( chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration key '${key}' usage${ - logMsgToAppend.trim().length > 0 && `. ${logMsgToAppend}` + logMsgToAppend.trim().length > 0 ? `. ${logMsgToAppend}` : '' }}` ); } diff --git a/ui/web/src/types/ChargingStationType.ts b/ui/web/src/types/ChargingStationType.ts index 24468392..9d2b530a 100644 --- a/ui/web/src/types/ChargingStationType.ts +++ b/ui/web/src/types/ChargingStationType.ts @@ -39,7 +39,7 @@ export type ChargingStationInfo = { ocppStrictCompliance?: boolean; ocppPersistentConfiguration?: boolean; stationInfoPersistentConfiguration?: boolean; - authorizationFile?: string; + idTagsFile?: string; nameSuffix?: string; fixedName?: boolean; iccid?: string;