mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
New RTYPE: DS records now supported! (#753)
Thanks to @haraldkoch for starting this, @McNetic for picking it up. * Added DS record type * Added DS for cloudflare provider with tests * Removed DS validation, fixed parse test * Added generated files * Added dnsimple ds record * Regenerated documentation matrix * rebased and regenerated * Updated integration tests * Rebase and regenerate * Enable DS record type for provider desec * Added DS record type * Added DS for cloudflare provider with tests * Removed DS validation, fixed parse test * Added generated files * Added dnsimple ds record * Regenerated documentation matrix * rebased and regenerated * Updated integration tests * Rebase and regenerate * Enable DS record type for provider desec * Rebase and fixes Co-authored-by: Robert Koch <robert@kochie.io> Co-authored-by: Nicolai Ehemann <nicolai.ehemann@enerko-informatik.de>
This commit is contained in:
54
models/t_ds.go
Normal file
54
models/t_ds.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// SetTargetDS sets the DS fields.
|
||||
func (rc *RecordConfig) SetTargetDS(keytag uint16, algorithm, digesttype uint8, digest string) error {
|
||||
rc.DsKeyTag = keytag
|
||||
rc.DsAlgorithm = algorithm
|
||||
rc.DsDigestType = digesttype
|
||||
rc.DsDigest = digest
|
||||
|
||||
if rc.Type == "" {
|
||||
rc.Type = "DS"
|
||||
}
|
||||
if rc.Type != "DS" {
|
||||
panic("assertion failed: SetTargetDS called when .Type is not DS")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetTargetDSStrings is like SetTargetDS but accepts strings.
|
||||
func (rc *RecordConfig) SetTargetDSStrings(keytag, algorithm, digesttype, digest string) error {
|
||||
u16keytag, err := strconv.ParseUint(keytag, 10, 16)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "DS KeyTag can't fit in 16 bits")
|
||||
}
|
||||
u8algorithm, err := strconv.ParseUint(algorithm, 10, 8)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "DS Algorithm can't fit in 8 bits")
|
||||
}
|
||||
u8digesttype, err := strconv.ParseUint(digesttype, 10, 8)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "DS DigestType can't fit in 8 bits")
|
||||
}
|
||||
|
||||
return rc.SetTargetDS(uint16(u16keytag), uint8(u8algorithm), uint8(u8digesttype), digest)
|
||||
}
|
||||
|
||||
// SetTargetDSString is like SetTargetDS but accepts one big string.
|
||||
func (rc *RecordConfig) SetTargetDSString(s string) error {
|
||||
part := strings.Fields(s)
|
||||
if len(part) != 4 {
|
||||
return errors.Errorf("DS value does not contain 5 fields: (%#v)", s)
|
||||
}
|
||||
fmt.Println(part)
|
||||
return rc.SetTargetDSStrings(part[0], part[1], part[2], part[3])
|
||||
}
|
Reference in New Issue
Block a user