diff --git a/src/fireedge/src/server/routes/api/sunstone/index.js b/src/fireedge/src/server/routes/api/sunstone/index.js new file mode 100644 index 0000000000..24863c110f --- /dev/null +++ b/src/fireedge/src/server/routes/api/sunstone/index.js @@ -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 diff --git a/src/fireedge/src/server/routes/api/sunstone/string-routes.js b/src/fireedge/src/server/routes/api/sunstone/string-routes.js new file mode 100644 index 0000000000..d06cdb0659 --- /dev/null +++ b/src/fireedge/src/server/routes/api/sunstone/string-routes.js @@ -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 diff --git a/src/fireedge/src/server/routes/api/sunstone/sunstone-functions.js b/src/fireedge/src/server/routes/api/sunstone/sunstone-functions.js new file mode 100644 index 0000000000..d459c4b33f --- /dev/null +++ b/src/fireedge/src/server/routes/api/sunstone/sunstone-functions.js @@ -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 diff --git a/src/fireedge/src/server/routes/api/sunstone/sunstone.js b/src/fireedge/src/server/routes/api/sunstone/sunstone.js new file mode 100644 index 0000000000..5f458e35bd --- /dev/null +++ b/src/fireedge/src/server/routes/api/sunstone/sunstone.js @@ -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 diff --git a/src/fireedge/src/server/utils/constants/defaults.js b/src/fireedge/src/server/utils/constants/defaults.js index 99f393b8c7..07fa2914e4 100644 --- a/src/fireedge/src/server/utils/constants/defaults.js +++ b/src/fireedge/src/server/utils/constants/defaults.js @@ -57,7 +57,8 @@ const defaults = { 'support', 'vcenter', 'zendesk', - 'provision' + 'provision', + 'sunstone' ], defaultApps: apps, httpMethod: {