Add option to specify surveil api url

Change-Id: Ia3abf43f1dfc0b076520437741b00837b8249d1e
This commit is contained in:
Vincent Fournier 2015-07-29 12:52:51 -04:00
parent c7c793b699
commit 6d40b87c7d
5 changed files with 130 additions and 101 deletions

View File

@ -31,12 +31,9 @@ angular.module('bansho.authentication', [])
login($scope.credentials);
};
if (authService.isAuthenticated()) {
login($scope.credentials);
}
configManager.loadDevelopmentConfig().then(function () {
var devConfig = configManager.getDevelopmentConfig();
if (devConfig.env === 'development') {
login({
'auth': {
@ -47,6 +44,8 @@ angular.module('bansho.authentication', [])
}
}
});
} else if (authService.isAuthenticated()) {
login($scope.credentials);
}
}, function () {
@ -55,13 +54,13 @@ angular.module('bansho.authentication', [])
}])
.factory('authService', [ '$http', '$location', '$rootScope', 'session', 'configManager', 'themeManager',
function ($http, $location, $rootScope, session, configManager, themeManager) {
.factory('authService', [ '$http', '$location', '$rootScope', 'session', 'configManager', 'themeManager', 'surveilConfig',
function ($http, $location, $rootScope, session, configManager, themeManager, surveilConfig) {
var authService = {};
authService.login = function (credentials) {
return $http
.post('surveil/v2/auth/tokens/', credentials)
.post(surveilConfig.getAuthUrl() + '/tokens/', credentials)
.success(function (data) {
$rootScope.isAuthenticated = true;

View File

@ -87,7 +87,8 @@ angular.module('bansho.config', [])
};
}])
.service('configManager', ['$http', '$q', 'componentsConfig', function ($http, $q, componentsConfig) {
.service('configManager', ['$http', '$q', 'componentsConfig', 'surveilConfig',
function ($http, $q, componentsConfig, surveilConfig) {
var config = {},
developmentConfig = {};
@ -97,6 +98,8 @@ angular.module('bansho.config', [])
$http.get('components/config/developmentConfig.json')
.success(function (config) {
developmentConfig = config;
surveilConfig.setSurveilApiUrl(config.surveilApiUrl);
surveilConfig.setAuthUrl(config.surveilAuthUrl);
promise.resolve();
})
.error(function() {
@ -141,7 +144,7 @@ angular.module('bansho.config', [])
var saveConfig = function () {
var responsePromise = $q.defer();
$http.post('surveil/v2/bansho/config', JSON.stringify(config.data))
$http.post(surveilConfig.endpoint('config'), JSON.stringify(config.data))
.success(function () {
responsePromise.resolve();
})
@ -157,14 +160,14 @@ angular.module('bansho.config', [])
componentsConfig.load();
$http.get('surveil/v2/bansho/config')
$http.get(surveilConfig.endpoint('config'))
.success(function (conf) {
if (!useStoredConfig || jQuery.isEmptyObject(conf)) {
$http.get('components/config/config.json')
.success(function (conf) {
config.data = conf;
$http.post('surveil/v2/bansho/config', JSON.stringify(conf))
$http.post(surveilConfig.endpoint('config'), JSON.stringify(conf))
.success(function () {
responsePromise.resolve();
})

View File

@ -2,5 +2,7 @@
"env": "production",
"username":"",
"password":"",
"useStoredConfig": true
"useStoredConfig": true,
"surveilApiUrl": "surveil/v2",
"surveilAuthUrl": "surveil/v2/auth"
}

View File

@ -3,10 +3,10 @@
'use strict';
angular.module('bansho.surveil')
.service('surveilStatus', ['$http', '$q', 'surveilQuery', 'componentsConfig',
function ($http, $q, surveilQuery, componentsConfig) {
.service('surveilStatus', ['$http', '$q', 'surveilQuery', 'componentsConfig', 'surveilConfig',
function ($http, $q, surveilQuery, componentsConfig, surveilConfig) {
var getMetric = function (host, service, metric) {
var url = 'surveil/v2/status/hosts/' + host,
var url = surveilConfig.endpoint('status') + '/hosts/' + host,
responsePromise = $q.defer();
if (service !== undefined) {
@ -25,7 +25,7 @@ angular.module('bansho.surveil')
};
var getMetricNames = function (host, service) {
var url = '/surveil/v2/status/hosts/' + host,
var url = surveilConfig.endpoint('status') + '/hosts/' + host,
responsePromise = $q.defer();
if (service !== undefined) {
@ -78,9 +78,9 @@ angular.module('bansho.surveil')
var hostQuery = surveilQuery(fields, filters.hosts),
serviceQuery = surveilQuery(fields, filters.services);
executeQuery('surveil/v2/status/hosts/', 'POST', hostQuery)
executeQuery(surveilConfig.endpoint('status') + '/hosts/', 'POST', hostQuery)
.success(function (hosts) {
executeQuery('surveil/v2/status/services/', 'POST', serviceQuery)
executeQuery(surveilConfig.endpoint('status') + '/services/', 'POST', serviceQuery)
.success(function (services) {
callback(hosts, services);
});
@ -129,7 +129,7 @@ angular.module('bansho.surveil')
"hosts": function (fields, filters, callback) {
var hostQuery = surveilQuery(fields, filters.hosts),
method = 'POST',
hostUrl = 'surveil/v2/status/hosts/';
hostUrl = surveilConfig.endpoint('status') + '/hosts/';
if (filters.hosts && filters.hosts.is && filters.hosts.is.host_name) {
hostUrl += filters.hosts.is.host_name;
@ -151,7 +151,7 @@ angular.module('bansho.surveil')
"events": function (fields, filters, callback) {
var query = surveilQuery(fields, filters.events);
executeQuery('surveil/v2/status/events/', 'POST', query)
executeQuery(surveilConfig.endpoint('status') + '/events/', 'POST', query)
.success(function (events) {
angular.forEach(events, function (event) {
angular.forEach(event, function (value, attr) {

View File

@ -1 +1,26 @@
angular.module('bansho.surveil', []);
angular.module('bansho.surveil', [])
.service('surveilConfig', function () {
var apiUrl,
authUrl,
surveilEndpoints = {};
return {
setSurveilApiUrl: function (surveilApiUrl) {
apiUrl = surveilApiUrl;
surveilEndpoints = {
status: apiUrl + '/status',
actions: apiUrl + '/actions',
config: apiUrl + '/bansho/config'
};
},
setAuthUrl: function (url) {
authUrl = url;
},
endpoint: function (endpoint) {
return surveilEndpoints[endpoint];
},
getAuthUrl: function () {
return authUrl;
}
};
});