2020-03-19 10:28:21 +00:00
|
|
|
import Service, { inject as service } from '@ember/service';
|
|
|
|
import { get } from '@ember/object';
|
2021-02-23 08:56:42 +00:00
|
|
|
import { getOwner } from '@ember/application';
|
|
|
|
import { match } from 'consul-ui/decorators/data-source';
|
|
|
|
import { singularize } from 'ember-inflector';
|
2020-03-19 10:28:21 +00:00
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class HttpService extends Service {
|
2021-02-23 08:56:42 +00:00
|
|
|
@service('repository/dc') datacenters;
|
2021-09-15 18:50:11 +00:00
|
|
|
@service('repository/dc') datacenter;
|
|
|
|
@service('repository/kv') kvs;
|
|
|
|
@service('repository/kv') kv;
|
2021-02-23 08:56:42 +00:00
|
|
|
@service('repository/node') leader;
|
|
|
|
@service('repository/service') gateways;
|
|
|
|
@service('repository/service-instance') 'proxy-service-instance';
|
|
|
|
@service('repository/proxy') 'proxy-instance';
|
|
|
|
@service('repository/nspace') namespaces;
|
2021-09-15 18:50:11 +00:00
|
|
|
@service('repository/nspace') namespace;
|
2021-02-23 08:56:42 +00:00
|
|
|
@service('repository/metrics') metrics;
|
|
|
|
@service('repository/oidc-provider') oidc;
|
2021-09-15 18:50:11 +00:00
|
|
|
@service('ui-config') 'ui-config';
|
|
|
|
@service('ui-config') notfound;
|
2020-11-09 09:25:35 +00:00
|
|
|
|
2021-02-23 08:56:42 +00:00
|
|
|
@service('data-source/protocols/http/blocking') type;
|
2020-11-09 09:25:35 +00:00
|
|
|
|
|
|
|
source(src, configuration) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const [, , , , model] = src.split('/');
|
2021-02-23 08:56:42 +00:00
|
|
|
const owner = getOwner(this);
|
|
|
|
const route = match(src);
|
|
|
|
const find = route.cb(route.params, owner);
|
|
|
|
|
|
|
|
const repo = this[model] || owner.lookup(`service:repository/${singularize(model)}`);
|
2021-09-15 18:50:11 +00:00
|
|
|
if (typeof repo.reconcile === 'function') {
|
|
|
|
configuration.createEvent = function(result = {}, configuration) {
|
|
|
|
const event = {
|
|
|
|
type: 'message',
|
|
|
|
data: result,
|
|
|
|
};
|
|
|
|
const meta = get(event, 'data.meta') || {};
|
|
|
|
if (typeof meta.range === 'undefined') {
|
|
|
|
repo.reconcile(meta);
|
|
|
|
}
|
|
|
|
return event;
|
2020-03-19 10:28:21 +00:00
|
|
|
};
|
2021-09-15 18:50:11 +00:00
|
|
|
}
|
2020-03-19 10:28:21 +00:00
|
|
|
return this.type.source(find, configuration);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|