2017-09-19 14:47:10 +00:00
|
|
|
import ApplicationSerializer from './application';
|
2019-07-30 21:58:01 +00:00
|
|
|
import isIp from 'is-ip';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
export default class NetworkSerializer extends ApplicationSerializer {
|
|
|
|
attrs = {
|
2017-09-19 14:47:10 +00:00
|
|
|
cidr: 'CIDR',
|
|
|
|
ip: 'IP',
|
|
|
|
mbits: 'MBits',
|
2020-06-11 21:23:00 +00:00
|
|
|
};
|
2019-07-30 21:58:01 +00:00
|
|
|
|
|
|
|
normalize(typeHash, hash) {
|
|
|
|
const ip = hash.IP;
|
|
|
|
|
|
|
|
if (isIp.v6(ip)) {
|
|
|
|
hash.IP = `[${ip}]`;
|
|
|
|
}
|
|
|
|
|
2019-09-04 14:39:56 +00:00
|
|
|
const reservedPorts = (hash.ReservedPorts || []).map(port => ({
|
|
|
|
name: port.Label,
|
|
|
|
port: port.Value,
|
|
|
|
to: port.To,
|
|
|
|
isDynamic: false,
|
|
|
|
}));
|
|
|
|
|
|
|
|
const dynamicPorts = (hash.DynamicPorts || []).map(port => ({
|
|
|
|
name: port.Label,
|
|
|
|
port: port.Value,
|
|
|
|
to: port.To,
|
|
|
|
isDynamic: true,
|
|
|
|
}));
|
|
|
|
|
|
|
|
hash.Ports = reservedPorts.concat(dynamicPorts).sortBy('name');
|
|
|
|
|
2020-06-11 21:23:00 +00:00
|
|
|
return super.normalize(...arguments);
|
|
|
|
}
|
|
|
|
}
|