final fixes
This commit is contained in:
@@ -51,7 +51,7 @@ func init() {
|
||||
// CloudflareDNSRes is a resource for managing DNS records in Cloudflare zones.
|
||||
// This resource uses the Cloudflare API to create, update, and delete DNS
|
||||
// records in a specified zone. It supports various record types including A,
|
||||
// AAAA, CNAME, MX, TXT, NS, SRV, and PTR records. The resource requires polling
|
||||
// AAAA, CNAME, MX, TXT, NS, and PTR records. The resource requires polling
|
||||
// to detect changes, as the Cloudflare API does not provide an event stream.
|
||||
// The Purge functionality allows enforcing that only managed DNS records exist
|
||||
// in the zone, removing any unmanaged records.
|
||||
@@ -74,14 +74,10 @@ type CloudflareDNSRes struct {
|
||||
// Type (e.g., IP address for A records, hostname for CNAME records).
|
||||
Content string `lang:"content"`
|
||||
|
||||
// Data is a value that's specific for SRV records, containing the priority,
|
||||
// weight, port, and SRV targets.
|
||||
Data *dns.SRVRecordData `lang:"srv_data"`
|
||||
|
||||
// Priority is the priority value for records that support it (e.g., MX
|
||||
// records). This is a pointer to distinguish between an unset value and
|
||||
// a zero value.
|
||||
Priority *int64 `lang:"priority"`
|
||||
Priority *float64 `lang:"priority"`
|
||||
|
||||
// Proxied specifies whether the record should be proxied through
|
||||
// Cloudflare's CDN. This is a pointer to distinguish between an unset
|
||||
@@ -164,7 +160,7 @@ func (obj *CloudflareDNSRes) Validate() error {
|
||||
// cloudflare accepts ~4req/s so this is safe enough even when managing lots
|
||||
// of records
|
||||
if obj.MetaParams().Poll == 0 || obj.MetaParams().Poll < 60 {
|
||||
return fmt.Errorf("cloudflare:dns requires polling, set Meta:poll param (e.g., 300s), min. 60s")
|
||||
return fmt.Errorf("cloudflare:dns requires polling, set Meta:poll param (e.g., 300s), min. 60s")
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -179,7 +175,6 @@ func (obj *CloudflareDNSRes) Init(init *engine.Init) error {
|
||||
option.WithAPIToken(obj.APIToken),
|
||||
)
|
||||
|
||||
//TODO: does it make more sense to check it here or in CheckApply()?
|
||||
zoneListParams := zones.ZoneListParams{
|
||||
Name: cloudflare.F(obj.Zone),
|
||||
}
|
||||
@@ -369,10 +364,6 @@ func (obj *CloudflareDNSRes) Cmp(r engine.Res) error {
|
||||
return fmt.Errorf("the priority param differs")
|
||||
}
|
||||
|
||||
if obj.Data != res.Data {
|
||||
return fmt.Errorf("the data param differs")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -440,7 +431,7 @@ func (obj *CloudflareDNSRes) buildRecordParam() (any, error) {
|
||||
param.Proxied = cloudflare.F(*obj.Proxied)
|
||||
}
|
||||
if obj.Priority != nil { // required for MX record
|
||||
param.Priority = cloudflare.F(float64(*obj.Priority))
|
||||
param.Priority = cloudflare.F(*obj.Priority)
|
||||
}
|
||||
if obj.Comment != "" {
|
||||
param.Comment = cloudflare.F(obj.Comment)
|
||||
@@ -464,23 +455,8 @@ func (obj *CloudflareDNSRes) buildRecordParam() (any, error) {
|
||||
|
||||
case "NS":
|
||||
param := dns.NSRecordParam{
|
||||
Name: cloudflare.F(obj.RecordName),
|
||||
Type: cloudflare.F(dns.NSRecordTypeNS),
|
||||
Data: cloudflare.F(obj.Data),
|
||||
TTL: cloudflare.F(ttl),
|
||||
}
|
||||
if obj.Proxied != nil {
|
||||
param.Proxied = cloudflare.F(*obj.Proxied)
|
||||
}
|
||||
if obj.Comment != "" {
|
||||
param.Comment = cloudflare.F(obj.Comment)
|
||||
}
|
||||
return param, nil
|
||||
|
||||
case "SRV":
|
||||
param := dns.SRVRecordParam{
|
||||
Name: cloudflare.F(obj.RecordName),
|
||||
Type: cloudflare.F(dns.SRVRecordTypeSRV),
|
||||
Type: cloudflare.F(dns.NSRecordTypeNS),
|
||||
Content: cloudflare.F(obj.Content),
|
||||
TTL: cloudflare.F(ttl),
|
||||
}
|
||||
@@ -593,12 +569,12 @@ func (obj *CloudflareDNSRes) needsUpdate(record dns.RecordResponse) bool {
|
||||
}
|
||||
|
||||
if obj.Priority != nil {
|
||||
if float64(*obj.Priority) != record.Priority {
|
||||
if *obj.Priority != record.Priority {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if obj.Comment != record.Comment {
|
||||
if obj.Comment != "" && obj.Comment != record.Comment {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -656,7 +632,7 @@ func (obj *CloudflareDNSRes) purgeCheckApply(ctx context.Context, apply bool) (b
|
||||
cfRes.Content)
|
||||
if cfRes.Priority != nil {
|
||||
// corner case for MX records which require priority set
|
||||
recordKey = fmt.Sprintf("%s:%d", recordKey, *cfRes.Priority)
|
||||
recordKey = fmt.Sprintf("%s:%g", recordKey, *cfRes.Priority)
|
||||
}
|
||||
excludes[recordKey] = true
|
||||
}
|
||||
@@ -667,6 +643,9 @@ func (obj *CloudflareDNSRes) purgeCheckApply(ctx context.Context, apply bool) (b
|
||||
for _, record := range allRecords {
|
||||
recordKey := fmt.Sprintf("%s:%s:%s", record.Name, record.Type,
|
||||
record.Content)
|
||||
if record.Priority != 0 {
|
||||
recordKey = fmt.Sprintf("%s:%g", recordKey, record.Priority)
|
||||
}
|
||||
|
||||
if excludes[recordKey] {
|
||||
continue
|
||||
@@ -715,7 +694,7 @@ func (obj *CloudflareDNSRes) normalizeRecordName(name string) string {
|
||||
return obj.Zone
|
||||
}
|
||||
|
||||
if strings.HasSuffix(name, "."+obj.Zone) || name == obj.Zone {
|
||||
if strings.HasSuffix(name, "."+obj.Zone) {
|
||||
return name
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user