final fixes
This commit is contained in:
@@ -51,7 +51,7 @@ func init() {
|
|||||||
// CloudflareDNSRes is a resource for managing DNS records in Cloudflare zones.
|
// CloudflareDNSRes is a resource for managing DNS records in Cloudflare zones.
|
||||||
// This resource uses the Cloudflare API to create, update, and delete DNS
|
// This resource uses the Cloudflare API to create, update, and delete DNS
|
||||||
// records in a specified zone. It supports various record types including A,
|
// 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.
|
// to detect changes, as the Cloudflare API does not provide an event stream.
|
||||||
// The Purge functionality allows enforcing that only managed DNS records exist
|
// The Purge functionality allows enforcing that only managed DNS records exist
|
||||||
// in the zone, removing any unmanaged records.
|
// 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).
|
// Type (e.g., IP address for A records, hostname for CNAME records).
|
||||||
Content string `lang:"content"`
|
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
|
// 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
|
// records). This is a pointer to distinguish between an unset value and
|
||||||
// a zero value.
|
// a zero value.
|
||||||
Priority *int64 `lang:"priority"`
|
Priority *float64 `lang:"priority"`
|
||||||
|
|
||||||
// Proxied specifies whether the record should be proxied through
|
// Proxied specifies whether the record should be proxied through
|
||||||
// Cloudflare's CDN. This is a pointer to distinguish between an unset
|
// Cloudflare's CDN. This is a pointer to distinguish between an unset
|
||||||
@@ -179,7 +175,6 @@ func (obj *CloudflareDNSRes) Init(init *engine.Init) error {
|
|||||||
option.WithAPIToken(obj.APIToken),
|
option.WithAPIToken(obj.APIToken),
|
||||||
)
|
)
|
||||||
|
|
||||||
//TODO: does it make more sense to check it here or in CheckApply()?
|
|
||||||
zoneListParams := zones.ZoneListParams{
|
zoneListParams := zones.ZoneListParams{
|
||||||
Name: cloudflare.F(obj.Zone),
|
Name: cloudflare.F(obj.Zone),
|
||||||
}
|
}
|
||||||
@@ -369,10 +364,6 @@ func (obj *CloudflareDNSRes) Cmp(r engine.Res) error {
|
|||||||
return fmt.Errorf("the priority param differs")
|
return fmt.Errorf("the priority param differs")
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Data != res.Data {
|
|
||||||
return fmt.Errorf("the data param differs")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -440,7 +431,7 @@ func (obj *CloudflareDNSRes) buildRecordParam() (any, error) {
|
|||||||
param.Proxied = cloudflare.F(*obj.Proxied)
|
param.Proxied = cloudflare.F(*obj.Proxied)
|
||||||
}
|
}
|
||||||
if obj.Priority != nil { // required for MX record
|
if obj.Priority != nil { // required for MX record
|
||||||
param.Priority = cloudflare.F(float64(*obj.Priority))
|
param.Priority = cloudflare.F(*obj.Priority)
|
||||||
}
|
}
|
||||||
if obj.Comment != "" {
|
if obj.Comment != "" {
|
||||||
param.Comment = cloudflare.F(obj.Comment)
|
param.Comment = cloudflare.F(obj.Comment)
|
||||||
@@ -466,21 +457,6 @@ func (obj *CloudflareDNSRes) buildRecordParam() (any, error) {
|
|||||||
param := dns.NSRecordParam{
|
param := dns.NSRecordParam{
|
||||||
Name: cloudflare.F(obj.RecordName),
|
Name: cloudflare.F(obj.RecordName),
|
||||||
Type: cloudflare.F(dns.NSRecordTypeNS),
|
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),
|
|
||||||
Content: cloudflare.F(obj.Content),
|
Content: cloudflare.F(obj.Content),
|
||||||
TTL: cloudflare.F(ttl),
|
TTL: cloudflare.F(ttl),
|
||||||
}
|
}
|
||||||
@@ -593,12 +569,12 @@ func (obj *CloudflareDNSRes) needsUpdate(record dns.RecordResponse) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if obj.Priority != nil {
|
if obj.Priority != nil {
|
||||||
if float64(*obj.Priority) != record.Priority {
|
if *obj.Priority != record.Priority {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if obj.Comment != record.Comment {
|
if obj.Comment != "" && obj.Comment != record.Comment {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,7 +632,7 @@ func (obj *CloudflareDNSRes) purgeCheckApply(ctx context.Context, apply bool) (b
|
|||||||
cfRes.Content)
|
cfRes.Content)
|
||||||
if cfRes.Priority != nil {
|
if cfRes.Priority != nil {
|
||||||
// corner case for MX records which require priority set
|
// 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
|
excludes[recordKey] = true
|
||||||
}
|
}
|
||||||
@@ -667,6 +643,9 @@ func (obj *CloudflareDNSRes) purgeCheckApply(ctx context.Context, apply bool) (b
|
|||||||
for _, record := range allRecords {
|
for _, record := range allRecords {
|
||||||
recordKey := fmt.Sprintf("%s:%s:%s", record.Name, record.Type,
|
recordKey := fmt.Sprintf("%s:%s:%s", record.Name, record.Type,
|
||||||
record.Content)
|
record.Content)
|
||||||
|
if record.Priority != 0 {
|
||||||
|
recordKey = fmt.Sprintf("%s:%g", recordKey, record.Priority)
|
||||||
|
}
|
||||||
|
|
||||||
if excludes[recordKey] {
|
if excludes[recordKey] {
|
||||||
continue
|
continue
|
||||||
@@ -715,7 +694,7 @@ func (obj *CloudflareDNSRes) normalizeRecordName(name string) string {
|
|||||||
return obj.Zone
|
return obj.Zone
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasSuffix(name, "."+obj.Zone) || name == obj.Zone {
|
if strings.HasSuffix(name, "."+obj.Zone) {
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user