2020-03-19 10:28:21 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
|
|
import { get } from '@ember/object';
|
|
|
|
|
|
|
|
export default Service.extend({
|
|
|
|
datacenters: service('repository/dc'),
|
2020-04-21 15:49:11 +00:00
|
|
|
namespaces: service('repository/nspace'),
|
2020-03-19 10:28:21 +00:00
|
|
|
token: service('repository/token'),
|
|
|
|
type: service('data-source/protocols/http/blocking'),
|
|
|
|
source: function(src, configuration) {
|
2020-04-21 15:49:11 +00:00
|
|
|
const [, , /*nspace*/ dc, model, ...rest] = src.split('/');
|
2020-03-19 10:28:21 +00:00
|
|
|
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;
|
2020-04-21 15:49:11 +00:00
|
|
|
case 'namespaces':
|
|
|
|
find = configuration => repo.findAll(configuration);
|
|
|
|
break;
|
2020-03-19 10:28:21 +00:00
|
|
|
case 'token':
|
|
|
|
find = configuration => repo.self(rest[1], dc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return this.type.source(find, configuration);
|
|
|
|
},
|
|
|
|
});
|