2019-03-28 22:40:13 +08:00
|
|
|
package models
|
|
|
|
|
|
|
|
import (
|
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.
2020-01-29 00:06:56 +08:00
|
|
|
"fmt"
|
2019-03-28 22:40:13 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetTargetNAPTR sets the NAPTR fields.
|
|
|
|
func (rc *RecordConfig) SetTargetNAPTR(order uint16, preference uint16, flags string, service string, regexp string, target string) error {
|
2021-06-25 06:26:21 +08:00
|
|
|
if target == "" {
|
|
|
|
target = "."
|
|
|
|
}
|
2019-03-28 22:40:13 +08:00
|
|
|
rc.NaptrOrder = order
|
|
|
|
rc.NaptrPreference = preference
|
|
|
|
rc.NaptrFlags = flags
|
|
|
|
rc.NaptrService = service
|
|
|
|
rc.NaptrRegexp = regexp
|
2019-03-29 19:01:52 +08:00
|
|
|
rc.SetTarget(target)
|
|
|
|
|
2019-03-28 22:40:13 +08:00
|
|
|
if rc.Type == "" {
|
|
|
|
rc.Type = "NAPTR"
|
|
|
|
}
|
|
|
|
if rc.Type != "NAPTR" {
|
|
|
|
panic("assertion failed: SetTargetNAPTR called when .Type is not NAPTR")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetNAPTRStrings is like SetTargetNAPTR but accepts strings.
|
|
|
|
func (rc *RecordConfig) SetTargetNAPTRStrings(order, preference, flags string, service string, regexp string, target string) error {
|
|
|
|
i64order, err := strconv.ParseUint(order, 10, 16)
|
|
|
|
if err != nil {
|
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.
2020-01-29 00:06:56 +08:00
|
|
|
return fmt.Errorf("NAPTR order does not fit in 16 bits: %w", err)
|
2019-03-28 22:40:13 +08:00
|
|
|
}
|
|
|
|
i64preference, err := strconv.ParseUint(preference, 10, 16)
|
|
|
|
if err != nil {
|
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.
2020-01-29 00:06:56 +08:00
|
|
|
return fmt.Errorf("NAPTR preference does not fit in 16 bits: %w", err)
|
2019-03-28 22:40:13 +08:00
|
|
|
}
|
|
|
|
return rc.SetTargetNAPTR(uint16(i64order), uint16(i64preference), flags, service, regexp, target)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetNAPTRString is like SetTargetNAPTR but accepts one big string.
|
|
|
|
func (rc *RecordConfig) SetTargetNAPTRString(s string) error {
|
|
|
|
part := strings.Fields(s)
|
|
|
|
if len(part) != 6 {
|
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.
2020-01-29 00:06:56 +08:00
|
|
|
return fmt.Errorf("NAPTR value does not contain 6 fields: (%#v)", s)
|
2019-03-28 22:40:13 +08:00
|
|
|
}
|
2020-03-01 22:36:55 +08:00
|
|
|
return rc.SetTargetNAPTRStrings(part[0], part[1], StripQuotes(part[2]), StripQuotes(part[3]), StripQuotes(part[4]), StripQuotes(part[5]))
|
2019-03-28 22:40:13 +08:00
|
|
|
}
|