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:
parent
5b96fec089
commit
87fd9f68db
52
src/fireedge/src/server/routes/api/sunstone/index.js
Normal file
52
src/fireedge/src/server/routes/api/sunstone/index.js
Normal 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
|
22
src/fireedge/src/server/routes/api/sunstone/string-routes.js
Normal file
22
src/fireedge/src/server/routes/api/sunstone/string-routes.js
Normal 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
|
@ -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
|
61
src/fireedge/src/server/routes/api/sunstone/sunstone.js
Normal file
61
src/fireedge/src/server/routes/api/sunstone/sunstone.js
Normal 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
|
@ -57,7 +57,8 @@ const defaults = {
|
||||
'support',
|
||||
'vcenter',
|
||||
'zendesk',
|
||||
'provision'
|
||||
'provision',
|
||||
'sunstone'
|
||||
],
|
||||
defaultApps: apps,
|
||||
httpMethod: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user