1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

F #5422: first steps sunstone yamls route

Signed-off-by: Jorge Lobo <jlobo@opennebula.io>
This commit is contained in:
Jorge Lobo 2021-06-29 18:04:53 +02:00
parent 5b96fec089
commit 87fd9f68db
No known key found for this signature in database
GPG Key ID: 9C21660F7B06905E
5 changed files with 166 additions and 1 deletions

View File

@ -0,0 +1,52 @@
/* Copyright 2002-2021, 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 { main: sunstone, routes: sunstoneRoutes } = require('./sunstone')
const { SUNSTONE } = require('./string-routes')
const privateRoutes = []
const publicRoutes = []
const fillRoute = (method, endpoint, action) => ({
httpMethod: method,
endpoint,
action
})
const fillPrivateRoutes = (methods = {}, path = '', action = () => undefined) => {
if (Object.keys(methods).length > 0 && methods.constructor === Object) {
Object.keys(methods).forEach((method) => {
privateRoutes.push(
fillRoute(method, path,
(req, res, next, conection, userId, user) => {
action(req, res, next, methods[method], user)
})
)
})
}
}
const generatePrivateRoutes = () => {
fillPrivateRoutes(sunstoneRoutes, SUNSTONE, sunstone)
return privateRoutes
}
const functionRoutes = {
private: generatePrivateRoutes(),
public: publicRoutes
}
module.exports = functionRoutes

View File

@ -0,0 +1,22 @@
/* Copyright 2002-2021, 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 SUNSTONE = 'sunstone'
const Actions = {
SUNSTONE
}
module.exports = Actions

View File

@ -0,0 +1,29 @@
/* Copyright 2002-2021, 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 { httpMethod } = require('server/utils/constants/defaults')
// const { httpResponse, parsePostData } = require('server/utils/server')
/* const {
internalServerError
} = require('server/utils/constants/http-codes') */
const sunstone = (res = {}, next = () => undefined, params = {}, userData = {}) => {
console.log('aca se tienen que obtener los YAMLS', global)
}
const sunstoneApi = {
sunstone
}
module.exports = sunstoneApi

View File

@ -0,0 +1,61 @@
/* Copyright 2002-2021, 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 { httpMethod, from: fromData } = require('server/utils/constants/defaults')
const { getParamsForObject } = require('server/utils/server')
const {
sunstone
} = require('./sunstone-functions')
const { GET } = httpMethod
const routes = {
[GET]: {
list: {
action: sunstone,
params: {
id: { from: fromData.resource, name: 'id', front: true }
}
}
}
}
const main = (req = {}, res = {}, next = () => undefined, routes = {}, user = {}, index = 0) => {
const resources = Object.keys(req[fromData.resource])
if (req && res && next && routes) {
const route = routes[`${req[fromData.resource][resources[index]]}`.toLowerCase()]
if (req && fromData && fromData.resource && req[fromData.resource] && route) {
if (Object.keys(route).length > 0 && route.constructor === Object) {
if (route.action && route.params && typeof route.action === 'function') {
const params = getParamsForObject(route.params, req)
route.action(res, next, params, user)
} else {
main(req, res, next, route, user, index + 1)
}
} else {
next()
}
} else {
next()
}
} else {
next()
}
}
const sunstoneApi = {
main,
routes
}
module.exports = sunstoneApi

View File

@ -57,7 +57,8 @@ const defaults = {
'support',
'vcenter',
'zendesk',
'provision'
'provision',
'sunstone'
],
defaultApps: apps,
httpMethod: {