github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/models/t_soa.go (about) 1 package models 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 ) 8 9 /* 10 11 Providers are not expected to support this record. 12 13 Most providers do not support SOA records. They generate them 14 dynamically behind the scenes. Providers like BIND (which is 15 software, not SaaS), must handle SOA records and emulate the dynamic 16 work that providers do. 17 18 */ 19 20 // SetTargetSOA sets the SOA fields. 21 func (rc *RecordConfig) SetTargetSOA(ns, mbox string, serial, refresh, retry, expire, minttl uint32) error { 22 rc.SetTarget(ns) // The NS field is stored as the .Target 23 rc.SoaMbox = mbox 24 rc.SoaSerial = serial 25 rc.SoaRefresh = refresh 26 rc.SoaRetry = retry 27 rc.SoaExpire = expire 28 rc.SoaMinttl = minttl 29 30 if rc.Type == "" { 31 rc.Type = "SOA" 32 } 33 if rc.Type != "SOA" { 34 panic("assertion failed: SetTargetSOA called when .Type is not SOA") 35 } 36 37 return nil 38 } 39 40 // SetTargetSOAStrings is like SetTargetSOA but accepts strings. 41 func (rc *RecordConfig) SetTargetSOAStrings(ns, mbox, serial, refresh, retry, expire, minttl string) error { 42 43 u32serial, err := strconv.ParseUint(serial, 10, 32) 44 if err != nil { 45 return fmt.Errorf("SOA serial '%v' is invalid: %w", serial, err) 46 } 47 48 u32refresh, err := strconv.ParseUint(refresh, 10, 32) 49 if err != nil { 50 return fmt.Errorf("SOA refresh '%v' is invalid: %w", refresh, err) 51 } 52 53 u32retry, err := strconv.ParseUint(retry, 10, 32) 54 if err != nil { 55 return fmt.Errorf("SOA retry '%v' is invalid: %w", retry, err) 56 } 57 58 u32expire, err := strconv.ParseUint(expire, 10, 32) 59 if err != nil { 60 return fmt.Errorf("SOA expire '%v' is invalid: %w", expire, err) 61 } 62 63 u32minttl, err := strconv.ParseUint(minttl, 10, 32) 64 if err != nil { 65 return fmt.Errorf("SOA minttl '%v' is invalid: %w", minttl, err) 66 } 67 68 return rc.SetTargetSOA(ns, mbox, uint32(u32serial), uint32(u32refresh), uint32(u32retry), uint32(u32expire), uint32(u32minttl)) 69 } 70 71 // SetTargetSOAString is like SetTargetSOA but accepts one big string. 72 func (rc *RecordConfig) SetTargetSOAString(s string) error { 73 part := strings.Fields(s) 74 if len(part) != 7 { 75 return fmt.Errorf("SOA value does not contain 7 fields: (%#v)", s) 76 } 77 return rc.SetTargetSOAStrings(part[0], part[1], part[2], part[3], part[4], part[5], part[6]) 78 }