Skip to content

Commit

Permalink
fix: Fix network policy rule displays error && validate rules
Browse files Browse the repository at this point in the history
  • Loading branch information
liyefox committed Jul 7, 2020
1 parent c14819e commit 09de84d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
18 changes: 12 additions & 6 deletions src/components/Modals/Network/Policies/IpBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,18 @@ export default class NetworkPoliciesIpBlockModal extends React.Component {
cidr.ip.valid = PATTERN_IP.test(ip.value)
cidr.mask.valid = PATTERN_IP_MASK.test(mask.value)
let validated = cidr.ip.valid && cidr.mask.valid

portRules.forEach(rule => {
rule.port.valid =
isEmpty(rule.port.value) || PATTERN_IP_MASK.test(rule.port.value)
validated = rule.port.valid
})
const isValidPort = function(v) {
return v !== '' && /^(?![0])(\d{0,5})$/.test(v) && v < 65536
}
if (validated) {
portRules.forEach(rule => {
rule.port.valid =
isEmpty(rule.port.value) || isValidPort(rule.port.value)
if (!rule.port.valid) {
validated = false
}
})
}
this.setState({
cidr,
portRules,
Expand Down
24 changes: 17 additions & 7 deletions src/pages/projects/containers/Network/Policies/RuleInfo/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,15 @@ export default class RuleInfo extends React.Component {
)}
</b>
</span>
<Icon name="port" />
{get(item, `spec.${direction}[0].ports`, []).map(rule => {
{get(item, `spec.${direction}[0].ports`, []).map((rule, i) => {
const showName = `${rule.port}/${rule.protocol}`
return (
<span className={styles.port} key={showName}>
<b>{showName}</b>
</span>
<>
{i === 0 && <Icon name="port" />}
<span className={styles.port} key={showName}>
<b>{showName}</b>
</span>
</>
)
})}
</div>
Expand Down Expand Up @@ -255,15 +257,23 @@ export default class RuleInfo extends React.Component {
const item = get(toJS(data), '_originData')
if (isEmpty(get(item, 'spec.egress[0].ports'))) {
if (!isEmpty(get(item, 'spec.egress[0].to'))) {
innerEgressData.push(item)
if (!isEmpty(get(item, 'spec.egress[0].to[0].ipBlock'))) {
outerEgressData.push(item)
} else {
innerEgressData.push(item)
}
}
} else {
outerEgressData.push(item)
}

if (isEmpty(get(item, 'spec.ingress[0].ports'))) {
if (!isEmpty(get(item, 'spec.ingress[0].from'))) {
innerIngressData.push(item)
if (!isEmpty(get(item, 'spec.ingress[0].from[0].ipBlock'))) {
outerIngressData.push(item)
} else {
innerIngressData.push(item)
}
}
} else {
outerIngressData.push(item)
Expand Down

0 comments on commit 09de84d

Please sign in to comment.