mirror of
https://github.com/status-im/consul.git
synced 2025-01-31 07:57:17 +00:00
fc14a412fd
* Add Partition to all our models * Add partitions into our serializers/fingerprinting * Make some amends to a few adapters ready for partitions * Amend blueprints to avoid linting error * Update all our repositories to include partitions, also Remove enabled/disable nspace repo and just use a nspace with conditionals * Ensure nspace and parition parameters always return '' no matter what * Ensure data-sink finds the model properly This will later be replaced by a @dataSink decorator but we are find kicking that can down the road a little more * Add all the new partition data layer * Add a way to set the title of the page from inside the route and make it accessibile via a route announcer * Make the Consul Route the default/basic one * Tweak nspace and partition abilities not to check the length * Thread partition through all the components that need it * Some ACL tweaks * Move the entire app to use partitions * Delete all the tests we no longer need * Update some Unit tests to use partition * Fix up KV title tests * Fix up a few more acceptance tests * Fixup and temporarily ignore some acceptance tests * Stop using ember-cli-page-objects fillable as it doesn't seem to work * Fix lint error * Remove old ACL related test * Add a tick after filling out forms * Fix token warning modal * Found some more places where we need a partition var * Fixup some more acceptance tests * Tokens still needs a repo service for CRUD * Remove acceptance tests we no longer need * Fixup and "FIXME ignore" a few tests * Remove an s * Disable blocking queries for KV to revert to previous release for now * Fixup adapter tests to follow async/function resolving interface * Fixup all the serializer integration tests * Fixup service/repo integration tests * Fixup deleting acceptance test * Fixup some ent tests * Make sure nspaces passes the dc through for when thats important * ...aaaand acceptance nspaces with the extra dc param
130 lines
3.7 KiB
JavaScript
130 lines
3.7 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import { runInDebug } from '@ember/debug';
|
|
import RepositoryService from 'consul-ui/services/repository';
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace';
|
|
import dataSource from 'consul-ui/decorators/data-source';
|
|
|
|
const findActiveNspace = function(nspaces, nspace) {
|
|
let found = nspaces.find(function(item) {
|
|
return item.Name === nspace.Name;
|
|
});
|
|
if (typeof found === 'undefined') {
|
|
runInDebug(_ =>
|
|
console.info(`${nspace.Name} not found in [${nspaces.map(item => item.Name).join(', ')}]`)
|
|
);
|
|
// if we can't find the nspace that was specified try default
|
|
found = nspaces.find(function(item) {
|
|
return item.Name === 'default';
|
|
});
|
|
// if there is no default just choose the first
|
|
if (typeof found === 'undefined') {
|
|
found = nspaces[0];
|
|
}
|
|
}
|
|
return found;
|
|
};
|
|
const modelName = 'nspace';
|
|
export default class NspaceEnabledService extends RepositoryService {
|
|
@service('router') router;
|
|
@service('container') container;
|
|
@service('env') env;
|
|
@service('form') form;
|
|
|
|
@service('settings') settings;
|
|
@service('repository/permission') permissions;
|
|
|
|
getPrimaryKey() {
|
|
return PRIMARY_KEY;
|
|
}
|
|
|
|
getSlugKey() {
|
|
return SLUG_KEY;
|
|
}
|
|
|
|
getModelName() {
|
|
return modelName;
|
|
}
|
|
|
|
@dataSource('/:partition/:ns/:dc/namespaces')
|
|
async findAll() {
|
|
if (!this.permissions.can('use nspaces')) {
|
|
return [];
|
|
}
|
|
return super.findAll(...arguments).catch(() => []);
|
|
}
|
|
|
|
@dataSource('/:partition/:ns/:dc/namespace/:id')
|
|
async findBySlug(params) {
|
|
let item;
|
|
if (params.id === '') {
|
|
item = await this.create({
|
|
Datacenter: params.dc,
|
|
Partition: params.partition,
|
|
ACLs: {
|
|
PolicyDefaults: [],
|
|
RoleDefaults: [],
|
|
},
|
|
});
|
|
} else {
|
|
item = await super.findBySlug(...arguments);
|
|
}
|
|
return this.form
|
|
.form(this.getModelName())
|
|
.setData(item)
|
|
.getData();
|
|
}
|
|
|
|
remove(item) {
|
|
// Namespace deletion is more of a soft delete.
|
|
// Therefore the namespace still exists once we've requested a delete/removal.
|
|
// This makes 'removing' more of a custom action rather than a standard
|
|
// ember-data delete.
|
|
// Here we use the same request for a delete but we bypass ember-data's
|
|
// destroyRecord/unloadRecord and serialization so we don't get
|
|
// ember data error messages when the UI tries to update a 'DeletedAt' property
|
|
// on an object that ember-data is trying to delete
|
|
const res = this.store.adapterFor('nspace').rpc(
|
|
(adapter, request, serialized, unserialized) => {
|
|
return adapter.requestForDeleteRecord(request, serialized, unserialized);
|
|
},
|
|
(serializer, respond, serialized, unserialized) => {
|
|
return item;
|
|
},
|
|
item,
|
|
'nspace'
|
|
);
|
|
return res;
|
|
}
|
|
|
|
authorize(dc, nspace) {
|
|
if (!this.env.var('CONSUL_ACLS_ENABLED')) {
|
|
return Promise.resolve([
|
|
{
|
|
Resource: 'operator',
|
|
Access: 'write',
|
|
Allow: true,
|
|
},
|
|
]);
|
|
}
|
|
return this.store.authorize(this.getModelName(), { dc: dc, ns: nspace }).catch(function(e) {
|
|
return [];
|
|
});
|
|
}
|
|
|
|
async getActive(paramsNspace = '') {
|
|
if (this.permissions.can('use nspaces')) {
|
|
return {
|
|
Name: 'default',
|
|
};
|
|
}
|
|
const nspaces = this.store.peekAll('nspace').toArray();
|
|
if (paramsNspace.length === 0) {
|
|
const token = await this.settings.findBySlug('token');
|
|
paramsNspace = token.Namespace || 'default';
|
|
}
|
|
// if there is only 1 namespace then use that, otherwise find the
|
|
// namespace object that corresponds to the active one
|
|
return nspaces.length === 1 ? nspaces[0] : findActiveNspace(nspaces, { Name: paramsNspace });
|
|
}
|
|
}
|