diff --git a/src/fireedge/src/public/containers/Websocket/index.js b/src/fireedge/src/public/containers/Websocket/index.js
index 457ceee3bc..b3abc623a0 100644
--- a/src/fireedge/src/public/containers/Websocket/index.js
+++ b/src/fireedge/src/public/containers/Websocket/index.js
@@ -16,7 +16,7 @@
import React, { useState, useEffect } from 'react';
import io from 'socket.io-client';
import { findStorageData } from '../../../utils';
-import constants from '../../../constants';
+import constants from 'client/constants';
const { jwtName } = constants;
diff --git a/src/fireedge/src/public/front-app.js b/src/fireedge/src/public/front-app.js
index 99f6667f7f..23b8c57215 100644
--- a/src/fireedge/src/public/front-app.js
+++ b/src/fireedge/src/public/front-app.js
@@ -14,7 +14,7 @@
/* -------------------------------------------------------------------------- */
import React from 'react';
-import { hydrate } from 'react-dom';
+import { hydrate, render } from 'react-dom';
import { createStore } from 'redux';
import root from 'window-or-global';
@@ -38,5 +38,7 @@ const element = document.getElementById('preloadState');
if (element) {
element.remove();
}
+const mainDiv = document.getElementById('root');
+const renderMethod = mainDiv && mainDiv.innerHTML !== '' ? hydrate : render;
-hydrate(, document.getElementById('root'));
+renderMethod(, document.getElementById('root'));
diff --git a/src/fireedge/src/routes/api/index.js b/src/fireedge/src/routes/api/index.js
index 6bffe8b662..761d7499d3 100644
--- a/src/fireedge/src/routes/api/index.js
+++ b/src/fireedge/src/routes/api/index.js
@@ -40,9 +40,8 @@ const {
} = require('./routes/zendesk');
const opennebulaActions = getRouteForOpennebulaCommand();
-
const routes = {
- private: {
+ private: [
...opennebulaActions,
...functions2faPrivate,
...functionsAuthPrivate,
@@ -50,14 +49,14 @@ const routes = {
...functionsSupportPrivate,
...functionsVcenterPrivate,
...functionsZendeskPrivate
- },
- public: {
+ ],
+ public: [
...functions2faPublic,
...functionsAuthPublic,
...functionsOneflowPublic,
...functionsSupportPublic,
...functionsVcenterPublic,
...functionsZendeskPublic
- }
+ ]
};
module.exports = routes;
diff --git a/src/fireedge/src/routes/api/routes/2fa/index.js b/src/fireedge/src/routes/api/routes/2fa/index.js
index 4bbf6ed166..730b366b5c 100644
--- a/src/fireedge/src/routes/api/routes/2fa/index.js
+++ b/src/fireedge/src/routes/api/routes/2fa/index.js
@@ -25,6 +25,11 @@ const {
default2FAOpennebulaVar,
default2FAOpennebulaTmpVar
} = require('../../../../utils/constants/defaults');
+const {
+ TWO_FACTOR_QR,
+ TWO_FACTOR_DELETE,
+ TWO_FACTOR_SETUP
+} = require('./string-routes');
const {
ok,
unauthorized,
@@ -91,9 +96,10 @@ const getUserInfoAuthenticated = (connect, userId, callback, next) => {
}
};
-const privateRoutes = {
- '2fqr': {
+const privateRoutes = [
+ {
httpMethod: POST,
+ endpoint: TWO_FACTOR_QR,
action: (req, res, next, connect, userId) => {
const secret = speakeasy.generateSecret({
length: 10,
@@ -163,8 +169,9 @@ const privateRoutes = {
}
}
},
- '2fsetup': {
+ {
httpMethod: POST,
+ endpoint: TWO_FACTOR_SETUP,
action: (req, res, next, connect, userId) => {
const connectOpennebula = connect();
getUserInfoAuthenticated(
@@ -231,8 +238,9 @@ const privateRoutes = {
);
}
},
- '2fdelete': {
+ {
httpMethod: DELETE,
+ endpoint: TWO_FACTOR_DELETE,
action: (req, res, next, connect, userId) => {
const connectOpennebula = connect();
getUserInfoAuthenticated(
@@ -283,9 +291,9 @@ const privateRoutes = {
);
}
}
-};
+];
-const publicRoutes = {};
+const publicRoutes = [];
const functionRoutes = {
private: privateRoutes,
diff --git a/src/fireedge/src/routes/api/routes/2fa/string-routes.js b/src/fireedge/src/routes/api/routes/2fa/string-routes.js
new file mode 100644
index 0000000000..2474f4a544
--- /dev/null
+++ b/src/fireedge/src/routes/api/routes/2fa/string-routes.js
@@ -0,0 +1,11 @@
+const TWO_FACTOR_SETUP = '2fsetup';
+const TWO_FACTOR_QR = '2fqr';
+const TWO_FACTOR_DELETE = '2fdelete';
+
+const Actions = {
+ TWO_FACTOR_SETUP,
+ TWO_FACTOR_QR,
+ TWO_FACTOR_DELETE
+};
+
+module.exports = Actions;
diff --git a/src/fireedge/src/routes/api/routes/auth/functions.js b/src/fireedge/src/routes/api/routes/auth/functions.js
index b59ee4833f..6ea0a54a9d 100644
--- a/src/fireedge/src/routes/api/routes/auth/functions.js
+++ b/src/fireedge/src/routes/api/routes/auth/functions.js
@@ -107,7 +107,7 @@ const setDates = () => {
const { MIN, MAX } = limitToken;
now = DateTime.local();
nowUnix = now.toSeconds();
- nowWithDays = now.plus({"days": extended ? MAX : MIN});
+ nowWithDays = now.plus({ days: extended ? MAX : MIN });
const diff = nowWithDays.diff(now, 'seconds');
relativeTime = diff.seconds;
};
diff --git a/src/fireedge/src/routes/api/routes/auth/index.js b/src/fireedge/src/routes/api/routes/auth/index.js
index c2eb90fe53..efcb84d01e 100644
--- a/src/fireedge/src/routes/api/routes/auth/index.js
+++ b/src/fireedge/src/routes/api/routes/auth/index.js
@@ -14,6 +14,9 @@
/* -------------------------------------------------------------------------- */
const { Map } = require('immutable');
+const {
+ AUTH,
+} = require('./string-routes');
const {
httpMethod,
defaultMethodLogin
@@ -48,11 +51,12 @@ const {
const { POST } = httpMethod;
-const privateRoutes = {};
+const privateRoutes = [];
-const publicRoutes = {
- auth: {
+const publicRoutes = [
+ {
httpMethod: POST,
+ endpoint: AUTH,
action: (req, res, next, connect) => {
if (req && res && connect) {
setReq(req);
@@ -119,7 +123,7 @@ const publicRoutes = {
}
}
}
-};
+];
const functionRoutes = {
private: privateRoutes,
diff --git a/src/fireedge/src/routes/api/routes/auth/string-routes.js b/src/fireedge/src/routes/api/routes/auth/string-routes.js
new file mode 100644
index 0000000000..485ce0dcd0
--- /dev/null
+++ b/src/fireedge/src/routes/api/routes/auth/string-routes.js
@@ -0,0 +1,7 @@
+const AUTH = 'auth';
+
+const Actions = {
+ AUTH
+};
+
+module.exports = Actions;
diff --git a/src/fireedge/src/routes/api/routes/oneflow/index.js b/src/fireedge/src/routes/api/routes/oneflow/index.js
index a9d594fe64..d1ae7711a3 100644
--- a/src/fireedge/src/routes/api/routes/oneflow/index.js
+++ b/src/fireedge/src/routes/api/routes/oneflow/index.js
@@ -42,62 +42,74 @@ const {
SERVICE_TEMPLATE_CREATE,
SERVICE_TEMPLATE_UPDATE,
SERVICE_TEMPLATE_ACTION
-} = require('./oneflow-routes');
+} = require('./string-routes');
const { GET, POST, DELETE, PUT } = httpMethod;
-const privateRoutes = {
- [SERVICE_ALL]: {
+const privateRoutes = [
+ {
httpMethod: GET,
+ endpoint: SERVICE_ALL,
action: serviceAll
},
- [SERVICE]: {
+ {
httpMethod: GET,
+ endpoint: SERVICE,
action: service
},
- [SERVICE_DELETE]: {
+ {
httpMethod: DELETE,
+ endpoint: SERVICE_DELETE,
action: serviceDelete
},
- [SERVICE_ADD_ACTION]: {
+ {
httpMethod: POST,
+ endpoint: SERVICE_ADD_ACTION,
action: serviceAddAction
},
- [SERVICE_ADD_SCALE]: {
+ {
httpMethod: POST,
+ endpoint: SERVICE_ADD_SCALE,
action: serviceAddScale
},
- [SERVICE_ADD_ROLE_ACTION]: {
+ {
httpMethod: POST,
+ endpoint: SERVICE_ADD_ROLE_ACTION,
action: serviceAddRoleAction
},
- [SERVICE_TEMPLATE_ALL]: {
+ {
httpMethod: GET,
+ endpoint: SERVICE_TEMPLATE_ALL,
action: serviceTemplateAll
},
- [SERVICE_TEMPLATE]: {
+ {
httpMethod: GET,
+ endpoint: SERVICE_TEMPLATE,
action: serviceTemplate
},
- [SERVICE_TEMPLATE_DELETE]: {
+ {
httpMethod: DELETE,
+ endpoint: SERVICE_TEMPLATE_DELETE,
action: serviceTemplateDelete
},
- [SERVICE_TEMPLATE_CREATE]: {
+ {
httpMethod: POST,
+ endpoint: SERVICE_TEMPLATE_CREATE,
action: serviceTemplateCreate
},
- [SERVICE_TEMPLATE_UPDATE]: {
+ {
httpMethod: PUT,
+ endpoint: SERVICE_TEMPLATE_UPDATE,
action: serviceTemplateUpdate
},
- [SERVICE_TEMPLATE_ACTION]: {
+ {
httpMethod: POST,
+ endpoint: SERVICE_TEMPLATE_ACTION,
action: serviceTemplateAction
}
-};
+];
-const publicRoutes = {};
+const publicRoutes = [];
const functionRoutes = {
private: privateRoutes,
diff --git a/src/fireedge/src/routes/api/routes/oneflow/oneflow-routes.js b/src/fireedge/src/routes/api/routes/oneflow/string-routes.js
similarity index 100%
rename from src/fireedge/src/routes/api/routes/oneflow/oneflow-routes.js
rename to src/fireedge/src/routes/api/routes/oneflow/string-routes.js
diff --git a/src/fireedge/src/routes/api/routes/support/index.js b/src/fireedge/src/routes/api/routes/support/index.js
index fe4ef3e550..0c99d0e6ef 100644
--- a/src/fireedge/src/routes/api/routes/support/index.js
+++ b/src/fireedge/src/routes/api/routes/support/index.js
@@ -13,9 +13,9 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
-const privateRoutes = {};
+const privateRoutes = [];
-const publicRoutes = {};
+const publicRoutes = [];
const functionRoutes = {
private: privateRoutes,
diff --git a/src/fireedge/src/routes/api/routes/vcenter/index.js b/src/fireedge/src/routes/api/routes/vcenter/index.js
index fe4ef3e550..0c99d0e6ef 100644
--- a/src/fireedge/src/routes/api/routes/vcenter/index.js
+++ b/src/fireedge/src/routes/api/routes/vcenter/index.js
@@ -13,9 +13,9 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
-const privateRoutes = {};
+const privateRoutes = [];
-const publicRoutes = {};
+const publicRoutes = [];
const functionRoutes = {
private: privateRoutes,
diff --git a/src/fireedge/src/routes/api/routes/zendesk/index.js b/src/fireedge/src/routes/api/routes/zendesk/index.js
index fe4ef3e550..0c99d0e6ef 100644
--- a/src/fireedge/src/routes/api/routes/zendesk/index.js
+++ b/src/fireedge/src/routes/api/routes/zendesk/index.js
@@ -13,9 +13,9 @@
/* limitations under the License. */
/* -------------------------------------------------------------------------- */
-const privateRoutes = {};
+const privateRoutes = [];
-const publicRoutes = {};
+const publicRoutes = [];
const functionRoutes = {
private: privateRoutes,
diff --git a/src/fireedge/src/routes/entrypoints/Api.js b/src/fireedge/src/routes/entrypoints/Api.js
index 91ed73849c..db822fbe87 100644
--- a/src/fireedge/src/routes/entrypoints/Api.js
+++ b/src/fireedge/src/routes/entrypoints/Api.js
@@ -17,10 +17,10 @@ const express = require('express');
const { defaults, httpCodes, params } = require('../../utils/constants');
const {
opennebulaConnect,
- checkRouteFunction,
+ checkIfIsARouteFunction,
commandXML,
checkOpennebulaCommand,
- validateRouteFunction,
+ checkMethodRouteFunction,
responseOpennebula,
httpResponse
} = require('../../utils');
@@ -85,7 +85,7 @@ router.all(
pass = getPassOpennebula()
) => opennebulaConnect(user, pass, RPC);
const { resource } = req.params;
- const routeFunction = checkRouteFunction(resource);
+ const routeFunction = checkIfIsARouteFunction(resource, httpMethod);
res.locals.httpCode = httpResponse(methodNotAllowed);
const dataSources = {
[fromData.resource]: getParamsState(),
@@ -93,7 +93,7 @@ router.all(
[fromData.postBody]: req.body
};
if (routeFunction) {
- const valRouteFunction = validateRouteFunction(
+ const valRouteFunction = checkMethodRouteFunction(
routeFunction,
httpMethod
);
diff --git a/src/fireedge/src/routes/entrypoints/middlewares/api/index.js b/src/fireedge/src/routes/entrypoints/middlewares/api/index.js
index ef8f22ef9c..6753a68c18 100644
--- a/src/fireedge/src/routes/entrypoints/middlewares/api/index.js
+++ b/src/fireedge/src/routes/entrypoints/middlewares/api/index.js
@@ -46,7 +46,9 @@ const validateResource = (req, res, next) => {
if (req && req.params && req.params.resource) {
const resource = req.params.resource;
status = serviceUnavailable;
- if (resource in authenticated) {
+ const finderCommand = rtnCommand =>
+ rtnCommand && rtnCommand.endpoint && rtnCommand.endpoint === resource;
+ if (authenticated.some(finderCommand)) {
const session = validateAuth(req);
if (
session &&
@@ -76,7 +78,7 @@ const validateResource = (req, res, next) => {
}
status = unauthorized;
}
- if (resource in nonAuthenticated) {
+ if (nonAuthenticated.some(finderCommand)) {
next();
return;
}
diff --git a/src/fireedge/src/utils/index.js b/src/fireedge/src/utils/index.js
index 61e66bb61e..c9cdec2b7e 100644
--- a/src/fireedge/src/utils/index.js
+++ b/src/fireedge/src/utils/index.js
@@ -91,7 +91,7 @@ const includeCSSbyHTML = (path = '') => {
return scripts;
};
-const validateRouteFunction = (routeFunction, httpMethod = '') => {
+const checkMethodRouteFunction = (routeFunction, httpMethod = '') => {
let rtn;
if (
routeFunction &&
@@ -105,12 +105,23 @@ const validateRouteFunction = (routeFunction, httpMethod = '') => {
return rtn;
};
-const checkRouteFunction = route => {
+const checkIfIsARouteFunction = (route, httpMethod) => {
let rtn = false;
- const { private: functionPrivate, public: functionPublic } = functionRoutes;
- const functions = { ...functionPrivate, ...functionPublic };
- if (route in functions) {
- rtn = functions[route];
+ if (route && route.length) {
+ const { private: functionPrivate, public: functionPublic } = functionRoutes;
+ const functions = [...functionPrivate, ...functionPublic];
+ const finderCommand = rtnCommand =>
+ rtnCommand &&
+ rtnCommand.endpoint &&
+ rtnCommand.endpoint === route &&
+ rtnCommand.httpMethod &&
+ rtnCommand.httpMethod === httpMethod &&
+ rtnCommand.action &&
+ typeof rtnCommand.action === 'function';
+ const find = functions.find(finderCommand);
+ if (find) {
+ rtn = find;
+ }
}
return rtn;
};
@@ -130,9 +141,9 @@ module.exports = {
getRouteForOpennebulaCommand,
getMethodForOpennebulaCommand,
commandXML,
- checkRouteFunction,
+ checkIfIsARouteFunction,
checkOpennebulaCommand,
- validateRouteFunction,
+ checkMethodRouteFunction,
responseOpennebula,
getConfig,
httpResponse
diff --git a/src/fireedge/src/utils/opennebula.js b/src/fireedge/src/utils/opennebula.js
index a0e0dab189..1bb789a4e8 100644
--- a/src/fireedge/src/utils/opennebula.js
+++ b/src/fireedge/src/utils/opennebula.js
@@ -118,8 +118,11 @@ const getMethodForOpennebulaCommand = () => {
};
const commandXML = (resource = '', method = '', defaultMethod = '') => {
+ let command = '';
const allowedActions = getMethodForOpennebulaCommand();
- let command = `${resource}`;
+ if (resource && resource.length) {
+ command = `${resource}`;
+ }
const commandWithDefault = defaultMethod
? `${command}.${defaultMethod}`
: command;
@@ -157,14 +160,19 @@ const getAllowedQueryParams = () => {
};
const getRouteForOpennebulaCommand = () => {
- const rtn = {};
+ const rtn = [];
if (commandsParams) {
const commands = Object.keys(commandsParams);
commands.forEach(command => {
if (command && command.length) {
- const commandString = command.split('.');
- if (!(commandString[0] in rtn)) {
- rtn[commandString[0]] = false; // false is a opennebula command
+ let commandString = command.split('.');
+ commandString = commandString[0];
+ const finderCommand = rtnCommand =>
+ rtnCommand &&
+ rtnCommand.endpoint &&
+ rtnCommand.endpoint === commandString;
+ if (!rtn.some(finderCommand)) {
+ rtn.push({ endpoint: commandString });
}
}
});