mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-22 20:54:49 +09:00
F #3951: Initial commit for fireedge
Authors - Jorge Logo jlobo@opennebula.io - Sergio Betanzos sbetanzos@opennebula.io
This commit is contained in:
95 files changed
+30088
No files matched your search
@@ -0,0 +1,2 @@
|
||||
src/**/*.css
|
||||
*.md
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"extends": [
|
||||
"./node_modules/jloboescalona-eslint-config/index.js"
|
||||
],
|
||||
"parser": "babel-eslint",
|
||||
"env": {
|
||||
"browser": true
|
||||
},
|
||||
"globals": {},
|
||||
"plugins": [],
|
||||
"rules": {
|
||||
"import/no-extraneous-dependencies": [
|
||||
"error",
|
||||
{
|
||||
"devDependencies": [
|
||||
"*.js"
|
||||
]
|
||||
}
|
||||
],
|
||||
"default-case": 0
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
# Sunstone React
|
||||
|
||||
New Sunstone incarnation in React.
|
||||
|
||||
## Build & Run
|
||||
|
||||
- **yarn** (this command import the dependecies).
|
||||
- **yarn build** (execute the javascript build "bundle")
|
||||
- **yarn start** (start the server in port 3000)
|
||||
|
||||
## Development
|
||||
- **yarn dev** (run server in mode development)
|
||||
|
||||
## How to use
|
||||
|
||||
- **Api**
|
||||
|
||||
REST Interface. Usually Returns OpenNebula resource info. Login returns a JSON Web Token (`JWT`).
|
||||
|
||||
- Login: POST: `http://localhost:3000/api/auth` with params: `user` and `pass`.
|
||||
- Other: check file `src/config/command-params.js`
|
||||
|
||||
- **zeroMQ**
|
||||
Websocket connection call to: `ws://127.0.0.1:3000/?token=JWT`
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
- [nodemon] Internal watch failed: watch ENOSPC
|
||||
for this error run `sudo sysctl fs.inotify.max_user_watches=582222 && sudo sysctl -p`
|
||||
|
||||
- Starting inspector on 127.0.0.1:9229 failed: address already in use
|
||||
for this error run `killall -9 node` and start app again
|
||||
|
||||
## Project description
|
||||
|
||||
- `disk`: this folder content the transpiled code.
|
||||
- `disk/public`: content the transpiled code valid for the HTML.
|
||||
- `node_modules`: dependencies for backend (NODE).
|
||||
- `src`: non-transpiled code.
|
||||
- `src/config`: configuration files (please do not modify if you do not know how it works).
|
||||
- `src/config/command-params.js`: it contains the different commands with the possible opennebula parameters.
|
||||
- `src/config/defaults.js`: it contains default string parameters.
|
||||
- `src/config/function-routes.js`: it contains routes that are not opennebula commands.
|
||||
- `src/config/http-codes.js`: it contains all http codes for routes.
|
||||
- `src/config/params.js`: it contains the parameters used by the paths, example: `http://localhost:3000/api/template/id=0/action=info`.
|
||||
- `src/config/routes-api.js`: gather the different routes used by the API.
|
||||
- `src/public`: contains the sunstone in react.
|
||||
- `src/routes`: contains the routes for node (API and WEB).
|
||||
- `src/utils`: utilities used by the application.
|
||||
- `src/index.js`: entrypoint node.
|
||||
- `config.yml`: enviroment config for user
|
||||
- `.eslintignore`: files ignored by the eslint
|
||||
- `copyStaticAssets.js`: copy the html resourses to dist/public path (.ico, .css, fonts, etc).
|
||||
- `packaje.json`: contains the name of the packages used by the application.
|
||||
- `webpack.config.js`: contains the JS transpiler configurations.
|
||||
- `yarn.lock`: contains the dependencies using the yarn command.
|
||||
@@ -0,0 +1,50 @@
|
||||
################################################################################
|
||||
# Server Configuration
|
||||
################################################################################
|
||||
|
||||
# System log (Morgan) prod or dev
|
||||
LOG: prod
|
||||
|
||||
# Enable cors (cross-origin resource sharing)
|
||||
CORS: true
|
||||
|
||||
# Webpack mode:
|
||||
# - development
|
||||
# - production
|
||||
MODE: development
|
||||
|
||||
# JWT user password encryption key (AUTH)
|
||||
TOKEN_SECRET: token_secreto
|
||||
|
||||
# JWT life time
|
||||
LIMIT_TOKEN:
|
||||
MIN: 14
|
||||
MAX: 30
|
||||
|
||||
# Zones Opeennebula
|
||||
# -ID: identificator zone
|
||||
# -RPC: URL connect to RPC (OPENNEBULA)
|
||||
# -ZEROMQ: URL connect to socket ZEROMQ
|
||||
# -VNC: URL connect to socket VNC
|
||||
|
||||
OPENNEBULA_ZONES:
|
||||
- ID: 0
|
||||
RPC: http://127.0.0.1:2633/RPC2
|
||||
ZEROMQ:
|
||||
VNC:
|
||||
- ID: 1
|
||||
RPC: http://localhost:2633/RPC2
|
||||
ZEROMQ:
|
||||
VNC:
|
||||
|
||||
|
||||
# Presentation information system (Config information)
|
||||
SYSTEM_DATA:
|
||||
NO_AUTH:
|
||||
- MODE
|
||||
AUTH:
|
||||
- MODE
|
||||
- OPENNEBULA_ZONES:
|
||||
- ID
|
||||
- VNC
|
||||
- ZEROMQ
|
||||
@@ -0,0 +1,54 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const { messageTerminal } = require('./src/utils');
|
||||
|
||||
const pathInternal = 'src/public/assets/';
|
||||
const pathExternal = 'dist/public/';
|
||||
|
||||
const config = {
|
||||
color: 'red',
|
||||
type: 'ERROR',
|
||||
error: '',
|
||||
message: 'Static assets copy: %s'
|
||||
};
|
||||
|
||||
const files = [
|
||||
{
|
||||
internal: `${pathInternal}favicon.png`,
|
||||
external: `${pathExternal}favicon.png`
|
||||
},
|
||||
{
|
||||
internal: `${pathInternal}logo.png`,
|
||||
external: `${pathExternal}logo.png`
|
||||
},
|
||||
{
|
||||
internal: `${pathInternal}fonts`,
|
||||
external: `${pathExternal}fonts`
|
||||
}
|
||||
];
|
||||
|
||||
try {
|
||||
files.forEach(({ internal, external }) => {
|
||||
fs.copySync(internal, external);
|
||||
});
|
||||
|
||||
const internalConfig = { color: 'green', type: 'OK', error: '' };
|
||||
messageTerminal({ ...config, ...internalConfig });
|
||||
} catch (err) {
|
||||
const internalConfig = { error: err.message };
|
||||
messageTerminal({ ...config, ...internalConfig });
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{}
|
||||
@@ -0,0 +1,74 @@
|
||||
El diseño del siguiente codigo esta basado en su totalidad en Javascript (ES6).
|
||||
|
||||
- **NodeJS** con **Express** para el backend.
|
||||
- **React**, **Redux** para el front.
|
||||
- **Webpack** para el transpilado de la aplicacion.
|
||||
- **NPM** para la gestion de los packages.
|
||||
|
||||
Cuando se transpila el código generado funciona tanto en el backend como en el frontend (Server-side Render)
|
||||
|
||||
#Motivacion:
|
||||
|
||||
en lo personal el sunstone actual esta lleno de inconvenientes los cuales mencionaré sin profundizar:
|
||||
|
||||
- Dependencias: muchas de las mismas son muy viejas y actualizarlas seria un riesgo de que no funcionen partes del sistema. tampoco se usan las dependencias en su totalidad.
|
||||
- Estado global: en el front end no existe un estado global al cual hacer uso para los diferentes componentes del mismo.
|
||||
- Reactividad: no es reactivo. se hace uso de JQuery y de handlebars. esto hase que al querer hacer algun cambio debes de tambien instanciar los callback para que pueda funcionar despues. tambien hace complicado la busqueda de errores en el codigo.
|
||||
- Manejo del DOM: ya que su fuerte es el hacer uso de jQuery el manejo de Clases y Id son indispensables, esto tambien puede traer uns serie de consecuencias.
|
||||
- Respuestas del XMLRPC: hay llamadas que al ser cambiadas a JSON pueden mutar (en vez de ser objetos pasan a ser arrays y viceversa).
|
||||
- Configuracion: es simple la instalacion del sunstone, pero ya es mas complicado al momento de usar el memcache y demas cosas para usar en produccion.
|
||||
- Traza de errores: es dificil hacer el seguimiento del codigo ya que no hay herramientas especializadas para el debug.
|
||||
- Reglas de LINT: no posee.
|
||||
- Los test e2e: se usa readiness (Ruby).
|
||||
|
||||
Ventajas:
|
||||
|
||||
- Dependencias actualizadas y testeadas.
|
||||
- Eliminacion de recursos deprecados como Bower y Grunt, para el transpilado, JQuery y handlebars para el manejo de vistas.
|
||||
- Creacion de estado Global: al momento de querer hacer consulta a un resurso se puede saber conectando el componente a redux.
|
||||
- Reactividad: no se debe de manejar las vistas y las acciones por separado.
|
||||
- Uso de API REST: se puede usar tambien para otro tipo de aplicaciones web.
|
||||
- Reglas de LINT: el codigo se hace mas legible.
|
||||
|
||||
Dependencias:
|
||||
- Principales: Node, Yarn, ZeroMQ
|
||||
- Descargadas al hacer uso del comando "Yarn o nom start":
|
||||
* Sistema: React,NodeJS,Helmet,Redux.
|
||||
* Desarrollo. Test y compilacion: Webpack, Babel, Cypress, Sass.
|
||||
|
||||
Herramientas de Debug:
|
||||
- Google Chrome (Browser).
|
||||
- React Developer Tools (Chrome plugin).
|
||||
- Redux DevTools (Chrome plugin).
|
||||
- Clear Cache (Chrome plugin).
|
||||
|
||||
Compilacion:
|
||||
|
||||
Server Side Rendering: al compilar una vez teniendo las dependencias instaladas Webpack se encargara de generar el codigo (Proceso) que estara ejecutandoce en node (Sunstone server) y tambien genera el javascript usado en el Browser (Cliente).
|
||||
|
||||
Memcache:
|
||||
no seria necesario el uso del memcache, actualmente se usa solamente para identificar el usuario del front con el backend, para esto se usaria un jwt, que es un token, dentro tuviese el id del usuario y el opennebula token, esto estaria cifrado por una clave que se guarda en el archivo config.yml
|
||||
|
||||
Views
|
||||
la idea es mantener las vistas (el concepto de vista seria la asociacion de recursos). esta "vista" estaran en los template de group. ya que cada usuario estaria almenos en un grupo. el orden seria el siguiente:
|
||||
- Al conectarme buscaria los grupos que el usuario posea.
|
||||
- Dependiendo del grupo del usuario se mostraria las diferentes vistas (estas vistas se guardarian cifradas en base64 ejemplo:
|
||||
VIEWS = [VIEW1="template_en_base64", VIEW2="template_en_base64", VIEW3="template_en_base64"]).
|
||||
- Para que un usuario pueda ver una vista particular:
|
||||
* se puede seleccionar una vista por defecto en el usertemplate, estaria cifrada en base64 ejemplo: DEFAULT_VIEW = "VIEW3".
|
||||
* se puede colocar una vista en particular cifrada en base64 ejemplo: VIEWS = [ VIEW1="template_en_base64", VIEW2="template_en_base64" ]
|
||||
|
||||
|
||||
|
||||
CONSULTAR:
|
||||
-que pasaria si en una federacion posee un namespace diferente a one.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Generated
+12035
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,92 @@
|
||||
{
|
||||
"name": "sunstone_react",
|
||||
"version": "1.0.0",
|
||||
"description": "Backend",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"build": "webpack --mode=production && concurrently \"npm run copy_static_assets\" \"npm run build:css\"",
|
||||
"build-node": "webpack --mode=production --env=node",
|
||||
"build-front": "webpack --mode=production --env=front && concurrently \"npm run copy_static_assets\" \"npm run build:css\"",
|
||||
"build:css": "node-sass src/public/scss/main.scss dist/public/app.css --output-style compressed",
|
||||
"dev": "webpack --mode=development && npm run copy_static_assets && concurrently \"webpack --watch\" \"npm run build:css\" \"nodemon --inspect dist\"",
|
||||
"start": "node dist/index",
|
||||
"copy_static_assets": "node copyStaticAssets.js"
|
||||
},
|
||||
"keywords": [
|
||||
"sunstone",
|
||||
"vm",
|
||||
"opennebula"
|
||||
],
|
||||
"author": "Jorge Lobo",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@material-ui/core": "^4.9.8",
|
||||
"@material-ui/icons": "^4.9.1",
|
||||
"atob": "^2.1.2",
|
||||
"axios": "^0.19.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"body-parser": "^1.19.0",
|
||||
"classnames": "^2.2.6",
|
||||
"colors": "^1.3.3",
|
||||
"compression": "^1.7.3",
|
||||
"concurrently": "^5.1.0",
|
||||
"cors": "^2.8.5",
|
||||
"express": "^4.16.4",
|
||||
"fs-extra": "^7.0.1",
|
||||
"helmet": "^3.21.0",
|
||||
"http": "^0.0.0",
|
||||
"immutable": "^4.0.0-rc.12",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"jwt-simple": "^0.5.6",
|
||||
"moment": "^2.24.0",
|
||||
"morgan": "^1.9.1",
|
||||
"node-pre-gyp": "^0.14.0",
|
||||
"one-datatable": "sbbarragan/material-table#develop",
|
||||
"prop-types": "^15.7.2",
|
||||
"qrcode": "^1.4.2",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6",
|
||||
"react-json-pretty": "^2.1.0",
|
||||
"react-perfect-scrollbar": "^1.5.3",
|
||||
"react-redux": "^7.1.0",
|
||||
"react-router-dom": "^4.3.1",
|
||||
"redux": "^4.0.4",
|
||||
"redux-thunk": "^2.3.0",
|
||||
"remove": "^0.1.5",
|
||||
"speakeasy": "^2.0.0",
|
||||
"sprintf-js": "^1.1.2",
|
||||
"upcast": "^4.0.0",
|
||||
"url": "^0.11.0",
|
||||
"websocket": "^1.0.30",
|
||||
"window-or-global": "^1.0.1",
|
||||
"xml2js": "^0.4.19",
|
||||
"xmlrpc": "^1.3.2",
|
||||
"yaml": "^1.7.2",
|
||||
"zeromq": "^5.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.8.4",
|
||||
"@babel/core": "^7.8.4",
|
||||
"@babel/plugin-proposal-class-properties": "^7.8.3",
|
||||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.8.3",
|
||||
"@babel/plugin-proposal-object-rest-spread": "^7.8.3",
|
||||
"@babel/plugin-proposal-optional-chaining": "^7.8.3",
|
||||
"@babel/preset-env": "^7.8.4",
|
||||
"@babel/preset-react": "^7.8.3",
|
||||
"babel-eslint": "^10.0.2",
|
||||
"babel-loader": "^8.0.6",
|
||||
"css-loader": "^3.2.0",
|
||||
"cypress": "^3.4.1",
|
||||
"enzyme": "^3.9.0",
|
||||
"enzyme-adapter-react-16": "^1.10.0",
|
||||
"eslint": "^6.1.0",
|
||||
"jloboescalona-eslint-config": "^1.1.0",
|
||||
"node-sass": "^4.12.0",
|
||||
"nodemon": "^1.18.10",
|
||||
"react-addons-test-utils": "^15.6.2",
|
||||
"style-loader": "^1.0.0",
|
||||
"webpack": "^4.29.5",
|
||||
"webpack-cli": "^3.3.7",
|
||||
"webpack-node-externals": "^1.7.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const { from, httpMethod } = require('./defaults');
|
||||
const acl = require('./commands/acl-commands');
|
||||
const cluster = require('./commands/cluster-commands');
|
||||
const datastore = require('./commands/datastore-commands');
|
||||
const document = require('./commands/document-commands');
|
||||
const group = require('./commands/group-commands');
|
||||
const groupsec = require('./commands/groupsec-commands');
|
||||
const hook = require('./commands/hook-commands');
|
||||
const host = require('./commands/host-commands');
|
||||
const image = require('./commands/image-commands');
|
||||
const market = require('./commands/market-commands');
|
||||
const system = require('./commands/system-commans');
|
||||
const template = require('./commands/template-commands');
|
||||
const user = require('./commands/user-commands');
|
||||
const vdc = require('./commands/vdc-commans');
|
||||
const vm = require('./commands/vm-commands');
|
||||
const vmgroup = require('./commands/vmgroup-commands');
|
||||
const vn = require('./commands/vn-commands');
|
||||
const vntemplate = require('./commands/vntemplate-commands');
|
||||
const vrouter = require('./commands/vrouter-commands');
|
||||
const zone = require('./commands/zone-commands');
|
||||
|
||||
module.exports = {
|
||||
...acl(from, httpMethod),
|
||||
...cluster(from, httpMethod),
|
||||
...datastore(from, httpMethod),
|
||||
...document(from, httpMethod),
|
||||
...group(from, httpMethod),
|
||||
...groupsec(from, httpMethod),
|
||||
...hook(from, httpMethod),
|
||||
...host(from, httpMethod),
|
||||
...image(from, httpMethod),
|
||||
...market(from, httpMethod),
|
||||
...system(from, httpMethod),
|
||||
...template(from, httpMethod),
|
||||
...user(from, httpMethod),
|
||||
...vdc(from, httpMethod),
|
||||
...vm(from, httpMethod),
|
||||
...vmgroup(from, httpMethod),
|
||||
...vn(from, httpMethod),
|
||||
...vntemplate(from, httpMethod),
|
||||
...vrouter(from, httpMethod),
|
||||
...zone(from, httpMethod)
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = ({ resource, postBody }, { GET, POST, DELETE }) => ({
|
||||
'acl.addrule': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
user: {
|
||||
from: postBody,
|
||||
default: '0x100000000'
|
||||
},
|
||||
resource: {
|
||||
from: postBody,
|
||||
default: '0x1000000000'
|
||||
},
|
||||
right: {
|
||||
from: postBody,
|
||||
default: '0x1'
|
||||
}
|
||||
}
|
||||
},
|
||||
'acl.delrule': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'acl.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,175 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'cluster.allocate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.addhost': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
host: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.delhost': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
host: {
|
||||
from: query,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.adddatastore': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.deldatastore': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.addvnet': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
vnet: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.delvnet': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
vnet: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'cluster.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'clusterpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,173 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'datastore.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
cluster: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastore.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastore.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastore.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastore.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastore.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastore.enable': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
enable: {
|
||||
from: postBody,
|
||||
default: true
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastore.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'datastorepool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,218 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'document.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
type: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.clone': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'document.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'documentpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
type: {
|
||||
from: query,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,134 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'group.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'group.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'group.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: -1
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'group.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'group.addadmin': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'group.deladmin': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'group.quota': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: resource,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'grouppool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'groupquota.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'groupquota.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,196 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'secgroup.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.clone': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.commit': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
vms: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgroup.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'secgrouppool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -3
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,164 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'hook.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'hook.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'hook.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'hook.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'hook.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'hook.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'hook.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'hook.retry': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
execution: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'hookpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'hooklog.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
minimun: {
|
||||
from: postBody, // epoch time
|
||||
default: ''
|
||||
},
|
||||
maximun: {
|
||||
from: postBody, // epoch time
|
||||
default: ''
|
||||
},
|
||||
id: {
|
||||
from: postBody,
|
||||
default: '' // check
|
||||
},
|
||||
execution: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,129 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = ({ resource, postBody, query }, { GET, PUT, DELETE }) => ({
|
||||
'host.allocate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
hostname: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
information: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
manager: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
cluster: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'host.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'host.status': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
status: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'host.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'host.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'host.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'host.monitoring': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'hostpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'hostpool.monitoring': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,302 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'image.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
capacity: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.clone': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.enable': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
enable: {
|
||||
from: postBody,
|
||||
default: true
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.persistent': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
persistent: {
|
||||
from: postBody,
|
||||
default: true
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.chtype': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
type: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.snapshotdelete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.snapshotrevert': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.snapshotflatten': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'image.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'imagepool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,341 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'market.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'market.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'market.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
update: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'market.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'market.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'market.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'market.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: -1
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'marketapp.allocate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.enable': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
enable: {
|
||||
from: postBody,
|
||||
default: true
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapp.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'marketapppool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,27 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (_, { GET }) => ({
|
||||
'system.version': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'system.config': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,248 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'template.allocate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.clone': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
image: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
image: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.instantiate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
pending: {
|
||||
from: postBody,
|
||||
default: false
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
image: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
image: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
extended: {
|
||||
from: query,
|
||||
default: false
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'templatepool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'template.unlock': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,214 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'user.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
username: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
password: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
driver: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: []
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.passwd': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
password: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.login': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
user: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
token: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
expire: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
gid: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.update': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
update: {
|
||||
from: postBody,
|
||||
default: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.chauth': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
driver: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
password: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.quota': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.chgrp': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.addgroup': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.delgroup': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
group: {
|
||||
from: query,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'user.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: -1
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'userpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'userquota.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'userquota.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,267 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'vdc.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
cluster: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: -1
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdcpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'vdc.addgroup': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.delgroup': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
group: {
|
||||
from: query,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.addcluster': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
cluster: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.delcluster': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: query,
|
||||
default: 0
|
||||
},
|
||||
cluster: {
|
||||
from: query,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.addhost': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
host: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.delhost': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
host: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.adddatastore': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.deldatastore': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.addvnet': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
vnet: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vdc.delvnet': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
zone: {
|
||||
from: query,
|
||||
default: 0
|
||||
},
|
||||
vnet: {
|
||||
from: query,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,636 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'vm.allocate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
status: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.deploy': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
host: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
enforce: {
|
||||
from: postBody,
|
||||
default: false
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.action': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
action: {
|
||||
from: postBody,
|
||||
default: 'stop'
|
||||
},
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.migrate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
host: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
livemigration: {
|
||||
from: postBody,
|
||||
default: false
|
||||
},
|
||||
enforce: {
|
||||
from: postBody,
|
||||
default: false
|
||||
},
|
||||
datastore: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
migration: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.disksaveas': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
disk: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
type: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.disksnapshotcreate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
disk: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
description: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.disksnapshotdelete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
disk: {
|
||||
from: query,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: query,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.disksnapshotrevert': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
disk: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.disksnapshotrename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
disk: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.attach': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.detach': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
disk: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.diskresize': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
disk: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
size: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.attachnic': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.detachnic': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
nic: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.snapshotcreate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.snapshotrevert': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.snapshotdelete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
snapshot: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.resize': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
enforce: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.updateconf': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: resource,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.recover': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
operation: {
|
||||
from: postBody,
|
||||
default: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.monitoring': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
level: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'vm.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -2
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
state: {
|
||||
from: query,
|
||||
default: -2
|
||||
},
|
||||
filterbykey: {
|
||||
from: query,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmpool.infoextended': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -2
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
state: {
|
||||
from: query,
|
||||
default: -2
|
||||
},
|
||||
filterbykey: {
|
||||
from: query,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmpool.monitoring': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -2
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmpool.accounting': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -2
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmpool.showback': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -2
|
||||
},
|
||||
start_month: {
|
||||
filter: query,
|
||||
default: -1
|
||||
},
|
||||
start_year: {
|
||||
filter: query,
|
||||
default: -1
|
||||
},
|
||||
end_month: {
|
||||
filter: query,
|
||||
default: -1
|
||||
},
|
||||
end_year: {
|
||||
filter: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmpool.calculateshowback': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
start_month: {
|
||||
filter: query,
|
||||
default: -1
|
||||
},
|
||||
start_year: {
|
||||
filter: query,
|
||||
default: -1
|
||||
},
|
||||
end_month: {
|
||||
filter: query,
|
||||
default: -1
|
||||
},
|
||||
end_year: {
|
||||
filter: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,192 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'vmgroup.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
defaul: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: postBody,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgroup.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vmgrouppool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,294 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'vn.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
cluster: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.add_ar': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.rm_ar': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
address: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.update_ar': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.reserve': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.free_ar': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
range: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.hold': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.release': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
level: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'vn.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vnpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -3
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,224 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'vntemplate.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.clone': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.instantiate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplate.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vntemplatepool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,254 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'vrouter.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
images: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.instantiate': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
number: {
|
||||
from: postBody,
|
||||
default: 1
|
||||
},
|
||||
template_id: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
pending: {
|
||||
from: postBody,
|
||||
default: false
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.attachnic': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.detachnic': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
nic: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
update: {
|
||||
from: postBody,
|
||||
default: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.chmod': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
user_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_use: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_manage: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
other_admin: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.chown': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
user_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
},
|
||||
group_id: {
|
||||
from: postBody,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: -1
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.lock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
lock: {
|
||||
from: postBody,
|
||||
default: 4
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouter.unlock': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'vrouterpool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
filter: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
start: {
|
||||
from: query,
|
||||
default: -1
|
||||
},
|
||||
end: {
|
||||
from: query,
|
||||
default: -1
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,96 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = (
|
||||
{ resource, postBody, query },
|
||||
{ GET, POST, PUT, DELETE }
|
||||
) => ({
|
||||
'zone.allocate': {
|
||||
// inspected
|
||||
httpMethod: POST,
|
||||
params: {
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'zone.delete': {
|
||||
// inspected
|
||||
httpMethod: DELETE,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'zone.update': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
template: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
},
|
||||
replace: {
|
||||
from: postBody,
|
||||
default: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
'zone.rename': {
|
||||
// inspected
|
||||
httpMethod: PUT,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
name: {
|
||||
from: postBody,
|
||||
default: ''
|
||||
}
|
||||
}
|
||||
},
|
||||
'zone.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {
|
||||
id: {
|
||||
from: resource,
|
||||
default: 0
|
||||
},
|
||||
decrypt: {
|
||||
from: query,
|
||||
default: false
|
||||
}
|
||||
}
|
||||
},
|
||||
'zone.raftstatus': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
},
|
||||
'zonepool.info': {
|
||||
// inspected
|
||||
httpMethod: GET,
|
||||
params: {}
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,74 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const default2FAOpennebulaVar = 'TWO_FACTOR_AUTH_SECRET';
|
||||
module.exports = {
|
||||
httpMethod: {
|
||||
GET: 'GET',
|
||||
POST: 'POST',
|
||||
PUT: 'PUT',
|
||||
DELETE: 'DELETE'
|
||||
},
|
||||
from: {
|
||||
resource: 'RESOURCE',
|
||||
query: 'QUERY',
|
||||
postBody: 'POST_BODY'
|
||||
},
|
||||
defaultOpennebulaZones: [
|
||||
{
|
||||
ID: 0,
|
||||
RPC: 'http://localhost:2633/RPC2',
|
||||
VNC: ''
|
||||
}
|
||||
],
|
||||
defaultConfigFile: `${__dirname}/../config.yml`,
|
||||
defaultTypeLog: 'prod',
|
||||
defaultWebpackMode: 'development',
|
||||
defaultConfigLogPath: '/var/log/one/',
|
||||
defaultConfigLogFile: 'sunstone.log',
|
||||
defaultBaseURL: '',
|
||||
defaultNamespace: 'one.',
|
||||
defaultMessageInvalidZone: 'Invalid Zone',
|
||||
default2FAIssuer: 'sunstone-UI',
|
||||
default2FAOpennebulaVar,
|
||||
default2FAOpennebulaTmpVar: `TMP_${default2FAOpennebulaVar}`,
|
||||
defaultGetMethod: 'info',
|
||||
defaultMessageProblemOpennebula: 'Problem with conection or xml parser',
|
||||
defaultMethodLogin: 'user.login',
|
||||
defaultMethodUserUpdate: 'user.update',
|
||||
defaultMethodUserInfo: 'user.info',
|
||||
defaultLang: 'en_US',
|
||||
translations: {
|
||||
en_US: 'English',
|
||||
ca: 'Catalan',
|
||||
cs_CZ: 'Czech',
|
||||
nl_NL: 'Dutch',
|
||||
da: 'Danish',
|
||||
fr_FR: 'French',
|
||||
de: 'German',
|
||||
it_IT: 'Italian',
|
||||
js: 'Japanese',
|
||||
lt_LT: 'Lithuanian',
|
||||
fa_IR: 'Persian',
|
||||
pl: 'Polish',
|
||||
pt_BR: 'Portiguese',
|
||||
pt_PT: 'Portuguese',
|
||||
tr_TR: 'Turkish',
|
||||
ru_RU: 'Russian',
|
||||
zh_CN: 'Simplified Chinese',
|
||||
sk_SK: 'Slovak',
|
||||
es_ES: 'Spanish'
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,517 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const { Map } = require('immutable');
|
||||
const { getConfig } = require('../utils/yml-connect');
|
||||
const moment = require('moment');
|
||||
const speakeasy = require('speakeasy');
|
||||
const qrcode = require('qrcode');
|
||||
|
||||
const {
|
||||
httpMethod,
|
||||
defaultNamespace,
|
||||
defaultMethodLogin,
|
||||
defaultMethodUserInfo,
|
||||
defaultMethodUserUpdate,
|
||||
default2FAIssuer,
|
||||
default2FAOpennebulaVar,
|
||||
default2FAOpennebulaTmpVar
|
||||
} = require('./defaults');
|
||||
const {
|
||||
ok,
|
||||
unauthorized,
|
||||
internalServerError
|
||||
} = require('../config/http-codes');
|
||||
const { from: fromData } = require('../config/defaults');
|
||||
const { createToken } = require('../utils/jwt-functions');
|
||||
const {
|
||||
responseOpennebula,
|
||||
checkOpennebulaCommand,
|
||||
paramsDefaultByCommandOpennebula,
|
||||
generateNewTemplate
|
||||
} = require('../utils/opennebula-functions');
|
||||
|
||||
// user config
|
||||
const appConfig = getConfig();
|
||||
|
||||
const limitToken = appConfig.LIMIT_TOKEN;
|
||||
const namespace = appConfig.NAMESPACE || defaultNamespace;
|
||||
const twoFactorAuthIssuer =
|
||||
appConfig.TWO_FACTOR_AUTH_ISSUER || default2FAIssuer;
|
||||
|
||||
const { POST, GET, DELETE } = httpMethod;
|
||||
|
||||
const getUserInfoAuthenticated = (connect, userId, callback, next) => {
|
||||
if (
|
||||
connect &&
|
||||
!!userId &&
|
||||
callback &&
|
||||
next &&
|
||||
typeof connect === 'function' &&
|
||||
typeof callback === 'function' &&
|
||||
typeof next === 'function' &&
|
||||
defaultMethodUserInfo
|
||||
) {
|
||||
const connectOpennebula = connect();
|
||||
const dataUser = {};
|
||||
// empty positions for validate...
|
||||
dataUser[fromData.resource] = {};
|
||||
dataUser[fromData.query] = {};
|
||||
dataUser[fromData.postBody] = {};
|
||||
dataUser[fromData.resource].id = userId;
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(
|
||||
defaultMethodUserInfo,
|
||||
GET
|
||||
);
|
||||
connectOpennebula(
|
||||
defaultMethodUserInfo,
|
||||
getOpennebulaMethod(dataUser),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
() => undefined,
|
||||
err,
|
||||
value,
|
||||
info => {
|
||||
if (info !== undefined && info !== null) {
|
||||
callback(info);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const privateRoutes = {
|
||||
'2fqr': {
|
||||
httpMethod: POST,
|
||||
action: (req, res, next, connect, userId) => {
|
||||
const secret = speakeasy.generateSecret({
|
||||
length: 10,
|
||||
name: twoFactorAuthIssuer
|
||||
});
|
||||
if (secret && secret.otpauth_url && secret.base32) {
|
||||
const { otpauth_url: otpURL, base32 } = secret;
|
||||
qrcode.toDataURL(otpURL, (err, dataURL) => {
|
||||
if (err) {
|
||||
res.locals.httpCode = Map(internalServerError).toObject();
|
||||
next();
|
||||
} else {
|
||||
const connectOpennebula = connect();
|
||||
getUserInfoAuthenticated(
|
||||
connect,
|
||||
userId,
|
||||
info => {
|
||||
if (info && info.USER && info.USER.TEMPLATE && req) {
|
||||
const dataUser = Map(req).toObject();
|
||||
const emptyTemplate = {};
|
||||
emptyTemplate[default2FAOpennebulaTmpVar] = base32;
|
||||
|
||||
dataUser[fromData.resource].id = userId;
|
||||
dataUser[fromData.postBody].template = generateNewTemplate(
|
||||
info.USER.TEMPLATE.SUNSTONE || {},
|
||||
emptyTemplate,
|
||||
[default2FAOpennebulaVar]
|
||||
);
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(
|
||||
defaultMethodUserUpdate,
|
||||
POST
|
||||
);
|
||||
connectOpennebula(
|
||||
defaultMethodUserUpdate,
|
||||
getOpennebulaMethod(dataUser),
|
||||
(error, value) => {
|
||||
responseOpennebula(
|
||||
() => undefined,
|
||||
error,
|
||||
value,
|
||||
pass => {
|
||||
if (pass !== undefined && pass !== null) {
|
||||
const codeOK = Map(ok).toObject();
|
||||
codeOK.data = {
|
||||
img: dataURL
|
||||
};
|
||||
res.locals.httpCode = codeOK;
|
||||
next();
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
'2fsetup': {
|
||||
httpMethod: POST,
|
||||
action: (req, res, next, connect, userId) => {
|
||||
const connectOpennebula = connect();
|
||||
getUserInfoAuthenticated(
|
||||
connect,
|
||||
userId,
|
||||
info => {
|
||||
if (
|
||||
info &&
|
||||
info.USER &&
|
||||
info.USER.TEMPLATE &&
|
||||
info.USER.TEMPLATE.SUNSTONE &&
|
||||
info.USER.TEMPLATE.SUNSTONE[default2FAOpennebulaTmpVar] &&
|
||||
fromData &&
|
||||
fromData.postBody &&
|
||||
req &&
|
||||
req[fromData.postBody] &&
|
||||
req[fromData.postBody].token
|
||||
) {
|
||||
const sunstone = info.USER.TEMPLATE.SUNSTONE;
|
||||
const token = req[fromData.postBody].token;
|
||||
const secret = sunstone[default2FAOpennebulaTmpVar];
|
||||
const verified = speakeasy.totp.verify({
|
||||
secret,
|
||||
encoding: 'base32',
|
||||
token
|
||||
});
|
||||
if (verified) {
|
||||
const emptyTemplate = {};
|
||||
emptyTemplate[default2FAOpennebulaVar] = secret;
|
||||
|
||||
const dataUser = Map(req).toObject();
|
||||
dataUser[fromData.resource].id = userId;
|
||||
dataUser[fromData.postBody].template = generateNewTemplate(
|
||||
sunstone || {},
|
||||
emptyTemplate,
|
||||
[default2FAOpennebulaTmpVar]
|
||||
);
|
||||
const getOpennebulaMethodUpdate = checkOpennebulaCommand(
|
||||
defaultMethodUserUpdate,
|
||||
POST
|
||||
);
|
||||
connectOpennebula(
|
||||
defaultMethodUserUpdate,
|
||||
getOpennebulaMethodUpdate(dataUser),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
() => undefined,
|
||||
err,
|
||||
value,
|
||||
pass => {
|
||||
if (pass !== undefined && pass !== null) {
|
||||
const codeOK = Map(ok).toObject();
|
||||
res.locals.httpCode = codeOK;
|
||||
}
|
||||
next();
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.locals.httpCode = Map(unauthorized).toObject();
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
},
|
||||
'2fdelete': {
|
||||
httpMethod: DELETE,
|
||||
action: (req, res, next, connect, userId) => {
|
||||
const connectOpennebula = connect();
|
||||
getUserInfoAuthenticated(
|
||||
connect,
|
||||
userId,
|
||||
info => {
|
||||
if (
|
||||
info &&
|
||||
info.USER &&
|
||||
info.USER.TEMPLATE &&
|
||||
info.USER.TEMPLATE.SUNSTONE
|
||||
) {
|
||||
const emptyTemplate = {};
|
||||
const dataUser = Map(req).toObject();
|
||||
dataUser[fromData.resource].id = userId;
|
||||
dataUser[fromData.postBody].template = generateNewTemplate(
|
||||
info.USER.TEMPLATE.SUNSTONE || {},
|
||||
emptyTemplate,
|
||||
[default2FAOpennebulaTmpVar, default2FAOpennebulaVar]
|
||||
);
|
||||
const getOpennebulaMethodUpdate = checkOpennebulaCommand(
|
||||
defaultMethodUserUpdate,
|
||||
POST
|
||||
);
|
||||
connectOpennebula(
|
||||
defaultMethodUserUpdate,
|
||||
getOpennebulaMethodUpdate(dataUser),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
() => undefined,
|
||||
err,
|
||||
value,
|
||||
pass => {
|
||||
if (pass !== undefined && pass !== null) {
|
||||
const codeOK = Map(ok).toObject();
|
||||
res.locals.httpCode = codeOK;
|
||||
}
|
||||
next();
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
},
|
||||
next
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const publicRoutes = {
|
||||
auth: {
|
||||
httpMethod: POST,
|
||||
action: (req, res, next, connect) => {
|
||||
const updaterResponse = code => {
|
||||
if (
|
||||
'id' in code &&
|
||||
'message' in code &&
|
||||
res &&
|
||||
res.locals &&
|
||||
res.locals.httpCode
|
||||
) {
|
||||
res.locals.httpCode = code;
|
||||
}
|
||||
};
|
||||
updaterResponse(Map(internalServerError).toObject());
|
||||
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(
|
||||
defaultMethodLogin,
|
||||
POST
|
||||
);
|
||||
|
||||
if (req && getOpennebulaMethod) {
|
||||
const user =
|
||||
(req &&
|
||||
fromData.postBody &&
|
||||
req[fromData.postBody] &&
|
||||
req[fromData.postBody].user) ||
|
||||
'';
|
||||
|
||||
const pass =
|
||||
(req &&
|
||||
fromData.postBody &&
|
||||
req[fromData.postBody] &&
|
||||
req[fromData.postBody].pass) ||
|
||||
'';
|
||||
|
||||
const token =
|
||||
(req && req[fromData.postBody] && req[fromData.postBody].token) || '';
|
||||
|
||||
const extended =
|
||||
(req && req[fromData.postBody] && req[fromData.postBody].extended) ||
|
||||
'';
|
||||
|
||||
if (user && pass && connect && limitToken) {
|
||||
const { MIN, MAX } = limitToken;
|
||||
|
||||
const now = moment();
|
||||
const nowUnix = now.unix();
|
||||
const nowWithDays = moment().add(extended ? MAX : MIN, 'days');
|
||||
const relativeTime = nowWithDays.diff(now, 'seconds');
|
||||
|
||||
let opennebulaToken;
|
||||
const connectOpennebula = connect(
|
||||
user,
|
||||
pass
|
||||
);
|
||||
const dataSourceWithExpirateDate = Map(req).toObject();
|
||||
|
||||
const userInfo = userData => {
|
||||
if (user && opennebulaToken && userData && userData.USER) {
|
||||
const informationUser = userData.USER;
|
||||
|
||||
// remove opennebula user tokens
|
||||
if (
|
||||
informationUser.LOGIN_TOKEN &&
|
||||
Array.isArray(informationUser.LOGIN_TOKEN)
|
||||
) {
|
||||
informationUser.LOGIN_TOKEN.map(loginToken => {
|
||||
if (
|
||||
loginToken &&
|
||||
loginToken.TOKEN &&
|
||||
loginToken.TOKEN !== opennebulaToken
|
||||
) {
|
||||
dataSourceWithExpirateDate[fromData.postBody].expire = 0;
|
||||
dataSourceWithExpirateDate[fromData.postBody].token =
|
||||
loginToken.TOKEN;
|
||||
|
||||
connectOpennebula(
|
||||
defaultMethodLogin,
|
||||
getOpennebulaMethod(dataSourceWithExpirateDate),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
() => undefined,
|
||||
err,
|
||||
value,
|
||||
() => undefined,
|
||||
next
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// validate 2fa token
|
||||
if (
|
||||
informationUser.TEMPLATE &&
|
||||
informationUser.TEMPLATE.SUNSTONE &&
|
||||
informationUser.TEMPLATE.SUNSTONE[default2FAOpennebulaVar]
|
||||
) {
|
||||
const secret =
|
||||
informationUser.TEMPLATE.SUNSTONE[default2FAOpennebulaVar];
|
||||
const verified = speakeasy.totp.verify({
|
||||
secret,
|
||||
encoding: 'base32',
|
||||
token
|
||||
});
|
||||
if (!verified) {
|
||||
const codeUnauthorized = Map(unauthorized).toObject();
|
||||
codeUnauthorized.data = { message: 'invalid 2fa token' };
|
||||
updaterResponse(codeUnauthorized);
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
// generate jwt
|
||||
const { ID: id } = informationUser;
|
||||
const dataJWT = { id, user, token: opennebulaToken };
|
||||
const jwt = createToken(
|
||||
dataJWT,
|
||||
nowUnix,
|
||||
nowWithDays.format('X')
|
||||
);
|
||||
if (jwt) {
|
||||
const codeOK = Map(ok).toObject();
|
||||
codeOK.data = { token: jwt };
|
||||
updaterResponse(codeOK);
|
||||
}
|
||||
next();
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
const authenticated = val => {
|
||||
const findTextError = `[${namespace + defaultMethodLogin}]`;
|
||||
if (val) {
|
||||
if (val.indexOf(findTextError) >= 0) {
|
||||
const codeUnauthorized = Map(unauthorized).toObject();
|
||||
updaterResponse(codeUnauthorized);
|
||||
next();
|
||||
} else {
|
||||
opennebulaToken = val;
|
||||
connectOpennebula(
|
||||
defaultMethodUserInfo,
|
||||
paramsDefaultByCommandOpennebula(defaultMethodUserInfo, GET),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
updaterResponse,
|
||||
err,
|
||||
value,
|
||||
userInfo,
|
||||
next
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
};
|
||||
|
||||
// add expire time unix for opennebula creation token
|
||||
dataSourceWithExpirateDate[fromData.postBody].expire = relativeTime;
|
||||
|
||||
connectOpennebula(
|
||||
defaultMethodLogin,
|
||||
getOpennebulaMethod(dataSourceWithExpirateDate),
|
||||
(err, value) => {
|
||||
responseOpennebula(
|
||||
updaterResponse,
|
||||
err,
|
||||
value,
|
||||
authenticated,
|
||||
next
|
||||
);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
res.locals.httpCode = Map(unauthorized).toObject();
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
},
|
||||
zendesk: {
|
||||
httpMethod: POST,
|
||||
action: (req, res, next) => {
|
||||
next();
|
||||
console.log('zendesk');
|
||||
}
|
||||
},
|
||||
latest: {
|
||||
httpMethod: POST,
|
||||
action: (req, res, next) => {
|
||||
next();
|
||||
console.log('latest version opennebula');
|
||||
}
|
||||
},
|
||||
support: {
|
||||
httpMethod: POST,
|
||||
action: (req, res, next) => {
|
||||
next();
|
||||
console.log('support token');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const functionRoutes = {
|
||||
private: privateRoutes,
|
||||
public: publicRoutes
|
||||
};
|
||||
|
||||
module.exports = functionRoutes;
|
||||
@@ -0,0 +1,43 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const httpCodes = {
|
||||
badRequest: {
|
||||
id: 400,
|
||||
message: 'Bad Request'
|
||||
},
|
||||
unauthorized: {
|
||||
id: 401,
|
||||
message: 'Unauthorized'
|
||||
},
|
||||
methodNotAllowed: {
|
||||
id: 405,
|
||||
message: 'Method not Allowed'
|
||||
},
|
||||
internalServerError: {
|
||||
id: 500,
|
||||
message: 'Internal Server Error'
|
||||
},
|
||||
serviceUnavailable: {
|
||||
id: 503,
|
||||
message: 'Service Unavailable'
|
||||
},
|
||||
ok: {
|
||||
id: 200,
|
||||
message: 'OK'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = httpCodes;
|
||||
@@ -0,0 +1,17 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const params = ['method', 'id', 'federation'];
|
||||
module.exports = params;
|
||||
@@ -0,0 +1,28 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const { getRouteForOpennebulaCommand } = require('../utils');
|
||||
const {
|
||||
private: functionPrivate,
|
||||
public: functionPublic
|
||||
} = require('./function-routes');
|
||||
|
||||
const opennebulaActions = getRouteForOpennebulaCommand();
|
||||
|
||||
const routes = {
|
||||
private: [...opennebulaActions, ...Object.keys(functionPrivate)],
|
||||
public: [...Object.keys(functionPublic)]
|
||||
};
|
||||
module.exports = routes;
|
||||
@@ -0,0 +1,125 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const compression = require('compression');
|
||||
const { env } = require('process');
|
||||
const helmet = require('helmet');
|
||||
const express = require('express');
|
||||
const morgan = require('morgan');
|
||||
const path = require('path');
|
||||
const cors = require('cors');
|
||||
const {
|
||||
existsSync,
|
||||
accessSync,
|
||||
constants: fsConstants,
|
||||
createWriteStream,
|
||||
readFileSync
|
||||
} = require('fs-extra');
|
||||
const { createServer: unsecureServer } = require('http');
|
||||
const { createServer: secureServer } = require('https');
|
||||
const bodyParser = require('body-parser');
|
||||
const { getConfig } = require('./utils/yml-connect');
|
||||
const {
|
||||
defaultConfigLogPath,
|
||||
defaultConfigLogFile,
|
||||
defaultTypeLog
|
||||
} = require('./config/defaults');
|
||||
const publicRoutes = require('./routes/public');
|
||||
const apiRoutes = require('./routes/api');
|
||||
const { messageTerminal, addWsServer } = require('./utils');
|
||||
|
||||
const app = express();
|
||||
|
||||
// user config
|
||||
const appConfig = getConfig();
|
||||
|
||||
// settings
|
||||
const port = appConfig.PORT || 3000;
|
||||
const userLog = appConfig.LOG || 'dev';
|
||||
|
||||
// ssl
|
||||
const key = `${__dirname}/../cert/key.pem`;
|
||||
const cert = `${__dirname}/../cert/cert.pem`;
|
||||
|
||||
let log = morgan('dev');
|
||||
if (userLog === defaultTypeLog) {
|
||||
let logPath = `${defaultConfigLogPath}`;
|
||||
if (env?.ONE_LOCATION) {
|
||||
logPath = env.ONE_LOCATION + logPath;
|
||||
}
|
||||
try {
|
||||
accessSync(logPath, fsConstants.W_OK);
|
||||
const logStream = createWriteStream(logPath + defaultConfigLogFile, {
|
||||
flags: 'a'
|
||||
});
|
||||
log = morgan('combined', { stream: logStream });
|
||||
} catch (err) {
|
||||
console.error('no access!');
|
||||
}
|
||||
}
|
||||
|
||||
app.use(helmet.hidePoweredBy());
|
||||
app.use(compression());
|
||||
|
||||
app.use('/static', express.static(path.resolve(__dirname, 'public')));
|
||||
|
||||
// log request
|
||||
app.use(log);
|
||||
|
||||
// cors
|
||||
if (appConfig.CORS) {
|
||||
app.use(cors());
|
||||
}
|
||||
|
||||
// post params parser body
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// routes
|
||||
app.use('/api', apiRoutes);
|
||||
app.use('/', publicRoutes);
|
||||
|
||||
// 404 - public
|
||||
app.get('*', (req, res) =>
|
||||
res
|
||||
.status(404)
|
||||
.send(
|
||||
`<body style="background-color: #3c3c3c;"><h1 style="font-family: sans-serif; color: #c7c7c7; text-align: center;">404 - Not Found</h1></body>`
|
||||
)
|
||||
);
|
||||
|
||||
// server
|
||||
const appServer =
|
||||
existsSync && key && cert && existsSync(key) && existsSync(cert)
|
||||
? secureServer(
|
||||
{
|
||||
key: readFileSync(key, 'utf8'),
|
||||
cert: readFileSync(cert, 'utf8')
|
||||
},
|
||||
app
|
||||
)
|
||||
: unsecureServer(app);
|
||||
|
||||
// connect to zeromq websocket
|
||||
addWsServer(appServer);
|
||||
|
||||
appServer.listen(port, () => {
|
||||
const config = {
|
||||
color: 'green',
|
||||
type: port,
|
||||
message: 'Server listen in port %s'
|
||||
};
|
||||
messageTerminal(config);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
export function setUser(name) {
|
||||
return {
|
||||
type: 'SETUSER',
|
||||
payload: {
|
||||
name
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function showMenu(displayMenu) {
|
||||
return {
|
||||
type: 'DISPLAY_MENU',
|
||||
payload: {
|
||||
displayMenu
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import { StaticRouter, BrowserRouter } from 'react-router-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import { TranslateProvider } from './components/HOC';
|
||||
import Router from './components/router';
|
||||
|
||||
const App = ({ location, context, store }) => (
|
||||
<Provider store={store}>
|
||||
{location && context ? (
|
||||
// server build
|
||||
<StaticRouter location={location} context={context}>
|
||||
<TranslateProvider>
|
||||
<Router />
|
||||
</TranslateProvider>
|
||||
</StaticRouter>
|
||||
) : (
|
||||
// browser build
|
||||
<BrowserRouter>
|
||||
<TranslateProvider>
|
||||
<Router />
|
||||
</TranslateProvider>
|
||||
</BrowserRouter>
|
||||
)}
|
||||
</Provider>
|
||||
);
|
||||
|
||||
App.propTypes = {
|
||||
location: PropTypes.string,
|
||||
context: PropTypes.shape({}),
|
||||
store: PropTypes.shape({})
|
||||
};
|
||||
|
||||
App.defaultProps = {
|
||||
location: '',
|
||||
context: {},
|
||||
store: {}
|
||||
};
|
||||
|
||||
export default App;
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
@@ -0,0 +1,82 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { useState, useEffect, Fragment } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { connect } from 'react-redux';
|
||||
import { requestData, removeStoreData, findStorageData } from '../../utils';
|
||||
import constants from '../../constants';
|
||||
import components from '../router/endpoints';
|
||||
import { setUser } from '../../actions';
|
||||
|
||||
const AuthLayout = ({ children, history, changeName }) => {
|
||||
const [show, setShow] = useState(false);
|
||||
|
||||
const redirectToLogin = () => {
|
||||
const { jwtName } = constants;
|
||||
removeStoreData(jwtName);
|
||||
const { login } = components;
|
||||
history.push(login.path);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const { jwtName, endpointsRoutes } = constants;
|
||||
if (findStorageData && findStorageData(jwtName)) {
|
||||
requestData(endpointsRoutes.userInfo).then(response => {
|
||||
if (response && response.data && response.data.USER) {
|
||||
const { USER: userInfo } = response.data;
|
||||
setShow(true);
|
||||
changeName(userInfo.NAME);
|
||||
} else {
|
||||
redirectToLogin();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
redirectToLogin();
|
||||
}
|
||||
}, []);
|
||||
|
||||
return show ? <Fragment>{children}</Fragment> : <Fragment />;
|
||||
};
|
||||
AuthLayout.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
PropTypes.node,
|
||||
PropTypes.string
|
||||
]),
|
||||
history: PropTypes.shape({
|
||||
push: PropTypes.func
|
||||
}),
|
||||
changeName: PropTypes.func
|
||||
};
|
||||
|
||||
AuthLayout.defaultProps = {
|
||||
children: '',
|
||||
history: {
|
||||
push: () => undefined
|
||||
},
|
||||
changeName: () => undefined
|
||||
};
|
||||
|
||||
const mapStateToProps = () => ({});
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
changeName: name => dispatch(setUser(name))
|
||||
});
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(AuthLayout);
|
||||
@@ -0,0 +1,85 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import { Drawer, Box, Grid } from '@material-ui/core';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import Header from '../containers/Header';
|
||||
import Footer from '../containers/Footer';
|
||||
import PrincipalMenu from '../containers/PrincipalMenu';
|
||||
import { showMenu } from '../../actions';
|
||||
|
||||
const InternalLayout = ({ children, display, displayMenu, title }) => (
|
||||
<Box
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
flexBasis: '100%'
|
||||
}}
|
||||
>
|
||||
<Header title={title} />
|
||||
<Drawer anchor="left" open={display} onClose={() => displayMenu(false)}>
|
||||
<PrincipalMenu />
|
||||
</Drawer>
|
||||
<Grid container style={{ flexGrow: 1 }}>
|
||||
<Grid item xs={12} style={{ flexGrow: 1, height: '100%' }}>
|
||||
{children}
|
||||
</Grid>
|
||||
<Grid
|
||||
item
|
||||
xs={12}
|
||||
className={'footer'}
|
||||
style={{ bottom: 0, position: 'sticky' }}
|
||||
>
|
||||
<Footer />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box>
|
||||
);
|
||||
|
||||
InternalLayout.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
PropTypes.node,
|
||||
PropTypes.string
|
||||
]),
|
||||
display: PropTypes.bool,
|
||||
displayMenu: PropTypes.func,
|
||||
title: PropTypes.string
|
||||
};
|
||||
|
||||
InternalLayout.defaultProps = {
|
||||
children: [],
|
||||
display: false,
|
||||
displayMenu: () => undefined,
|
||||
title: ''
|
||||
};
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { General } = state;
|
||||
return {
|
||||
display: General.displayMenu
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
displayMenu: display => dispatch(showMenu(display))
|
||||
});
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(InternalLayout);
|
||||
@@ -0,0 +1,116 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { useState, createContext as CreateContext } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Select } from '@material-ui/core';
|
||||
import { sprintf } from 'sprintf-js';
|
||||
import root from 'window-or-global';
|
||||
import { translations, defaultLang } from '../../../config/defaults';
|
||||
|
||||
const langDefault = defaultLang;
|
||||
const TranslateContext = new CreateContext();
|
||||
|
||||
const TranslateProvider = ({ children }) => {
|
||||
const [current, setCurrent] = useState(langDefault);
|
||||
|
||||
const changeLang = (lang = langDefault) => {
|
||||
setCurrent(lang);
|
||||
};
|
||||
|
||||
const value = {
|
||||
currentLang: current,
|
||||
changeLang
|
||||
};
|
||||
|
||||
return (
|
||||
<TranslateContext.Provider value={value}>
|
||||
{children}
|
||||
</TranslateContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
const Tr = (str = '', fixedValues) => {
|
||||
let rtn = str;
|
||||
if (root && root.locale && root.locale[str]) {
|
||||
const translate = root.locale[str];
|
||||
rtn = translate;
|
||||
if (!!fixedValues && Array.isArray(fixedValues)) {
|
||||
rtn = sprintf(translate, ...fixedValues);
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const Translate = ({ word, values }) => {
|
||||
const handleChange = (e, changeLang) => {
|
||||
if (
|
||||
e &&
|
||||
e.target &&
|
||||
e.target.value &&
|
||||
changeLang &&
|
||||
typeof changeLang === 'function'
|
||||
) {
|
||||
changeLang(e.target.value);
|
||||
}
|
||||
};
|
||||
|
||||
const selector = current => {
|
||||
if (!word && current.changeLang) {
|
||||
const languages = Object.keys(translations);
|
||||
return (
|
||||
<Select
|
||||
native
|
||||
type="select"
|
||||
onChange={e => handleChange(e, current.changeLang)}
|
||||
>
|
||||
{languages.map(language => (
|
||||
<option
|
||||
value={language}
|
||||
key={language}
|
||||
>{`${translations[language]} (${language})`}</option>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
const valuesTr = !!values && !Array.isArray(values) ? [values] : values;
|
||||
return Tr(word, valuesTr);
|
||||
};
|
||||
|
||||
return <TranslateContext.Consumer>{selector}</TranslateContext.Consumer>;
|
||||
};
|
||||
|
||||
TranslateProvider.propTypes = {
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.arrayOf(PropTypes.node),
|
||||
PropTypes.node
|
||||
])
|
||||
};
|
||||
|
||||
TranslateProvider.defaultProps = {
|
||||
children: []
|
||||
};
|
||||
|
||||
Translate.propTypes = {
|
||||
word: PropTypes.string,
|
||||
values: PropTypes.oneOfType([PropTypes.string, PropTypes.array])
|
||||
};
|
||||
|
||||
Translate.defaultProps = {
|
||||
word: '',
|
||||
values: ''
|
||||
};
|
||||
|
||||
export { TranslateContext, TranslateProvider, Translate, Tr };
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import AuthLayout from './AuthLayout';
|
||||
import InternalLayout from './InternalLayout';
|
||||
import {
|
||||
TranslateContext,
|
||||
TranslateProvider,
|
||||
Translate,
|
||||
Tr
|
||||
} from './Translate';
|
||||
|
||||
export {
|
||||
AuthLayout,
|
||||
InternalLayout,
|
||||
TranslateContext,
|
||||
TranslateProvider,
|
||||
Translate,
|
||||
Tr
|
||||
};
|
||||
@@ -0,0 +1,26 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
|
||||
function Dashboard() {
|
||||
return (
|
||||
<div>
|
||||
<h2>Dashboard</h2>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Dashboard;
|
||||
@@ -0,0 +1,28 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { Fragment } from 'react';
|
||||
import { Translate } from '../../HOC/Translate';
|
||||
import constants from '../../../constants';
|
||||
|
||||
const { NoFound } = constants;
|
||||
const Error404 = props =>
|
||||
props.children || (
|
||||
<Fragment>
|
||||
<Translate word={NoFound} />
|
||||
</Fragment>
|
||||
);
|
||||
|
||||
export default Error404;
|
||||
@@ -0,0 +1,31 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import { Grid, Link } from '@material-ui/core';
|
||||
import classnames from 'classnames';
|
||||
import constants from '../../../constants';
|
||||
|
||||
const { by } = constants;
|
||||
const { text, url } = by;
|
||||
const Footer = () => (
|
||||
<Grid className={classnames('footer')}>
|
||||
<Grid item>
|
||||
<Link href={url}>{text}</Link>
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
|
||||
export default Footer;
|
||||
@@ -0,0 +1,118 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { useState, useRef, Fragment } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Popper,
|
||||
Grow,
|
||||
Paper,
|
||||
MenuItem,
|
||||
MenuList,
|
||||
ClickAwayListener,
|
||||
Divider
|
||||
} from '@material-ui/core';
|
||||
import AccountCircleIcon from '@material-ui/icons/AccountCircle';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Translate } from '../../HOC';
|
||||
import constants from '../../../constants';
|
||||
|
||||
const User = props => {
|
||||
const { SignOut, Language, Groups } = constants;
|
||||
const [open, setOpen] = useState(false);
|
||||
const anchorRef = useRef(null);
|
||||
const { current } = anchorRef;
|
||||
const handleToggle = () => {
|
||||
setOpen(prevOpen => !prevOpen);
|
||||
};
|
||||
const handleClose = e => {
|
||||
if (current && current.contains(e.target)) {
|
||||
return;
|
||||
}
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<Button
|
||||
ref={anchorRef}
|
||||
color="inherit"
|
||||
aria-controls={open ? 'menu-list-grow' : undefined}
|
||||
aria-haspopup="true"
|
||||
onClick={handleToggle}
|
||||
>
|
||||
<AccountCircleIcon />
|
||||
</Button>
|
||||
<Popper
|
||||
open={open}
|
||||
anchorEl={current}
|
||||
role={undefined}
|
||||
transition
|
||||
disablePortal
|
||||
>
|
||||
{({ TransitionProps, placement }) => (
|
||||
<Grow
|
||||
{...TransitionProps}
|
||||
style={{
|
||||
transformOrigin:
|
||||
placement === 'bottom' ? 'center top' : 'center bottom'
|
||||
}}
|
||||
>
|
||||
<Paper>
|
||||
<ClickAwayListener onClickAway={handleClose}>
|
||||
<MenuList autoFocusItem={open} id="menu-list-grow">
|
||||
<MenuItem onClick={handleClose}>Settings</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem onClick={handleClose}>
|
||||
<Translate word={SignOut} />
|
||||
</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem onClick={handleClose}>
|
||||
<Translate word={Groups} />
|
||||
</MenuItem>
|
||||
</MenuList>
|
||||
</ClickAwayListener>
|
||||
</Paper>
|
||||
</Grow>
|
||||
)}
|
||||
</Popper>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
User.propTypes = {
|
||||
logoff: PropTypes.bool
|
||||
};
|
||||
|
||||
User.defaultProps = {
|
||||
logoff: false
|
||||
};
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { General } = state;
|
||||
return {
|
||||
logoff: General.logoff
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
clearData: display => dispatch(showMenu(display))
|
||||
});
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(User);
|
||||
@@ -0,0 +1,117 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { useState, useRef, Fragment } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Popper,
|
||||
Grow,
|
||||
Paper,
|
||||
MenuItem,
|
||||
MenuList,
|
||||
ClickAwayListener,
|
||||
Divider
|
||||
} from '@material-ui/core';
|
||||
import LanguageIcon from '@material-ui/icons/Language';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import { Translate } from '../../HOC';
|
||||
import constants from '../../../constants';
|
||||
|
||||
const Zone = () => {
|
||||
const { SignOut, Language, Groups } = constants;
|
||||
const [open, setOpen] = useState(false);
|
||||
const anchorRef = useRef(null);
|
||||
const { current } = anchorRef;
|
||||
const handleToggle = () => {
|
||||
setOpen(prevOpen => !prevOpen);
|
||||
};
|
||||
const handleClose = e => {
|
||||
if (current && current.contains(e.target)) {
|
||||
return;
|
||||
}
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
<Button
|
||||
ref={anchorRef}
|
||||
color="inherit"
|
||||
aria-controls={open ? 'menu-list-grow' : undefined}
|
||||
aria-haspopup="true"
|
||||
onClick={handleToggle}
|
||||
>
|
||||
<LanguageIcon />
|
||||
pepe
|
||||
</Button>
|
||||
<Popper
|
||||
open={open}
|
||||
anchorEl={current}
|
||||
role={undefined}
|
||||
transition
|
||||
disablePortal
|
||||
>
|
||||
{({ TransitionProps, placement }) => (
|
||||
<Grow
|
||||
{...TransitionProps}
|
||||
style={{
|
||||
transformOrigin:
|
||||
placement === 'bottom' ? 'center top' : 'center bottom'
|
||||
}}
|
||||
>
|
||||
<Paper>
|
||||
<ClickAwayListener onClickAway={handleClose}>
|
||||
<MenuList autoFocusItem={open} id="menu-list-grow">
|
||||
<MenuItem onClick={handleClose}>Settings</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem onClick={handleClose}>
|
||||
<Translate word={SignOut} />
|
||||
</MenuItem>
|
||||
<Divider />
|
||||
<MenuItem onClick={handleClose}>
|
||||
<Translate word={Groups} />
|
||||
</MenuItem>
|
||||
</MenuList>
|
||||
</ClickAwayListener>
|
||||
</Paper>
|
||||
</Grow>
|
||||
)}
|
||||
</Popper>
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
Zone.propTypes = {
|
||||
zone: PropTypes.string
|
||||
};
|
||||
|
||||
Zone.defaultProps = {
|
||||
zone: ''
|
||||
};
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { General } = state;
|
||||
return {
|
||||
zone: General.zone
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => ({});
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Zone);
|
||||
@@ -0,0 +1,78 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import { AppBar, Toolbar, IconButton, Typography } from '@material-ui/core';
|
||||
import MenuIcon from '@material-ui/icons/Menu';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import classnames from 'classnames';
|
||||
import User from './User';
|
||||
import Zone from './Zone';
|
||||
import { showMenu } from '../../../actions';
|
||||
|
||||
const Header = ({ display, displayMenu: displayMenuFromProps, title }) => {
|
||||
const displayMenu = () => {
|
||||
displayMenuFromProps(!display);
|
||||
};
|
||||
return (
|
||||
<AppBar position="sticky" className={classnames('header')}>
|
||||
<Toolbar>
|
||||
<IconButton
|
||||
onClick={displayMenu}
|
||||
edge="start"
|
||||
className=""
|
||||
color="inherit"
|
||||
aria-label="menu"
|
||||
>
|
||||
<MenuIcon />
|
||||
</IconButton>
|
||||
<Typography variant="h6" style={{ flexGrow: 1 }}>
|
||||
<b className={classnames('title')}>{title}</b>
|
||||
</Typography>
|
||||
<User />
|
||||
<Zone />
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
);
|
||||
};
|
||||
|
||||
Header.propTypes = {
|
||||
display: PropTypes.bool,
|
||||
displayMenu: PropTypes.func,
|
||||
title: PropTypes.string
|
||||
};
|
||||
|
||||
Header.defaultProps = {
|
||||
display: false,
|
||||
displayMenu: () => undefined,
|
||||
title: ''
|
||||
};
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { General } = state;
|
||||
return {
|
||||
display: General.displayMenu
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
displayMenu: display => dispatch(showMenu(display))
|
||||
});
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Header);
|
||||
@@ -0,0 +1,70 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { createRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import MaterialTable from 'one-datatable';
|
||||
import { Refresh as RefreshIcon } from '@material-ui/icons';
|
||||
import { Translate } from '../../HOC';
|
||||
import { requestData } from '../../../utils';
|
||||
import HostColumns from './host-columns';
|
||||
|
||||
const Clusters = ({ name }) => {
|
||||
const tableRef = createRef();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<MaterialTable
|
||||
tableRef={tableRef}
|
||||
title={
|
||||
<h2>
|
||||
<Translate word={name} />
|
||||
</h2>
|
||||
}
|
||||
columns={HostColumns.columns}
|
||||
data={query =>
|
||||
new Promise(resolve => {
|
||||
requestData('/api/hostpool/info').then(result => {
|
||||
const values = Object.values(result?.data?.HOST_POOL);
|
||||
resolve({
|
||||
data: values,
|
||||
page: query.page,
|
||||
totalCount: values.length
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
actions={[
|
||||
{
|
||||
icon: () => <RefreshIcon />,
|
||||
tooltip: 'Refresh Data',
|
||||
isFreeAction: true,
|
||||
onClick: () => tableRef?.current?.onQueryChange()
|
||||
}
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Clusters.propTypes = {
|
||||
name: PropTypes.string
|
||||
};
|
||||
|
||||
Clusters.defaultProps = {
|
||||
name: ''
|
||||
};
|
||||
|
||||
export default Clusters;
|
||||
@@ -0,0 +1,71 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { createRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import MaterialTable from 'one-datatable';
|
||||
import { Refresh as RefreshIcon } from '@material-ui/icons';
|
||||
|
||||
import { Translate } from '../../HOC';
|
||||
import { requestData } from '../../../utils';
|
||||
import HostColumns from './host-columns';
|
||||
|
||||
const Hosts = ({ name }) => {
|
||||
const tableRef = createRef();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<MaterialTable
|
||||
tableRef={tableRef}
|
||||
title={
|
||||
<h2>
|
||||
<Translate word={name} />
|
||||
</h2>
|
||||
}
|
||||
columns={HostColumns.columns}
|
||||
data={query =>
|
||||
new Promise(resolve => {
|
||||
requestData('/api/hostpool/info').then(result => {
|
||||
const values = Object.values(result?.data?.HOST_POOL);
|
||||
resolve({
|
||||
data: values,
|
||||
page: query.page,
|
||||
totalCount: values.length
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
actions={[
|
||||
{
|
||||
icon: () => <RefreshIcon />,
|
||||
tooltip: 'Refresh Data',
|
||||
isFreeAction: true,
|
||||
onClick: () => tableRef?.current?.onQueryChange()
|
||||
}
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Hosts.propTypes = {
|
||||
name: PropTypes.string
|
||||
};
|
||||
|
||||
Hosts.defaultProps = {
|
||||
name: ''
|
||||
};
|
||||
|
||||
export default Hosts;
|
||||
@@ -0,0 +1,69 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { createRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import MaterialTable from 'one-datatable';
|
||||
import { Refresh as RefreshIcon } from '@material-ui/icons';
|
||||
|
||||
import { Translate } from '../../HOC';
|
||||
import { requestData } from '../../../utils';
|
||||
import HostColumns from './host-columns';
|
||||
|
||||
const Zones = ({ name }) => {
|
||||
const tableRef = createRef();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<MaterialTable
|
||||
tableRef={tableRef}
|
||||
title={
|
||||
<h2>
|
||||
<Translate word={name} />
|
||||
</h2>
|
||||
}
|
||||
columns={HostColumns.columns}
|
||||
data={query =>
|
||||
new Promise(resolve => {
|
||||
requestData('/api/hostpool/info').then(result => {
|
||||
const values = Object.values(result?.data?.HOST_POOL);
|
||||
resolve({
|
||||
data: values,
|
||||
page: query.page,
|
||||
totalCount: values.length
|
||||
});
|
||||
});
|
||||
})
|
||||
}
|
||||
actions={[
|
||||
{
|
||||
icon: () => <RefreshIcon />,
|
||||
tooltip: 'Refresh Data',
|
||||
isFreeAction: true,
|
||||
onClick: () => tableRef?.current?.onQueryChange()
|
||||
}
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Zones.propTypes = {
|
||||
name: PropTypes.string
|
||||
};
|
||||
|
||||
Zones.defaultProps = {
|
||||
name: ''
|
||||
};
|
||||
export default Zones;
|
||||
@@ -0,0 +1,86 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import { LinearProgress } from '@material-ui/core';
|
||||
|
||||
const statusBar = (title, ratio) => (
|
||||
<div>
|
||||
{title}
|
||||
<LinearProgress variant="determinate" value={ratio} />
|
||||
</div>
|
||||
);
|
||||
|
||||
function format(size) {
|
||||
if (typeof size !== 'number' || size === 0) {
|
||||
return '0';
|
||||
}
|
||||
const baseLog = Math.floor(Math.log(size) / Math.log(1024));
|
||||
console.log(baseLog);
|
||||
return `${(size / 1024 ** baseLog).toFixed(2) * 1}${
|
||||
['kB', 'MB', 'GB', 'TB'][baseLog]
|
||||
}`;
|
||||
}
|
||||
|
||||
export default {
|
||||
columns: [
|
||||
{ title: 'ID', field: 'ID' },
|
||||
{ title: 'Name', field: 'NAME' },
|
||||
{ title: 'Cluster', field: 'CLUSTER' },
|
||||
{ title: 'RVMs', field: 'HOST_SHARE.RUNNING_VMS', type: 'numeric' },
|
||||
{
|
||||
title: 'Allocated CPU',
|
||||
field: 'HOST_SHARE.MAX_CPU',
|
||||
type: 'numeric',
|
||||
render: row => {
|
||||
const usage = parseInt(row?.HOST_SHARE?.CPU_USAGE, 10);
|
||||
const max = parseInt(row?.HOST_SHARE?.MAX_CPU, 10);
|
||||
const ratio = Math.round((usage / max) * 100);
|
||||
const info = `${format(usage)} / ${format(max)} (${ratio}%)`;
|
||||
return statusBar(info, ratio);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Allocated MEM',
|
||||
field: 'HOST_SHARE.MAX_MEM',
|
||||
type: 'numeric',
|
||||
render: row => {
|
||||
console.log(row);
|
||||
const usage = parseInt(row?.HOST_SHARE?.MEM_USAGE, 10);
|
||||
const max = parseInt(row?.HOST_SHARE?.MAX_MEM, 10);
|
||||
const ratio = Math.round((usage / max) * 100);
|
||||
const info = `${format(usage)} / ${format(max)} (${ratio}%)`;
|
||||
return statusBar(info, ratio);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: 'Status',
|
||||
field: 'STATE',
|
||||
lookup: {
|
||||
'0': 'INIT',
|
||||
'1': 'UPDATE',
|
||||
'2': 'ON',
|
||||
'3': 'ERROR',
|
||||
'4': 'DISABLED',
|
||||
'5': 'RETRY',
|
||||
'6': 'INIT',
|
||||
'7': 'DISABLED',
|
||||
'8': 'OFF'
|
||||
}
|
||||
},
|
||||
{ title: 'IM MAD', field: 'IM_MAD' },
|
||||
{ title: 'VM MAD', field: 'VM_MAD' }
|
||||
]
|
||||
};
|
||||
@@ -0,0 +1,20 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import Clusters from './Clusters';
|
||||
import Hosts from './Hosts';
|
||||
import Zones from './Zones';
|
||||
|
||||
export { Clusters, Hosts, Zones };
|
||||
@@ -0,0 +1,238 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { Fragment, useState } from 'react';
|
||||
|
||||
import {
|
||||
Button,
|
||||
TextField,
|
||||
Box,
|
||||
FormControlLabel,
|
||||
Checkbox,
|
||||
Grid
|
||||
} from '@material-ui/core';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import constants from '../../../constants';
|
||||
import { endpoints as routerEndpoints } from '../../../components/router';
|
||||
import { requestData, removeStoreData, storage } from '../../../utils';
|
||||
import { Translate, Tr } from '../../HOC';
|
||||
|
||||
const { SignIn, Username, Password, keepLoggedIn, Token2FA } = constants;
|
||||
|
||||
const Login = ({ history, baseURL }) => {
|
||||
const [user, setUser] = useState('');
|
||||
const [pass, setPass] = useState('');
|
||||
const [token, setToken] = useState('');
|
||||
const [writeToken, setWriteToken] = useState(false);
|
||||
const [showError, setShowError] = useState(false);
|
||||
const [keepLogged, setKeepLogged] = useState(false);
|
||||
|
||||
const handleChange = (type = '', element) => {
|
||||
if (
|
||||
element &&
|
||||
element.preventDefault &&
|
||||
element.target &&
|
||||
element.target.type &&
|
||||
type
|
||||
) {
|
||||
if (showError) {
|
||||
setShowError(!showError);
|
||||
}
|
||||
const { target } = element;
|
||||
switch (type) {
|
||||
case 'user':
|
||||
setUser(target.value);
|
||||
break;
|
||||
case 'pass':
|
||||
setPass(target.value);
|
||||
break;
|
||||
case 'token':
|
||||
setToken(target.value);
|
||||
break;
|
||||
case 'keepLogged':
|
||||
setKeepLogged(!keepLogged);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const handleSubmit = element => {
|
||||
const { jwtName, endpointsRoutes } = constants;
|
||||
const loginParams = {
|
||||
data: { user, pass },
|
||||
method: 'POST',
|
||||
authenticate: false,
|
||||
baseURL
|
||||
};
|
||||
if (writeToken && token) {
|
||||
loginParams.data.token = token;
|
||||
}
|
||||
if (element && element.preventDefault) {
|
||||
element.preventDefault();
|
||||
if (user && pass) {
|
||||
removeStoreData(jwtName);
|
||||
requestData(endpointsRoutes.login, loginParams).then(response => {
|
||||
if (response && response.data) {
|
||||
const { id, data } = response;
|
||||
const { token: opennebulaToken, message } = data;
|
||||
setShowError(false);
|
||||
if (id === 401 && message) {
|
||||
setWriteToken(true);
|
||||
} else if (id === 200 && opennebulaToken) {
|
||||
setWriteToken(false);
|
||||
storage(jwtName, opennebulaToken, keepLogged);
|
||||
history.push(routerEndpoints.dashboard.path);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
setShowError(true);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const inputs = writeToken ? (
|
||||
<Grid item xs style={{ marginBottom: '1rem' }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
required
|
||||
label={Tr(Token2FA)}
|
||||
defaultValue={token}
|
||||
autoComplete="off"
|
||||
placeholder={Tr(Token2FA)}
|
||||
onChange={e => {
|
||||
handleChange('token', e);
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
) : (
|
||||
<Fragment>
|
||||
<Grid item xs={12} style={{ marginBottom: '1rem' }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
required
|
||||
label={Tr(Username)}
|
||||
defaultValue={user}
|
||||
autoComplete="off"
|
||||
onChange={e => {
|
||||
handleChange('user', e);
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item xs={12} style={{ marginBottom: '1rem' }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
required
|
||||
label={Tr(Password)}
|
||||
defaultValue={pass}
|
||||
type="password"
|
||||
autoComplete="off"
|
||||
onChange={e => {
|
||||
handleChange('pass', e);
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
</Fragment>
|
||||
);
|
||||
|
||||
return (
|
||||
<Box
|
||||
style={{
|
||||
width: '100%',
|
||||
height: '100vh',
|
||||
justifyContent: 'center',
|
||||
display: 'flex',
|
||||
alignItems: 'center'
|
||||
}}
|
||||
>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<Grid container>
|
||||
{inputs}
|
||||
<Grid item xs={12}>
|
||||
<Grid
|
||||
container
|
||||
direction="row"
|
||||
justify="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<Grid item md={6} style={{ textAlign: 'center' }}>
|
||||
<FormControlLabel
|
||||
control={
|
||||
<Checkbox
|
||||
checked={keepLogged}
|
||||
onChange={e => {
|
||||
handleChange('keepLogged', e);
|
||||
}}
|
||||
color="primary"
|
||||
/>
|
||||
}
|
||||
label={Tr(keepLoggedIn)}
|
||||
/>
|
||||
</Grid>
|
||||
<Grid item md={6} style={{ textAlign: 'center' }}>
|
||||
<Button variant="contained" color="primary" type="submit">
|
||||
<Translate word={SignIn} />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</form>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
Login.propTypes = {
|
||||
baseURL: PropTypes.string,
|
||||
history: PropTypes.shape({
|
||||
push: PropTypes.func
|
||||
}),
|
||||
match: PropTypes.shape({
|
||||
params: PropTypes.shape({}),
|
||||
path: PropTypes.string,
|
||||
isExact: PropTypes.bool,
|
||||
url: PropTypes.string
|
||||
})
|
||||
};
|
||||
|
||||
Login.defaultProps = {
|
||||
baseURL: '',
|
||||
history: {
|
||||
push: () => undefined
|
||||
},
|
||||
match: {
|
||||
params: {},
|
||||
path: '',
|
||||
isExact: false,
|
||||
url: ''
|
||||
}
|
||||
};
|
||||
|
||||
const mapStateToProps = state => {
|
||||
const { System } = state;
|
||||
return {
|
||||
baseURL: System.baseURL
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = () => ({});
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
mapDispatchToProps
|
||||
)(Login);
|
||||
@@ -0,0 +1,18 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import Login from './Login';
|
||||
|
||||
export default Login;
|
||||
@@ -0,0 +1,116 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Grid,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemText,
|
||||
ExpansionPanel,
|
||||
ExpansionPanelSummary,
|
||||
ExpansionPanelDetails,
|
||||
Divider
|
||||
} from '@material-ui/core';
|
||||
import classnames from 'classnames';
|
||||
import { Link } from 'react-router-dom';
|
||||
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
|
||||
import endpoints from '../../router/endpoints';
|
||||
|
||||
const PrincipalMenu = () => {
|
||||
const [expanded, setExpanded] = useState('');
|
||||
|
||||
const handleChange = panel => (event, newExpanded) => {
|
||||
setExpanded(newExpanded ? panel : false);
|
||||
};
|
||||
|
||||
const routeElement = (title = '', { path = '/', menu = true }) =>
|
||||
menu && (
|
||||
<ListItem key={`menu-key-${title}`}>
|
||||
<ListItemText
|
||||
primary={
|
||||
<Link
|
||||
to={path}
|
||||
className={classnames(
|
||||
'link',
|
||||
'MuiTypography-root',
|
||||
'MuiLink-root',
|
||||
'MuiLink-underlineHover',
|
||||
'MuiTypography-colorPrimary'
|
||||
)}
|
||||
>
|
||||
{title.replace('_', ' ')}
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
</ListItem>
|
||||
);
|
||||
|
||||
const routeElements = (title = '', routes = {}) => {
|
||||
const internal = Object.entries(routes)?.map(
|
||||
([internalTitle, internalRoutes]) =>
|
||||
internalRoutes.component && routeElement(internalTitle, internalRoutes)
|
||||
);
|
||||
|
||||
return (
|
||||
internal.some(components => components !== undefined) && (
|
||||
<ExpansionPanel
|
||||
square
|
||||
expanded={expanded === title}
|
||||
onChange={handleChange(title)}
|
||||
key={`menu-key-${title}`}
|
||||
>
|
||||
<ExpansionPanelSummary
|
||||
aria-controls="panel1d-content"
|
||||
id="panel1d-header"
|
||||
expandIcon={<ExpandMoreIcon />}
|
||||
className={classnames('link')}
|
||||
>
|
||||
{title.replace('_', ' ')}
|
||||
</ExpansionPanelSummary>
|
||||
<ExpansionPanelDetails className={classnames('internalNav')}>
|
||||
<List disablePadding style={{ width: '100%' }}>
|
||||
{internal}
|
||||
</List>
|
||||
</ExpansionPanelDetails>
|
||||
</ExpansionPanel>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={classnames('menu')}>
|
||||
<Grid container>
|
||||
<Grid item className={classnames('logo-wrapper')}>
|
||||
<img
|
||||
className={classnames('logo')}
|
||||
src="/static/logo.png"
|
||||
alt="Opennebula"
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Divider />
|
||||
<List>
|
||||
{Object.entries(endpoints)?.map(([title, routes]) =>
|
||||
routes.component
|
||||
? routeElement(title, routes)
|
||||
: routeElements(title, routes)
|
||||
)}
|
||||
</List>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default PrincipalMenu;
|
||||
@@ -0,0 +1,27 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import { Translate } from '../../HOC';
|
||||
import constants from '../../../constants';
|
||||
|
||||
const { settings } = constants;
|
||||
const Settings = () => (
|
||||
<div>
|
||||
<Translate word={settings} />
|
||||
</div>
|
||||
);
|
||||
|
||||
export default Settings;
|
||||
@@ -0,0 +1,301 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
TextField,
|
||||
Grid,
|
||||
Container,
|
||||
FormControl,
|
||||
InputLabel,
|
||||
Select,
|
||||
MenuItem
|
||||
} from '@material-ui/core';
|
||||
import PropTypes from 'prop-types';
|
||||
import constants from '../../../constants';
|
||||
import commands from '../../../../config/commands-params';
|
||||
import { requestData } from '../../../utils';
|
||||
import { Translate, Tr } from '../../HOC';
|
||||
|
||||
const { Submit, Response } = constants;
|
||||
|
||||
const InputsComponents = ({ name, value, onChange }) => (
|
||||
<Grid item>
|
||||
<TextField
|
||||
key={`api-key-${name}`}
|
||||
name={name}
|
||||
label={name}
|
||||
multiline
|
||||
rows="4"
|
||||
defaultValue={value}
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
style={{ width: '100%', marginBottom: '1rem' }}
|
||||
onChange={e => {
|
||||
onChange(e?.target?.value || '', name);
|
||||
}}
|
||||
/>
|
||||
</Grid>
|
||||
);
|
||||
InputsComponents.propTypes = {
|
||||
name: PropTypes.string,
|
||||
value: PropTypes.oneOfType([
|
||||
PropTypes.string,
|
||||
PropTypes.bool,
|
||||
PropTypes.number,
|
||||
PropTypes.array
|
||||
]),
|
||||
onChange: PropTypes.func
|
||||
};
|
||||
|
||||
InputsComponents.defaultProps = {
|
||||
name: '',
|
||||
value: '',
|
||||
onChange: () => undefined
|
||||
};
|
||||
|
||||
const ResponseComponent = ({ data = '' }) => (
|
||||
<TextField
|
||||
disabled
|
||||
label={Tr(Response)}
|
||||
multiline
|
||||
rows="4"
|
||||
value={data}
|
||||
variant="outlined"
|
||||
fullWidth
|
||||
InputProps={{ style: { height: '100%' } }}
|
||||
// eslint-disable-next-line react/jsx-no-duplicate-props
|
||||
inputProps={{ style: { height: '100%' } }}
|
||||
style={{ height: '100%' }}
|
||||
/>
|
||||
);
|
||||
ResponseComponent.propTypes = {
|
||||
data: PropTypes.string
|
||||
};
|
||||
|
||||
ResponseComponent.defaultProps = {
|
||||
data: ''
|
||||
};
|
||||
|
||||
const FormComponent = ({ title = '', params = {}, method = 'GET' }) => {
|
||||
const [data, setData] = useState('');
|
||||
const [paramsState, setParamsState] = useState(params);
|
||||
const handleValue = (value, name) => {
|
||||
paramsState[name] = { ...paramsState[name], value };
|
||||
setParamsState(paramsState);
|
||||
};
|
||||
|
||||
const body = () => {
|
||||
const rtn = {};
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
Object.entries(paramsState)?.forEach(([name, value]) => {
|
||||
if (value?.from === 'POST_BODY') {
|
||||
rtn[name] = value.value || value.default;
|
||||
}
|
||||
});
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const query = () => {
|
||||
let rtn = '';
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
Object.entries(paramsState)?.forEach(([name, value]) => {
|
||||
if (value?.from === 'QUERY') {
|
||||
rtn += `${rtn.length ? '&' : ''}${name}=${encodeURI(
|
||||
value.value || value.default
|
||||
)}`;
|
||||
}
|
||||
});
|
||||
return `?${rtn}`;
|
||||
};
|
||||
|
||||
const resource = () => {
|
||||
let rtn = '';
|
||||
// eslint-disable-next-line no-unused-expressions
|
||||
Object.entries(paramsState)?.forEach(([name, value]) => {
|
||||
if (value?.from === 'RESOURCE') {
|
||||
rtn = `/${value.value || value.default}`;
|
||||
}
|
||||
});
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const postParams = {
|
||||
data: body(),
|
||||
method,
|
||||
authenticate: true
|
||||
};
|
||||
|
||||
const url = () => `api/${title.replace('.', '/') + resource() + query()}`;
|
||||
|
||||
const handleSubmit = e => {
|
||||
if (e && e.preventDefault) {
|
||||
e.preventDefault();
|
||||
requestData(url(), postParams).then(response => {
|
||||
if (response && response.id) {
|
||||
const { id } = response;
|
||||
if (id === 401) {
|
||||
console.log('ERROR');
|
||||
} else if (id === 200) {
|
||||
setData(JSON.stringify(response));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs>
|
||||
<form onSubmit={e => handleSubmit(e, method)} autoComplete="off">
|
||||
<Grid container direction="column">
|
||||
{Object.entries(paramsState)?.map(([name, paramState]) => {
|
||||
const { default: defaultValue, value } = paramState;
|
||||
return (
|
||||
<InputsComponents
|
||||
name={name}
|
||||
value={value || defaultValue}
|
||||
key={`form-api-${name}`}
|
||||
onChange={handleValue}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
<Grid item style={{ textAlign: 'right' }}>
|
||||
<Button variant="contained" color="primary" type="submit">
|
||||
<Translate word={Submit} />
|
||||
</Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</form>
|
||||
</Grid>
|
||||
<Grid item xs>
|
||||
<ResponseComponent data={data} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
FormComponent.propTypes = {
|
||||
title: PropTypes.string,
|
||||
params: PropTypes.shape({}),
|
||||
method: PropTypes.string
|
||||
};
|
||||
|
||||
FormComponent.defaultProps = {
|
||||
title: '',
|
||||
params: {},
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
const Group = ({ title = '', params = {}, method = 'GET' }) => (
|
||||
<Grid item xs={12} style={{ marginBottom: '2rem' }}>
|
||||
<h2>{title}</h2>
|
||||
<FormComponent title={title} params={params} method={method} />
|
||||
</Grid>
|
||||
);
|
||||
Group.propTypes = {
|
||||
title: PropTypes.string,
|
||||
params: PropTypes.shape({}),
|
||||
method: PropTypes.string
|
||||
};
|
||||
|
||||
Group.defaultProps = {
|
||||
title: '',
|
||||
params: {},
|
||||
method: 'GET'
|
||||
};
|
||||
|
||||
const Selector = ({ selected = '', setActionSelected = () => undefined }) => {
|
||||
const handleChange = e => {
|
||||
setActionSelected(e?.target?.value || '');
|
||||
};
|
||||
return (
|
||||
<FormControl variant="outlined" fullWidth>
|
||||
<InputLabel>
|
||||
<Translate word="Select Action" />
|
||||
</InputLabel>
|
||||
<Select
|
||||
labelId="demo-simple-select-outlined-label"
|
||||
id="select-action"
|
||||
value={selected}
|
||||
onChange={handleChange}
|
||||
label={Tr('Select Action')}
|
||||
>
|
||||
<MenuItem value="">
|
||||
<Translate word="none" />
|
||||
</MenuItem>
|
||||
{Object.keys(commands)?.map(action => (
|
||||
<MenuItem key={`selector-action-${action}`} value={action}>
|
||||
{action}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
);
|
||||
};
|
||||
Selector.propTypes = {
|
||||
selected: PropTypes.string,
|
||||
setActionSelected: PropTypes.func
|
||||
};
|
||||
|
||||
Selector.defaultProps = {
|
||||
selected: '',
|
||||
setActionSelected: () => undefined
|
||||
};
|
||||
|
||||
const RenderAction = ({ selected }) => {
|
||||
let rtn = '';
|
||||
if (selected && commands[selected]) {
|
||||
const values = commands[selected];
|
||||
const method = (values && values.httpMethod) || 'GET';
|
||||
const params = values && values.params;
|
||||
rtn = (
|
||||
<Group
|
||||
title={selected}
|
||||
params={params}
|
||||
method={method}
|
||||
key={`group-api${selected}`}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
RenderAction.propTypes = {
|
||||
selected: PropTypes.string
|
||||
};
|
||||
RenderAction.defaultProps = {
|
||||
selected: ''
|
||||
};
|
||||
|
||||
const TestApi = () => {
|
||||
const [actionSelected, setActionSelected] = useState('');
|
||||
return (
|
||||
<Container>
|
||||
<Grid container direction="row">
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs style={{ padding: '2rem 0' }}>
|
||||
<Selector
|
||||
selected={actionSelected}
|
||||
setActionSelected={setActionSelected}
|
||||
/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<RenderAction selected={actionSelected} />
|
||||
</Grid>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestApi;
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { Component } from 'react';
|
||||
import { w3cwebsocket as W3CWebSocket } from 'websocket';
|
||||
import JSONPretty from 'react-json-pretty';
|
||||
import { messageTerminal } from '../../../../utils/general-functions';
|
||||
|
||||
class WSConsole extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
data: ''
|
||||
};
|
||||
}
|
||||
|
||||
componentWillMount() {
|
||||
const client = new W3CWebSocket(
|
||||
'ws://127.0.0.1:3000?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIwIiwiYXVkIjoib25lYWRtaW4iLCJqdGkiOiJkYzNjMmJkMDhlODM3MmU0NWY5MDVmNjE0ZjdkMDE0YmQ2ZmE3ZTVjYjlmNjU1OTRjNjRjYzMzZjNiYmYxY2IyIiwiaWF0IjoxNTY5MjIxOTgwLCJleHAiOjE1NzA0MzE1ODB9.ESxu8xeGNVQCAJ2T5-93y2cWofXCNxvsAdT0Jt5Qt5I'
|
||||
);
|
||||
|
||||
client.onopen = () => {
|
||||
const config = {
|
||||
color: 'green',
|
||||
type: 'ERROR',
|
||||
message: 'WebSocket Client Connected'
|
||||
};
|
||||
messageTerminal(config);
|
||||
};
|
||||
|
||||
client.onmessage = message => {
|
||||
if (message && message.data) {
|
||||
this.setState({
|
||||
data: JSON.parse(message.data)
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
const { data } = this.state;
|
||||
return <JSONPretty id="json-pretty" data={data} />;
|
||||
}
|
||||
}
|
||||
|
||||
export default WSConsole;
|
||||
@@ -0,0 +1,18 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import WSConsole from './WSConsole';
|
||||
|
||||
export default { WSConsole };
|
||||
@@ -0,0 +1,74 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import Login from './login';
|
||||
import Settings from '../containers/Settings';
|
||||
import TestApi from '../containers/TestApi';
|
||||
import Dashboard from '../containers/Dashboard';
|
||||
import { Clusters, Hosts, Zones } from '../containers/Infrastructure';
|
||||
|
||||
const endpoints = {
|
||||
login: {
|
||||
path: '/',
|
||||
authenticated: false,
|
||||
menu: false,
|
||||
component: Login
|
||||
},
|
||||
dashboard: {
|
||||
path: '/dashboard',
|
||||
component: () => <Dashboard />
|
||||
},
|
||||
settings: {
|
||||
path: '/settings',
|
||||
component: () => <Settings />
|
||||
},
|
||||
test_api: {
|
||||
path: '/test-api',
|
||||
component: () => <TestApi />
|
||||
},
|
||||
// infrastructure
|
||||
infrastructure: {
|
||||
clusters: {
|
||||
path: '/clusters',
|
||||
component: () => <Clusters />
|
||||
},
|
||||
hosts: {
|
||||
path: '/hosts',
|
||||
component: () => <Hosts />
|
||||
},
|
||||
zones: {
|
||||
path: '/zones',
|
||||
component: () => <Zones />
|
||||
}
|
||||
},
|
||||
// networks
|
||||
networks: {
|
||||
vnets: {
|
||||
path: '/vnets'
|
||||
},
|
||||
vnets_templates: {
|
||||
path: '/vnets-templates'
|
||||
},
|
||||
vnets_topology: {
|
||||
path: '/vnets-topology'
|
||||
},
|
||||
vnets_secgroup: {
|
||||
path: '/secgroup'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default endpoints;
|
||||
@@ -0,0 +1,61 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React, { createElement } from 'react';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import { AuthLayout } from '../HOC';
|
||||
import Error404 from '../containers/Error404';
|
||||
import InternalLayout from '../HOC/InternalLayout';
|
||||
import endpoints from './endpoints';
|
||||
|
||||
const routeElement = (
|
||||
title = '',
|
||||
{ path = '/', authenticated = true, component }
|
||||
) => (
|
||||
<Route
|
||||
key={`key-${title.replace(' ', '-')}`}
|
||||
exact
|
||||
path={path}
|
||||
component={({ match, history }) =>
|
||||
authenticated ? (
|
||||
<AuthLayout history={history} match={match}>
|
||||
<InternalLayout title={title.replace('_', ' ')}>
|
||||
{createElement(component)}
|
||||
</InternalLayout>
|
||||
</AuthLayout>
|
||||
) : (
|
||||
createElement(component, { history, match })
|
||||
)
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
function Routes() {
|
||||
return (
|
||||
<Switch>
|
||||
{Object.entries(endpoints)?.map(([title, routes]) =>
|
||||
routes.component
|
||||
? routeElement(title, routes)
|
||||
: Object.entries(routes)?.map(([internalTitle, route]) =>
|
||||
routeElement(internalTitle, route)
|
||||
)
|
||||
)}
|
||||
<Route component={() => <Error404 />} />
|
||||
</Switch>
|
||||
);
|
||||
}
|
||||
|
||||
export default Routes;
|
||||
export { endpoints };
|
||||
@@ -0,0 +1,47 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import LoginComponent from '../containers/Login';
|
||||
|
||||
const Login = ({ history, match }) => (
|
||||
<LoginComponent history={history} match={match} />
|
||||
);
|
||||
|
||||
Login.propTypes = {
|
||||
history: PropTypes.shape({
|
||||
push: PropTypes.func
|
||||
}),
|
||||
match: PropTypes.shape({
|
||||
params: PropTypes.shape({}),
|
||||
path: PropTypes.string,
|
||||
isExact: PropTypes.bool,
|
||||
url: PropTypes.string
|
||||
})
|
||||
};
|
||||
|
||||
Login.defaultProps = {
|
||||
history: {
|
||||
push: () => undefined
|
||||
},
|
||||
match: {
|
||||
params: {},
|
||||
path: '',
|
||||
isExact: false,
|
||||
url: ''
|
||||
}
|
||||
};
|
||||
export default Login;
|
||||
@@ -0,0 +1,38 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
module.exports = {
|
||||
checkbox: 'checkbox',
|
||||
classInputInvalid: 'is-invalid',
|
||||
NoFound: 'No found',
|
||||
SignIn: 'Sign In',
|
||||
Language: 'Language',
|
||||
Username: 'Username',
|
||||
Password: 'Password',
|
||||
keepLoggedIn: 'Keep me logged in',
|
||||
Token2FA: '2FA Token',
|
||||
SignOut: 'Sign Out',
|
||||
jwtName: 'SunstoneToken',
|
||||
Submit: 'Submit',
|
||||
Respose: 'Response',
|
||||
by: {
|
||||
text: 'Opennebula Systems',
|
||||
url: 'https://opennebula.org/'
|
||||
},
|
||||
endpointsRoutes: {
|
||||
login: '/api/auth/',
|
||||
userInfo: '/api/user/info'
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import constants from './constants';
|
||||
|
||||
export default { ...constants };
|
||||
@@ -0,0 +1,35 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import React from 'react';
|
||||
import { hydrate } from 'react-dom';
|
||||
import { createStore } from 'redux';
|
||||
import root from 'window-or-global';
|
||||
import rootReducer from '../public/reducers';
|
||||
import App from './app';
|
||||
|
||||
const preloadedState = root.__PRELOADED_STATE__;
|
||||
|
||||
delete root.__PRELOADED_STATE__;
|
||||
|
||||
const store = createStore(
|
||||
rootReducer(),
|
||||
preloadedState,
|
||||
root.__REDUX_DEVTOOLS_EXTENSION__ && root.__REDUX_DEVTOOLS_EXTENSION__()
|
||||
);
|
||||
|
||||
document.getElementById('preloadState').remove();
|
||||
|
||||
hydrate(<App store={store} />, document.getElementById('root'));
|
||||
@@ -0,0 +1,58 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const initial = {
|
||||
logoff: false,
|
||||
displayMenu: false,
|
||||
zone: 0,
|
||||
loading: true
|
||||
};
|
||||
|
||||
const General = (state = initial, action) => {
|
||||
switch (action.type) {
|
||||
case 'DISPLAY _LOADING': {
|
||||
const { loading } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
loading
|
||||
};
|
||||
}
|
||||
case 'CHANGE_ZONE': {
|
||||
const { zone } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
zone
|
||||
};
|
||||
}
|
||||
case 'LOG_OFF': {
|
||||
const { logoff } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
logoff
|
||||
};
|
||||
}
|
||||
case 'DISPLAY_MENU': {
|
||||
const { displayMenu } = action.payload;
|
||||
return {
|
||||
...state,
|
||||
displayMenu
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = General;
|
||||
@@ -0,0 +1,30 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const { combineReducers } = require('redux');
|
||||
const Opennebula = require('./opennebula');
|
||||
const Zendesk = require('./zendesk');
|
||||
const General = require('./general');
|
||||
const GetConfigSystem = require('./system');
|
||||
|
||||
const rootReducers = config =>
|
||||
combineReducers({
|
||||
System: GetConfigSystem(config),
|
||||
Opennebula,
|
||||
Zendesk,
|
||||
General
|
||||
});
|
||||
|
||||
module.exports = rootReducers;
|
||||
@@ -0,0 +1,56 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const initial = {
|
||||
user: {
|
||||
name: ''
|
||||
},
|
||||
vm: [],
|
||||
templates: [],
|
||||
services: [],
|
||||
datastores: [],
|
||||
virtualRouters: [],
|
||||
vmGroups: [],
|
||||
images: [],
|
||||
files: [],
|
||||
marketPlaces: [],
|
||||
apps: [],
|
||||
virtualNetworks: [],
|
||||
networkTemplates: [],
|
||||
securityGroups: [],
|
||||
clusters: [],
|
||||
hosts: [],
|
||||
zones: [],
|
||||
groups: [],
|
||||
vdc: [],
|
||||
acl: []
|
||||
};
|
||||
|
||||
const Opennebula = (state = initial, action) => {
|
||||
switch (action.type) {
|
||||
case 'SETUSER': {
|
||||
const { user } = state; // extract position and rename
|
||||
const newUserState = { ...user, ...action.payload }; // merge all data user with new
|
||||
return {
|
||||
...state,
|
||||
user: newUserState
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Opennebula;
|
||||
@@ -0,0 +1,84 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
let initial = {};
|
||||
|
||||
const GetConfigSystem = config => {
|
||||
let data = {};
|
||||
if (config) {
|
||||
const systemData = config();
|
||||
if (
|
||||
systemData?.SYSTEM_DATA?.NO_AUTH &&
|
||||
Array.isArray(systemData?.SYSTEM_DATA?.NO_AUTH)
|
||||
) {
|
||||
const dataNoAuth = systemData.SYSTEM_DATA.NO_AUTH;
|
||||
const render = (finder, configData, result = {}) => {
|
||||
const rtn = result;
|
||||
const allowedTypes = ['string', 'number', 'boolean'];
|
||||
if (finder && Array.isArray(finder)) {
|
||||
finder.forEach(find => {
|
||||
const entriesFind = Object.entries(find);
|
||||
const [key, value] = entriesFind && entriesFind[0];
|
||||
const findKey = key && key === '0' ? find : key;
|
||||
const findValue = key && key !== '0' && value;
|
||||
if (findKey in configData && configData[findKey] !== null) {
|
||||
const typeElement = typeof configData[findKey];
|
||||
if (allowedTypes.includes(typeElement)) {
|
||||
rtn[findKey] = configData[findKey];
|
||||
} else if (Array.isArray(configData[findKey])) {
|
||||
const xxx = configData[findKey].reduce(
|
||||
(accValue, currentValue) => {
|
||||
const validate = render(
|
||||
findValue,
|
||||
currentValue,
|
||||
rtn[findKey]
|
||||
);
|
||||
if (Object.entries(validate).length > 0) {
|
||||
accValue.push(validate);
|
||||
}
|
||||
return accValue;
|
||||
},
|
||||
[]
|
||||
);
|
||||
rtn[findKey] = xxx;
|
||||
} else {
|
||||
rtn[findKey] = render(
|
||||
findValue,
|
||||
configData[findKey],
|
||||
rtn[findKey]
|
||||
);
|
||||
}
|
||||
}
|
||||
if (configData[findKey] === null) {
|
||||
rtn[findKey] = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
data = render(dataNoAuth, systemData);
|
||||
}
|
||||
initial = { ...initial, ...data };
|
||||
}
|
||||
|
||||
return (state = initial, action) => {
|
||||
switch (action.type) {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = GetConfigSystem;
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const initial = {
|
||||
user: {
|
||||
name: ''
|
||||
},
|
||||
tickets: []
|
||||
};
|
||||
|
||||
const Zendesk = (state = initial, action) => {
|
||||
switch (action.type) {
|
||||
case 'SETTICKET': {
|
||||
const { tickets } = state;
|
||||
return {
|
||||
...state,
|
||||
tickets
|
||||
};
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = Zendesk;
|
||||
@@ -0,0 +1,18 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
.content{
|
||||
background-color: $tertiary;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
.footer{
|
||||
background-color: $quaternary;
|
||||
text-align: center;
|
||||
padding: .3rem;
|
||||
a{
|
||||
color: $secondary
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
.header{
|
||||
border-bottom: 2px solid $primary;
|
||||
background-color: $secondary;
|
||||
.title{
|
||||
text-transform: capitalize;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -0,0 +1,56 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
$primary: #C7C9C8;
|
||||
$secondary: #FFF;
|
||||
$tertiary: #FAFAFA;
|
||||
$quaternary: #353735;
|
||||
|
||||
$font_primary: #353735;
|
||||
$font_secondary: red;
|
||||
|
||||
@font-face {
|
||||
font-family: 'LatoWeb';
|
||||
src: url('fonts/Lato-Regular.eot'); /* IE9 Compat Modes */
|
||||
src: url('fonts/Lato-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
|
||||
url('fonts/Lato-Regular.woff2') format('woff2'), /* Modern Browsers */
|
||||
url('fonts/Lato-Regular.woff') format('woff'), /* Modern Browsers */
|
||||
url('fonts/Lato-Regular.ttf') format('truetype');
|
||||
font-style: normal;
|
||||
font-weight: normal;
|
||||
text-rendering: optimizeLegibility;
|
||||
}
|
||||
|
||||
@import "header";
|
||||
@import "login";
|
||||
@import "footer";
|
||||
@import "menu";
|
||||
@import "content";
|
||||
|
||||
html, body{
|
||||
font-family: 'LatoWeb';
|
||||
background-color: $secondary;
|
||||
color: $font_primary;
|
||||
min-height: 100vh;
|
||||
margin: 0px;
|
||||
display: flex;
|
||||
width: 100%;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
#root{
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
.menu{
|
||||
color: $secondary;
|
||||
width: 15rem;
|
||||
|
||||
.link{
|
||||
text-transform: capitalize;
|
||||
color: $font_primary;
|
||||
}
|
||||
.logo-wrapper{
|
||||
padding: 1rem 2rem;
|
||||
}
|
||||
.logo{
|
||||
width: 100%;
|
||||
}
|
||||
.internalNav{
|
||||
padding-top: 0px;
|
||||
padding-bottom: 0px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
export * from './utils';
|
||||
@@ -0,0 +1,120 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
import axios from 'axios';
|
||||
import root from 'window-or-global';
|
||||
import constants from '../constants';
|
||||
import { messageTerminal } from '../../utils/general-functions';
|
||||
|
||||
export const storage = (name = '', data = '', keepData = false) => {
|
||||
if (name && data && root && root.localStorage && root.sessionStorage) {
|
||||
if (keepData && root.localStorage.setItem) {
|
||||
root.localStorage.setItem(name, data);
|
||||
} else if (root.sessionStorage.setItem) {
|
||||
root.sessionStorage.setItem(name, data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const removeStoreData = (items = []) => {
|
||||
let itemsToRemove = items;
|
||||
if (!Array.isArray(items)) {
|
||||
itemsToRemove = [items];
|
||||
}
|
||||
itemsToRemove.forEach(e => {
|
||||
if (root && root.localStorage && root.sessionStorage) {
|
||||
root.localStorage.removeItem(e);
|
||||
root.sessionStorage.removeItem(e);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const findStorageData = (name = '') => {
|
||||
let rtn = false;
|
||||
if (root && root.localStorage && root.sessionStorage && name) {
|
||||
if (root.localStorage.getItem && root.localStorage.getItem(name)) {
|
||||
rtn = root.localStorage.getItem(name);
|
||||
} else if (
|
||||
root.sessionStorage.getItem &&
|
||||
root.sessionStorage.getItem(name)
|
||||
) {
|
||||
rtn = root.sessionStorage.getItem(name);
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
export const requestData = (
|
||||
url = '',
|
||||
params = {
|
||||
method: 'GET',
|
||||
json: true,
|
||||
data: {},
|
||||
authenticate: true,
|
||||
onUploadProgress: null,
|
||||
baseURL: '',
|
||||
error: e => e
|
||||
}
|
||||
) => {
|
||||
const config = {
|
||||
url,
|
||||
method: params.method,
|
||||
baseURL: params.baseURL,
|
||||
headers: {},
|
||||
validateStatus: status => status >= 200 && status <= 401
|
||||
};
|
||||
const { jwtName } = constants;
|
||||
const json = params.json ? params.json : true;
|
||||
let rtn = null;
|
||||
if (json) {
|
||||
config.headers['Content-Type'] = 'application/json';
|
||||
}
|
||||
if (params.data && params.method.toUpperCase() !== 'GET') {
|
||||
config.data = params.data;
|
||||
}
|
||||
|
||||
if (
|
||||
params.onUploadProgress &&
|
||||
typeof params.onUploadProgress === 'function'
|
||||
) {
|
||||
config.onUploadProgress = params.onUploadProgress;
|
||||
}
|
||||
|
||||
if (params.authenticate && findStorageData && findStorageData(jwtName)) {
|
||||
config.headers.Authorization = `Bearer ${findStorageData(jwtName)}`;
|
||||
}
|
||||
|
||||
return axios
|
||||
.request(config)
|
||||
.then(response => {
|
||||
if (response && response.statusText && response.data) {
|
||||
rtn =
|
||||
json && typeof response === 'string'
|
||||
? response.data.json()
|
||||
: response.data;
|
||||
return rtn;
|
||||
}
|
||||
throw Error(response.statusText);
|
||||
})
|
||||
.catch(e => {
|
||||
const configErrorParser = {
|
||||
color: 'red',
|
||||
type: e,
|
||||
message: 'Error request: %s'
|
||||
};
|
||||
messageTerminal(configErrorParser);
|
||||
return params.error(rtn);
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,261 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const express = require('express');
|
||||
const { Map } = require('immutable');
|
||||
const {
|
||||
private: authenticated,
|
||||
public: nonAuthenticated
|
||||
} = require('../config/routes-api');
|
||||
const params = require('../config/params');
|
||||
const { getConfig } = require('../utils/yml-connect');
|
||||
const {
|
||||
opennebulaConnect,
|
||||
validateAuth,
|
||||
createParamsState,
|
||||
createQueriesState,
|
||||
checkRouteFunction,
|
||||
commandXML,
|
||||
checkOpennebulaCommand,
|
||||
getAllowedQueryParams,
|
||||
validateRouteFunction,
|
||||
responseOpennebula
|
||||
} = require('../utils');
|
||||
const {
|
||||
defaultOpennebulaZones,
|
||||
defaultMessageInvalidZone,
|
||||
defaultGetMethod,
|
||||
httpMethod: httpMethods
|
||||
} = require('../config/defaults');
|
||||
|
||||
const httpCodes = require('../config/http-codes');
|
||||
const { from: fromData } = require('../config/defaults');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
express();
|
||||
|
||||
const defaultParams = Map(createParamsState());
|
||||
const defaultQueries = Map(createQueriesState());
|
||||
|
||||
let paramsState = defaultParams.toObject();
|
||||
let queriesState = defaultQueries.toObject();
|
||||
let idUserOpennebula = '';
|
||||
let userOpennebula = '';
|
||||
let passOpennebula = '';
|
||||
|
||||
// user config
|
||||
const appConfig = getConfig();
|
||||
|
||||
const opennebulaZones = appConfig.OPENNEBULA_ZONES || defaultOpennebulaZones;
|
||||
|
||||
const clearStates = () => {
|
||||
paramsState = defaultParams.toObject();
|
||||
queriesState = defaultQueries.toObject();
|
||||
idUserOpennebula = '';
|
||||
userOpennebula = '';
|
||||
passOpennebula = '';
|
||||
};
|
||||
|
||||
const paramsToRoutes = () =>
|
||||
Object.keys(params).reduce(
|
||||
(resources, param) => String(resources).concat(`/:${params[param]}?`),
|
||||
'/:resource?'
|
||||
);
|
||||
|
||||
const validateResource = (req, res, next) => {
|
||||
const { badRequest, unauthorized, serviceUnavailable } = httpCodes;
|
||||
let status = badRequest;
|
||||
if (req && req.params && req.params.resource) {
|
||||
const resource = req.params.resource;
|
||||
status = serviceUnavailable;
|
||||
if (authenticated.includes(resource)) {
|
||||
const session = validateAuth(req);
|
||||
if (
|
||||
session &&
|
||||
'iss' in session &&
|
||||
'aud' in session &&
|
||||
'jti' in session &&
|
||||
'iat' in session &&
|
||||
'exp' in session
|
||||
) {
|
||||
idUserOpennebula = session.iss;
|
||||
userOpennebula = session.aud;
|
||||
passOpennebula = session.jti;
|
||||
next();
|
||||
return;
|
||||
}
|
||||
status = unauthorized;
|
||||
}
|
||||
if (nonAuthenticated.includes(resource)) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
}
|
||||
res.status(status.id).json(status);
|
||||
};
|
||||
|
||||
const optionalParameters = (req, res, next) => {
|
||||
if (req && req.params) {
|
||||
let start = true;
|
||||
const keys = Object.keys(req.params);
|
||||
keys.map(param => {
|
||||
if (start) {
|
||||
start = false;
|
||||
return start;
|
||||
}
|
||||
if (req.params[param]) {
|
||||
const matches = req.params[param].match(/(^[\w]*=)/gi);
|
||||
if (matches && matches[0]) {
|
||||
params.map(parameter => {
|
||||
if (
|
||||
matches[0].replace(/=/g, '').toLowerCase() ===
|
||||
parameter.toLowerCase()
|
||||
) {
|
||||
const removeKey = new RegExp(`^${parameter}=`, 'i');
|
||||
if (paramsState[parameter] === null) {
|
||||
paramsState[parameter] = req.params[param].replace(
|
||||
removeKey,
|
||||
''
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
paramsState[param] = req.params[param];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
const optionalQueries = (req, res, next) => {
|
||||
if (req && req.query) {
|
||||
const keys = Object.keys(req.query);
|
||||
const queries = getAllowedQueryParams();
|
||||
keys.map(query => {
|
||||
if (req.query[query] && queries.includes(query)) {
|
||||
queriesState[query] = req.query[query];
|
||||
}
|
||||
});
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
const getDataZone = () => {
|
||||
let rtn;
|
||||
if (opennebulaZones && Array.isArray(opennebulaZones)) {
|
||||
const { federation } = paramsState;
|
||||
rtn = opennebulaZones[0];
|
||||
if (federation !== null) {
|
||||
rtn = opennebulaZones.find(
|
||||
zone => zone && zone.ID !== undefined && String(zone.ID) === federation
|
||||
);
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
router.all(
|
||||
paramsToRoutes(),
|
||||
[validateResource, optionalParameters, optionalQueries],
|
||||
(req, res, next) => {
|
||||
const { internalServerError, ok, methodNotAllowed } = httpCodes;
|
||||
const { method: httpMethod } = req;
|
||||
res.locals.httpCode = Map(internalServerError).toObject();
|
||||
const zone = getDataZone();
|
||||
if (zone) {
|
||||
const { RPC } = zone;
|
||||
const connectOpennebula = (
|
||||
user = userOpennebula,
|
||||
pass = passOpennebula
|
||||
) => opennebulaConnect(user, pass, RPC);
|
||||
const { resource } = req.params;
|
||||
const routeFunction = checkRouteFunction(resource);
|
||||
res.locals.httpCode = Map(methodNotAllowed).toObject();
|
||||
const dataSources = {
|
||||
[fromData.resource]: paramsState,
|
||||
[fromData.query]: queriesState,
|
||||
[fromData.postBody]: req.body
|
||||
};
|
||||
if (routeFunction !== undefined) {
|
||||
const valRouteFunction = validateRouteFunction(
|
||||
routeFunction,
|
||||
httpMethod
|
||||
);
|
||||
if (valRouteFunction) {
|
||||
valRouteFunction(
|
||||
dataSources,
|
||||
res,
|
||||
next,
|
||||
connectOpennebula,
|
||||
idUserOpennebula
|
||||
);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
} else {
|
||||
const { method } = paramsState;
|
||||
const command = commandXML(
|
||||
resource,
|
||||
method,
|
||||
httpMethod === httpMethods.GET && defaultGetMethod
|
||||
);
|
||||
const getOpennebulaMethod = checkOpennebulaCommand(command, httpMethod);
|
||||
if (getOpennebulaMethod) {
|
||||
const response = val => {
|
||||
res.locals.httpCode = Map(ok).toObject();
|
||||
res.locals.httpCode.data = val || {};
|
||||
if (typeof val === 'string') {
|
||||
res.locals.httpCode.data = {};
|
||||
res.locals.httpCode.message = val;
|
||||
}
|
||||
next();
|
||||
};
|
||||
|
||||
const updaterResponse = code => {
|
||||
if ('id' in code && 'message' in code) {
|
||||
res.locals.httpCode = code;
|
||||
}
|
||||
};
|
||||
const connect = connectOpennebula(
|
||||
userOpennebula,
|
||||
passOpennebula,
|
||||
RPC
|
||||
);
|
||||
connect(
|
||||
command,
|
||||
getOpennebulaMethod(dataSources),
|
||||
(err, value) =>
|
||||
responseOpennebula(updaterResponse, err, value, response, next)
|
||||
);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
res.locals.httpCode.message += `: ${defaultMessageInvalidZone}`;
|
||||
next();
|
||||
}
|
||||
},
|
||||
(req, res) => {
|
||||
clearStates();
|
||||
const { httpCode } = res.locals;
|
||||
res.status(httpCode.id).json(httpCode);
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,83 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const React = require('react');
|
||||
const express = require('express');
|
||||
const { renderToString } = require('react-dom/server');
|
||||
const root = require('window-or-global');
|
||||
const { createStore, compose, applyMiddleware } = require('redux');
|
||||
const thunk = require('redux-thunk').default;
|
||||
const classnames = require('classnames');
|
||||
const { ServerStyleSheets } = require('@material-ui/core/styles');
|
||||
const rootReducer = require('../public/reducers');
|
||||
const App = require('../public/app').default;
|
||||
const { getConfig } = require('../utils/yml-connect');
|
||||
const {
|
||||
includeMAPSJSbyHTML,
|
||||
includeJSbyHTML,
|
||||
includeCSSbyHTML
|
||||
} = require('../utils');
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('*', (req, res) => {
|
||||
const context = {};
|
||||
const pathPublic = `${__dirname}/public`;
|
||||
|
||||
const composeEnhancer =
|
||||
(root && root.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) || compose;
|
||||
|
||||
const store = createStore(
|
||||
rootReducer(getConfig),
|
||||
composeEnhancer(applyMiddleware(thunk))
|
||||
);
|
||||
|
||||
const sheets = new ServerStyleSheets();
|
||||
const component = renderToString(
|
||||
sheets.collect(<App location={req.url} context={context} store={store} />)
|
||||
);
|
||||
const css = sheets.toString();
|
||||
|
||||
const html = `
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<link rel='shortcut icon' type='image/png' href='/static/favicon.png' />
|
||||
<meta name="viewport" content="minimum-scale=1, initial-scale=1, width=device-width">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<style id="jss-server-side">${css}</style>
|
||||
${includeCSSbyHTML(pathPublic)}
|
||||
</head>
|
||||
<body>
|
||||
<div id="root">${component}</div>
|
||||
<script id="preloadState">
|
||||
window.__PRELOADED_STATE__ = ${JSON.stringify(store.getState()).replace(
|
||||
/</g,
|
||||
'\\u003c'
|
||||
)}
|
||||
</script>
|
||||
${includeJSbyHTML(pathPublic) + includeMAPSJSbyHTML(pathPublic)}
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
if (context.url) {
|
||||
res.writeHead(301, { Location: context.url });
|
||||
res.end();
|
||||
} else {
|
||||
res.send(html);
|
||||
}
|
||||
});
|
||||
module.exports = router;
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const colors = require('colors');
|
||||
|
||||
const messageTerminal = ({ color, type, error, message }) => {
|
||||
const colorConsole = color || 'red';
|
||||
const typeConsole = type || '';
|
||||
const errorConsole = error || '';
|
||||
const messageConsole = message || 'Message Console ';
|
||||
const consoleColor =
|
||||
colorConsole === 'green'
|
||||
? colors.green(messageConsole)
|
||||
: colors.red(messageConsole);
|
||||
console.log(consoleColor, typeConsole, errorConsole);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
messageTerminal
|
||||
};
|
||||
@@ -0,0 +1,135 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const params = require('../config/params');
|
||||
const { defaultTypeLog } = require('../config/defaults');
|
||||
const functionRoutes = require('../config/function-routes');
|
||||
const { validateAuth } = require('./jwt-functions');
|
||||
const { messageTerminal } = require('./general-functions');
|
||||
const { addWsServer } = require('./ws-zeromq');
|
||||
const { getConfig } = require('./yml-connect');
|
||||
|
||||
// user config
|
||||
const appConfig = getConfig();
|
||||
|
||||
const mode = appConfig.LOG || defaultTypeLog;
|
||||
|
||||
const {
|
||||
responseOpennebula,
|
||||
opennebulaConnect,
|
||||
getMethodForOpennebulaCommand,
|
||||
commandXML,
|
||||
getAllowedQueryParams,
|
||||
getRouteForOpennebulaCommand,
|
||||
checkOpennebulaCommand
|
||||
} = require('./opennebula-functions');
|
||||
|
||||
const createParamsState = () => {
|
||||
const rtn = {};
|
||||
if (params && Array.isArray(params)) {
|
||||
params.map(param => {
|
||||
rtn[param] = null;
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const createQueriesState = () => {
|
||||
const rtn = {};
|
||||
const queries = getAllowedQueryParams();
|
||||
if (queries && Array.isArray(queries)) {
|
||||
queries.map(query => {
|
||||
rtn[query] = null;
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const includeMAPSJSbyHTML = (path = '') => {
|
||||
let scripts = '';
|
||||
if (mode === defaultTypeLog) {
|
||||
fs.readdirSync(path).map(file => {
|
||||
if (file.match(/\w*\.js\.map+$\b/gi)) {
|
||||
scripts += `<script src="/static/${file}" type="application/json"></script>`;
|
||||
}
|
||||
});
|
||||
}
|
||||
return scripts;
|
||||
};
|
||||
|
||||
const includeJSbyHTML = (path = '') => {
|
||||
let scripts = '';
|
||||
fs.readdirSync(path).map(file => {
|
||||
if (file.match(/\w*\.js+$\b/gi)) {
|
||||
scripts += `<script src="/static/${file}"></script>`;
|
||||
}
|
||||
});
|
||||
return scripts;
|
||||
};
|
||||
|
||||
const includeCSSbyHTML = (path = '') => {
|
||||
let scripts = '';
|
||||
fs.readdirSync(path).map(file => {
|
||||
if (file.match(/\w*\.css+$\b/gi)) {
|
||||
scripts += `<link rel="stylesheet" href="/static/${file}"></link>`;
|
||||
}
|
||||
});
|
||||
return scripts;
|
||||
};
|
||||
|
||||
const validateRouteFunction = (routeFunction, httpMethod = '') => {
|
||||
let rtn;
|
||||
if (
|
||||
routeFunction &&
|
||||
routeFunction.httpMethod &&
|
||||
routeFunction.httpMethod === httpMethod &&
|
||||
routeFunction.action &&
|
||||
typeof routeFunction.action === 'function'
|
||||
) {
|
||||
rtn = routeFunction.action;
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const checkRouteFunction = route => {
|
||||
let rtn;
|
||||
const { private: functionPrivate, public: functionPublic } = functionRoutes;
|
||||
const functions = { ...functionPrivate, ...functionPublic };
|
||||
if (route in functions) {
|
||||
rtn = functions[route];
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addWsServer,
|
||||
validateAuth,
|
||||
createParamsState,
|
||||
getAllowedQueryParams,
|
||||
createQueriesState,
|
||||
opennebulaConnect,
|
||||
includeMAPSJSbyHTML,
|
||||
includeJSbyHTML,
|
||||
includeCSSbyHTML,
|
||||
messageTerminal,
|
||||
getRouteForOpennebulaCommand,
|
||||
getMethodForOpennebulaCommand,
|
||||
commandXML,
|
||||
checkRouteFunction,
|
||||
checkOpennebulaCommand,
|
||||
validateRouteFunction,
|
||||
responseOpennebula
|
||||
};
|
||||
@@ -0,0 +1,87 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const jwt = require('jwt-simple');
|
||||
const moment = require('moment');
|
||||
const { messageTerminal } = require('../utils/general-functions');
|
||||
const { getConfig } = require('./yml-connect');
|
||||
|
||||
// user config
|
||||
const appConfig = getConfig();
|
||||
|
||||
const tokenSecret = appConfig.TOKEN_SECRET || null;
|
||||
|
||||
const createToken = (
|
||||
{ id: iss, user: aud, token: jti },
|
||||
iat = '',
|
||||
exp = ''
|
||||
) => {
|
||||
let rtn = null;
|
||||
if (iss && aud && jti && iat && exp && tokenSecret) {
|
||||
const payload = {
|
||||
iss,
|
||||
aud,
|
||||
jti,
|
||||
iat,
|
||||
exp
|
||||
};
|
||||
rtn = jwt.encode(payload, tokenSecret);
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const validateAuth = req => {
|
||||
let rtn = false;
|
||||
if (req && req.headers && req.headers.authorization) {
|
||||
const authorization = req.headers.authorization;
|
||||
const removeBearer = new RegExp('^Bearer ', 'i');
|
||||
const token = authorization.replace(removeBearer, '');
|
||||
try {
|
||||
const payload = jwt.decode(token, tokenSecret);
|
||||
if (
|
||||
payload &&
|
||||
'iss' in payload &&
|
||||
'aud' in payload &&
|
||||
'jti' in payload &&
|
||||
'iat' in payload &&
|
||||
'exp' in payload &&
|
||||
payload.exp >= moment().unix()
|
||||
) {
|
||||
const { iss, aud, jti, iat, exp } = payload;
|
||||
rtn = {
|
||||
iss,
|
||||
aud,
|
||||
jti,
|
||||
iat,
|
||||
exp
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
const config = {
|
||||
color: 'red',
|
||||
type: 'ERROR',
|
||||
error,
|
||||
message: 'Error: %s'
|
||||
};
|
||||
messageTerminal(config);
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createToken,
|
||||
validateAuth
|
||||
};
|
||||
@@ -0,0 +1,284 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const upcast = require('upcast');
|
||||
const url = require('url');
|
||||
const rpc = require('xmlrpc');
|
||||
const xml2js = require('xml2js');
|
||||
const { Map } = require('immutable');
|
||||
const { sprintf } = require('sprintf-js');
|
||||
const httpCodes = require('../config/http-codes');
|
||||
const commandsParams = require('../config/commands-params');
|
||||
const {
|
||||
from,
|
||||
defaultNamespace,
|
||||
defaultMessageProblemOpennebula
|
||||
} = require('../config/defaults');
|
||||
|
||||
// user config
|
||||
const { getConfig } = require('./yml-connect');
|
||||
|
||||
const appConfig = getConfig();
|
||||
const namespace = appConfig.namespace || defaultNamespace;
|
||||
|
||||
const opennebulaConnect = (username = '', password = '', path = '') => {
|
||||
let rtn = () => null;
|
||||
if (username && password && path) {
|
||||
let xmlClient = null;
|
||||
const parsedHostname = url.parse(path);
|
||||
const protocol = parsedHostname.protocol;
|
||||
if (protocol === 'https:') {
|
||||
xmlClient = rpc.createSecureClient(path);
|
||||
} else {
|
||||
xmlClient = rpc.createClient(path);
|
||||
}
|
||||
if (xmlClient && xmlClient.methodCall) {
|
||||
rtn = (action = '', parameters = [], callback = () => undefined) => {
|
||||
if (action && parameters && Array.isArray(parameters) && callback) {
|
||||
const xmlParameters = [`${username}:${password}`, ...parameters];
|
||||
xmlClient.methodCall(
|
||||
namespace + action,
|
||||
xmlParameters,
|
||||
(err, value) => {
|
||||
if (!(err || (value && !value[0]))) {
|
||||
const messageCall = value[1];
|
||||
if (typeof messageCall === 'string' && messageCall.length > 0) {
|
||||
xml2js.parseString(
|
||||
messageCall,
|
||||
{
|
||||
explicitArray: false,
|
||||
trim: true,
|
||||
normalize: true,
|
||||
includeWhiteChars: true,
|
||||
strict: false
|
||||
},
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
callback(error, undefined); // error parse xml
|
||||
return;
|
||||
}
|
||||
callback(
|
||||
undefined,
|
||||
error === null && result === null ? messageCall : result
|
||||
); // success
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
callback(err, value && value[1]); // error call opennebula
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const responseOpennebula = (res, err, value, response, next) => {
|
||||
if (err && res && typeof res === 'function') {
|
||||
const { internalServerError } = httpCodes;
|
||||
const codeError = Map(internalServerError).toObject();
|
||||
codeError.message += `: ${defaultMessageProblemOpennebula}`;
|
||||
res(codeError);
|
||||
next();
|
||||
} else if (typeof response === 'function') {
|
||||
response(value);
|
||||
}
|
||||
};
|
||||
|
||||
const getMethodForOpennebulaCommand = () => {
|
||||
const rtn = [];
|
||||
if (commandsParams) {
|
||||
const commands = Object.keys(commandsParams);
|
||||
commands.map(command => {
|
||||
if (command && command.length) {
|
||||
const commandString = command.split('.');
|
||||
if (!rtn.includes(commandString[1])) {
|
||||
rtn.push(commandString[1]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const commandXML = (resource = '', method = '', defaultMethod = '') => {
|
||||
const allowedActions = getMethodForOpennebulaCommand();
|
||||
let command = `${resource}`;
|
||||
const commandWithDefault = defaultMethod
|
||||
? `${command}.${defaultMethod}`
|
||||
: command;
|
||||
if (typeof method === 'string' && method !== 'action') {
|
||||
command = allowedActions.includes(method)
|
||||
? `${command}.${method}`
|
||||
: commandWithDefault;
|
||||
}
|
||||
return command;
|
||||
};
|
||||
|
||||
const getAllowedQueryParams = () => {
|
||||
const rtn = [];
|
||||
const allowedQuerys = Object.keys(commandsParams);
|
||||
if (from && from.query) {
|
||||
const { query } = from;
|
||||
allowedQuerys.map(allowedQuery => {
|
||||
const command = commandsParams[allowedQuery];
|
||||
if (command && command.params) {
|
||||
const internalParams = Object.keys(command.params);
|
||||
internalParams.map(internalParam => {
|
||||
if (
|
||||
command.params[internalParam] &&
|
||||
command.params[internalParam].from &&
|
||||
command.params[internalParam].from === query &&
|
||||
!rtn.includes(internalParam)
|
||||
) {
|
||||
rtn.push(internalParam);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const getRouteForOpennebulaCommand = () => {
|
||||
const rtn = [];
|
||||
if (commandsParams) {
|
||||
const commands = Object.keys(commandsParams);
|
||||
commands.map(command => {
|
||||
if (command && command.length) {
|
||||
const commandString = command.split('.');
|
||||
if (!rtn.includes(commandString[0])) {
|
||||
rtn.push(commandString[0]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const checkPositionInDataSource = dataSource => {
|
||||
let rtn = true;
|
||||
if (dataSource && from) {
|
||||
const fromKeys = Object.values(from);
|
||||
fromKeys.map(key => {
|
||||
if (!(key && dataSource && key in dataSource)) {
|
||||
rtn = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const checkOpennebulaCommand = (
|
||||
command = '',
|
||||
method = '',
|
||||
commandParams = true
|
||||
) => {
|
||||
let rtn = false;
|
||||
if (command && method && commandsParams && from) {
|
||||
if (
|
||||
commandsParams &&
|
||||
commandsParams[command] &&
|
||||
commandsParams[command].params &&
|
||||
commandsParams[command].httpMethod &&
|
||||
commandsParams[command].httpMethod === method
|
||||
) {
|
||||
rtn = commandParams
|
||||
? dataSource => {
|
||||
let rtnParams = false;
|
||||
if (dataSource && checkPositionInDataSource(dataSource)) {
|
||||
const { params: paramsForCommand } = commandsParams[command];
|
||||
const internalParams = [];
|
||||
Object.keys(paramsForCommand).map(param => {
|
||||
const parameter = paramsForCommand[param];
|
||||
if (
|
||||
'default' in parameter &&
|
||||
'from' in parameter &&
|
||||
parameter.from in dataSource &&
|
||||
param in dataSource[parameter.from] &&
|
||||
dataSource[parameter.from][param]
|
||||
) {
|
||||
internalParams.push(
|
||||
upcast.to(
|
||||
dataSource[parameter.from][param],
|
||||
upcast.type(parameter.default)
|
||||
)
|
||||
);
|
||||
} else {
|
||||
internalParams.push(parameter.default);
|
||||
}
|
||||
});
|
||||
if (internalParams) {
|
||||
rtnParams = internalParams;
|
||||
}
|
||||
}
|
||||
return rtnParams;
|
||||
}
|
||||
: commandsParams[command];
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const paramsDefaultByCommandOpennebula = (command = '', httpCode = '') => {
|
||||
const rtn = [];
|
||||
if (command && httpCode) {
|
||||
const getDefaultValues = checkOpennebulaCommand(command, httpCode, false);
|
||||
if (getDefaultValues && getDefaultValues.params) {
|
||||
const defaultParams = Object.keys(getDefaultValues.params);
|
||||
defaultParams.map(defaultParam => {
|
||||
if (
|
||||
getDefaultValues.params &&
|
||||
defaultParam &&
|
||||
getDefaultValues.params[defaultParam] &&
|
||||
'default' in getDefaultValues.params[defaultParam]
|
||||
) {
|
||||
rtn.push(getDefaultValues.params[defaultParam].default);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
const generateNewTemplate = (
|
||||
current = {},
|
||||
addPositions = {},
|
||||
removedPositions = [],
|
||||
wrapper = 'SUNSTONE=[%1$s]'
|
||||
) => {
|
||||
const positions = Object.entries({ ...current, ...addPositions })
|
||||
.filter(position => position && !removedPositions.includes(position))
|
||||
.map(([position, value]) => `${position}=${value}`)
|
||||
.join(', ');
|
||||
|
||||
return sprintf(wrapper, positions);
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
opennebulaConnect,
|
||||
responseOpennebula,
|
||||
getMethodForOpennebulaCommand,
|
||||
commandXML,
|
||||
getAllowedQueryParams,
|
||||
getRouteForOpennebulaCommand,
|
||||
checkPositionInDataSource,
|
||||
checkOpennebulaCommand,
|
||||
paramsDefaultByCommandOpennebula,
|
||||
generateNewTemplate
|
||||
};
|
||||
@@ -0,0 +1,126 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const atob = require('atob');
|
||||
|
||||
const { server: Server } = require('websocket');
|
||||
const { socket } = require('zeromq');
|
||||
const xml2js = require('xml2js');
|
||||
|
||||
const { messageTerminal } = require('./general-functions');
|
||||
const { getConfig } = require('./yml-connect');
|
||||
const { validateAuth } = require('./jwt-functions');
|
||||
const { unauthorized } = require('../config/http-codes');
|
||||
|
||||
// user config
|
||||
const appConfig = getConfig();
|
||||
|
||||
const zeromqType = appConfig.ZEROTYPE || 'tcp';
|
||||
const zeromqPort = appConfig.ZEROPORT || 2101;
|
||||
const zeromqHost = appConfig.ZEROHOST || '127.0.0.1';
|
||||
|
||||
const addWsServer = appServer => {
|
||||
if (
|
||||
appServer &&
|
||||
appServer.constructor &&
|
||||
appServer.constructor.name &&
|
||||
appServer.constructor.name === 'Server'
|
||||
) {
|
||||
// create the server
|
||||
const wsServer = new Server({
|
||||
httpServer: appServer
|
||||
});
|
||||
|
||||
// connect to zeromq
|
||||
const zeromqSock = socket('sub');
|
||||
const address = `${zeromqType}://${zeromqHost}:${zeromqPort}`;
|
||||
|
||||
try {
|
||||
zeromqSock.connect(address);
|
||||
let clients = [];
|
||||
|
||||
wsServer.on('request', request => {
|
||||
if (
|
||||
request &&
|
||||
request.resourceURL &&
|
||||
request.resourceURL.query &&
|
||||
request.resourceURL.query.token &&
|
||||
validateAuth({
|
||||
headers: { authorization: request.resourceURL.query.token }
|
||||
})
|
||||
) {
|
||||
const clientConnection = request.accept(null, request.origin);
|
||||
clients.push(clientConnection);
|
||||
zeromqSock.subscribe('');
|
||||
zeromqSock.on('message', (...args) => {
|
||||
const mssgs = [];
|
||||
// broadcast
|
||||
clients.map(client => {
|
||||
Array.prototype.slice.call(args).forEach(arg => {
|
||||
mssgs.push(arg.toString());
|
||||
});
|
||||
|
||||
if (mssgs[0] && mssgs[1]) {
|
||||
xml2js.parseString(
|
||||
atob(mssgs[1]),
|
||||
{
|
||||
explicitArray: false,
|
||||
trim: true,
|
||||
normalize: true,
|
||||
includeWhiteChars: true,
|
||||
strict: false
|
||||
},
|
||||
(error, result) => {
|
||||
if (error) {
|
||||
const configErrorParser = {
|
||||
color: 'red',
|
||||
type: error,
|
||||
message: 'Error parser: %s'
|
||||
};
|
||||
messageTerminal(configErrorParser);
|
||||
return;
|
||||
}
|
||||
client.send(
|
||||
JSON.stringify({ command: mssgs[0], data: result })
|
||||
);
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
const { id, message } = unauthorized;
|
||||
request.reject(id, message);
|
||||
}
|
||||
});
|
||||
|
||||
wsServer.on('close', request => {
|
||||
// clear connection to broadcast
|
||||
clients = clients.filter(client => client !== request);
|
||||
});
|
||||
} catch (error) {
|
||||
const configErrorZeroMQ = {
|
||||
color: 'red',
|
||||
type: error,
|
||||
message: '%s'
|
||||
};
|
||||
messageTerminal(configErrorZeroMQ);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
addWsServer
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const YAML = require('yaml');
|
||||
const { defaultConfigFile } = require('../config/defaults');
|
||||
|
||||
const getConfig = () => {
|
||||
let rtn = {};
|
||||
if (
|
||||
defaultConfigFile &&
|
||||
fs &&
|
||||
fs.readFileSync &&
|
||||
fs.existsSync &&
|
||||
fs.existsSync(defaultConfigFile)
|
||||
) {
|
||||
const file = fs.readFileSync(defaultConfigFile, 'utf8');
|
||||
rtn = YAML.parse(file);
|
||||
}
|
||||
return rtn;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getConfig
|
||||
};
|
||||
@@ -0,0 +1,99 @@
|
||||
/* Copyright 2002-2019, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
const nodeExternals = require('webpack-node-externals');
|
||||
const path = require('path');
|
||||
const { getConfig } = require('./src/utils/yml-connect');
|
||||
const { defaultWebpackMode } = require('./src/config/defaults');
|
||||
|
||||
const appConfig = getConfig();
|
||||
|
||||
// settings
|
||||
const mode = appConfig.MODE || defaultWebpackMode;
|
||||
const devtool = mode === defaultWebpackMode ? 'inline-source-map' : '';
|
||||
const js = {
|
||||
test: /\.js$/,
|
||||
exclude: /node_modules/,
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env', '@babel/preset-react'],
|
||||
plugins: [
|
||||
'@babel/plugin-proposal-class-properties',
|
||||
'@babel/plugin-proposal-object-rest-spread',
|
||||
'@babel/plugin-proposal-nullish-coalescing-operator',
|
||||
'@babel/plugin-proposal-optional-chaining'
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const serverConfig = {
|
||||
mode,
|
||||
target: 'node',
|
||||
node: {
|
||||
__dirname: false
|
||||
},
|
||||
externals: [nodeExternals()],
|
||||
entry: {
|
||||
'index.js': path.resolve(__dirname, 'src/index.js')
|
||||
},
|
||||
module: {
|
||||
rules: [js]
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
filename: '[name]'
|
||||
},
|
||||
devtool
|
||||
};
|
||||
|
||||
const clientConfig = {
|
||||
mode,
|
||||
target: 'web',
|
||||
entry: {
|
||||
'app.js': path.resolve(__dirname, 'src/public/front-app.js')
|
||||
},
|
||||
module: {
|
||||
rules: [js]
|
||||
},
|
||||
optimization: {
|
||||
splitChunks: {
|
||||
chunks: 'all'
|
||||
}
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, 'dist/public'),
|
||||
filename: '[name]'
|
||||
},
|
||||
devtool
|
||||
};
|
||||
|
||||
module.exports = env => {
|
||||
let build = [];
|
||||
if (env) {
|
||||
switch (env) {
|
||||
case 'front':
|
||||
build.push(clientConfig);
|
||||
break;
|
||||
case 'node':
|
||||
build.push(serverConfig);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
build = [serverConfig, clientConfig];
|
||||
}
|
||||
return build;
|
||||
};
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user