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-07-17 13:42:45 +00:00
|
|
|
nodes: service('repository/node'),
|
|
|
|
node: service('repository/node'),
|
|
|
|
gateways: service('repository/service'),
|
2020-07-09 09:08:47 +00:00
|
|
|
services: service('repository/service'),
|
2020-07-17 13:42:45 +00:00
|
|
|
service: service('repository/service'),
|
|
|
|
['service-instance']: service('repository/service'),
|
|
|
|
proxies: service('repository/proxy'),
|
|
|
|
['proxy-instance']: service('repository/proxy'),
|
|
|
|
['discovery-chain']: service('repository/discovery-chain'),
|
|
|
|
coordinates: service('repository/coordinate'),
|
|
|
|
sessions: service('repository/session'),
|
2020-04-21 15:49:11 +00:00
|
|
|
namespaces: service('repository/nspace'),
|
2020-07-09 09:08:47 +00:00
|
|
|
intentions: service('repository/intention'),
|
|
|
|
intention: service('repository/intention'),
|
|
|
|
kv: service('repository/kv'),
|
2020-03-19 10:28:21 +00:00
|
|
|
token: service('repository/token'),
|
2020-04-22 16:30:26 +00:00
|
|
|
policies: service('repository/policy'),
|
|
|
|
policy: service('repository/policy'),
|
|
|
|
roles: service('repository/role'),
|
2020-05-11 15:37:11 +00:00
|
|
|
oidc: service('repository/oidc-provider'),
|
2020-07-17 13:42:45 +00:00
|
|
|
|
2020-03-19 10:28:21 +00:00
|
|
|
type: service('data-source/protocols/http/blocking'),
|
2020-07-17 13:42:45 +00:00
|
|
|
|
2020-03-19 10:28:21 +00:00
|
|
|
source: function(src, configuration) {
|
2020-07-17 13:42:45 +00:00
|
|
|
// TODO: Consider adding/requiring 'action': nspace, dc, model, action, ...rest
|
|
|
|
const [, nspace, dc, model, ...rest] = src.split('/').map(decodeURIComponent);
|
|
|
|
// nspaces can be filled, blank or *
|
|
|
|
// so we might get urls like //dc/services
|
2020-03-19 10:28:21 +00:00
|
|
|
let find;
|
|
|
|
const repo = this[model];
|
2020-06-03 17:46:20 +00:00
|
|
|
if (repo.shouldReconcile(src)) {
|
2020-03-19 10:28:21 +00:00
|
|
|
configuration.createEvent = function(result = {}, configuration) {
|
|
|
|
const event = {
|
|
|
|
type: 'message',
|
|
|
|
data: result,
|
|
|
|
};
|
2020-04-24 13:37:55 +00:00
|
|
|
repo.reconcile(get(event, 'data.meta'));
|
2020-03-19 10:28:21 +00:00
|
|
|
return event;
|
|
|
|
};
|
|
|
|
}
|
2020-05-11 15:37:11 +00:00
|
|
|
let method, slug;
|
2020-03-19 10:28:21 +00:00
|
|
|
switch (model) {
|
|
|
|
case 'datacenters':
|
2020-04-21 15:49:11 +00:00
|
|
|
case 'namespaces':
|
|
|
|
find = configuration => repo.findAll(configuration);
|
|
|
|
break;
|
2020-07-09 09:08:47 +00:00
|
|
|
case 'services':
|
2020-07-17 13:42:45 +00:00
|
|
|
case 'nodes':
|
2020-04-22 16:30:26 +00:00
|
|
|
case 'roles':
|
|
|
|
case 'policies':
|
|
|
|
find = configuration => repo.findAllByDatacenter(dc, nspace, configuration);
|
|
|
|
break;
|
2020-07-09 09:08:47 +00:00
|
|
|
case 'intentions':
|
|
|
|
[method, ...slug] = rest;
|
|
|
|
switch (method) {
|
|
|
|
case 'for-service':
|
2020-07-17 13:42:45 +00:00
|
|
|
find = configuration => repo.findByService(slug, dc, nspace, configuration);
|
2020-07-09 09:08:47 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
find = configuration => repo.findAllByDatacenter(dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-07-17 13:42:45 +00:00
|
|
|
case 'coordinates':
|
|
|
|
[method, ...slug] = rest;
|
|
|
|
switch (method) {
|
|
|
|
case 'for-node':
|
|
|
|
find = configuration => repo.findAllByNode(slug, dc, configuration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'proxies':
|
|
|
|
[method, ...slug] = rest;
|
|
|
|
switch (method) {
|
|
|
|
case 'for-service':
|
|
|
|
find = configuration => repo.findAllBySlug(slug, dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'gateways':
|
|
|
|
[method, ...slug] = rest;
|
|
|
|
switch (method) {
|
|
|
|
case 'for-service':
|
|
|
|
find = configuration => repo.findGatewayBySlug(slug, dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'sessions':
|
|
|
|
[method, ...slug] = rest;
|
|
|
|
switch (method) {
|
|
|
|
case 'for-node':
|
|
|
|
find = configuration => repo.findByNode(slug, dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'token':
|
|
|
|
find = configuration => repo.self(rest[1], dc);
|
|
|
|
break;
|
|
|
|
case 'service':
|
|
|
|
case 'discovery-chain':
|
|
|
|
case 'node':
|
|
|
|
find = configuration => repo.findBySlug(rest[0], dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
case 'service-instance':
|
|
|
|
case 'proxy-instance':
|
|
|
|
// id, node, service
|
|
|
|
find = configuration =>
|
|
|
|
repo.findInstanceBySlug(rest[0], rest[1], rest[2], dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
case 'policy':
|
2020-07-20 17:04:43 +00:00
|
|
|
case 'kv':
|
2020-07-09 09:08:47 +00:00
|
|
|
case 'intention':
|
2020-07-17 13:42:45 +00:00
|
|
|
slug = rest[0];
|
2020-07-09 09:08:47 +00:00
|
|
|
if (slug) {
|
|
|
|
find = configuration => repo.findBySlug(slug, dc, nspace, configuration);
|
|
|
|
} else {
|
|
|
|
find = configuration =>
|
|
|
|
Promise.resolve(repo.create({ Datacenter: dc, Namespace: nspace }));
|
|
|
|
}
|
|
|
|
break;
|
2020-05-11 15:37:11 +00:00
|
|
|
case 'oidc':
|
|
|
|
[method, ...slug] = rest;
|
|
|
|
switch (method) {
|
|
|
|
case 'providers':
|
|
|
|
find = configuration => repo.findAllByDatacenter(dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
case 'provider':
|
|
|
|
find = configuration => repo.findBySlug(slug[0], dc, nspace);
|
|
|
|
break;
|
|
|
|
case 'authorize':
|
|
|
|
find = configuration =>
|
|
|
|
repo.authorize(slug[0], slug[1], slug[2], dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2020-03-19 10:28:21 +00:00
|
|
|
}
|
|
|
|
return this.type.source(find, configuration);
|
|
|
|
},
|
|
|
|
});
|