Add get settings by identifier REST endpoint
MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -183,6 +183,7 @@ class RequestMapper {
[ServerAction.TRANSACTION_CONSUMPTION]: TransactionService.handleGetTransactionConsumption.bind(this),
[ServerAction.CHARGING_STATIONS_OCPP_PARAMETERS]: ChargingStationService.handleGetChargingStationOcppParameters.bind(this),
[ServerAction.CHARGING_STATIONS_IN_ERROR]: ChargingStationService.handleGetChargingStationsInError.bind(this),
+ [ServerAction.SETTING_BY_INDENTIFIER]: SettingService.handleGetSettingByIdentifier.bind(this),
[ServerAction.SETTINGS]: SettingService.handleGetSettings.bind(this),
[ServerAction.SETTING]: SettingService.handleGetSetting.bind(this),
[ServerAction.CHECK_BILLING_CONNECTION]: BillingService.handleCheckBillingConnection.bind(this),

MODIFY
src/server/rest/v1/service/SettingService.ts
src/server/rest/v1/service/SettingService.ts
@@ -81,6 +81,36 @@ export default class SettingService {
next();
}
+ public static async handleGetSettingByIdentifier(action: ServerAction, req: Request, res: Response, next: NextFunction) {
+ // Filter
+ const settingID = SettingSecurity.filterSettingRequestByID(req.query);
+ UtilsService.assertIdIsProvided(action, settingID, MODULE_NAME, 'handleGetSettingByIdentifier', req.user);
+ // Check auth
+ if (!Authorizations.canReadSetting(req.user)) {
+ throw new AppAuthError({
+ errorCode: HTTPAuthError.ERROR,
+ user: req.user,
+ action: Action.READ, entity: Entity.SETTING,
+ module: MODULE_NAME, method: 'handleGetSettingByIdentifier',
+ value: settingID
+ });
+ }
+ // Get it
+ const setting = await SettingStorage.getSettingByIdentifier(req.user.tenantID, settingID);
+ UtilsService.assertObjectExists(action, setting, `Setting with Identifier '${settingID}' does not exist`,
+ MODULE_NAME, 'handleGetSettingByIdentifier', req.user);
+ // Process the sensitive data if any
+ // Hash sensitive data before being sent to the front end
+ Cypher.hashSensitiveDataInJSON(setting);
+ // If Crypto Settings, hash key
+ if (setting.identifier === 'crypto') {
+ setting.content.crypto.key = Cypher.hash(setting.content.crypto.key);
+ }
+ // Return
+ res.json(setting);
+ next();
+ }
+
public static async handleGetSettings(action: ServerAction, req: Request, res: Response, next: NextFunction) {
// Check auth
if (!Authorizations.canListSettings(req.user)) {

MODIFY
src/types/Server.ts
src/types/Server.ts
@@ -324,6 +324,7 @@ export enum ServerAction {
SYNCHRONIZE_REFUNDED_TRANSACTIONS = 'SynchronizeRefundedTransactions',
SETTING_CREATE = 'SettingCreate',
+ SETTING_BY_INDENTIFIER = 'SettingByIdentifier',
SETTINGS = 'Settings',
SETTING = 'Setting',
SETTING_UPDATE = 'SettingUpdate',

Add get settings by identifier REST endpoint