mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2025-01-08 00:51:20 +00:00
fix(DNS): Handle CAA records
This commit is contained in:
parent
c17d87c348
commit
c86c00cdf0
|
@ -12,6 +12,28 @@ CloudflareDnsRecord _fromDnsRecord(
|
||||||
if (type == 'MX' && name == '@') {
|
if (type == 'MX' && name == '@') {
|
||||||
name = rootDomain;
|
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(
|
return CloudflareDnsRecord(
|
||||||
content: dnsRecord.content,
|
content: dnsRecord.content,
|
||||||
name: name,
|
name: name,
|
||||||
|
|
|
@ -38,8 +38,9 @@ class CloudflareDnsRecord {
|
||||||
CloudflareDnsRecord({
|
CloudflareDnsRecord({
|
||||||
required this.type,
|
required this.type,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.content,
|
|
||||||
required this.zoneName,
|
required this.zoneName,
|
||||||
|
this.content,
|
||||||
|
this.data,
|
||||||
this.ttl = 3600,
|
this.ttl = 3600,
|
||||||
this.priority = 10,
|
this.priority = 10,
|
||||||
this.id,
|
this.id,
|
||||||
|
@ -75,6 +76,9 @@ class CloudflareDnsRecord {
|
||||||
/// Example: A valid IPv4 address "198.51.100.4"
|
/// Example: A valid IPv4 address "198.51.100.4"
|
||||||
final String? content;
|
final String? content;
|
||||||
|
|
||||||
|
/// Some record types require data object instead of the content.
|
||||||
|
final Map<String, dynamic>? data;
|
||||||
|
|
||||||
/// The domain of the record.
|
/// The domain of the record.
|
||||||
///
|
///
|
||||||
/// Example: example.com
|
/// Example: example.com
|
||||||
|
|
|
@ -22,8 +22,9 @@ CloudflareDnsRecord _$CloudflareDnsRecordFromJson(Map<String, dynamic> json) =>
|
||||||
CloudflareDnsRecord(
|
CloudflareDnsRecord(
|
||||||
type: json['type'] as String,
|
type: json['type'] as String,
|
||||||
name: json['name'] as String?,
|
name: json['name'] as String?,
|
||||||
content: json['content'] as String?,
|
|
||||||
zoneName: json['zone_name'] 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,
|
ttl: (json['ttl'] as num?)?.toInt() ?? 3600,
|
||||||
priority: (json['priority'] as num?)?.toInt() ?? 10,
|
priority: (json['priority'] as num?)?.toInt() ?? 10,
|
||||||
id: json['id'] as String?,
|
id: json['id'] as String?,
|
||||||
|
@ -37,6 +38,7 @@ Map<String, dynamic> _$CloudflareDnsRecordToJson(
|
||||||
'type': instance.type,
|
'type': instance.type,
|
||||||
'name': instance.name,
|
'name': instance.name,
|
||||||
'content': instance.content,
|
'content': instance.content,
|
||||||
|
'data': instance.data,
|
||||||
'zone_name': instance.zoneName,
|
'zone_name': instance.zoneName,
|
||||||
'ttl': instance.ttl,
|
'ttl': instance.ttl,
|
||||||
'priority': instance.priority,
|
'priority': instance.priority,
|
||||||
|
|
|
@ -9,6 +9,26 @@ DigitalOceanDnsRecord _fromDnsRecord(
|
||||||
String content = dnsRecord.content ?? '';
|
String content = dnsRecord.content ?? '';
|
||||||
name = convert(name);
|
name = convert(name);
|
||||||
content = convert(content);
|
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(
|
return DigitalOceanDnsRecord(
|
||||||
name: name,
|
name: name,
|
||||||
data: content,
|
data: content,
|
||||||
|
|
|
@ -44,6 +44,8 @@ class DigitalOceanDnsRecord {
|
||||||
required this.ttl,
|
required this.ttl,
|
||||||
required this.data,
|
required this.data,
|
||||||
this.priority,
|
this.priority,
|
||||||
|
this.flags,
|
||||||
|
this.tag,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory DigitalOceanDnsRecord.fromDnsRecord(
|
factory DigitalOceanDnsRecord.fromDnsRecord(
|
||||||
|
@ -78,6 +80,12 @@ class DigitalOceanDnsRecord {
|
||||||
/// The priority for SRV and MX records.
|
/// The priority for SRV and MX records.
|
||||||
final int? priority;
|
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) =>
|
static DigitalOceanDnsRecord fromJson(final Map<String, dynamic> json) =>
|
||||||
_$DigitalOceanDnsRecordFromJson(json);
|
_$DigitalOceanDnsRecordFromJson(json);
|
||||||
Map<String, dynamic> toJson() => _$DigitalOceanDnsRecordToJson(this);
|
Map<String, dynamic> toJson() => _$DigitalOceanDnsRecordToJson(this);
|
||||||
|
|
|
@ -27,6 +27,8 @@ DigitalOceanDnsRecord _$DigitalOceanDnsRecordFromJson(
|
||||||
ttl: (json['ttl'] as num).toInt(),
|
ttl: (json['ttl'] as num).toInt(),
|
||||||
data: json['data'] as String,
|
data: json['data'] as String,
|
||||||
priority: (json['priority'] as num?)?.toInt(),
|
priority: (json['priority'] as num?)?.toInt(),
|
||||||
|
flags: (json['flags'] as num?)?.toInt(),
|
||||||
|
tag: json['tag'] as String?,
|
||||||
);
|
);
|
||||||
|
|
||||||
Map<String, dynamic> _$DigitalOceanDnsRecordToJson(
|
Map<String, dynamic> _$DigitalOceanDnsRecordToJson(
|
||||||
|
@ -38,4 +40,6 @@ Map<String, dynamic> _$DigitalOceanDnsRecordToJson(
|
||||||
'ttl': instance.ttl,
|
'ttl': instance.ttl,
|
||||||
'data': instance.data,
|
'data': instance.data,
|
||||||
'priority': instance.priority,
|
'priority': instance.priority,
|
||||||
|
'flags': instance.flags,
|
||||||
|
'tag': instance.tag,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue