2021-09-15 18:50:11 +00:00
|
|
|
import Route from 'consul-ui/routing/route';
|
2020-12-08 15:47:55 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2021-09-15 18:50:11 +00:00
|
|
|
import { set, action } from '@ember/object';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class TopologyRoute extends Route {
|
2020-12-16 09:18:29 +00:00
|
|
|
@service('data-source/service') data;
|
|
|
|
@service('repository/intention') repo;
|
2021-01-19 15:40:39 +00:00
|
|
|
@service('feedback') feedback;
|
2020-12-08 15:47:55 +00:00
|
|
|
|
2020-12-16 09:18:29 +00:00
|
|
|
@action
|
|
|
|
async createIntention(source, destination) {
|
2021-01-19 15:40:39 +00:00
|
|
|
// begin with a create action as it makes more sense if the we can't even
|
|
|
|
// get a list of intentions
|
2021-12-09 09:45:24 +00:00
|
|
|
let notification = this.feedback.notification('create', 'intention');
|
2021-01-19 15:40:39 +00:00
|
|
|
try {
|
|
|
|
// intentions will be a proxy object
|
|
|
|
let intentions = await this.intentions;
|
2022-09-15 08:43:17 +00:00
|
|
|
let intention = intentions.find((item) => {
|
2021-01-19 15:40:39 +00:00
|
|
|
return (
|
|
|
|
item.Datacenter === source.Datacenter &&
|
|
|
|
item.SourceName === source.Name &&
|
|
|
|
item.SourceNS === source.Namespace &&
|
2022-02-11 13:58:01 +00:00
|
|
|
item.SourcePartition === source.Partition &&
|
2021-01-19 15:40:39 +00:00
|
|
|
item.DestinationName === destination.Name &&
|
2022-02-11 13:58:01 +00:00
|
|
|
item.DestinationNS === destination.Namespace &&
|
|
|
|
item.DestinationPartition === destination.Partition
|
2021-01-19 15:40:39 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
if (typeof intention === 'undefined') {
|
|
|
|
intention = this.repo.create({
|
|
|
|
Datacenter: source.Datacenter,
|
|
|
|
SourceName: source.Name,
|
|
|
|
SourceNS: source.Namespace || 'default',
|
2022-02-11 13:58:01 +00:00
|
|
|
SourcePartition: source.Partition || 'default',
|
2021-01-19 15:40:39 +00:00
|
|
|
DestinationName: destination.Name,
|
|
|
|
DestinationNS: destination.Namespace || 'default',
|
2022-02-11 13:58:01 +00:00
|
|
|
DestinationPartition: destination.Partition || 'default',
|
2021-01-19 15:40:39 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// we found an intention in the find higher up, so we are updating
|
2021-12-09 09:45:24 +00:00
|
|
|
notification = this.feedback.notification('update', 'intention');
|
2021-01-19 15:40:39 +00:00
|
|
|
}
|
|
|
|
set(intention, 'Action', 'allow');
|
|
|
|
await this.repo.persist(intention);
|
|
|
|
notification.success(intention);
|
|
|
|
} catch (e) {
|
|
|
|
notification.error(e);
|
|
|
|
}
|
2020-12-16 09:18:29 +00:00
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
2021-01-19 15:40:39 +00:00
|
|
|
afterModel(model, transition) {
|
2021-09-15 18:50:11 +00:00
|
|
|
const params = {
|
|
|
|
...this.optionalParams(),
|
|
|
|
...this.paramsFor('dc'),
|
|
|
|
...this.paramsFor('dc.services.show'),
|
|
|
|
};
|
2021-01-19 15:40:39 +00:00
|
|
|
this.intentions = this.data.source(
|
2022-09-15 08:43:17 +00:00
|
|
|
(uri) =>
|
2021-09-15 18:50:11 +00:00
|
|
|
uri`/${params.partition}/${params.nspace}/${params.dc}/intentions/for-service/${params.name}`
|
2021-01-19 15:40:39 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async deactivate(transition) {
|
|
|
|
const intentions = await this.intentions;
|
|
|
|
intentions.destroy();
|
|
|
|
}
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|