From: KIRAN KASHALKAR Date: Fri, 24 Mar 2017 05:08:50 +0000 (-0400) Subject: NOTICKET: Refactor with sessions. Now holds auth on server X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=5a83ca0dc3306b54e1db18b9e05e860fed21324e;p=osm%2FUI.git NOTICKET: Refactor with sessions. Now holds auth on server Signed-off-by: KIRAN KASHALKAR --- diff --git a/skyquake/framework/core/api_utils/constants.js b/skyquake/framework/core/api_utils/constants.js index 0aac7d2d0..7f54797f5 100644 --- a/skyquake/framework/core/api_utils/constants.js +++ b/skyquake/framework/core/api_utils/constants.js @@ -73,6 +73,7 @@ constants.SOCKET_BASE_PORT = 3500; constants.SOCKET_POOL_LENGTH = 20; constants.SERVER_PORT = process.env.SERVER_PORT || 8000; constants.SECURE_SERVER_PORT = process.env.SECURE_SERVER_PORT || 8443; +constants.REJECT_UNAUTHORIZED = false; constants.BASE_PACKAGE_UPLOAD_DESTINATION = 'upload/packages/'; constants.PACKAGE_MANAGER_SERVER_PORT = 4567; diff --git a/skyquake/framework/core/api_utils/sockets.js b/skyquake/framework/core/api_utils/sockets.js index 5e0b25bfb..0cd491883 100644 --- a/skyquake/framework/core/api_utils/sockets.js +++ b/skyquake/framework/core/api_utils/sockets.js @@ -33,6 +33,7 @@ var url = require('url'); var sockjs = require('sockjs'); var websocket_multiplex = require('websocket-multiplex'); var utils = require('./utils.js'); +var configurationAPI = require('../modules/api/configuration.js'); var Subscriptions = function() { @@ -278,7 +279,7 @@ function PollingSocket(url, req, interval, config) { self.isClosed = false; var requestHeaders = {}; _.extend(requestHeaders, { - 'Authorization': req.get('Authorization') + Cookie: req.get('Cookie') }); var pollServer = function() { diff --git a/skyquake/framework/core/api_utils/utils.js b/skyquake/framework/core/api_utils/utils.js index 5b17279d5..68775f8fe 100644 --- a/skyquake/framework/core/api_utils/utils.js +++ b/skyquake/framework/core/api_utils/utils.js @@ -95,7 +95,7 @@ var validateResponse = function(callerName, error, response, body, resolve, reje var checkAuthorizationHeader = function(req) { return new Promise(function(resolve, reject) { - if (req.get('Authorization') == null) { + if (req.session && req.session.authorization == null) { reject(); } else { resolve(); @@ -200,7 +200,7 @@ var passThroughConstructor = function(app) { uri: uri, method: 'GET', headers: _.extend({}, CONSTANTS.HTTP_HEADERS.accept[type], { - 'Authorization': req.get('Authorization'), + 'Authorization': req.session && req.session.authorization, forever: CONSTANTS.FOREVER_ON, rejectUnauthorized: false, }) diff --git a/skyquake/framework/core/modules/api/descriptorModelMetaAPI.js b/skyquake/framework/core/modules/api/descriptorModelMetaAPI.js index b0223b2ab..34d30b36e 100644 --- a/skyquake/framework/core/modules/api/descriptorModelMetaAPI.js +++ b/skyquake/framework/core/modules/api/descriptorModelMetaAPI.js @@ -36,7 +36,7 @@ ModelMeta.get = function(req) { uri: utils.confdPort(api_server) + '/api/schema/nsd-catalog/nsd', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -46,7 +46,7 @@ ModelMeta.get = function(req) { uri: utils.confdPort(api_server) + '/api/schema/vnfd-catalog/vnfd', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, diff --git a/skyquake/framework/core/modules/api/projectManagementAPI.js b/skyquake/framework/core/modules/api/projectManagementAPI.js index d73eb215c..8eace6b29 100644 --- a/skyquake/framework/core/modules/api/projectManagementAPI.js +++ b/skyquake/framework/core/modules/api/projectManagementAPI.js @@ -36,7 +36,7 @@ ProjectManagement.get = function(req) { uri: utils.confdPort(api_server) + '/api/operational/project', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -75,7 +75,7 @@ ProjectManagement.create = function(req) { uri: utils.confdPort(api_server) + '/api/config/project', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, json: data, @@ -115,7 +115,7 @@ ProjectManagement.update = function(req) { uri: utils.confdPort(api_server) + '/api/config/project', method: 'PUT', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, json: data, @@ -157,7 +157,7 @@ ProjectManagement.delete = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); rp({ url: url, diff --git a/skyquake/framework/core/modules/api/restconf.js b/skyquake/framework/core/modules/api/restconf.js index 5ba0eb5aa..03f27213e 100644 --- a/skyquake/framework/core/modules/api/restconf.js +++ b/skyquake/framework/core/modules/api/restconf.js @@ -45,7 +45,7 @@ restconfAPI['streams'].get = function(req) { url: uri + url + '?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, diff --git a/skyquake/framework/core/modules/api/sessions.js b/skyquake/framework/core/modules/api/sessions.js new file mode 100644 index 000000000..c8a02239c --- /dev/null +++ b/skyquake/framework/core/modules/api/sessions.js @@ -0,0 +1,205 @@ +/* + * + * Copyright 2016 RIFT.IO Inc + * + * 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. + * + */ + +/** + * sessions api module. Provides API functions for sessions + * @module framework/core/modules/api/sessions + * @author Kiran Kashalkar + */ + +var Promise = require('bluebird'); +var constants = require('../../api_utils/constants'); +var utils = require('../../api_utils/utils'); +var request = utils.request; +var rp = require('request-promise'); +var sessionsAPI = {}; +var _ = require('lodash'); +var base64 = require('base-64'); +var APIVersion = '/v2'; + +function logAndReject(mesg, reject) { + res.errorMessage = { + error: mesg + } + console.log(mesg); + reject(res); +} + +function logAndRedirectToLogin(mesg, res, req) { + console.log(mesg); + res.render('login.html?api_server=' + req.query['api_server']); + res.end(); +} + +sessionsAPI.create = function(req, res) { + var api_server = req.query["api_server"]; + var uri = utils.confdPort(api_server); + var login_url = uri + APIVersion + '/api/login'; + var project_url = uri + APIVersion + '/api/operational/project'; + var authorization_header_string = 'Basic ' + base64.encode(req.body['username'] + ':' + req.body['password']); + return new Promise(function(resolve, reject) { + Promise.all([ + rp({ + url: login_url, + method: 'POST', + headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': authorization_header_string + }), + forever: constants.FOREVER_ON, + rejectUnauthorized: constants.REJECT_UNAUTHORIZED, + resolveWithFullResponse: true + }), + rp({ + url: project_url, + method: 'GET', + headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { + 'Authorization': authorization_header_string + }), + forever: constants.FOREVER_ON, + rejectUnauthorized: constants.REJECT_UNAUTHORIZED, + resolveWithFullResponse: true + }) + + ]).then(function(results) { + // results[0].statusCode => 200/201 + // results[1].body.collection['rw-project:project'] => List of projects OR 204 with no content + if (results[0].statusCode != constants.HTTP_RESPONSE_CODES.SUCCESS.OK) { + var errorMsg = 'Invalid credentials provided!'; + logAndRedirectToLogin(errorMsg, res, req); + return; + } + + var username = req.body['username']; + var project_list_for_user = []; + + if (results[1].statusCode == constants.HTTP_RESPONSE_CODES.SUCCESS.NO_CONTENT) { + console.log('No projects added or user ', username ,' not privileged to view projects.'); + } else { + // go through projects and get list of projects that this user belongs to. + // pick first one as default project? + + var projects = JSON.parse(results[1].body).collection['rw-project:project']; + projects && projects.map(function(project) { + project['project-config'] && + project['project-config']['user'] && + project['project-config']['user'].map(function(user) { + if (user['user-name'] == username) { + project_list_for_user.push(project.name); + } + }); + }); + + req.session.projectId = (project_list_for_user.length > 0) && project_list_for_user[0]; + } + + req.session.authorization = authorization_header_string; + req.session.loggedIn = true; + + var successMsg = 'User =>' + username + ' successfully logged in.'; + successMsg += req.session.projectId ? 'Project =>' + req.session.projectId + ' set as default.' : ''; + + console.log(successMsg); + + var response = { + statusCode: constants.HTTP_RESPONSE_CODES.SUCCESS.CREATED, + data: JSON.stringify({ + status: successMsg + }) + }; + resolve(response); + + }).catch(function(error) { + // Something went wrong - Redirect to /login + var errorMsg = 'Error logging in or getting list of projects. Error: ' + error; + console.log(errorMsg); + logAndRedirectToLogin(errorMsg, res, req); + }); + }) +}; + +sessionsAPI.addProjectToSession = function(req, res) { + return new Promise(function(resolve, reject) { + if (req.session && req.session.loggedIn == true) { + req.session.projectId = req.params.projectId; + var successMsg = 'Added project' + projectId + ' to session' + req.sessionID; + console.log(successMsg); + + return resolve ({ + statusCode: constants.HTTP_RESPONSE_CODES.SUCCESS.OK, + data: JSON.stringify({ + status: successMsg + }) + }); + } + + var errorMsg = 'Session does not exist or not logged in'; + logAndReject(errorMsg, reject); + }); +} + +sessionsAPI.delete = function(req, res) { + var reqRef = req; + var res = res; + var api_server = req.query["api_server"]; + var uri = utils.confdPort(api_server); + var url = uri + '/api/logout'; + return new Promise(function(resolve, reject) { + Promise.all([ + rp({ + url: url, + method: 'POST', + headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { + 'Authorization': req.session.authorization + }), + forever: constants.FOREVER_ON, + rejectUnauthorized: constants.REJECT_UNAUTHORIZED + }), + new Promise(function(success, failure) { + req.session.destroy(function(err) { + if (err) { + var errorMsg = 'Error deleting session. Error: ' + err; + console.log(errorMsg); + success({ + status: 'error', + message: errorMsg + }); + } + + var successMsg = 'Success deleting session'; + console.log(successMsg); + + success({ + status: 'success', + message: successMsg + }); + }); + }) + ]).then(function(result) { + // assume the session was deleted! + var message = 'Session was deleted.' + logAndRedirectToLogin(message, res, req); + + }).catch(function(error) { + var message = 'Error deleting session or logging out. Error:' + error; + logAndRedirectToLogin(message, res, req); + }); + }); +} + + +module.exports = sessionsAPI; diff --git a/skyquake/framework/core/modules/api/userManagementAPI.js b/skyquake/framework/core/modules/api/userManagementAPI.js index 397212232..e88a5dca7 100644 --- a/skyquake/framework/core/modules/api/userManagementAPI.js +++ b/skyquake/framework/core/modules/api/userManagementAPI.js @@ -36,7 +36,7 @@ UserManagement.get = function(req) { uri: utils.confdPort(api_server) + '/api/operational/user-config/users', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -75,7 +75,7 @@ UserManagement.create = function(req) { uri: utils.confdPort(api_server) + '/api/config/user-config', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, json: data, @@ -115,7 +115,7 @@ UserManagement.update = function(req) { uri: utils.confdPort(api_server) + '/api/operations/change-password', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, json: { @@ -136,7 +136,7 @@ UserManagement.update = function(req) { uri: utils.confdPort(api_server) + '/api/config/user-config', method: 'PUT', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, json: data, @@ -179,7 +179,7 @@ UserManagement.delete = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); rp({ url: url, diff --git a/skyquake/framework/core/modules/routes/configuration.js b/skyquake/framework/core/modules/routes/configuration.js index b789ff043..37d87feff 100644 --- a/skyquake/framework/core/modules/routes/configuration.js +++ b/skyquake/framework/core/modules/routes/configuration.js @@ -74,7 +74,7 @@ function checkAuth(uri, req){ uri: uri, method: 'GET', headers: _.extend({}, { - 'Authorization': req.get('Authorization'), + 'Authorization': req.session && req.session.authorization, forever: CONSTANTS.FOREVER_ON, rejectUnauthorized: false, }) diff --git a/skyquake/framework/core/modules/routes/navigation.js b/skyquake/framework/core/modules/routes/navigation.js index 82c7ec580..9b8fbf7ec 100644 --- a/skyquake/framework/core/modules/routes/navigation.js +++ b/skyquake/framework/core/modules/routes/navigation.js @@ -37,8 +37,20 @@ Router.use(bodyParser.urlencoded({ extended: true })); -Router.get('/', cors(), function(req, res, next) { - res.redirect('/launchpad/?api_server=' + req.protocol + '://' + configurationAPI.globalConfiguration.get().api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname)); +Router.get('/login.html', cors(), function(req, res) { + res.render('login.html'); + res.end(); +}); + +Router.get('/', cors(), function(req, res) { + var api_server = req.query['api_server'] || (req.protocol + '://' + configurationAPI.globalConfiguration.get().api_server); + if (req.session.loggedIn) { + console.log('Logged in. Redirect to launchpad') + res.redirect('/launchpad/?api_server=' + api_server + '&upload_server=' + req.protocol + '://' + (configurationAPI.globalConfiguration.get().upload_server || req.hostname)); + } else { + console.log('Redirect to login.html'); + res.redirect('login.html?api_server=' + api_server); + } }); Router.get('/nav', cors(), function(req, res) { diff --git a/skyquake/framework/core/modules/routes/sessions.js b/skyquake/framework/core/modules/routes/sessions.js new file mode 100644 index 000000000..bd2179bef --- /dev/null +++ b/skyquake/framework/core/modules/routes/sessions.js @@ -0,0 +1,62 @@ + +/* + * + * Copyright 2016 RIFT.IO Inc + * + * 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. + * + */ + +/** + * Node sessions routes module. + * Provides a RESTful API to manage sessions. + * @module framework/core/modules/routes/sessions + * @author Kiran Kashalkar + */ + +var cors = require('cors'); +var bodyParser = require('body-parser'); +var sessionsAPI = require('../api/sessions'); +var Router = require('express').Router(); +var utils = require('../../api_utils/utils'); +var CONSTANTS = require('../../api_utils/constants.js'); +var request = require('request'); +var _ = require('lodash'); + +Router.use(bodyParser.json()); +Router.use(cors()); +Router.use(bodyParser.urlencoded({ + extended: true +})); + +Router.post('/session', cors(), function(req, res) { + sessionsAPI.create(req, res).then(function(data) { + utils.sendSuccessResponse(data, res); + }); +}); + +// For project switcher UI +Router.put('/session/:projectId', cors(), function(req, res) { + sessionsAPI.addProjectToSession(req, res).then(function(data) { + utils.sendSuccessResponse(data, res); + }, function(error) { + utils.sendErrorResponse(error, res); + }); +}); + +Router.delete('/session', cors(), function(req, res) { + sessionsAPI.delete(req, res); +}); + + +module.exports = Router; diff --git a/skyquake/framework/core/views/login.html b/skyquake/framework/core/views/login.html new file mode 100644 index 000000000..eb5e71474 --- /dev/null +++ b/skyquake/framework/core/views/login.html @@ -0,0 +1,118 @@ + + + +Login Page + + + + +
+ +

Launchpad Login

+
+
+ +
+ + \ No newline at end of file diff --git a/skyquake/framework/utils/utils.js b/skyquake/framework/utils/utils.js index e8e9ad1a9..be3278d08 100644 --- a/skyquake/framework/utils/utils.js +++ b/skyquake/framework/utils/utils.js @@ -129,8 +129,9 @@ Utils.getDescriptorModelMeta = function() { } Utils.addAuthorizationStub = function(xhr) { - var Auth = window.sessionStorage.getItem("auth"); - xhr.setRequestHeader('Authorization', 'Basic ' + Auth); + // NO-OP now that we are dealing with it on the server + // var Auth = window.sessionStorage.getItem("auth"); + // xhr.setRequestHeader('Authorization', 'Basic ' + Auth); }; Utils.getByteDataWithUnitPrefix = function(number, precision) { @@ -208,10 +209,22 @@ Utils.clearAuthentication = function(callback) { window.sessionStorage.removeItem("auth"); AuthActions.notAuthenticated(); window.sessionStorage.setItem("locationRefHash", window.location.hash); + $.ajax({ + url: '//' + window.location.hostname + ':' + window.location.port + '/session?api_server=' + API_SERVER, + type: 'DELETE', + success: function(data) { + console.log('User logged out'); + }, + error: function(data) { + console.log('Problem logging user out'); + } + }); + + if (callback) { callback(); } else { - window.location.hash = Utils.loginHash; + window.location.replace(window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + '/?api_server=' + API_SERVER); } } Utils.isNotAuthenticated = function(windowLocation, callback) { diff --git a/skyquake/package.json b/skyquake/package.json index 857856246..60d22db3a 100644 --- a/skyquake/package.json +++ b/skyquake/package.json @@ -12,6 +12,7 @@ "dependencies": { "alt": "^0.18.3", "alt-container": "^1.0.2", + "base-64": "^0.1.0", "bluebird": "^3.4.1", "body-parser": "^1.14.2", "cors": "^2.7.1", diff --git a/skyquake/plugins/about/api/about.js b/skyquake/plugins/about/api/about.js index d77a43a22..82cbafb2f 100644 --- a/skyquake/plugins/about/api/about.js +++ b/skyquake/plugins/about/api/about.js @@ -32,7 +32,7 @@ About.getVCS = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion + '/api/operational/vcs/info?deep', @@ -64,7 +64,7 @@ About.getVersion = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion + '/api/operational/version?deep', @@ -116,7 +116,7 @@ About.uptime = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion + '/api/operational/uptime/uptime', diff --git a/skyquake/plugins/accounts/api/accounts.js b/skyquake/plugins/accounts/api/accounts.js index ec74f51e7..cf0e4048d 100644 --- a/skyquake/plugins/accounts/api/accounts.js +++ b/skyquake/plugins/accounts/api/accounts.js @@ -93,7 +93,7 @@ function getAccount(req) { _.extend( requestHeaders, id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); @@ -160,7 +160,7 @@ function updateAccount(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: url, @@ -194,7 +194,7 @@ function deleteAccount(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: url, @@ -238,7 +238,7 @@ function refreshAccountConnectionStatus (req) { var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); return new Promise(function(resolve, reject) { diff --git a/skyquake/plugins/accounts/api/cloud_account/cloudAccount.js b/skyquake/plugins/accounts/api/cloud_account/cloudAccount.js index 54757507e..28f780cd5 100644 --- a/skyquake/plugins/accounts/api/cloud_account/cloudAccount.js +++ b/skyquake/plugins/accounts/api/cloud_account/cloudAccount.js @@ -40,7 +40,7 @@ Cloud.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -77,7 +77,7 @@ Cloud.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -128,7 +128,7 @@ Cloud.create = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -167,7 +167,7 @@ Cloud.update = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -209,7 +209,7 @@ Cloud.delete = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion + '/api/config/cloud/account/' + id, @@ -237,7 +237,7 @@ Cloud.getResources = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -280,7 +280,7 @@ Cloud.getPools = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ diff --git a/skyquake/plugins/accounts/api/config_agent/configAgent.js b/skyquake/plugins/accounts/api/config_agent/configAgent.js index 8d1734b16..e717c4e56 100644 --- a/skyquake/plugins/accounts/api/config_agent/configAgent.js +++ b/skyquake/plugins/accounts/api/config_agent/configAgent.js @@ -37,7 +37,7 @@ ConfigAgentAccount.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -77,7 +77,7 @@ ConfigAgentAccount.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -130,7 +130,7 @@ ConfigAgentAccount.create = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -169,7 +169,7 @@ ConfigAgentAccount.update = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -211,7 +211,7 @@ ConfigAgentAccount.delete = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + '/api/config/config-agent/account/' + id, diff --git a/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js b/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js index 6757c2891..a3ddf0b21 100644 --- a/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js +++ b/skyquake/plugins/accounts/api/sdn_account/sdnAccount.js @@ -38,7 +38,7 @@ Sdn.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + '/api/operational/sdn/account?deep', @@ -77,7 +77,7 @@ Sdn.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -130,7 +130,7 @@ Sdn.create = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -168,7 +168,7 @@ Sdn.update = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -211,7 +211,7 @@ Sdn.delete = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ diff --git a/skyquake/plugins/composer/api/composer.js b/skyquake/plugins/composer/api/composer.js index ebe56360c..a4f9bd9a4 100644 --- a/skyquake/plugins/composer/api/composer.js +++ b/skyquake/plugins/composer/api/composer.js @@ -40,7 +40,7 @@ Composer.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/nsd-catalog/nsd?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -50,7 +50,7 @@ Composer.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/vnfd-catalog/vnfd?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -60,7 +60,7 @@ Composer.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/operational/ns-instance-opdata?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -73,7 +73,7 @@ Composer.get = function(req) { // headers: _.extend({}, // constants.HTTP_HEADERS.accept.collection, // { - // 'Authorization': req.get('Authorization') + // 'Authorization': req.session && req.session.authorization // }), // forever: constants.FOREVER_ON, // rejectUnauthorized: false, @@ -173,7 +173,7 @@ Composer.delete = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog/' + catalogType + '/' + id, method: 'DELETE', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -189,7 +189,7 @@ Composer.delete = function(req) { Composer.getVNFD = function(req) { var api_server = req.query['api_server']; var vnfdID = req.body.data; - var authorization = req.get('Authorization'); + var authorization = req.session && req.session.authorization; var VNFDs = []; if (typeof(vnfdID) == "object" && vnfdID.constructor.name == "Array") { vnfdID.map(function(id) { @@ -254,7 +254,7 @@ Composer.create = function(req) { return new Promise(function(resolve, reject) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + '/api/config/' + catalogType + '-catalog', @@ -284,7 +284,7 @@ Composer.updateSave = function(req) { return new Promise(function(resolve, reject) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog' + '/' + catalogType + '/' + id, @@ -325,7 +325,7 @@ Composer.update = function(req) { uri: utils.confdPort(api_server) + '/api/operations/package-update', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -377,7 +377,7 @@ Composer.upload = function(req) { uri: utils.confdPort(api_server) + '/api/operations/package-create', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -439,7 +439,7 @@ Composer.addFile = function(req) { uri: utils.confdPort(api_server) + '/api/operations/package-file-add', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -477,7 +477,7 @@ Composer.exportPackage = function(req) { uri: utils.confdPort(api_server) + '/api/operations/package-export', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -535,7 +535,7 @@ FileManager.get = function(req) { uri: utils.confdPort(api_server) + '/api/operations/rw-pkg-mgmt:package-file-delete', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), json: payload, forever: constants.FOREVER_ON, @@ -557,7 +557,7 @@ FileManager.get = function(req) { uri: utils.confdPort(api_server) + '/api/operations/rw-pkg-mgmt:package-file-add', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), json: payload, forever: constants.FOREVER_ON, @@ -579,7 +579,7 @@ FileManager.get = function(req) { uri: utils.confdPort(api_server) + '/api/operations/get-package-endpoint', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), json: payload, forever: constants.FOREVER_ON, @@ -600,7 +600,7 @@ FileManager.get = function(req) { uri: api_server + ':' + parsedEndpoint.port + parsedEndpoint.path, method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -631,7 +631,7 @@ FileManager.job = function(req) { url: uri + url + '?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, diff --git a/skyquake/plugins/composer/api/packageFileHandler.js b/skyquake/plugins/composer/api/packageFileHandler.js index cc9cca7c3..b38abdecc 100644 --- a/skyquake/plugins/composer/api/packageFileHandler.js +++ b/skyquake/plugins/composer/api/packageFileHandler.js @@ -6,7 +6,7 @@ var constants = require('../../../framework/core/api_utils/constants.js'); var fs = require('fs'); var _ = require('lodash'); -PackageFileHandler = {}; +var PackageFileHandler = {}; function deleteFile(filename) { setTimeout(function() { @@ -18,7 +18,7 @@ function checkStatus(req, transactionId, isUpdate) { var upload_server = req.query['upload_server']; var headers = _.extend({}, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); var type = isUpdate ? 'update' : 'upload'; diff --git a/skyquake/plugins/config/api/ro.js b/skyquake/plugins/config/api/ro.js index 99fb1d73c..5b2a33440 100644 --- a/skyquake/plugins/config/api/ro.js +++ b/skyquake/plugins/config/api/ro.js @@ -18,7 +18,7 @@ return new Promise(function(resolve, reject) { _.extend( requestHeaders, id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); @@ -71,7 +71,7 @@ function updateAccount(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: url, diff --git a/skyquake/plugins/debug/api/debug.js b/skyquake/plugins/debug/api/debug.js index 5d6e0ea36..b02ae8826 100644 --- a/skyquake/plugins/debug/api/debug.js +++ b/skyquake/plugins/debug/api/debug.js @@ -33,7 +33,7 @@ crashDetails.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion +'/api/operational/crash?deep', diff --git a/skyquake/plugins/launchpad/api/launchpad.js b/skyquake/plugins/launchpad/api/launchpad.js index 6fb01704a..1ba038bd1 100644 --- a/skyquake/plugins/launchpad/api/launchpad.js +++ b/skyquake/plugins/launchpad/api/launchpad.js @@ -55,7 +55,7 @@ RPC.executeNSServicePrimitive = function(req) { var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); request({ @@ -88,7 +88,7 @@ RPC.getNSServicePrimitiveValues = function(req) { var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); request({ @@ -136,7 +136,7 @@ RPC.refreshAccountConnectionStatus = function(req) { var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); return new Promise(function(resolve, reject) { @@ -174,7 +174,7 @@ Catalog.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/nsd-catalog/nsd?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -184,7 +184,7 @@ Catalog.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/vnfd-catalog/vnfd?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -194,7 +194,7 @@ Catalog.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/operational/ns-instance-opdata?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -207,7 +207,7 @@ Catalog.get = function(req) { // headers: _.extend({}, // constants.HTTP_HEADERS.accept.collection, // { - // 'Authorization': req.get('Authorization') + // 'Authorization': req.session && req.session.authorization // }), // forever: constants.FOREVER_ON, // rejectUnauthorized: false, @@ -318,7 +318,7 @@ Catalog.delete = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog/' + catalogType + '/' + id, method: 'DELETE', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -334,7 +334,7 @@ Catalog.delete = function(req) { Catalog.getVNFD = function(req) { var api_server = req.query['api_server']; var vnfdID = req.body.data; - var authorization = req.get('Authorization'); + var authorization = req.session && req.session.authorization; var VNFDs = []; if (typeof(vnfdID) == "object" && vnfdID.constructor.name == "Array") { vnfdID.map(function(id) { @@ -399,7 +399,7 @@ Catalog.create = function(req) { return new Promise(function(resolve, reject) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog', @@ -429,7 +429,7 @@ Catalog.update = function(req) { return new Promise(function(resolve, reject) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + APIVersion + '/api/config/' + catalogType + '-catalog' + '/' + catalogType + '/' + id, @@ -513,7 +513,7 @@ NSR.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/nsd-catalog/nsd?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -536,7 +536,7 @@ NSR.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/operational/ns-instance-config/nsr' + (id ? '/' + id : '') + '?deep', method: 'GET', headers: _.extend({}, id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -560,7 +560,7 @@ NSR.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/operational/ns-instance-opdata/nsr' + (id ? '/' + id : '') + '?deep', method: 'GET', headers: _.extend({}, id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -860,7 +860,7 @@ NSR.create = function(req) { return new Promise(function(resolve, reject) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + APIVersion + '/api/config/ns-instance-config', @@ -904,7 +904,7 @@ NSR.delete = function(req) { return new Promise(function(resolve, reject) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + APIVersion + '/api/config/ns-instance-config/nsr/' + id, @@ -1000,7 +1000,7 @@ NSR.setStatus = function(req) { } var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + APIVersion + '/api/config/ns-instance-config/nsr/' + id + '/admin-status/', @@ -1053,7 +1053,7 @@ NSR.createScalingGroupInstance = function(req) { constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); @@ -1102,7 +1102,7 @@ NSR.deleteScalingGroupInstance = function(req) { constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); @@ -1146,7 +1146,7 @@ NSR.nsd.vld.get = function(req) { _.extend(requestHeaders, vld_id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); @@ -1191,7 +1191,7 @@ NSR.nsd.vld.create = function(req) { return new Promise(function(resolve, reject) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ uri: utils.confdPort(api_server) + '/api/config/ns-instance-config/nsr/' + nsr_id + '/nsd/vld' + (vld_id ? '/' + vld_id : ''), @@ -1233,7 +1233,7 @@ NSR.nsd.vld.delete = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization } ); @@ -1260,7 +1260,7 @@ VNFR.get = function(req) { var uri = utils.confdPort(api_server); uri += APIVersion + '/api/operational/vnfr-catalog/vnfr' + (id ? '/' + id : '') + '?deep'; var headers = _.extend({}, id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); return new Promise(function(resolve, reject) { request({ @@ -1335,7 +1335,7 @@ VNFR.getByNSR = function(req) { delete reqClone.params.id; uri += APIVersion + '/api/operational/ns-instance-opdata/nsr/' + id + '?deep'; var headers = _.extend({}, id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); return new Promise(function(resolve, reject) { if (VNFR.cachedNSR[id]) { @@ -1382,7 +1382,7 @@ VLR.get = function(req) { var uri = utils.confdPort(api_server); uri += APIVersion + '/api/operational/vlr-catalog/vlr' + (id ? '/' + id : '') + '?deep'; var headers = _.extend({}, id ? constants.HTTP_HEADERS.accept.data : constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); return new Promise(function(resolve, reject) { request({ @@ -1413,7 +1413,7 @@ RIFT.api = function(req) { url: uri + url + '?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -1442,7 +1442,7 @@ ComputeTopology.get = function(req) { method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -1490,7 +1490,7 @@ ComputeTopology.get = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/operational/vnfr-catalog/vnfr/' + vnfrId + '?deep', method: 'GET', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -1581,7 +1581,7 @@ NetworkTopology.get = function(req) { var uri = utils.confdPort(api_server); uri += APIVersion + '/api/operational/network?deep'; var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); return new Promise(function(resolve, reject) { request({ @@ -1612,7 +1612,7 @@ VDUR.get = function(req) { var uri = utils.confdPort(api_server); uri += APIVersion + '/api/operational/vnfr-catalog/vnfr/' + vnfrID + '/vdur/' + vdurID + '?deep'; var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); return new Promise(function(resolve, reject) { request({ @@ -1639,7 +1639,7 @@ VDUR.consoleUrl.get = function(req) { var uri = utils.confdPort(api_server); uri += APIVersion + '/api/operational/vnfr-console/vnfr/' + vnfrID + '/vdur/' + vdurID + '/console-url' + '?deep'; var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); return new Promise(function(resolve, reject) { request({ @@ -1666,7 +1666,7 @@ CloudAccount.get = function(req) { var uri = utils.confdPort(api_server); uri += APIVersion + '/api/operational/cloud/account?deep'; var headers = _.extend({}, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); return new Promise(function(resolve, reject) { request({ @@ -1703,7 +1703,7 @@ ConfigAgentAccount.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.collection, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -1743,7 +1743,7 @@ ConfigAgentAccount.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -1796,7 +1796,7 @@ ConfigAgentAccount.create = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -1835,7 +1835,7 @@ ConfigAgentAccount.update = function(req) { _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ @@ -1877,7 +1877,7 @@ ConfigAgentAccount.delete = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion + '/api/config/config-agent/account/' + id, @@ -1903,7 +1903,7 @@ DataCenters.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion + '/api/operational/datacenters?deep', @@ -1944,7 +1944,7 @@ SSHkey.get = function(req) { var requestHeaders = {}; _.extend(requestHeaders, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); request({ url: utils.confdPort(api_server) + APIVersion + '/api/config/key-pair?deep', @@ -1984,7 +1984,7 @@ SSHkey.delete = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/key-pair/' + id, method: 'DELETE', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: constants.FOREVER_ON, rejectUnauthorized: false, @@ -2005,7 +2005,7 @@ SSHkey.post = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/key-pair/', method: 'POST', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), json: data, forever: constants.FOREVER_ON, @@ -2028,7 +2028,7 @@ SSHkey.put = function(req) { uri: utils.confdPort(api_server) + APIVersion + '/api/config/key-pair/', method: 'PUT', headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), json: data, forever: constants.FOREVER_ON, diff --git a/skyquake/plugins/logging/api/logging.js b/skyquake/plugins/logging/api/logging.js index 06c27d8c5..08103d8d3 100644 --- a/skyquake/plugins/logging/api/logging.js +++ b/skyquake/plugins/logging/api/logging.js @@ -43,7 +43,7 @@ var Test = {}; function buildGetRequestOptions(req, endpoint) { var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); var api_server = req.query["api_server"]; var requestOptions = { @@ -60,7 +60,7 @@ function buildPutRequestOptions(req, endpoint, jsonData) { var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); var api_server = req.query["api_server"]; var requestOptions = { @@ -79,7 +79,7 @@ function buildDeleteRequestOptions(req, endpoint) { var headers = _.extend({}, constants.HTTP_HEADERS.accept.data, constants.HTTP_HEADERS.content_type.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }); var api_server = req.query["api_server"]; var requestOptions = { @@ -447,7 +447,7 @@ SysLogViewer.get = function(req) { headers: _.extend({}, constants.HTTP_HEADERS.accept.data, { - 'Authorization': req.get('Authorization') + 'Authorization': req.session && req.session.authorization }), forever: foreverOn, rejectUnauthorized: false diff --git a/skyquake/plugins/logging/api/transforms.js b/skyquake/plugins/logging/api/transforms.js index 2e2b8dceb..301b1eb32 100644 --- a/skyquake/plugins/logging/api/transforms.js +++ b/skyquake/plugins/logging/api/transforms.js @@ -40,7 +40,8 @@ Support.severities = function() { * Class to convert RESTConf data to logging plugin */ - +var LoggingConfigDecoder = {}; +var LoggingConfigEncoder = {}; LoggingConfigDecoder = function(debugMode) { this.debugMode = debugMode || false diff --git a/skyquake/skyquake.js b/skyquake/skyquake.js index 3fd904dbf..4c5adcf93 100644 --- a/skyquake/skyquake.js +++ b/skyquake/skyquake.js @@ -105,6 +105,9 @@ if (cluster.isMaster && clusteredLaunch) { var app = express(); + app.set('views', __dirname + '/framework/core/views'); + app.engine('html', require('ejs').renderFile); + app.use(session({ secret: 'ritio rocks', resave: true, @@ -137,6 +140,7 @@ if (cluster.isMaster && clusteredLaunch) { var configurationAPI = require('./framework/core/modules/api/configuration'); var userManagement_routes = require('./framework/core/modules/routes/userManagement'); var projectManagement_routes = require('./framework/core/modules/routes/projectManagement'); + var session_routes = require('./framework/core/modules/routes/sessions'); /** * Processing when a plugin is added or modified * @param {string} plugin_name - Name of the plugin @@ -158,6 +162,15 @@ if (cluster.isMaster && clusteredLaunch) { } + /** + * Serve jquery + */ + app.use('/jquery', express.static('./node_modules/jquery/dist/jquery.min.js')); + /** + * Serve images + */ + app.use('/img', express.static('./framework/style/img')); + /** * Start listening on a port * @param {string} port - Port to listen on @@ -222,6 +235,9 @@ if (cluster.isMaster && clusteredLaunch) { //Configure project management route(s) app.use(projectManagement_routes); + //Configure session route(s) + app.use(session_routes); + // app.get('/testme', function(req, res) { // res.sendFile(__dirname + '/index.html'); // });