diff --git a/lib/logic/models/json/dns_providers/cloudflare_dns_adapter.dart b/lib/logic/models/json/dns_providers/cloudflare_dns_adapter.dart index 8046555c..3ddef522 100644 --- a/lib/logic/models/json/dns_providers/cloudflare_dns_adapter.dart +++ b/lib/logic/models/json/dns_providers/cloudflare_dns_adapter.dart @@ -12,6 +12,28 @@ CloudflareDnsRecord _fromDnsRecord( if (type == 'MX' && name == '@') { name = rootDomain; } + if (type == 'CAA') { + // Split the content string into parts + // e.g. '0 issue "letsencrypt.org"' -> ['0', 'issue', 'letsencrypt.org'] + final List parts = dnsRecord.content!.split(' '); + if (parts.length != 3) { + throw ArgumentError('Invalid CAA record content: ${dnsRecord.content}'); + } + final data = { + 'flags': int.parse(parts[0]), + 'tag': parts[1], + 'value': parts[2].replaceAll('"', ''), + }; + return CloudflareDnsRecord( + content: null, + name: name, + type: type, + zoneName: rootDomain, + id: null, + ttl: dnsRecord.ttl, + data: data, + ); + } return CloudflareDnsRecord( content: dnsRecord.content, name: name, diff --git a/lib/logic/models/json/dns_providers/cloudflare_dns_info.dart b/lib/logic/models/json/dns_providers/cloudflare_dns_info.dart index ec3c837c..6c3f218f 100644 --- a/lib/logic/models/json/dns_providers/cloudflare_dns_info.dart +++ b/lib/logic/models/json/dns_providers/cloudflare_dns_info.dart @@ -38,8 +38,9 @@ class CloudflareDnsRecord { CloudflareDnsRecord({ required this.type, required this.name, - required this.content, required this.zoneName, + this.content, + this.data, this.ttl = 3600, this.priority = 10, this.id, @@ -75,6 +76,9 @@ class CloudflareDnsRecord { /// Example: A valid IPv4 address "198.51.100.4" final String? content; + /// Some record types require data object instead of the content. + final Map? data; + /// The domain of the record. /// /// Example: example.com diff --git a/lib/logic/models/json/dns_providers/cloudflare_dns_info.g.dart b/lib/logic/models/json/dns_providers/cloudflare_dns_info.g.dart index 298fc205..bc48fbe1 100644 --- a/lib/logic/models/json/dns_providers/cloudflare_dns_info.g.dart +++ b/lib/logic/models/json/dns_providers/cloudflare_dns_info.g.dart @@ -22,8 +22,9 @@ CloudflareDnsRecord _$CloudflareDnsRecordFromJson(Map json) => CloudflareDnsRecord( type: json['type'] as String, name: json['name'] as String?, - content: json['content'] as String?, zoneName: json['zone_name'] as String, + content: json['content'] as String?, + data: json['data'] as Map?, ttl: (json['ttl'] as num?)?.toInt() ?? 3600, priority: (json['priority'] as num?)?.toInt() ?? 10, id: json['id'] as String?, @@ -37,6 +38,7 @@ Map _$CloudflareDnsRecordToJson( 'type': instance.type, 'name': instance.name, 'content': instance.content, + 'data': instance.data, 'zone_name': instance.zoneName, 'ttl': instance.ttl, 'priority': instance.priority, diff --git a/lib/logic/models/json/dns_providers/digital_ocean_dns_adapter.dart b/lib/logic/models/json/dns_providers/digital_ocean_dns_adapter.dart index 0fb6cc48..e21c2453 100644 --- a/lib/logic/models/json/dns_providers/digital_ocean_dns_adapter.dart +++ b/lib/logic/models/json/dns_providers/digital_ocean_dns_adapter.dart @@ -9,6 +9,26 @@ DigitalOceanDnsRecord _fromDnsRecord( String content = dnsRecord.content ?? ''; name = convert(name); content = convert(content); + + if (dnsRecord.type == 'CAA') { + // Split the content string into parts + // e.g. '0 issue "letsencrypt.org"' -> ['0', 'issue', 'letsencrypt.org'] + final List parts = dnsRecord.content!.split(' '); + if (parts.length != 3) { + throw ArgumentError('Invalid CAA record content: ${dnsRecord.content}'); + } + return DigitalOceanDnsRecord( + name: name, + data: parts[2].replaceAll('"', ''), + ttl: dnsRecord.ttl, + type: dnsRecord.type, + priority: dnsRecord.priority, + id: null, + flags: int.parse(parts[0]), + tag: parts[1], + ); + } + return DigitalOceanDnsRecord( name: name, data: content, diff --git a/lib/logic/models/json/dns_providers/digital_ocean_dns_info.dart b/lib/logic/models/json/dns_providers/digital_ocean_dns_info.dart index be23f711..2f5ab217 100644 --- a/lib/logic/models/json/dns_providers/digital_ocean_dns_info.dart +++ b/lib/logic/models/json/dns_providers/digital_ocean_dns_info.dart @@ -44,6 +44,8 @@ class DigitalOceanDnsRecord { required this.ttl, required this.data, this.priority, + this.flags, + this.tag, }); factory DigitalOceanDnsRecord.fromDnsRecord( @@ -78,6 +80,12 @@ class DigitalOceanDnsRecord { /// The priority for SRV and MX records. final int? priority; + /// The flags for CAA records. + final int? flags; + + /// The tag for CAA records. + final String? tag; + static DigitalOceanDnsRecord fromJson(final Map json) => _$DigitalOceanDnsRecordFromJson(json); Map toJson() => _$DigitalOceanDnsRecordToJson(this); diff --git a/lib/logic/models/json/dns_providers/digital_ocean_dns_info.g.dart b/lib/logic/models/json/dns_providers/digital_ocean_dns_info.g.dart index df419647..df443c06 100644 --- a/lib/logic/models/json/dns_providers/digital_ocean_dns_info.g.dart +++ b/lib/logic/models/json/dns_providers/digital_ocean_dns_info.g.dart @@ -27,6 +27,8 @@ DigitalOceanDnsRecord _$DigitalOceanDnsRecordFromJson( ttl: (json['ttl'] as num).toInt(), data: json['data'] as String, priority: (json['priority'] as num?)?.toInt(), + flags: (json['flags'] as num?)?.toInt(), + tag: json['tag'] as String?, ); Map _$DigitalOceanDnsRecordToJson( @@ -38,4 +40,6 @@ Map _$DigitalOceanDnsRecordToJson( 'ttl': instance.ttl, 'data': instance.data, 'priority': instance.priority, + 'flags': instance.flags, + 'tag': instance.tag, };