From 15042c5fdee2d617c1d533699334cbf044f1a97e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 20 Aug 2021 08:36:11 +0200 Subject: [PATCH] Add charging station template fields for HTTP basic authentication MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- README.md | 2 ++ package-lock.json | 47 +++++++++++++++---------- package.json | 8 ++--- src/charging-station/ChargingStation.ts | 10 ++++-- src/types/ChargingStationTemplate.ts | 2 ++ 5 files changed, 43 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index d3a59792..8e2c6312 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ stationTemplateURLs | | {}[] | { file: string; numberOfStations: number; }[] | a Key | Value(s) | Default Value | Value type | Description --- | -------| --------------| ---------- | ------------ supervisionURL | | '' | string | connection URI to OCPP-J server +supervisionUser | | '' | string | basic HTTP authentication user to OCPP-J server +supervisionPassword | | '' | string | basic HTTP authentication password to OCPP-J server ocppVersion | 1.6 | 1.6 | string | OCPP version ocppProtocol | json | json | string | OCPP protocol authorizationFile | | '' | string | RFID tags list file relative to src/assets path diff --git a/package-lock.json b/package-lock.json index c26c6076..3e8a654b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1834,9 +1834,9 @@ } }, "@types/node": { - "version": "14.17.9", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.9.tgz", - "integrity": "sha512-CMjgRNsks27IDwI785YMY0KLt3co/c0cQ5foxHYv/shC2w8oOnVwz5Ubq1QG5KzrcW+AXk6gzdnxIkDnTvzu3g==" + "version": "14.17.10", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.10.tgz", + "integrity": "sha512-09x2d6kNBwjHgyh3jOUE2GE4DFoxDriDvWdu6mFhMP1ysynGYazt4ecZmJlL6/fe4Zi2vtYvTvtL7epjQQrBhA==" }, "@types/offscreencanvas": { "version": "2019.3.0", @@ -5769,9 +5769,9 @@ } }, "eslint-import-resolver-node": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.5.tgz", - "integrity": "sha512-XMoPKjSpXbkeJ7ZZ9icLnJMTY5Mc1kZbCakHquaFsXPpyWOwK0TK6CODO+0ca54UoM9LKOxyUNnoVZRl8TeaAg==", + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz", + "integrity": "sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw==", "dev": true, "requires": { "debug": "^3.2.7", @@ -5883,26 +5883,26 @@ } }, "eslint-plugin-import": { - "version": "2.24.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.24.0.tgz", - "integrity": "sha512-Kc6xqT9hiYi2cgybOc0I2vC9OgAYga5o/rAFinam/yF/t5uBqxQbauNPMC6fgb640T/89P0gFoO27FOilJ/Cqg==", + "version": "2.24.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.24.1.tgz", + "integrity": "sha512-KSFWhNxPH8OGJwpRJJs+Z7I0a13E2iFQZJIvSnCu6KUs4qmgAm3xN9GYBCSoiGWmwA7gERZPXqYQjcoCROnYhQ==", "dev": true, "requires": { "array-includes": "^3.1.3", "array.prototype.flat": "^1.2.4", "debug": "^2.6.9", "doctrine": "^2.1.0", - "eslint-import-resolver-node": "^0.3.5", + "eslint-import-resolver-node": "^0.3.6", "eslint-module-utils": "^2.6.2", "find-up": "^2.0.0", "has": "^1.0.3", - "is-core-module": "^2.4.0", + "is-core-module": "^2.6.0", "minimatch": "^3.0.4", - "object.values": "^1.1.3", + "object.values": "^1.1.4", "pkg-up": "^2.0.0", "read-pkg-up": "^3.0.0", "resolve": "^1.20.0", - "tsconfig-paths": "^3.9.0" + "tsconfig-paths": "^3.10.1" }, "dependencies": { "debug": { @@ -5932,6 +5932,15 @@ "locate-path": "^2.0.0" } }, + "is-core-module": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.6.0.tgz", + "integrity": "sha512-wShG8vs60jKfPWpF2KZRaAtvt3a20OAn7+IJ6hLPECpSABLcKtFKTTI4ZtH5QcBruBHlq+WsdHWyz0BCZW7svQ==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, "load-json-file": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-4.0.0.tgz", @@ -14525,9 +14534,9 @@ "dev": true }, "tar": { - "version": "6.1.8", - "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.8.tgz", - "integrity": "sha512-sb9b0cp855NbkMJcskdSYA7b11Q8JsX4qe4pyUAfHp+Y6jBjJeek2ZVlwEfWayshEIwlIzXx0Fain3QG9JPm2A==", + "version": "6.1.10", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.10.tgz", + "integrity": "sha512-kvvfiVvjGMxeUNB6MyYv5z7vhfFRwbwCXJAeL0/lnbrttBVqcMOnpHUf0X42LrPMR8mMpgapkJMchFH4FSHzNA==", "requires": { "chownr": "^2.0.0", "fs-minipass": "^2.0.0", @@ -14803,9 +14812,9 @@ "integrity": "sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw==" }, "ts-node": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.2.0.tgz", - "integrity": "sha512-FstYHtQz6isj8rBtYMN4bZdnXN1vq4HCbqn9vdNQcInRqtB86PePJQIxE6es0PhxKWhj2PHuwbG40H+bxkZPmg==", + "version": "10.2.1", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.2.1.tgz", + "integrity": "sha512-hCnyOyuGmD5wHleOQX6NIjJtYVIO8bPP8F2acWkB4W06wdlkgyvJtubO/I9NkI88hCFECbsEgoLc0VNkYmcSfw==", "dev": true, "requires": { "@cspotcode/source-map-support": "0.6.1", diff --git a/package.json b/package.json index 3ea01b99..e1bd82db 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "mongodb": "^4.1.0", "poolifier": "^2.0.2", "source-map-support": "^0.5.19", - "tar": "^6.1.8", + "tar": "^6.1.10", "tslib": "^2.3.1", "uuid": "^8.3.2", "winston": "^3.3.3", @@ -84,7 +84,7 @@ "@rollup/plugin-json": "^4.1.0", "@types/mocha": "^9.0.0", "@types/mochawesome": "^6.2.1", - "@types/node": "^14.17.9", + "@types/node": "^14.17.10", "@types/tar": "^4.0.5", "@types/uuid": "^8.3.1", "@types/ws": "^7.4.7", @@ -94,7 +94,7 @@ "clinic": "^9.0.0", "cross-env": "^7.0.3", "eslint": "^7.32.0", - "eslint-plugin-import": "^2.24.0", + "eslint-plugin-import": "^2.24.1", "eslint-plugin-jsdoc": "^36.0.7", "eslint-plugin-node": "^11.1.0", "expect": "^27.0.6", @@ -112,7 +112,7 @@ "rollup-plugin-istanbul": "^3.0.0", "rollup-plugin-terser": "^7.0.2", "rollup-plugin-typescript2": "^0.30.0", - "ts-node": "^10.2.0", + "ts-node": "^10.2.1", "typescript": "^4.3.5" } } diff --git a/src/charging-station/ChargingStation.ts b/src/charging-station/ChargingStation.ts index e9420089..de675622 100644 --- a/src/charging-station/ChargingStation.ts +++ b/src/charging-station/ChargingStation.ts @@ -5,12 +5,13 @@ import { ConnectorPhaseRotation, StandardParametersKey, SupportedFeatureProfiles import Connectors, { Connector, SampledValueTemplate } from '../types/Connectors'; import { MeterValueMeasurand, MeterValuePhase } from '../types/ocpp/MeterValues'; import Requests, { AvailabilityType, BootNotificationRequest, IncomingRequest, IncomingRequestCommand } from '../types/ocpp/Requests'; -import WebSocket, { MessageEvent } from 'ws'; +import WebSocket, { ClientOptions, MessageEvent } from 'ws'; import AutomaticTransactionGenerator from './AutomaticTransactionGenerator'; import { ChargePointStatus } from '../types/ocpp/ChargePointStatus'; import { ChargingProfile } from '../types/ocpp/ChargingProfile'; import ChargingStationInfo from '../types/ChargingStationInfo'; +import { ClientRequestArgs } from 'http'; import Configuration from '../utils/Configuration'; import Constants from '../utils/Constants'; import FileUtils from '../utils/FileUtils'; @@ -938,9 +939,12 @@ export default class ChargingStation { } } - private openWSConnection(options?: WebSocket.ClientOptions, forceCloseOpened = false): void { - options ?? {} as WebSocket.ClientOptions; + private openWSConnection(options?: ClientOptions & ClientRequestArgs, forceCloseOpened = false): void { + options ?? {}; options?.handshakeTimeout ?? this.getConnectionTimeout() * 1000; + if (!Utils.isNullOrUndefined(this.stationInfo.supervisionUser) && !Utils.isNullOrUndefined(this.stationInfo.supervisionPassword)) { + options.auth = `${this.stationInfo.supervisionUser}:${this.stationInfo.supervisionPassword}`; + } if (this.isWebSocketOpen() && forceCloseOpened) { this.wsConnection.close(); } diff --git a/src/types/ChargingStationTemplate.ts b/src/types/ChargingStationTemplate.ts index 0136ab32..5b91d0d2 100644 --- a/src/types/ChargingStationTemplate.ts +++ b/src/types/ChargingStationTemplate.ts @@ -34,6 +34,8 @@ export interface AutomaticTransactionGenerator { export default interface ChargingStationTemplate { supervisionURL?: string; + supervisionUser?: string; + supervisionPassword?: string; ocppVersion?: OCPPVersion; ocppProtocol?: OCPPProtocol; authorizationFile?: string; -- 2.34.1