2014-04-23 22:51:06 +00:00
|
|
|
//
|
2014-05-01 14:24:41 +00:00
|
|
|
// Superclass to be used by all of the main routes below.
|
2014-04-23 22:51:06 +00:00
|
|
|
//
|
2014-04-23 18:01:42 +00:00
|
|
|
App.BaseRoute = Ember.Route.extend({
|
2014-05-04 21:07:41 +00:00
|
|
|
rootKey: '',
|
2014-06-02 14:35:46 +00:00
|
|
|
condensedView: false,
|
2014-05-01 14:00:36 +00:00
|
|
|
|
2014-06-04 21:15:10 +00:00
|
|
|
// Don't record characters in browser history
|
|
|
|
// for the "search" query item (filter)
|
|
|
|
queryParams: {
|
|
|
|
filter: {
|
|
|
|
replace: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-04 21:05:00 +00:00
|
|
|
getParentAndGrandparent: function(key) {
|
2014-05-04 21:07:41 +00:00
|
|
|
var parentKey = this.rootKey,
|
|
|
|
grandParentKey = this.rootKey,
|
2014-05-04 21:05:00 +00:00
|
|
|
parts = key.split('/');
|
2014-05-01 14:00:36 +00:00
|
|
|
|
2014-05-04 21:05:00 +00:00
|
|
|
if (parts.length > 0) {
|
2014-05-01 14:00:36 +00:00
|
|
|
parts.pop();
|
|
|
|
parentKey = parts.join("/") + "/";
|
2014-05-04 21:05:00 +00:00
|
|
|
}
|
2014-05-01 14:00:36 +00:00
|
|
|
|
2014-05-04 21:05:00 +00:00
|
|
|
if (parts.length > 1) {
|
2014-05-01 14:00:36 +00:00
|
|
|
parts.pop();
|
|
|
|
grandParentKey = parts.join("/") + "/";
|
|
|
|
}
|
|
|
|
|
2014-05-05 00:58:27 +00:00
|
|
|
return {
|
|
|
|
parent: parentKey,
|
|
|
|
grandParent: grandParentKey,
|
|
|
|
isRoot: parentKey === '/'
|
2014-08-21 19:14:33 +00:00
|
|
|
};
|
2014-05-01 14:00:36 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
removeDuplicateKeys: function(keys, matcher) {
|
|
|
|
// Loop over the keys
|
|
|
|
keys.forEach(function(item, index) {
|
|
|
|
if (item.get('Key') == matcher) {
|
|
|
|
// If we are in a nested folder and the folder
|
|
|
|
// name matches our position, remove it
|
|
|
|
keys.splice(index, 1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return keys;
|
|
|
|
},
|
|
|
|
|
2014-04-29 17:06:26 +00:00
|
|
|
actions: {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Used to link to keys that are not objects,
|
|
|
|
// like parents and grandParents
|
2014-04-29 17:06:26 +00:00
|
|
|
linkToKey: function(key) {
|
2014-05-16 20:38:45 +00:00
|
|
|
if (key == "/") {
|
2014-08-21 19:14:33 +00:00
|
|
|
this.transitionTo('kv.show', "");
|
2014-05-16 20:38:45 +00:00
|
|
|
}
|
|
|
|
else if (key.slice(-1) === '/' || key === this.rootKey) {
|
2014-08-21 19:14:33 +00:00
|
|
|
this.transitionTo('kv.show', key);
|
2014-04-29 17:06:26 +00:00
|
|
|
} else {
|
2014-08-21 19:14:33 +00:00
|
|
|
this.transitionTo('kv.edit', key);
|
2014-04-29 17:06:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-21 20:36:50 +00:00
|
|
|
});
|
|
|
|
|
2014-04-23 22:51:06 +00:00
|
|
|
//
|
|
|
|
// The route for choosing datacenters, typically the first route loaded.
|
|
|
|
//
|
2014-04-30 21:31:40 +00:00
|
|
|
App.IndexRoute = App.BaseRoute.extend({
|
|
|
|
// Retrieve the list of datacenters
|
2014-04-30 18:02:20 +00:00
|
|
|
model: function(params) {
|
2016-02-09 13:26:48 +00:00
|
|
|
return Ember.$.getJSON(consulHost + '/v1/catalog/datacenters').then(function(data) {
|
2014-08-21 19:14:33 +00:00
|
|
|
return data;
|
|
|
|
});
|
2014-04-27 14:42:21 +00:00
|
|
|
},
|
|
|
|
|
2014-04-30 20:30:14 +00:00
|
|
|
afterModel: function(model, transition) {
|
2014-04-30 21:31:40 +00:00
|
|
|
// If we only have one datacenter, jump
|
|
|
|
// straight to it and bypass the global
|
|
|
|
// view
|
2014-04-30 20:30:14 +00:00
|
|
|
if (model.get('length') === 1) {
|
|
|
|
this.transitionTo('services', model[0]);
|
2014-04-23 18:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// The parent route for all resources. This keeps the top bar
|
|
|
|
// functioning, as well as the per-dc requests.
|
2014-04-25 17:49:36 +00:00
|
|
|
App.DcRoute = App.BaseRoute.extend({
|
|
|
|
model: function(params) {
|
2015-12-16 20:32:56 +00:00
|
|
|
var token = App.get('settings.token');
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Return a promise hash to retreieve the
|
|
|
|
// dcs and nodes used in the header
|
2014-04-30 20:30:14 +00:00
|
|
|
return Ember.RSVP.hash({
|
|
|
|
dc: params.dc,
|
2016-02-09 13:26:48 +00:00
|
|
|
dcs: Ember.$.getJSON(consulHost + '/v1/catalog/datacenters'),
|
|
|
|
nodes: Ember.$.getJSON(formatUrl(consulHost + '/v1/internal/ui/nodes', params.dc, token)).then(function(data) {
|
2014-10-04 09:45:09 +00:00
|
|
|
var objs = [];
|
2014-04-30 18:02:20 +00:00
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Merge the nodes into a list and create objects out of them
|
2014-04-30 20:30:14 +00:00
|
|
|
data.map(function(obj){
|
|
|
|
objs.push(App.Node.create(obj));
|
|
|
|
});
|
2014-04-25 20:24:36 +00:00
|
|
|
|
2014-04-30 20:30:14 +00:00
|
|
|
return objs;
|
2016-05-15 00:44:28 +00:00
|
|
|
}),
|
|
|
|
coordinates: Ember.$.getJSON(formatUrl(consulHost + '/v1/coordinate/nodes', params.dc, token)).then(function(data) {
|
|
|
|
return data;
|
2014-04-30 20:30:14 +00:00
|
|
|
})
|
2014-04-30 18:02:20 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-04-30 20:30:14 +00:00
|
|
|
setupController: function(controller, models) {
|
|
|
|
controller.set('content', models.dc);
|
|
|
|
controller.set('nodes', models.nodes);
|
|
|
|
controller.set('dcs', models.dcs);
|
2016-05-15 00:44:28 +00:00
|
|
|
controller.set('coordinates', models.coordinates);
|
2014-05-01 16:24:40 +00:00
|
|
|
controller.set('isDropdownVisible', false);
|
|
|
|
},
|
2014-04-23 18:01:42 +00:00
|
|
|
});
|
|
|
|
|
2014-04-29 18:49:07 +00:00
|
|
|
App.KvIndexRoute = App.BaseRoute.extend({
|
2014-04-29 17:06:26 +00:00
|
|
|
beforeModel: function() {
|
2014-08-21 19:14:33 +00:00
|
|
|
this.transitionTo('kv.show', this.rootKey);
|
2014-04-29 17:06:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
App.KvShowRoute = App.BaseRoute.extend({
|
|
|
|
model: function(params) {
|
2014-05-04 21:05:00 +00:00
|
|
|
var key = params.key;
|
2014-04-30 22:05:44 +00:00
|
|
|
var dc = this.modelFor('dc').dc;
|
2014-08-25 18:48:42 +00:00
|
|
|
var token = App.get('settings.token');
|
2014-04-28 22:23:01 +00:00
|
|
|
|
2014-04-30 22:31:45 +00:00
|
|
|
// Return a promise has with the ?keys for that namespace
|
|
|
|
// and the original key requested in params
|
|
|
|
return Ember.RSVP.hash({
|
|
|
|
key: key,
|
2016-02-09 13:26:48 +00:00
|
|
|
keys: Ember.$.getJSON(formatUrl(consulHost + '/v1/kv/' + key + '?keys&seperator=/', dc, token)).then(function(data) {
|
2014-10-04 09:45:09 +00:00
|
|
|
var objs = [];
|
2014-04-30 22:31:45 +00:00
|
|
|
data.map(function(obj){
|
|
|
|
objs.push(App.Key.create({Key: obj}));
|
|
|
|
});
|
|
|
|
return objs;
|
|
|
|
})
|
2014-04-30 19:02:31 +00:00
|
|
|
});
|
2014-04-28 22:23:01 +00:00
|
|
|
},
|
|
|
|
|
2014-04-30 22:31:45 +00:00
|
|
|
setupController: function(controller, models) {
|
|
|
|
var key = models.key;
|
2014-05-01 14:00:36 +00:00
|
|
|
var parentKeys = this.getParentAndGrandparent(key);
|
|
|
|
models.keys = this.removeDuplicateKeys(models.keys, models.key);
|
2014-04-30 22:05:44 +00:00
|
|
|
|
2014-04-30 22:31:45 +00:00
|
|
|
controller.set('content', models.keys);
|
2014-05-01 14:00:36 +00:00
|
|
|
controller.set('parentKey', parentKeys.parent);
|
|
|
|
controller.set('grandParentKey', parentKeys.grandParent);
|
2014-05-05 00:58:27 +00:00
|
|
|
controller.set('isRoot', parentKeys.isRoot);
|
2014-04-30 14:09:41 +00:00
|
|
|
controller.set('newKey', App.Key.create());
|
2014-05-05 07:56:21 +00:00
|
|
|
controller.set('rootKey', this.rootKey);
|
2014-04-29 17:06:26 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
App.KvEditRoute = App.BaseRoute.extend({
|
|
|
|
model: function(params) {
|
2014-05-04 21:05:00 +00:00
|
|
|
var key = params.key;
|
2014-04-30 22:05:44 +00:00
|
|
|
var dc = this.modelFor('dc').dc;
|
2014-08-21 19:14:33 +00:00
|
|
|
var parentKeys = this.getParentAndGrandparent(key);
|
2014-08-25 18:48:42 +00:00
|
|
|
var token = App.get('settings.token');
|
2014-04-30 19:02:31 +00:00
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Return a promise hash to get the data for both columns
|
2014-04-30 20:30:14 +00:00
|
|
|
return Ember.RSVP.hash({
|
2014-06-06 18:26:30 +00:00
|
|
|
dc: dc,
|
2014-08-25 18:48:42 +00:00
|
|
|
token: token,
|
2016-02-09 13:26:48 +00:00
|
|
|
key: Ember.$.getJSON(formatUrl(consulHost + '/v1/kv/' + key, dc, token)).then(function(data) {
|
2014-04-30 21:31:40 +00:00
|
|
|
// Convert the returned data to a Key
|
2014-04-30 20:30:14 +00:00
|
|
|
return App.Key.create().setProperties(data[0]);
|
|
|
|
}),
|
2016-02-09 13:26:48 +00:00
|
|
|
keys: keysPromise = Ember.$.getJSON(formatUrl(consulHost + '/v1/kv/' + parentKeys.parent + '?keys&seperator=/', dc, token)).then(function(data) {
|
2014-10-04 09:45:09 +00:00
|
|
|
var objs = [];
|
2014-04-30 20:30:14 +00:00
|
|
|
data.map(function(obj){
|
|
|
|
objs.push(App.Key.create({Key: obj}));
|
|
|
|
});
|
|
|
|
return objs;
|
|
|
|
}),
|
2014-04-30 19:02:31 +00:00
|
|
|
});
|
2014-04-29 17:06:26 +00:00
|
|
|
},
|
2014-04-29 17:34:13 +00:00
|
|
|
|
2014-06-06 18:26:30 +00:00
|
|
|
// Load the session on the key, if there is one
|
|
|
|
afterModel: function(models) {
|
|
|
|
if (models.key.get('isLocked')) {
|
2016-02-09 13:26:48 +00:00
|
|
|
return Ember.$.getJSON(formatUrl(consulHost + '/v1/session/info/' + models.key.Session, models.dc, models.token)).then(function(data) {
|
2014-08-21 19:14:33 +00:00
|
|
|
models.session = data[0];
|
|
|
|
return models;
|
2014-06-06 18:26:30 +00:00
|
|
|
});
|
|
|
|
} else {
|
2014-08-21 19:14:33 +00:00
|
|
|
return models;
|
2014-06-06 18:26:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-04-30 20:30:14 +00:00
|
|
|
setupController: function(controller, models) {
|
2014-05-01 14:00:36 +00:00
|
|
|
var key = models.key;
|
|
|
|
var parentKeys = this.getParentAndGrandparent(key.get('Key'));
|
|
|
|
models.keys = this.removeDuplicateKeys(models.keys, parentKeys.parent);
|
2014-04-30 22:31:45 +00:00
|
|
|
|
2014-05-01 14:00:36 +00:00
|
|
|
controller.set('content', models.key);
|
|
|
|
controller.set('parentKey', parentKeys.parent);
|
|
|
|
controller.set('grandParentKey', parentKeys.grandParent);
|
2014-05-05 07:56:21 +00:00
|
|
|
controller.set('isRoot', parentKeys.isRoot);
|
2014-05-01 02:16:12 +00:00
|
|
|
controller.set('siblings', models.keys);
|
2014-05-05 00:51:34 +00:00
|
|
|
controller.set('rootKey', this.rootKey);
|
2014-06-06 18:26:30 +00:00
|
|
|
controller.set('session', models.session);
|
2014-04-28 22:23:01 +00:00
|
|
|
}
|
|
|
|
});
|
2014-04-24 17:47:14 +00:00
|
|
|
|
2014-04-23 18:01:42 +00:00
|
|
|
App.ServicesRoute = App.BaseRoute.extend({
|
2014-04-30 18:02:20 +00:00
|
|
|
model: function(params) {
|
2014-08-21 19:14:33 +00:00
|
|
|
var dc = this.modelFor('dc').dc;
|
2014-08-25 18:48:42 +00:00
|
|
|
var token = App.get('settings.token');
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Return a promise to retrieve all of the services
|
2016-02-09 13:26:48 +00:00
|
|
|
return Ember.$.getJSON(formatUrl(consulHost + '/v1/internal/ui/services', dc, token)).then(function(data) {
|
2014-10-04 09:45:09 +00:00
|
|
|
var objs = [];
|
2014-04-30 18:02:20 +00:00
|
|
|
data.map(function(obj){
|
|
|
|
objs.push(App.Service.create(obj));
|
|
|
|
});
|
2014-08-21 19:14:33 +00:00
|
|
|
return objs;
|
2014-04-30 18:02:20 +00:00
|
|
|
});
|
|
|
|
},
|
2014-04-24 17:47:14 +00:00
|
|
|
setupController: function(controller, model) {
|
2014-04-30 18:02:20 +00:00
|
|
|
controller.set('services', model);
|
2014-04-24 17:47:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-24 19:18:11 +00:00
|
|
|
|
2014-04-25 17:25:12 +00:00
|
|
|
App.ServicesShowRoute = App.BaseRoute.extend({
|
2014-04-24 17:47:14 +00:00
|
|
|
model: function(params) {
|
2014-08-21 19:14:33 +00:00
|
|
|
var dc = this.modelFor('dc').dc;
|
2014-08-25 18:48:42 +00:00
|
|
|
var token = App.get('settings.token');
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Here we just use the built-in health endpoint, as it gives us everything
|
|
|
|
// we need.
|
2016-02-09 13:26:48 +00:00
|
|
|
return Ember.$.getJSON(formatUrl(consulHost + '/v1/health/service/' + params.name, dc, token)).then(function(data) {
|
2014-10-04 09:45:09 +00:00
|
|
|
var objs = [];
|
2014-04-30 18:02:20 +00:00
|
|
|
data.map(function(obj){
|
|
|
|
objs.push(App.Node.create(obj));
|
|
|
|
});
|
|
|
|
return objs;
|
|
|
|
});
|
2014-06-11 21:14:20 +00:00
|
|
|
},
|
|
|
|
setupController: function(controller, model) {
|
|
|
|
var tags = [];
|
|
|
|
model.map(function(obj){
|
2016-09-15 08:37:45 +00:00
|
|
|
if (obj.Service.Tags !== null) {
|
|
|
|
tags = tags.concat(obj.Service.Tags);
|
|
|
|
}
|
2014-06-11 21:14:20 +00:00
|
|
|
});
|
|
|
|
|
2014-08-21 19:14:33 +00:00
|
|
|
tags = tags.filter(function(n){ return n !== undefined; });
|
|
|
|
tags = tags.uniq().join(', ');
|
2014-06-11 21:14:20 +00:00
|
|
|
|
|
|
|
controller.set('content', model);
|
|
|
|
controller.set('tags', tags);
|
2014-05-01 03:39:41 +00:00
|
|
|
}
|
2014-04-21 20:36:50 +00:00
|
|
|
});
|
2014-04-23 18:01:42 +00:00
|
|
|
|
2016-05-15 00:44:28 +00:00
|
|
|
function distance(a, b) {
|
|
|
|
a = a.Coord;
|
|
|
|
b = b.Coord;
|
|
|
|
var sum = 0;
|
|
|
|
for (var i = 0; i < a.Vec.length; i++) {
|
|
|
|
var diff = a.Vec[i] - b.Vec[i];
|
|
|
|
sum += diff * diff;
|
|
|
|
}
|
|
|
|
var rtt = Math.sqrt(sum) + a.Height + b.Height;
|
|
|
|
|
|
|
|
var adjusted = rtt + a.Adjustment + b.Adjustment;
|
|
|
|
if (adjusted > 0.0) {
|
|
|
|
rtt = adjusted;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.round(rtt * 100000.0) / 100.0;
|
|
|
|
}
|
|
|
|
|
2014-04-25 17:32:41 +00:00
|
|
|
App.NodesShowRoute = App.BaseRoute.extend({
|
2014-04-24 19:18:11 +00:00
|
|
|
model: function(params) {
|
2016-05-15 00:44:28 +00:00
|
|
|
var dc = this.modelFor('dc');
|
2014-08-25 18:48:42 +00:00
|
|
|
var token = App.get('settings.token');
|
|
|
|
|
2016-05-18 17:05:16 +00:00
|
|
|
var min = 999999999;
|
|
|
|
var max = -999999999;
|
2016-05-15 00:44:28 +00:00
|
|
|
var sum = 0;
|
|
|
|
var distances = [];
|
|
|
|
dc.coordinates.forEach(function (node) {
|
|
|
|
if (params.name == node.Node) {
|
|
|
|
dc.coordinates.forEach(function (other) {
|
2016-05-15 13:13:52 +00:00
|
|
|
if (node.Node != other.Node) {
|
|
|
|
var dist = distance(node, other);
|
2016-05-18 17:05:16 +00:00
|
|
|
distances.push({ node: other.Node, distance: dist });
|
2016-05-15 13:13:52 +00:00
|
|
|
sum += dist;
|
2016-05-18 17:05:16 +00:00
|
|
|
if (dist < min) {
|
|
|
|
min = dist;
|
|
|
|
}
|
|
|
|
if (dist > max) {
|
|
|
|
max = dist;
|
|
|
|
}
|
2016-05-15 13:13:52 +00:00
|
|
|
}
|
2016-05-15 00:44:28 +00:00
|
|
|
});
|
2016-05-18 17:05:16 +00:00
|
|
|
distances.sort(function (a, b) {
|
|
|
|
return a.distance - b.distance;
|
|
|
|
});
|
2016-05-15 00:44:28 +00:00
|
|
|
}
|
|
|
|
});
|
2016-05-17 17:43:50 +00:00
|
|
|
var n = distances.length;
|
|
|
|
var halfN = Math.floor(n / 2);
|
|
|
|
var median;
|
2016-08-09 00:38:22 +00:00
|
|
|
|
|
|
|
if (n > 0) {
|
|
|
|
if (n % 2) {
|
|
|
|
// odd
|
|
|
|
median = distances[halfN].distance;
|
|
|
|
} else {
|
|
|
|
median = (distances[halfN - 1].distance + distances[halfN].distance) / 2;
|
|
|
|
}
|
2016-05-17 17:43:50 +00:00
|
|
|
} else {
|
2016-08-09 00:38:22 +00:00
|
|
|
median = 0;
|
|
|
|
min = 0;
|
|
|
|
max = 0;
|
2016-05-17 17:43:50 +00:00
|
|
|
}
|
2016-05-15 00:44:28 +00:00
|
|
|
|
2017-07-09 00:16:05 +00:00
|
|
|
// Return a promise hash of the node
|
2014-04-30 19:25:31 +00:00
|
|
|
return Ember.RSVP.hash({
|
2016-05-15 00:44:28 +00:00
|
|
|
dc: dc.dc,
|
2014-08-25 18:48:42 +00:00
|
|
|
token: token,
|
2016-05-15 00:44:28 +00:00
|
|
|
tomography: {
|
|
|
|
distances: distances,
|
|
|
|
n: distances.length,
|
|
|
|
min: parseInt(min * 100) / 100,
|
2016-05-17 17:43:50 +00:00
|
|
|
median: parseInt(median * 100) / 100,
|
2016-05-15 00:44:28 +00:00
|
|
|
max: parseInt(max * 100) / 100
|
|
|
|
},
|
|
|
|
node: Ember.$.getJSON(formatUrl(consulHost + '/v1/internal/ui/node/' + params.name, dc.dc, token)).then(function(data) {
|
2014-08-21 19:14:33 +00:00
|
|
|
return App.Node.create(data);
|
2014-04-30 19:25:31 +00:00
|
|
|
})
|
2014-04-30 18:02:20 +00:00
|
|
|
});
|
2014-04-24 19:18:11 +00:00
|
|
|
},
|
|
|
|
|
2014-06-06 19:11:26 +00:00
|
|
|
// Load the sessions for the node
|
|
|
|
afterModel: function(models) {
|
2016-02-09 13:26:48 +00:00
|
|
|
return Ember.$.getJSON(formatUrl(consulHost + '/v1/session/node/' + models.node.Node, models.dc, models.token)).then(function(data) {
|
2014-08-21 19:14:33 +00:00
|
|
|
models.sessions = data;
|
|
|
|
return models;
|
2014-06-06 19:11:26 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2014-04-30 19:25:31 +00:00
|
|
|
setupController: function(controller, models) {
|
|
|
|
controller.set('content', models.node);
|
2014-06-06 19:11:26 +00:00
|
|
|
controller.set('sessions', models.sessions);
|
2016-05-15 00:44:28 +00:00
|
|
|
controller.set('tomography', models.tomography);
|
2014-04-24 19:18:11 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
App.NodesRoute = App.BaseRoute.extend({
|
2014-04-30 18:02:20 +00:00
|
|
|
model: function(params) {
|
2014-08-21 19:14:33 +00:00
|
|
|
var dc = this.modelFor('dc').dc;
|
2014-08-25 18:48:42 +00:00
|
|
|
var token = App.get('settings.token');
|
|
|
|
|
2014-04-30 21:31:40 +00:00
|
|
|
// Return a promise containing the nodes
|
2016-02-09 13:26:48 +00:00
|
|
|
return Ember.$.getJSON(formatUrl(consulHost + '/v1/internal/ui/nodes', dc, token)).then(function(data) {
|
2014-10-04 09:45:09 +00:00
|
|
|
var objs = [];
|
2014-04-30 18:02:20 +00:00
|
|
|
data.map(function(obj){
|
|
|
|
objs.push(App.Node.create(obj));
|
|
|
|
});
|
2014-08-21 19:14:33 +00:00
|
|
|
return objs;
|
2014-04-30 18:02:20 +00:00
|
|
|
});
|
|
|
|
},
|
2014-04-24 19:18:11 +00:00
|
|
|
setupController: function(controller, model) {
|
2014-10-04 09:45:09 +00:00
|
|
|
controller.set('nodes', model);
|
2014-04-24 19:18:11 +00:00
|
|
|
}
|
|
|
|
});
|
2014-08-21 21:44:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
App.AclsRoute = App.BaseRoute.extend({
|
|
|
|
model: function(params) {
|
|
|
|
var dc = this.modelFor('dc').dc;
|
2014-08-22 00:43:08 +00:00
|
|
|
var token = App.get('settings.token');
|
2014-08-21 21:44:17 +00:00
|
|
|
// Return a promise containing the ACLS
|
2016-02-09 13:26:48 +00:00
|
|
|
return Ember.$.getJSON(formatUrl(consulHost + '/v1/acl/list', dc, token)).then(function(data) {
|
2014-10-04 09:45:09 +00:00
|
|
|
var objs = [];
|
2014-08-21 21:44:17 +00:00
|
|
|
data.map(function(obj){
|
2014-08-22 19:25:10 +00:00
|
|
|
if (obj.ID === "anonymous") {
|
2014-08-22 23:03:46 +00:00
|
|
|
objs.unshift(App.Acl.create(obj));
|
2014-08-22 19:25:10 +00:00
|
|
|
} else {
|
|
|
|
objs.push(App.Acl.create(obj));
|
|
|
|
}
|
2014-08-21 21:44:17 +00:00
|
|
|
});
|
|
|
|
return objs;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
error: function(error, transition) {
|
|
|
|
// If consul returns 401, ACLs are disabled
|
|
|
|
if (error && error.status === 401) {
|
|
|
|
this.transitionTo('dc.aclsdisabled');
|
|
|
|
// If consul returns 403, they key isn't authorized for that
|
|
|
|
// action.
|
|
|
|
} else if (error && error.status === 403) {
|
|
|
|
this.transitionTo('dc.unauthorized');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController: function(controller, model) {
|
|
|
|
controller.set('acls', model);
|
2014-08-22 23:46:32 +00:00
|
|
|
controller.set('newAcl', App.Acl.create());
|
2014-08-21 21:44:17 +00:00
|
|
|
}
|
|
|
|
});
|
2014-08-21 23:00:37 +00:00
|
|
|
|
2014-08-22 19:25:10 +00:00
|
|
|
App.AclsShowRoute = App.BaseRoute.extend({
|
|
|
|
model: function(params) {
|
|
|
|
var dc = this.modelFor('dc').dc;
|
|
|
|
var token = App.get('settings.token');
|
2014-08-25 18:48:42 +00:00
|
|
|
|
2017-07-09 00:16:05 +00:00
|
|
|
// Return a promise hash of the ACLs
|
2014-08-22 19:25:10 +00:00
|
|
|
return Ember.RSVP.hash({
|
|
|
|
dc: dc,
|
2016-02-09 13:26:48 +00:00
|
|
|
acl: Ember.$.getJSON(formatUrl(consulHost + '/v1/acl/info/'+ params.id, dc, token)).then(function(data) {
|
2014-08-22 19:25:10 +00:00
|
|
|
return App.Acl.create(data[0]);
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
setupController: function(controller, models) {
|
|
|
|
controller.set('content', models.acl);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-08-22 23:03:46 +00:00
|
|
|
App.SettingsRoute = App.BaseRoute.extend({
|
|
|
|
model: function(params) {
|
|
|
|
return App.get('settings');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2014-08-21 23:00:37 +00:00
|
|
|
// Adds any global parameters we need to set to a url/path
|
|
|
|
function formatUrl(url, dc, token) {
|
2015-10-20 03:06:51 +00:00
|
|
|
if (token == null) {
|
|
|
|
token = "";
|
|
|
|
}
|
2014-08-21 23:00:37 +00:00
|
|
|
if (url.indexOf("?") > 0) {
|
|
|
|
// If our url has existing params
|
|
|
|
url = url + "&dc=" + dc;
|
|
|
|
url = url + "&token=" + token;
|
|
|
|
} else {
|
|
|
|
// Our url doesn't have params
|
|
|
|
url = url + "?dc=" + dc;
|
|
|
|
url = url + "&token=" + token;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
}
|