2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2020-10-05 17:07:35 +00:00
|
|
|
import Serializer from './application';
|
|
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/topology';
|
2020-11-12 15:40:15 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-10-05 17:07:35 +00:00
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
export default class TopologySerializer extends Serializer {
|
2020-11-12 15:40:15 +00:00
|
|
|
@service('store') store;
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
primaryKey = PRIMARY_KEY;
|
|
|
|
slugKey = SLUG_KEY;
|
|
|
|
|
|
|
|
respondForQueryRecord(respond, query) {
|
2020-11-12 15:40:15 +00:00
|
|
|
const intentionSerializer = this.store.serializerFor('intention');
|
2022-09-15 08:43:17 +00:00
|
|
|
return super.respondForQueryRecord(function (cb) {
|
|
|
|
return respond(function (headers, body) {
|
|
|
|
body.Downstreams.forEach((item) => {
|
2020-11-12 15:40:15 +00:00
|
|
|
item.Intention.SourceName = item.Name;
|
|
|
|
item.Intention.SourceNS = item.Namespace;
|
|
|
|
item.Intention.DestinationName = query.id;
|
|
|
|
item.Intention.DestinationNS = query.ns || 'default';
|
|
|
|
intentionSerializer.ensureID(item.Intention);
|
|
|
|
});
|
2022-09-15 08:43:17 +00:00
|
|
|
body.Upstreams.forEach((item) => {
|
2020-11-12 15:40:15 +00:00
|
|
|
item.Intention.SourceName = query.id;
|
|
|
|
item.Intention.SourceNS = query.ns || 'default';
|
|
|
|
item.Intention.DestinationName = item.Name;
|
|
|
|
item.Intention.DestinationNS = item.Namespace;
|
|
|
|
intentionSerializer.ensureID(item.Intention);
|
|
|
|
});
|
2020-10-05 17:07:35 +00:00
|
|
|
return cb(headers, {
|
|
|
|
...body,
|
|
|
|
[SLUG_KEY]: query.id,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, query);
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|