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"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetTargetCAA sets the CAA fields.
|
|
|
|
func (rc *RecordConfig) SetTargetCAA(flag uint8, tag string, target string) error {
|
|
|
|
rc.CaaTag = tag
|
|
|
|
rc.CaaFlag = flag
|
2018-03-20 05:18:58 +08:00
|
|
|
rc.SetTarget(target)
|
2018-02-16 01:02:50 +08:00
|
|
|
if rc.Type == "" {
|
|
|
|
rc.Type = "CAA"
|
|
|
|
}
|
|
|
|
if rc.Type != "CAA" {
|
|
|
|
panic("assertion failed: SetTargetCAA called when .Type is not CAA")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tag != "issue" && tag != "issuewild" && tag != "iodef" {
|
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("CAA tag (%v) is not one of issue/issuewild/iodef", tag)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetCAAStrings is like SetTargetCAA but accepts strings.
|
|
|
|
func (rc *RecordConfig) SetTargetCAAStrings(flag, tag, target string) error {
|
|
|
|
i64flag, err := strconv.ParseUint(flag, 10, 8)
|
|
|
|
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("CAA flag does not fit in 8 bits: %w", err)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
|
|
|
return rc.SetTargetCAA(uint8(i64flag), tag, target)
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetTargetCAAString is like SetTargetCAA but accepts one big string.
|
|
|
|
// Ex: `0 issue "letsencrypt.org"`
|
|
|
|
func (rc *RecordConfig) SetTargetCAAString(s string) error {
|
2022-01-25 22:57:20 +08:00
|
|
|
part, err := ParseQuotedFields(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-16 01:02:50 +08:00
|
|
|
if len(part) != 3 {
|
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("CAA value does not contain 3 fields: (%#v)", s)
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|
2022-06-18 21:58:55 +08:00
|
|
|
return rc.SetTargetCAAStrings(part[0], part[1], part[2])
|
2018-02-16 01:02:50 +08:00
|
|
|
}
|