github.com/philhug/dnscontrol@v0.2.4-0.20180625181521-921fa9849001/models/t_caa.go (about) 1 package models 2 3 import ( 4 "strconv" 5 "strings" 6 7 "github.com/pkg/errors" 8 ) 9 10 // SetTargetCAA sets the CAA fields. 11 func (rc *RecordConfig) SetTargetCAA(flag uint8, tag string, target string) error { 12 rc.CaaTag = tag 13 rc.CaaFlag = flag 14 rc.SetTarget(target) 15 if rc.Type == "" { 16 rc.Type = "CAA" 17 } 18 if rc.Type != "CAA" { 19 panic("assertion failed: SetTargetCAA called when .Type is not CAA") 20 } 21 22 if tag != "issue" && tag != "issuewild" && tag != "iodef" { 23 return errors.Errorf("CAA tag (%v) is not one of issue/issuewild/iodef", tag) 24 } 25 26 return nil 27 } 28 29 // SetTargetCAAStrings is like SetTargetCAA but accepts strings. 30 func (rc *RecordConfig) SetTargetCAAStrings(flag, tag, target string) error { 31 i64flag, err := strconv.ParseUint(flag, 10, 8) 32 if err != nil { 33 return errors.Wrap(err, "CAA flag does not fit in 8 bits") 34 } 35 return rc.SetTargetCAA(uint8(i64flag), tag, target) 36 } 37 38 // SetTargetCAAString is like SetTargetCAA but accepts one big string. 39 // Ex: `0 issue "letsencrypt.org"` 40 func (rc *RecordConfig) SetTargetCAAString(s string) error { 41 part := strings.Fields(s) 42 if len(part) != 3 { 43 return errors.Errorf("CAA value does not contain 3 fields: (%#v)", s) 44 } 45 return rc.SetTargetCAAStrings(part[0], part[1], StripQuotes(part[2])) 46 }