1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

CLOUDFLAREAPI: Add NAPTR record support (#2548)

This commit is contained in:
asn-iac
2023-09-07 13:31:34 -07:00
committed by GitHub
parent 0b5de1adf2
commit af91e37043
3 changed files with 31 additions and 1 deletions

View File

@ -19,7 +19,7 @@ If a feature is definitively not supported for whatever reason, we would also li
| [`AXFRDDNS`](providers/axfrddns.md) | ❌ | ✅ | ❌ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❌ | ❌ | ❌ | ❌ | | [`AXFRDDNS`](providers/axfrddns.md) | ❌ | ✅ | ❌ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❌ | ❌ | ❌ | ❌ |
| [`AZURE_DNS`](providers/azure_dns.md) | ✅ | ✅ | ❌ | ❌ | ✅ | ❔ | ❌ | ❌ | ✅ | ❔ | ✅ | ❌ | ❌ | ❔ | ✅ | ✅ | ✅ | ✅ | | [`AZURE_DNS`](providers/azure_dns.md) | ✅ | ✅ | ❌ | ❌ | ✅ | ❔ | ❌ | ❌ | ✅ | ❔ | ✅ | ❌ | ❌ | ❔ | ✅ | ✅ | ✅ | ✅ |
| [`BIND`](providers/bind.md) | ✅ | ✅ | ❌ | ❔ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | | [`BIND`](providers/bind.md) | ✅ | ✅ | ❌ | ❔ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ |
| [`CLOUDFLAREAPI`](providers/cloudflareapi.md) | ✅ | ✅ | ❌ | ✅ | ✅ | ❔ | ❌ | | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❌ | ✅ | ✅ | ✅ | | [`CLOUDFLAREAPI`](providers/cloudflareapi.md) | ✅ | ✅ | ❌ | ✅ | ✅ | ❔ | ❌ | | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❌ | ✅ | ✅ | ✅ |
| [`CLOUDNS`](providers/cloudns.md) | ❌ | ✅ | ❌ | ✅ | ✅ | ❔ | ❌ | ❔ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❔ | ✅ | ✅ | ✅ | | [`CLOUDNS`](providers/cloudns.md) | ❌ | ✅ | ❌ | ✅ | ✅ | ❔ | ❌ | ❔ | ✅ | ❔ | ✅ | ✅ | ✅ | ❔ | ❔ | ✅ | ✅ | ✅ |
| [`CSCGLOBAL`](providers/cscglobal.md) | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | ✅ | ❔ | ❔ | ❔ | ❔ | ❌ | ✅ | ✅ | | [`CSCGLOBAL`](providers/cscglobal.md) | ✅ | ✅ | ✅ | ❔ | ✅ | ❔ | ❔ | ❔ | ❔ | ❔ | ✅ | ❔ | ❔ | ❔ | ❔ | ❌ | ✅ | ✅ |
| [`DESEC`](providers/desec.md) | ❌ | ✅ | ❌ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | | [`DESEC`](providers/desec.md) | ❌ | ✅ | ❌ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ | ✅ | ❔ | ✅ | ✅ | ✅ |

View File

@ -45,6 +45,7 @@ var features = providers.DocumentationNotes{
providers.CanUseCAA: providers.Can(), providers.CanUseCAA: providers.Can(),
providers.CanUseDSForChildren: providers.Can(), providers.CanUseDSForChildren: providers.Can(),
providers.CanUseLOC: providers.Cannot(), providers.CanUseLOC: providers.Cannot(),
providers.CanUseNAPTR: providers.Can(),
providers.CanUsePTR: providers.Can(), providers.CanUsePTR: providers.Can(),
providers.CanUseSRV: providers.Can(), providers.CanUseSRV: providers.Can(),
providers.CanUseSSHFP: providers.Can(), providers.CanUseSSHFP: providers.Can(),
@ -793,6 +794,15 @@ func (c cfTarget) FQDN() string {
return strings.TrimRight(string(c), ".") + "." return strings.TrimRight(string(c), ".") + "."
} }
type cfNaptrRecData struct {
Flags string `json:"flags"`
Order uint16 `json:"order"`
Preference uint16 `json:"preference"`
Regex string `json:"regex"`
Replacement string `json:"replacement"`
Service string `json:"service"`
}
// uint16Zero converts value to uint16 or returns 0. // uint16Zero converts value to uint16 or returns 0.
func uint16Zero(value interface{}) uint16 { func uint16Zero(value interface{}) uint16 {
switch v := value.(type) { switch v := value.(type) {

View File

@ -118,6 +118,17 @@ func cfSshfpData(rec *models.RecordConfig) *cfRecData {
} }
} }
func cfNaptrData(rec *models.RecordConfig) *cfNaptrRecData {
return &cfNaptrRecData{
Flags: rec.NaptrFlags,
Order: rec.NaptrOrder,
Preference: rec.NaptrPreference,
Regex: rec.NaptrRegexp,
Replacement: rec.GetTargetField(),
Service: rec.NaptrService,
}
}
func (c *cloudflareProvider) createRec(rec *models.RecordConfig, domainID string) []*models.Correction { func (c *cloudflareProvider) createRec(rec *models.RecordConfig, domainID string) []*models.Correction {
var id string var id string
content := rec.GetTargetField() content := rec.GetTargetField()
@ -159,6 +170,9 @@ func (c *cloudflareProvider) createRec(rec *models.RecordConfig, domainID string
cf.Name = rec.GetLabelFQDN() cf.Name = rec.GetLabelFQDN()
} else if rec.Type == "DS" { } else if rec.Type == "DS" {
cf.Data = cfDSData(rec) cf.Data = cfDSData(rec)
} else if rec.Type == "NAPTR" {
cf.Data = cfNaptrData(rec)
cf.Name = rec.GetLabelFQDN()
} }
resp, err := c.cfClient.CreateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(domainID), cf) resp, err := c.cfClient.CreateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(domainID), cf)
if err != nil { if err != nil {
@ -225,6 +239,9 @@ func (c *cloudflareProvider) createRecDiff2(rec *models.RecordConfig, domainID s
cf.Name = rec.GetLabelFQDN() cf.Name = rec.GetLabelFQDN()
} else if rec.Type == "DS" { } else if rec.Type == "DS" {
cf.Data = cfDSData(rec) cf.Data = cfDSData(rec)
} else if rec.Type == "NAPTR" {
cf.Data = cfNaptrData(rec)
cf.Name = rec.GetLabelFQDN()
} }
resp, err := c.cfClient.CreateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(domainID), cf) resp, err := c.cfClient.CreateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(domainID), cf)
if err != nil { if err != nil {
@ -275,6 +292,9 @@ func (c *cloudflareProvider) modifyRecord(domainID, recID string, proxied bool,
} else if rec.Type == "DS" { } else if rec.Type == "DS" {
r.Data = cfDSData(rec) r.Data = cfDSData(rec)
r.Content = "" r.Content = ""
} else if rec.Type == "NAPTR" {
r.Data = cfNaptrData(rec)
r.Name = rec.GetLabelFQDN()
} }
_, err := c.cfClient.UpdateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(domainID), r) _, err := c.cfClient.UpdateDNSRecord(context.Background(), cloudflare.ZoneIdentifier(domainID), r)
return err return err