mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Switch to Go 1.13 error wrapping (#604)
* Replaced errors.Wrap with fmt.Errorf (#589) * Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\) Replace: fmt.Errorf($2: %w$3, $1) * Replaced errors.Wrapf with fmt.Errorf (#589) * Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\) Replace: fmt.Errorf($2: %w$3, $1) * Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\) * Replace: fmt.Errorf($2: %w$3$4, $1) * Replaced errors.Errorf with fmt.Errorf (#589) * Find: errors\.Errorf Replace: fmt.Errorf * Cleaned up remaining imports * Cleanup * Regenerate provider support matrix This was broken by #533 ... and it's now the third time this has been missed.
This commit is contained in:
committed by
Tom Limoncelli
parent
cae35a2c8f
commit
825ba2d081
@ -4,8 +4,6 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// ReverseDomainName turns a CIDR block into a reversed (in-addr) name.
|
||||
@ -20,13 +18,13 @@ func ReverseDomainName(cidr string) (string, error) {
|
||||
}
|
||||
base = strings.TrimRight(base, ".")
|
||||
if !a.Equal(c.IP) {
|
||||
return "", errors.Errorf("CIDR %v has 1 bits beyond the mask", cidr)
|
||||
return "", fmt.Errorf("CIDR %v has 1 bits beyond the mask", cidr)
|
||||
}
|
||||
|
||||
bits, total := c.Mask.Size()
|
||||
var toTrim int
|
||||
if bits == 0 {
|
||||
return "", errors.Errorf("Cannot use /0 in reverse cidr")
|
||||
return "", fmt.Errorf("Cannot use /0 in reverse cidr")
|
||||
}
|
||||
|
||||
// Handle IPv4 "Classless in-addr.arpa delegation" RFC2317:
|
||||
@ -41,16 +39,16 @@ func ReverseDomainName(cidr string) (string, error) {
|
||||
// Handle IPv4 Class-full and IPv6:
|
||||
if total == 32 {
|
||||
if bits%8 != 0 {
|
||||
return "", errors.Errorf("IPv4 mask must be multiple of 8 bits")
|
||||
return "", fmt.Errorf("IPv4 mask must be multiple of 8 bits")
|
||||
}
|
||||
toTrim = (total - bits) / 8
|
||||
} else if total == 128 {
|
||||
if bits%4 != 0 {
|
||||
return "", errors.Errorf("IPv6 mask must be multiple of 4 bits")
|
||||
return "", fmt.Errorf("IPv6 mask must be multiple of 4 bits")
|
||||
}
|
||||
toTrim = (total - bits) / 4
|
||||
} else {
|
||||
return "", errors.Errorf("Address is not IPv4 or IPv6: %v", cidr)
|
||||
return "", fmt.Errorf("Address is not IPv4 or IPv6: %v", cidr)
|
||||
}
|
||||
|
||||
parts := strings.SplitN(base, ".", toTrim+1)
|
||||
|
@ -6,8 +6,6 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// PtrNameMagic implements the PTR magic.
|
||||
@ -22,7 +20,7 @@ func PtrNameMagic(name, domain string) (string, error) {
|
||||
if strings.HasSuffix(name, "."+domain+".") {
|
||||
return strings.TrimSuffix(name, "."+domain+"."), nil
|
||||
}
|
||||
return name, errors.Errorf("PTR record %v in wrong domain (%v)", name, domain)
|
||||
return name, fmt.Errorf("PTR record %v in wrong domain (%v)", name, domain)
|
||||
}
|
||||
|
||||
// If the domain is .arpa, we do magic.
|
||||
@ -57,7 +55,7 @@ func ipv4magic(name, domain string) (string, error) {
|
||||
return strings.SplitN(rev, ".", 2)[0], nil
|
||||
}
|
||||
|
||||
return "", errors.Errorf("PTR record %v in wrong IPv4 domain (%v)", name, domain)
|
||||
return "", fmt.Errorf("PTR record %v in wrong IPv4 domain (%v)", name, domain)
|
||||
}
|
||||
|
||||
var isRfc2317Format1 = regexp.MustCompile(`(\d{1,3})/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.in-addr\.arpa$`)
|
||||
@ -112,7 +110,7 @@ func ipv6magic(name, domain string) (string, error) {
|
||||
return name, err
|
||||
}
|
||||
if !strings.HasSuffix(rev, "."+domain) {
|
||||
err = errors.Errorf("PTR record %v in wrong IPv6 domain (%v)", name, domain)
|
||||
err = fmt.Errorf("PTR record %v in wrong IPv6 domain (%v)", name, domain)
|
||||
}
|
||||
return strings.TrimSuffix(rev, "."+domain), err
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
package transform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// IpConversion describes an IP conversion.
|
||||
@ -17,7 +16,7 @@ type IpConversion struct {
|
||||
func ipToUint(i net.IP) (uint32, error) {
|
||||
parts := i.To4()
|
||||
if parts == nil || len(parts) != 4 {
|
||||
return 0, errors.Errorf("%s is not an ipv4 address", parts.String())
|
||||
return 0, fmt.Errorf("%s is not an ipv4 address", parts.String())
|
||||
}
|
||||
r := uint32(parts[0])<<24 | uint32(parts[1])<<16 | uint32(parts[2])<<8 | uint32(parts[3])
|
||||
return r, nil
|
||||
@ -39,7 +38,7 @@ func DecodeTransformTable(transforms string) ([]IpConversion, error) {
|
||||
for ri, row := range rows {
|
||||
items := strings.Split(row, "~")
|
||||
if len(items) != 4 {
|
||||
return nil, errors.Errorf("transform_table rows should have 4 elements. (%v) found in row (%v) of %#v", len(items), ri, transforms)
|
||||
return nil, fmt.Errorf("transform_table rows should have 4 elements. (%v) found in row (%v) of %#v", len(items), ri, transforms)
|
||||
}
|
||||
for i, item := range items {
|
||||
items[i] = strings.TrimSpace(item)
|
||||
@ -58,7 +57,7 @@ func DecodeTransformTable(transforms string) ([]IpConversion, error) {
|
||||
}
|
||||
addr := net.ParseIP(ip)
|
||||
if addr == nil {
|
||||
return nil, errors.Errorf("%s is not a valid ip address", ip)
|
||||
return nil, fmt.Errorf("%s is not a valid ip address", ip)
|
||||
}
|
||||
ips = append(ips, addr)
|
||||
}
|
||||
@ -75,10 +74,10 @@ func DecodeTransformTable(transforms string) ([]IpConversion, error) {
|
||||
low, _ := ipToUint(con.Low)
|
||||
high, _ := ipToUint(con.High)
|
||||
if low > high {
|
||||
return nil, errors.Errorf("transform_table Low should be less than High. row (%v) %v>%v (%v)", ri, con.Low, con.High, transforms)
|
||||
return nil, fmt.Errorf("transform_table Low should be less than High. row (%v) %v>%v (%v)", ri, con.Low, con.High, transforms)
|
||||
}
|
||||
if len(con.NewBases) > 0 && len(con.NewIPs) > 0 {
|
||||
return nil, errors.Errorf("transform_table_rows should only specify one of NewBases or NewIPs, Not both")
|
||||
return nil, fmt.Errorf("transform_table_rows should only specify one of NewBases or NewIPs, Not both")
|
||||
}
|
||||
result = append(result, con)
|
||||
}
|
||||
@ -93,7 +92,7 @@ func TransformIP(address net.IP, transforms []IpConversion) (net.IP, error) {
|
||||
return nil, err
|
||||
}
|
||||
if len(ips) != 1 {
|
||||
return nil, errors.Errorf("Expect exactly one ip for TransformIP result. Got: %s", ips)
|
||||
return nil, fmt.Errorf("Expect exactly one ip for TransformIP result. Got: %s", ips)
|
||||
}
|
||||
return ips[0], err
|
||||
}
|
||||
|
Reference in New Issue
Block a user