|
| 1 | +package rtype |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/StackExchange/dnscontrol/v4/models" |
| 7 | + "github.com/StackExchange/dnscontrol/v4/pkg/domaintags" |
| 8 | + "github.com/StackExchange/dnscontrol/v4/pkg/rtypecontrol" |
| 9 | + "github.com/miekg/dns" |
| 10 | +) |
| 11 | + |
| 12 | +func init() { |
| 13 | + rtypecontrol.Register(&DS{}) |
| 14 | +} |
| 15 | + |
| 16 | +// DS RR. |
| 17 | +type DS struct { |
| 18 | + dns.DS |
| 19 | +} |
| 20 | + |
| 21 | +// Name returns the DNS record type as a string. |
| 22 | +func (handle *DS) Name() string { |
| 23 | + return "DS" |
| 24 | +} |
| 25 | + |
| 26 | +// FromArgs fills in the RecordConfig from []any, which is typically from a parsed config file. |
| 27 | +func (handle *DS) FromArgs(dcn *domaintags.DomainNameVarieties, rec *models.RecordConfig, args []any) error { |
| 28 | + if err := rtypecontrol.PaveArgs(args[1:], "wbbs"); err != nil { |
| 29 | + return fmt.Errorf("ERROR: (%s) [DS(%q, %v)]: %w", |
| 30 | + rec.FilePos, |
| 31 | + rec.Name, rtypecontrol.StringifyQuoted(args[1:]), |
| 32 | + err) |
| 33 | + } |
| 34 | + fields := &DS{ |
| 35 | + dns.DS{ |
| 36 | + KeyTag: args[1].(uint16), |
| 37 | + Algorithm: args[2].(uint8), |
| 38 | + DigestType: args[3].(uint8), |
| 39 | + Digest: args[4].(string), |
| 40 | + }, |
| 41 | + } |
| 42 | + |
| 43 | + return handle.FromStruct(dcn, rec, args[0].(string), fields) |
| 44 | +} |
| 45 | + |
| 46 | +// FromStruct fills in the RecordConfig from a struct, typically from an API response. |
| 47 | +func (handle *DS) FromStruct(dcn *domaintags.DomainNameVarieties, rec *models.RecordConfig, name string, fields any) error { |
| 48 | + rec.F = fields |
| 49 | + |
| 50 | + rec.ZonefilePartial = rec.GetTargetRFC1035Quoted() |
| 51 | + rec.Comparable = rec.ZonefilePartial |
| 52 | + |
| 53 | + handle.CopyToLegacyFields(rec) |
| 54 | + return nil |
| 55 | +} |
| 56 | + |
| 57 | +// CopyToLegacyFields populates the legacy fields of the RecordConfig using the fields in .F. |
| 58 | +func (handle *DS) CopyToLegacyFields(rec *models.RecordConfig) { |
| 59 | + ds := rec.F.(*DS) |
| 60 | + _ = rec.SetTargetDS(ds.KeyTag, ds.Algorithm, ds.DigestType, ds.Digest) |
| 61 | +} |
0 commit comments