Skip to content

Commit

Permalink
More consts
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 committed Nov 13, 2024
1 parent 4bb6603 commit fbf1970
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions cmd/metal-api/internal/metal/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,17 +284,17 @@ func validatePorts(ports []int) error {
}

func validateCIDRs(cidrs []string) error {
af := ""
var af AddressFamily
for _, cidr := range cidrs {
p, err := netip.ParsePrefix(cidr)
if err != nil {
return fmt.Errorf("invalid cidr: %w", err)
}
var newaf string
var newaf AddressFamily
if p.Addr().Is4() {
newaf = "ipv4"
newaf = IPv4AddressFamily
} else if p.Addr().Is6() {
newaf = "ipv6"
newaf = IPv6AddressFamily
}
if af != "" && af != newaf {
return fmt.Errorf("mixed address family in one rule is not supported:%v", cidrs)
Expand Down
7 changes: 4 additions & 3 deletions cmd/metal-api/internal/metal/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"
"net/netip"
"strconv"
"strings"

"github.com/samber/lo"
)
Expand Down Expand Up @@ -239,10 +240,10 @@ const (

// ToAddressFamily will convert a string af to a AddressFamily
func ToAddressFamily(af string) AddressFamily {
switch af {
case "IPv4", "ipv4":
switch strings.ToLower(af) {
case "ipv4":
return IPv4AddressFamily
case "IPv6", "ipv6":
case "ipv6":
return IPv6AddressFamily
}
return IPv4AddressFamily
Expand Down

0 comments on commit fbf1970

Please sign in to comment.