Skip to content

Commit

Permalink
Merge pull request #90 from akamai/dns_maint
Browse files Browse the repository at this point in the history
Add parsing for CERT and TSLA records. Remove parsing for MX records.…
  • Loading branch information
edglynes authored May 15, 2020
2 parents aac49c7 + a1d26b6 commit 708e81b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 32 deletions.
29 changes: 14 additions & 15 deletions configdns-v2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ func (e *ZoneError) Network() bool {
func (e *ZoneError) NotFound() bool {
if e.err == nil && e.httpErrorMessage == "" && e.apiErrorMessage == "" {
return true
} else if e.err != nil {
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Response.StatusCode == 404 {
return true
}
}
} else if e.err != nil {
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Response.StatusCode == 404 {
return true
}
}
return false
}

Expand All @@ -57,14 +57,13 @@ func (e *ZoneError) ValidationFailed() bool {
}

func (e *ZoneError) ConcurrencyConflict() bool {
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Response.StatusCode == 409 {
return true
}
return false
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Response.StatusCode == 409 {
return true
}
return false
}


func (e *ZoneError) Error() string {
if e.Network() {
return fmt.Sprintf("Zone \"%s\" network error: [%s]", e.zoneName, e.httpErrorMessage)
Expand All @@ -74,9 +73,9 @@ func (e *ZoneError) Error() string {
return fmt.Sprintf("Zone \"%s\" not found.", e.zoneName)
}

if e.ConcurrencyConflict() {
return fmt.Sprintf("Modification Confict: [%s]", e.apiErrorMessage)
}
if e.ConcurrencyConflict() {
return fmt.Sprintf("Modification Confict: [%s]", e.apiErrorMessage)
}

if e.FailedToSave() {
return fmt.Sprintf("Zone \"%s\" failed to save: [%s]", e.zoneName, e.err.Error())
Expand Down
59 changes: 43 additions & 16 deletions configdns-v2/record_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1"
edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid"
"net"
"sort"
//"sort"
"strconv"
"strings"
)
Expand Down Expand Up @@ -382,21 +382,23 @@ func ParseRData(rtype string, rdata []string) map[string]interface{} {
fieldMap["software"] = parts[1]
break
}

case "MX":
sort.Strings(rdata)
parts := strings.Split(rdata[0], " ")
fieldMap["priority"], _ = strconv.Atoi(parts[0])
if len(rdata) > 1 {
parts = strings.Split(rdata[1], " ")
tpri, _ := strconv.Atoi(parts[0])
fieldMap["priority_increment"] = tpri - fieldMap["priority"].(int)
}
for _, rcontent := range rdata {
parts := strings.Split(rcontent, " ")
newrdata = append(newrdata, parts[1])
}
fieldMap["target"] = newrdata
/*
// too many variations to calculate pri and increment
case "MX":
sort.Strings(rdata)
parts := strings.Split(rdata[0], " ")
fieldMap["priority"], _ = strconv.Atoi(parts[0])
if len(rdata) > 1 {
parts = strings.Split(rdata[1], " ")
tpri, _ := strconv.Atoi(parts[0])
fieldMap["priority_increment"] = tpri - fieldMap["priority"].(int)
}
for _, rcontent := range rdata {
parts := strings.Split(rcontent, " ")
newrdata = append(newrdata, parts[1])
}
fieldMap["target"] = newrdata
*/

case "NAPTR":
for _, rcontent := range rdata {
Expand Down Expand Up @@ -536,6 +538,31 @@ func ParseRData(rtype string, rdata []string) map[string]interface{} {
}
fieldMap["target"] = newrdata

case "CERT":
for _, rcontent := range rdata {
parts := strings.Split(rcontent, " ")
val, err := strconv.Atoi(parts[0])
if err == nil {
fieldMap["type_value"] = val
} else {
fieldMap["type_mnemonic"] = parts[0]
}
fieldMap["keytag"], _ = strconv.Atoi(parts[1])
fieldMap["algorithm"], _ = strconv.Atoi(parts[2])
fieldMap["certificate"] = parts[3]
break
}

case "TLSA":
for _, rcontent := range rdata {
parts := strings.Split(rcontent, " ")
fieldMap["usage"], _ = strconv.Atoi(parts[0])
fieldMap["selector"], _ = strconv.Atoi(parts[1])
fieldMap["match_type"], _ = strconv.Atoi(parts[2])
fieldMap["certificate"] = parts[3]
break
}

default:
for _, rcontent := range rdata {
newrdata = append(newrdata, rcontent)
Expand Down
2 changes: 1 addition & 1 deletion configdns-v2/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"io/ioutil"
"log"
"reflect"
"sync"
"strings"
"sync"
)

var (
Expand Down

0 comments on commit 708e81b

Please sign in to comment.