mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix(mod/dashboard): grab the leader URL
query etcd to find the URL of the leader before making any http requests that can't be redirected from a browser like PUT/POST and DELETE.
This commit is contained in:
parent
a1ec895b91
commit
4c06e19cf2
@ -2,10 +2,11 @@
|
||||
|
||||
angular.module('etcd', [])
|
||||
|
||||
.factory('EtcdV2', ['$http', function($http) {
|
||||
.factory('EtcdV2', ['$http', '$q', function($http, $q) {
|
||||
var keyPrefix = '/v2/keys/'
|
||||
var statsPrefix = '/v2/stats/'
|
||||
var baseURL = '/v2/'
|
||||
var leaderURL = ''
|
||||
|
||||
delete $http.defaults.headers.common['X-Requested-With'];
|
||||
|
||||
@ -45,19 +46,23 @@ angular.module('etcd', [])
|
||||
};
|
||||
|
||||
self.set = function(keyValue) {
|
||||
return $http({
|
||||
url: self.path(),
|
||||
data: $.param({value: keyValue}),
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
return getLeader().then(function(leader) {
|
||||
return $http({
|
||||
url: leader + self.path(),
|
||||
data: $.param({value: keyValue}),
|
||||
method: 'PUT',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
self.deleteKey = function(keyValue) {
|
||||
return $http({
|
||||
url: self.path(),
|
||||
method: 'DELETE',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
return getLeader().then(function(leader) {
|
||||
return $http({
|
||||
url: leader + self.path(),
|
||||
method: 'DELETE',
|
||||
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -79,8 +84,18 @@ angular.module('etcd', [])
|
||||
return self
|
||||
}
|
||||
|
||||
function getLeader() {
|
||||
return newStat('leader').get().then(function(response) {
|
||||
return newKey('/_etcd/machines/' + response.data.leader).get().then(function(response) {
|
||||
// TODO: do something better here p.s. I hate javascript
|
||||
var data = JSON.parse('{"' + decodeURI(response.data.value.replace(/&/g, "\",\"").replace(/=/g,"\":\"")) + '"}');
|
||||
return data.etcd;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
getStat: newStat,
|
||||
getKey: newKey
|
||||
getKey: newKey,
|
||||
}
|
||||
}]);
|
||||
|
@ -94,23 +94,23 @@ angular.module('etcdBrowser', ['ngRoute', 'etcd', 'timeRelative'])
|
||||
|
||||
$scope.saveData = function() {
|
||||
// TODO: fixup etcd to allow for empty values
|
||||
$scope.key.set($scope.singleValue || ' ').success(function (data, status, headers, config) {
|
||||
$scope.key.set($scope.singleValue || ' ').then(function(response) {
|
||||
$scope.save = 'etcd-save-hide';
|
||||
$scope.preview = 'etcd-preview-hide';
|
||||
$scope.back();
|
||||
$scope.writingNew = false;
|
||||
}).error(function (data, status, headers, config) {
|
||||
}, function (response) {
|
||||
$scope.showSaveError(data.message);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteKey = function() {
|
||||
$scope.key.deleteKey().success(function (data, status, headers, config) {
|
||||
$scope.key.deleteKey().then(function(response) {
|
||||
//TODO: remove loader
|
||||
$scope.save = 'etcd-save-hide';
|
||||
$scope.preview = 'etcd-preview-hide';
|
||||
$scope.back();
|
||||
}).error(function (data, status, headers, config) {
|
||||
}, function (response) {
|
||||
//TODO: remove loader
|
||||
//show errors
|
||||
$scope.showBrowseError('Could not delete the key');
|
||||
|
Loading…
x
Reference in New Issue
Block a user