Skip to content

Commit

Permalink
[cf] fixed MX/SRV records parsing (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
buglloc authored Dec 9, 2023
1 parent c9afbd8 commit 129b76a
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/upstream/ucloudflare/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ func RuleFromCF(r cloudflare.DNSRecord) (Rule, error) {
return Rule{}, fmt.Errorf("unexpected record type: %s", r.Type)
}

uRule, err := upstream.NewRule(fqdn.FQDN(r.Name), rType, strings.TrimSpace(r.Content))
content := r.Content
switch r.Type {
case "MX":
content = fmt.Sprintf("%d %s", *r.Priority, r.Content)
case "SRV":
dp := r.Data.(map[string]interface{})
content = fmt.Sprintf("%.f %s", dp["priority"], r.Content)
// Cloudflare's API, annoyingly, automatically prepends the weight
// and port into content, separated by tabs.
content = strings.Replace(content, "\t", " ", -1)
}

uRule, err := upstream.NewRule(fqdn.FQDN(r.Name), rType, strings.TrimSpace(content))
if err != nil {
return Rule{}, err
}
Expand Down

0 comments on commit 129b76a

Please sign in to comment.