2019-12-17 18:47:37 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import RepositoryService from 'consul-ui/services/repository';
|
2020-02-21 16:48:54 +00:00
|
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace';
|
2019-12-17 18:47:37 +00:00
|
|
|
|
|
|
|
const modelName = 'nspace';
|
2021-05-26 16:43:46 +00:00
|
|
|
export default class NspaceEnabledService extends RepositoryService {
|
|
|
|
@service('router') router;
|
|
|
|
@service('container') container;
|
|
|
|
@service('env') env;
|
2020-11-09 09:25:35 +00:00
|
|
|
|
2021-05-26 16:43:46 +00:00
|
|
|
@service('settings') settings;
|
2020-11-09 09:25:35 +00:00
|
|
|
|
|
|
|
getPrimaryKey() {
|
2020-02-21 16:48:54 +00:00
|
|
|
return PRIMARY_KEY;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getSlugKey() {
|
2020-02-21 16:48:54 +00:00
|
|
|
return SLUG_KEY;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getModelName() {
|
2019-12-17 18:47:37 +00:00
|
|
|
return modelName;
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-02-23 08:56:42 +00:00
|
|
|
findAll(params, configuration = {}) {
|
2019-12-17 18:47:37 +00:00
|
|
|
const query = {};
|
|
|
|
if (typeof configuration.cursor !== 'undefined') {
|
|
|
|
query.index = configuration.cursor;
|
2020-07-17 13:42:45 +00:00
|
|
|
query.uri = configuration.uri;
|
2019-12-17 18:47:37 +00:00
|
|
|
}
|
|
|
|
return this.store.query(this.getModelName(), query);
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
authorize(dc, nspace) {
|
2021-05-26 16:43:46 +00:00
|
|
|
if (!this.env.var('CONSUL_ACLS_ENABLED')) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return Promise.resolve([
|
|
|
|
{
|
|
|
|
Resource: 'operator',
|
|
|
|
Access: 'write',
|
|
|
|
Allow: true,
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
return this.store.authorize(this.getModelName(), { dc: dc, ns: nspace }).catch(function(e) {
|
|
|
|
return [];
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
|
2021-05-26 16:43:46 +00:00
|
|
|
getActive(paramsNspace) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return this.settings
|
|
|
|
.findBySlug('nspace')
|
|
|
|
.then(function(nspace) {
|
|
|
|
// If we can't figure out the nspace from the URL use
|
|
|
|
// the previously saved nspace and if thats not there
|
|
|
|
// then just use default
|
2021-05-26 16:43:46 +00:00
|
|
|
return paramsNspace || nspace || 'default';
|
2019-12-17 18:47:37 +00:00
|
|
|
})
|
|
|
|
.then(nspace => this.settings.persist({ nspace: nspace }))
|
|
|
|
.then(function(item) {
|
|
|
|
return {
|
2021-05-26 16:43:46 +00:00
|
|
|
Name: item.nspace,
|
2019-12-17 18:47:37 +00:00
|
|
|
};
|
|
|
|
});
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|
|
|
|
}
|