Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firewall rules: remove source and destination address duplicates when managing rule #235

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ function mapSourceAddressesToUi(rule: FirewallRule) {
for (const srcIp of rule.src_ip) {
const srcAddr = srcIp as RuleHost
const addrFound = addressOptions.value.find((addr: NeComboboxOption) => {
return addr.id === srcAddr.value
return addr.id === `${srcAddr.value} ${srcAddr.label} (${srcAddr.type})`
})

if (addrFound) {
Expand Down Expand Up @@ -303,7 +303,7 @@ function mapDestinationAddressesToUi(rule: FirewallRule) {
for (const destIp of rule.dest_ip) {
const destAddr = destIp as RuleHost
const addrFound = addressOptions.value.find((addr: NeComboboxOption) => {
return addr.id === destAddr.value
return addr.id === `${destAddr.value} ${destAddr.label} (${destAddr.type})`
})

if (addrFound) {
Expand Down Expand Up @@ -347,7 +347,7 @@ async function listHostSuggestions() {
const description = `${host.label} (${host.type})`

return {
id: host.value,
id: `${host.value} ${description}`,
label: host.value,
description
}
Expand Down Expand Up @@ -475,20 +475,20 @@ function validate() {
if (props.ruleType !== 'output') {
for (const sourceAddress of sourceAddresses.value) {
// check if it's an ip address
const ipAddressValidation = validateIpAddress(sourceAddress.id)
const ipAddressValidation = validateIpAddress(sourceAddress.label)

if (!ipAddressValidation.valid) {
// check if it's a cidr
const ipCidrValidation = validateIpCidr(sourceAddress.id)
const ipCidrValidation = validateIpCidr(sourceAddress.label)

if (!ipCidrValidation.valid) {
// check if it's an ipv4 or ipv6 address range
const ipRangeValidation = validateIpAddressRange(sourceAddress.id)
const ipRangeValidation = validateIpAddressRange(sourceAddress.label)

if (!ipRangeValidation.valid) {
errorBag.value.set('src_ip', [
t('standalone.firewall_rules.invalid_source_address_value', {
value: sourceAddress.id
value: sourceAddress.label
})
])
if (isValidationOk) {
Expand Down Expand Up @@ -518,20 +518,20 @@ function validate() {
if (props.ruleType !== 'input') {
for (const destinationAddress of destinationAddresses.value) {
// check if it's an ip address
const ipAddressValidation = validateIpAddress(destinationAddress.id)
const ipAddressValidation = validateIpAddress(destinationAddress.label)

if (!ipAddressValidation.valid) {
// check if it's a cidr
const ipCidrValidation = validateIpCidr(destinationAddress.id)
const ipCidrValidation = validateIpCidr(destinationAddress.label)

if (!ipCidrValidation.valid) {
// check if it's an ipv4 or ipv6 address range
const ipRangeValidation = validateIpAddressRange(destinationAddress.id)
const ipRangeValidation = validateIpAddressRange(destinationAddress.label)

if (!ipRangeValidation.valid) {
errorBag.value.set('dest_ip', [
t('standalone.firewall_rules.invalid_destination_address_value', {
value: destinationAddress.id
value: destinationAddress.label
})
])
if (isValidationOk) {
Expand Down Expand Up @@ -656,19 +656,27 @@ async function saveRule() {

if (props.ruleType !== 'output') {
// source addresses
ruleData.src_ip = sourceAddresses.value.map((address) => {
return address.id
})
ruleData.src_ip = [
...new Set(
sourceAddresses.value.map((address) => {
return address.label
})
)
]

// source zone
ruleData.src = sourceZone.value
}

if (props.ruleType !== 'input') {
// destination addresses
ruleData.dest_ip = destinationAddresses.value.map((address) => {
return address.id
})
ruleData.dest_ip = [
...new Set(
destinationAddresses.value.map((address) => {
return address.label
})
)
]

// destination zone
ruleData.dest = destinationZone.value
Expand Down
Loading