Moved endpoint from post to get + added timestamp for each connection
MODIFY
src/integration/asset/schneider/AssetSchneiderIntegration.ts
src/integration/asset/schneider/AssetSchneiderIntegration.ts
@@ -3,6 +3,7 @@ import BackendError from '../../../exception/BackendError';
import { ServerAction } from '../../../types/Server';
import { AssetConnectionSetting, AssetSetting } from '../../../types/Setting';
import Constants from '../../../utils/Constants';
+import Cypher from '../../../utils/Cypher';
import AssetIntegration from '../AssetIntegration';
@@ -20,7 +21,7 @@ export default class AssetSchneiderIntegration extends AssetIntegration<AssetSet
const params = new URLSearchParams();
params.append('grant_type', 'password');
params.append('username', this.connection.connection.user);
- params.append('password', this.connection.connection.password);
+ params.append('password', Cypher.decrypt(this.connection.connection.password));
// Send credentials to get the token
await axios.post(`${this.connection.url}/GetToken`, params,
{

MODIFY
src/server/rest/CentralRestServerService.ts
src/server/rest/CentralRestServerService.ts
@@ -65,7 +65,6 @@ class RequestMapper {
[ServerAction.COMPANY_CREATE]: CompanyService.handleCreateCompany.bind(this),
[ServerAction.ADD_ASSET_TO_SITE_AREA]: SiteAreaService.handleAssignAssetsToSiteArea.bind(this),
[ServerAction.REMOVE_ASSET_TO_SITE_AREA]: SiteAreaService.handleAssignAssetsToSiteArea.bind(this),
- [ServerAction.ASSET_TEST_CONNECTION]: AssetService.handleCheckAssetConnection.bind(this),
[ServerAction.ASSET_CREATE]: AssetService.handleCreateAsset.bind(this),
[ServerAction.TENANT_CREATE]: TenantService.handleCreateTenant.bind(this),
[ServerAction.SITE_CREATE]: SiteService.handleCreateSite.bind(this),
@@ -130,6 +129,7 @@ class RequestMapper {
[ServerAction.ASSET]: AssetService.handleGetAsset.bind(this),
[ServerAction.ASSET_IMAGE]: AssetService.handleGetAssetImage.bind(this),
[ServerAction.ASSET_IN_ERROR]: AssetService.handleGetAssetsInError.bind(this),
+ [ServerAction.ASSET_TEST_CONNECTION]: AssetService.handleCheckAssetConnection.bind(this),
[ServerAction.SITES]: SiteService.handleGetSites.bind(this),
[ServerAction.SITE]: SiteService.handleGetSite.bind(this),
[ServerAction.SITE_IMAGE]: SiteService.handleGetSiteImage.bind(this),

MODIFY
src/server/rest/service/AssetService.ts
src/server/rest/service/AssetService.ts
@@ -27,9 +27,9 @@ export default class AssetService {
UtilsService.assertComponentIsActiveFromToken(req.user, TenantComponents.ASSET,
Action.CHECK_CONNECTION, Entity.ASSET, MODULE_NAME, 'handleCheckAssetConnection');
// Filter request
- const filteredRequest = AssetSecurity.filterAssetTestConnection(req.body);
+ const filteredRequest = AssetSecurity.filterAssetRequestByID(req.query);
// Get asset connection type
- const assetImpl = await AssetFactory.getAssetImpl(req.user.tenantID, filteredRequest.id);
+ const assetImpl = await AssetFactory.getAssetImpl(req.user.tenantID, filteredRequest);
// Asset has unknown connection type
if (!assetImpl) {
throw new AppError({
@@ -73,8 +73,8 @@ export default class AssetService {
});
// Create fail response
const response = {
- connectionIsValid: false,
- statusErrorCode: error.response.status
+ isConnectionValid: false,
+ error: (error.response && error.response.data) ? error.response.data.error : 'unknown_connection_error'
}
res.json(Object.assign(response));
}

MODIFY
src/server/rest/service/security/AssetSecurity.ts
src/server/rest/service/security/AssetSecurity.ts
@@ -46,20 +46,6 @@ export default class AssetSecurity {
return AssetSecurity._filterAssetRequest(request);
}
- public static filterAssetTestConnection(request: any): Partial<AssetConnectionSetting> {
- return {
- id: sanitize(request.id),
- name: sanitize(request.name),
- description: sanitize(request.description),
- url: sanitize(request.url),
- type: sanitize(request.type),
- connection: {
- user: sanitize(request.connection.user),
- password: sanitize(request.connection.password)
- }
- }
- }
-
public static _filterAssetRequest(request: any): Partial<Asset> {
const filteredRequest: Partial<Asset> = {};
filteredRequest.name = sanitize(request.name),

MODIFY
src/server/rest/service/security/SettingSecurity.ts
src/server/rest/service/security/SettingSecurity.ts
@@ -165,6 +165,11 @@ export default class SettingSecurity {
description: sanitize(connection.description),
url: sanitize(connection.url),
type: sanitize(connection.type),
+ timestamp: new Date(),
+ connection: {
+ user: sanitize(connection.connection.user),
+ password: sanitize(connection.connection.password)
+ }
};
// Check type
switch (connection.type) {

MODIFY
src/types/Setting.ts
src/types/Setting.ts
@@ -216,6 +216,7 @@ export interface AssetConnectionSetting {
name: string;
description: string;
url: string;
+ timestamp: Date;
type: AssetConnectionType;
connection?: AssetSchneiderConnectionType;
}

Moved endpoint from post to get + added timestamp for each connection