2018-02-16 01:02:50 +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"
|
2018-02-16 01:02:50 +08:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetTargetSRV sets the SRV fields.
|
|
|
|
func (rc *RecordConfig) SetTargetSRV(priority, weight, port uint16, target string) error {
|
|
|
|
rc.SrvPriority = priority
|
|
|
|
rc.SrvWeight = weight
|
|
|
|
rc.SrvPort = port
|
2018-03-20 05:18:58 +08:00
|
|
|
rc.SetTarget(target)
|
2018-02-16 01:02:50 +08:00
|
|
|
if rc.Type == "" {
|
|
|
|
rc.Type = "SRV"
|
|
|
|
}
|
|
|
|
if rc.Type != "SRV" {
|
|
|
|
panic("assertion failed: SetTargetSRV called when .Type is not SRV")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-12-08 05:30:04 +08:00
|
|
|
// setTargetSRVIntAndStrings is like SetTargetSRV but accepts priority as an int, the other parameters as strings.
|
|
|
|
func (rc *RecordConfig) setTargetSRVIntAndStrings(priority uint16, weight, port, target string) (err error) {
|
2018-02-16 01:02:50 +08:00
|
|
|
var i64weight, i64port uint64
|
|
|
|
if i64weight, err = strconv.ParseUint(weight, 10, 16); err == nil {
|
|
|
|
if i64port, err = strconv.ParseUint(port, 10, 16); err == nil {
|
|
|
|
return rc.SetTargetSRV(priority, uint16(i64weight), uint16(i64port), target)
|
|
|
|
}
|
|
|
|
}
|
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("SRV value too big for uint16: %w", err)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetSRVStrings is like SetTargetSRV but accepts all parameters as strings.
|
|
|
|
func (rc *RecordConfig) SetTargetSRVStrings(priority, weight, port, target string) (err error) {
|
|
|
|
var i64priority uint64
|
|
|
|
if i64priority, err = strconv.ParseUint(priority, 10, 16); err == nil {
|
2018-12-08 05:30:04 +08:00
|
|
|
return rc.setTargetSRVIntAndStrings(uint16(i64priority), weight, port, target)
|
2018-02-16 01:02:50 +08: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.
2020-01-29 00:06:56 +08:00
|
|
|
return fmt.Errorf("SRV value too big for uint16: %w", err)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetSRVPriorityString is like SetTargetSRV but accepts priority as an
|
|
|
|
// uint16 and the rest of the values joined in a string that needs to be parsed.
|
|
|
|
// This is a helper function that comes in handy when a provider re-uses the MX preference
|
|
|
|
// field as the SRV priority.
|
|
|
|
func (rc *RecordConfig) SetTargetSRVPriorityString(priority uint16, s string) error {
|
|
|
|
part := strings.Fields(s)
|
2019-11-15 00:25:20 +08:00
|
|
|
switch len(part) {
|
|
|
|
case 3:
|
|
|
|
return rc.setTargetSRVIntAndStrings(priority, part[0], part[1], part[2])
|
|
|
|
case 2:
|
|
|
|
return rc.setTargetSRVIntAndStrings(priority, part[0], part[1], ".")
|
|
|
|
default:
|
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("SRV value does not contain 3 fields: (%#v)", s)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetSRVString is like SetTargetSRV but accepts one big string to be parsed.
|
|
|
|
func (rc *RecordConfig) SetTargetSRVString(s string) error {
|
|
|
|
part := strings.Fields(s)
|
|
|
|
if len(part) != 4 {
|
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("SRC value does not contain 4 fields: (%#v)", s)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
return rc.SetTargetSRVStrings(part[0], part[1], part[2], part[3])
|
|
|
|
}
|