Merge "fix: Fix source port/port range"

This commit is contained in:
Zuul 2022-04-07 09:21:21 +00:00 committed by Gerrit Code Review
commit 74df8da69e

View File

@ -215,7 +215,15 @@ export default class Create extends ModalAction {
label: t('Source Port/Port Range'), label: t('Source Port/Port Range'),
type: 'port-range', type: 'port-range',
required: showSourcePort, required: showSourcePort,
hidden: !showSourcePort, hidden: !showSourcePort || this.state.direction === 'egress',
},
{
name: 'destination_port',
label: t('Destination Port/Port Range'),
type: 'input',
required: showSourcePort,
help: t('Input destination port or port range(example: 80 or 80:160)'),
hidden: !showSourcePort || this.state.direction === 'ingress',
}, },
{ {
name: 'ipProtocol', name: 'ipProtocol',
@ -284,6 +292,8 @@ export default class Create extends ModalAction {
const { match: { params: { id } = {} } = {} } = containerProps; const { match: { params: { id } = {} } = {} } = containerProps;
const { const {
sourcePort, sourcePort,
destination_port,
direction,
protocol, protocol,
ipProtocol, ipProtocol,
icmpType, icmpType,
@ -295,7 +305,10 @@ export default class Create extends ModalAction {
const range = const range =
['custom_udp', 'custom_tcp'].includes(protocol) && ['custom_udp', 'custom_tcp'].includes(protocol) &&
portOrRange === 'range'; portOrRange === 'range';
const ports = sourcePort.split(':'); const ports =
values.direction === 'ingress'
? sourcePort.split(':')
: destination_port.split(':');
const newProtocol = const newProtocol =
protocol !== 'custom_protocol' protocol !== 'custom_protocol'
? this.defaultRules[protocol].ip_protocol ? this.defaultRules[protocol].ip_protocol
@ -315,6 +328,7 @@ export default class Create extends ModalAction {
? parseInt(ports[1] || ports[0], 10) ? parseInt(ports[1] || ports[0], 10)
: null, : null,
protocol: newProtocol, protocol: newProtocol,
direction,
...rest, ...rest,
}; };
if (protocol.includes('all')) { if (protocol.includes('all')) {