2019-12-17 18:47:37 +00:00
|
|
|
import Serializer from './application';
|
|
|
|
import { get } from '@ember/object';
|
|
|
|
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace';
|
|
|
|
|
2020-11-09 17:29:12 +00:00
|
|
|
export default class NspaceSerializer extends Serializer {
|
|
|
|
primaryKey = PRIMARY_KEY;
|
|
|
|
slugKey = SLUG_KEY;
|
|
|
|
|
2021-09-15 18:50:11 +00:00
|
|
|
respondForQuery(respond, query, data, modelClass) {
|
|
|
|
return super.respondForQuery(
|
|
|
|
cb =>
|
|
|
|
respond((headers, body) =>
|
|
|
|
cb(
|
|
|
|
headers,
|
|
|
|
body.map(function(item) {
|
|
|
|
item.Namespace = item.Name;
|
|
|
|
item.Datacenter = query.dc;
|
|
|
|
if (get(item, 'ACLs.PolicyDefaults')) {
|
|
|
|
item.ACLs.PolicyDefaults = item.ACLs.PolicyDefaults.map(function(item) {
|
|
|
|
item.template = '';
|
|
|
|
return item;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
// Both of these might come though unset so we make sure we at least
|
|
|
|
// have an empty array here so we can add children to them if we
|
|
|
|
// need to whilst saving nspaces
|
|
|
|
['PolicyDefaults', 'RoleDefaults'].forEach(function(prop) {
|
|
|
|
if (typeof item.ACLs === 'undefined') {
|
|
|
|
item.ACLs = [];
|
|
|
|
}
|
|
|
|
if (typeof item.ACLs[prop] === 'undefined') {
|
|
|
|
item.ACLs[prop] = [];
|
|
|
|
}
|
|
|
|
});
|
2019-12-17 18:47:37 +00:00
|
|
|
return item;
|
2021-09-15 18:50:11 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
),
|
|
|
|
query
|
|
|
|
);
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respondForQueryRecord(respond, serialized, data) {
|
2021-09-15 18:50:11 +00:00
|
|
|
return super.respondForQuery(
|
|
|
|
cb =>
|
|
|
|
respond((headers, body) => {
|
|
|
|
body.Datacenter = serialized.dc;
|
|
|
|
body.Namespace = body.Name;
|
|
|
|
return cb(headers, body);
|
|
|
|
}),
|
|
|
|
serialized,
|
|
|
|
data
|
|
|
|
);
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respondForCreateRecord(respond, serialized, data) {
|
2021-09-15 18:50:11 +00:00
|
|
|
return super.respondForCreateRecord(
|
|
|
|
cb =>
|
|
|
|
respond((headers, body) => {
|
|
|
|
body.Datacenter = serialized.dc;
|
|
|
|
body.Namespace = body.Name;
|
|
|
|
return cb(headers, body);
|
|
|
|
}),
|
|
|
|
serialized,
|
|
|
|
data
|
|
|
|
);
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
respondForUpdateRecord(respond, serialized, data) {
|
2019-12-17 18:47:37 +00:00
|
|
|
return respond((headers, body) => {
|
|
|
|
return body;
|
|
|
|
});
|
2020-11-09 17:29:12 +00:00
|
|
|
}
|
|
|
|
}
|