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'),
|
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-03-19 10:28:21 +00:00
|
|
|
type: service('data-source/protocols/http/blocking'),
|
|
|
|
source: function(src, configuration) {
|
2020-04-22 16:30:26 +00:00
|
|
|
// TODO: Consider adding/requiring nspace, dc, model, action, ...rest
|
|
|
|
const [, nspace, dc, model, ...rest] = src.split('/');
|
|
|
|
// TODO: Consider throwing if we have an empty nspace or dc
|
|
|
|
// we are going to use '*' for 'all' when we need that
|
|
|
|
// and an empty value is the same as 'default'
|
|
|
|
// reasoning for potentially doing it here is, uri's should
|
|
|
|
// always be complete, they should never have things like '///model'
|
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,
|
|
|
|
};
|
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':
|
|
|
|
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;
|
2020-04-22 16:30:26 +00:00
|
|
|
case 'roles':
|
|
|
|
case 'policies':
|
|
|
|
find = configuration => repo.findAllByDatacenter(dc, nspace, configuration);
|
|
|
|
break;
|
|
|
|
case 'policy':
|
|
|
|
find = configuration => repo.findBySlug(rest[0], dc, nspace, configuration);
|
|
|
|
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);
|
|
|
|
},
|
|
|
|
});
|