fix(DNS): Handle CAA records

This commit is contained in:
Inex Code 2024-12-06 20:57:20 +03:00
parent c17d87c348
commit c86c00cdf0
No known key found for this signature in database
6 changed files with 62 additions and 2 deletions

View file

@ -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<String> parts = dnsRecord.content!.split(' ');
if (parts.length != 3) {
throw ArgumentError('Invalid CAA record content: ${dnsRecord.content}');
}
final data = <String, dynamic>{
'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,

View file

@ -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<String, dynamic>? data;
/// The domain of the record.
///
/// Example: example.com

View file

@ -22,8 +22,9 @@ CloudflareDnsRecord _$CloudflareDnsRecordFromJson(Map<String, dynamic> 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<String, dynamic>?,
ttl: (json['ttl'] as num?)?.toInt() ?? 3600,
priority: (json['priority'] as num?)?.toInt() ?? 10,
id: json['id'] as String?,
@ -37,6 +38,7 @@ Map<String, dynamic> _$CloudflareDnsRecordToJson(
'type': instance.type,
'name': instance.name,
'content': instance.content,
'data': instance.data,
'zone_name': instance.zoneName,
'ttl': instance.ttl,
'priority': instance.priority,

View file

@ -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<String> 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,

View file

@ -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<String, dynamic> json) =>
_$DigitalOceanDnsRecordFromJson(json);
Map<String, dynamic> toJson() => _$DigitalOceanDnsRecordToJson(this);

View file

@ -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<String, dynamic> _$DigitalOceanDnsRecordToJson(
@ -38,4 +40,6 @@ Map<String, dynamic> _$DigitalOceanDnsRecordToJson(
'ttl': instance.ttl,
'data': instance.data,
'priority': instance.priority,
'flags': instance.flags,
'tag': instance.tag,
};