mirror of https://github.com/hashicorp/consul
35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
import Service, { inject as service } from '@ember/service';
|
|
import { get } from '@ember/object';
|
|
|
|
export default Service.extend({
|
|
datacenters: service('repository/dc'),
|
|
token: service('repository/token'),
|
|
type: service('data-source/protocols/http/blocking'),
|
|
source: function(src, configuration) {
|
|
const [, dc /*nspace*/, , model, ...rest] = src.split('/');
|
|
let find;
|
|
const repo = this[model];
|
|
if (typeof repo.reconcile === 'function') {
|
|
configuration.createEvent = function(result = {}, configuration) {
|
|
const event = {
|
|
type: 'message',
|
|
data: result,
|
|
};
|
|
if (repo.reconcile === 'function') {
|
|
repo.reconcile(get(event, 'data.meta') || {});
|
|
}
|
|
return event;
|
|
};
|
|
}
|
|
switch (model) {
|
|
case 'datacenters':
|
|
find = configuration => repo.findAll(configuration);
|
|
break;
|
|
case 'token':
|
|
find = configuration => repo.self(rest[1], dc);
|
|
break;
|
|
}
|
|
return this.type.source(find, configuration);
|
|
},
|
|
});
|