/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
sendSuccessResponse: sendSuccessResponse,
- passThroughConstructor: passThroughConstructor
+ passThroughConstructor: passThroughConstructor
};
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
/**
- * Node configuration routes module.
+ * Node configuration routes module.
* Provides a RESTful API to provide configuration
* details such as api_server.
* @module framework/core/modules/routes/configuration
var configurationAPI = require('../api/configuration');
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.get('/server-configuration', cors(), function(req, res) {
configurationAPI.get(req).then(function(data) {
utils.sendSuccessResponse(data, res);
- }, function(error) {
- utils.sendErrorResponse(error, res);
- });
+ }, function(error) {
+ utils.sendErrorResponse(error, res);
+ });
+});
+
+Router.get('/check-auth', function(req, res) {
+ console.log('testing auth')
+ var api_server = req.query["api_server"];
+ var uri = utils.confdPort(api_server) + '/api/config/';
+
+ checkAuth(uri, req).then(function(data) {
+ utils.sendSuccessResponse(data, res);
+ }, function(error) {
+ utils.sendErrorResponse(error, res);
+ });
});
+function checkAuth(uri, req){
+ return new Promise(function(resolve, reject) {
+ request({
+ uri: uri,
+ method: 'GET',
+ headers: _.extend({}, {
+ 'Authorization': req.get('Authorization'),
+ forever: CONSTANTS.FOREVER_ON,
+ rejectUnauthorized: false,
+ })
+ }, function(error, response, body) {
+ console.log(arguments)
+ if( response.statusCode == 401) {
+ reject({statusCode: 401, error: response.body});
+ } else {
+ resolve({statusCode:200, data:response.body})
+ }
+ });
+ });
+}
+
+
module.exports = Router;
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
var $ = require('jquery');
var rw = require('utils/rw.js');
var API_SERVER = rw.getSearchParams(window.location).api_server;
-var NODE_PORT = 3000;
+let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
var SockJS = require('sockjs-client');
var Utils = {};
var AuthBase64 = btoa(username + ":" + password);
window.sessionStorage.setItem("auth", AuthBase64);
self.detectInactivity();
- if (cb) {
- cb();
- }
+ $.ajax({
+ url: '//' + window.location.hostname + ':' + NODE_PORT + '/check-auth?api_server=' + API_SERVER,
+ type: 'GET',
+ beforeSend: Utils.addAuthorizationStub,
+ success: function(data) {
+ //console.log("LoggingSource.getLoggingConfig success call. data=", data);
+ if (cb) {
+ cb();
+ };
+ },
+ error: function(data) {
+ Utils.clearAuthentication();
+ }
+ });
}
Utils.clearAuthentication = function(callback) {
var self = this;
type: 'GET',
// beforeSend: Utils.addAuthorizationStub,
success: function(data) {
+ Utils.detectInactivity();
resolve(data);
}
})
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
var Accounts = {};
var nameSpace = {
cloud: 'cloud',
- sdn: 'sdn-account',
+ sdn: 'sdn',
'config-agent': 'config-agent'
};
Accounts.get = function(req) {
type: req.params.type
})
});
- })
+ }, function(reason) {
+ reject(reason);
+ })
} else {
getAll(req, resolve, reject);
}
statusCode: 200,
data: ReturnData
});
+ }, function(reason) {
+ reject(reason);
})
}
}
var id = req.params.id || req.params.name;
var requestHeaders = {};
var type = nameSpace[req.params.type];
- var url = utils.confdPort(api_server) + '/api/operational/' + type;
- //SDN model doesn't follow convention
- if (type != 'sdn-account') {
- url += '/account';
- }
+ var url = utils.confdPort(api_server) + '/api/operational/' + type + '/account';
if (id) {
url += '/' + id;
}
var data;
var objKey = 'rw-' + type + ':account';
//SDN model doesn't follow convention
- if (type == 'sdn-account') {
- objKey = 'rw-sdn:sdn-account';
- }
if (utils.validateResponse(type.toUpperCase() + '.get', error, response, body, resolve, reject)) {
try {
data = JSON.parse(response.body);
if (!id) {
data = data.collection;
}
-
data = data[objKey]
} catch (e) {
console.log('Problem with "' + type.toUpperCase() + '.get"', e);
var url = utils.confdPort(api_server) + '/api/config/' + type;
var method = 'POST'
if (!id) {
- if (type == 'sdn-account') {
- createData = {
- 'sdn-account': Array.isArray(data) ? data : [data]
- }
- } else {
- createData = {
- 'account': Array.isArray(data) ? data : [data]
- }
+ createData = {
+ 'account': Array.isArray(data) ? data : [data]
}
console.log('Creating ' + type + ' account: ', createData);
} else {
method = 'PUT';
- if (type == 'sdn-account') {
- url += '/' + id;
- createData['rw-sdn:sdn-account'] = Array.isArray(data) ? data : [data];
-
- } else {
- url += '/account/' + id;
- createData['rw-' + type + ':account'] = Array.isArray(data) ? data : [data];
- }
- //createData = createData[0];
+ url += '/account/' + id;
+ createData['rw-' + type + ':account'] = Array.isArray(data) ? data : [data];
}
var requestHeaders = {};
var createData = {};
var url = utils.confdPort(api_server) + '/api/config/' + type;
- if (type == 'sdn-account') {
- url += '/' + id;
- } else {
- url += '/account/' + id;
- }
+ url += '/account/' + id;
return new Promise(function(resolve, reject) {
_.extend(requestHeaders,
constants.HTTP_HEADERS.accept.data,
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
'Authorization': req.get('Authorization')
});
request({
- url: utils.confdPort(api_server) + '/api/operational/sdn-account?deep',
+ url: utils.confdPort(api_server) + '/api/operational/sdn/account?deep',
type: 'GET',
headers: requestHeaders,
forever: constants.FOREVER_ON,
var data;
if (utils.validateResponse('Sdn.get', error, response, body, resolve, reject)) {
try {
- data = JSON.parse(response.body).collection['rw-sdn:sdn-account']
+ data = JSON.parse(response.body).collection['rw-sdn:account']
} catch (e) {
console.log('Problem with "Sdn.get"', e);
});
request({
- url: utils.confdPort(api_server) + '/api/operational/sdn-account/' + id + '?deep',
+ url: utils.confdPort(api_server) + '/api/operational/sdn/account/' + id + '?deep',
type: 'GET',
headers: requestHeaders,
forever: constants.FOREVER_ON,
var data;
if (utils.validateResponse('Sdn.get', error, response, body, resolve, reject)) {
try {
- data = JSON.parse(response.body)['rw-sdn:sdn-account'];
+ data = JSON.parse(response.body)['rw-sdn:sdn'];
} catch (e) {
console.log('Problem with "Sdn.get"', e);
});
request({
- url: utils.confdPort(api_server) + '/api/config/sdn-account',
+ url: utils.confdPort(api_server) + '/api/config/sdn/account',
method: 'POST',
headers: requestHeaders,
forever: constants.FOREVER_ON,
return new Promise(function(resolve, reject) {
var jsonData = {
- "rw-sdn:sdn-account": data
+ "rw-sdn:sdn": data
};
console.log('Updating SDN account ', id, ' with', JSON.stringify(jsonData));
});
request({
- url: utils.confdPort(api_server) + '/api/config/sdn-account/' + id,
+ url: utils.confdPort(api_server) + '/api/config/sdn/account/' + id,
method: 'PUT',
headers: requestHeaders,
forever: constants.FOREVER_ON,
});
request({
- url: utils.confdPort(api_server) + '/api/config/sdn-account/' + id,
+ url: utils.confdPort(api_server) + '/api/config/sdn/account/' + id,
method: 'DELETE',
headers: requestHeaders,
forever: constants.FOREVER_ON,
/*
- *
+ *
* Copyright 2016 RIFT.IO Inc
*
* Licensed under the Apache License, Version 2.0 (the "License");
}
}
componentWillUnmount() {
+ this.props.store.closeSocket();
this.props.store.unlisten(this.storeListener);
}
setUp(props){
<div className="accountForm-content" style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}>
<div style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}>
<AccountConnectivityStatus status={Account['connection-status'].status} />
- {Account['connection-status'].status.toUpperCase()}
+ {Account['connection-status'] && Account['connection-status'].status && Account['connection-status'].status.toUpperCase()}
</div>
<Button className="refreshList light" onClick={this.props.store.refreshAccount.bind(this, Account.name, AccountType)} label="REFRESH STATUS"></Button>
</div>
{
- Account['connection-status'].status.toUpperCase() === 'FAILURE' ?
+ (Account['connection-status'] && Account['connection-status'].status && Account['connection-status'].status.toUpperCase()) === 'FAILURE' ?
displayFailureMessage(Account['connection-status'].details) : null
}
</div>
return new Promise(function(resolve, reject) {
//If socket connection already exists, eat the request.
if(state.socket) {
+ console.log('connection already exists')
return resolve(false);
}
$.ajax({
import AccountActions from './accountActions.js';
import AccountSource from './accountSource.js';
-
+var Utils = require('utils/utils.js');
var rw = require('utils/rw.js');
var altImage = rw.getSearchParams(window.location).alt_image;
openAccountSocketSuccess = (connection) => {
let self = this;
let ws = window.multiplexer.channel(connection);
-
if (!connection) return;
this.setState({
socket: ws.ws,
ws.onmessage = (socket) => {
try {
var data = JSON.parse(socket.data);
+ Utils.checkAuthentication(data.statusCode, function() {
+ self.closeSocket();
+ });
let SdnOptions = [{
label: 'Select an SDN Account',
value: false
}
generateOptionsByName(data) {
let results = [];
- if (data.constructor.name == "Array") {
+ if (data && data.constructor.name == "Array") {
data.map(function(d) {
results.push({
label: d.name,
}
}
-
-/**
- *Cloud
- *
- * {"name":"eng2","account-type":"openstack","openstack":{"key":"lmaultsb","secret":"mypasswd","auth_url":"http://engstack.eng.riftio.com:5000/v3/","tenant":"lmaultsb","mgmt-network":"private"}}
-Name
-Path
-
-
-SDN
-
-
- *
- *
- */
const onFocus = onFocusPropertyFormInputElement.bind(container, property, path, value);
const placeholder = changeCase.title(property.name);
const className = ClassNames(property.name + '-input', {'-is-guid': isGuid});
- const fieldValue = value ? value.constructor.name == "String" ? value : '' : undefined;
+ const fieldValue = value ? (value.constructor.name != "Object") ? value : '' : undefined;
if (isEnumeration) {
const enumeration = Property.getEnumeration(property, value);
const options = enumeration.map((d, i) => {
}
}
-export default class AccountStore {
+export default class ConfigStore {
constructor() {
this.account = {};
this.accountType = 'openmano';
}
</div>
<div className="form-actions">
- <Button className="light" label="Cancel" />
<Button key="4" role="button" className="update dark" label="Update" onClick={this.updateAccount} />
</div>
</form>
let newState = {
dataCenters: dataCenters || []
};
- if (this.ro['account-type'] == 'openmano') {
+ if (this.ro && this.ro['account-type'] == 'openmano') {
newState.dataCenterID = dataCenters[this.ro.name][0].uuid
}
this.setState(newState)
return window.location.hash = 'launchpad/' + tokenizedHash[2];
}
launchNSRError(error) {
- Alt.actions.global.showError.defer('Something went wrong while trying to instantiate. Check the error logs for more information');
+ var msg = 'Something went wrong while trying to instantiate. Check the error logs for more information';
+ if(error) {
+ msg = error;
+ }
+ Alt.actions.global.showNotification.defer(msg);
Alt.actions.global.hideScreenLoader.defer();
this.setState({
isLoading: false
}).fail(function(xhr){
//Authentication and the handling of fail states should be wrapped up into a connection class.
Utils.checkAuthentication(xhr.status);
- reject();
+ var error;
+ if(xhr.responseText) {
+ try {
+ error = JSON.parse(xhr.responseText);
+ error = JSON.parse(error.error)['rpc-reply']['rpc-error']['error-message'];
+ } catch(e){
+ console.log(e);
+ }
+ }
+ reject(error);
});
})
},