2023-08-01 02:40:25 +00:00
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
2023-11-09 13:21:56 +00:00
|
|
|
import 'package:selfprivacy/logic/models/hive/server_domain.dart';
|
|
|
|
import 'package:selfprivacy/logic/models/json/dns_records.dart';
|
2023-08-01 02:40:25 +00:00
|
|
|
|
|
|
|
part 'cloudflare_dns_info.g.dart';
|
2023-11-09 13:21:56 +00:00
|
|
|
part 'cloudflare_dns_adapter.dart';
|
2023-08-01 02:40:25 +00:00
|
|
|
|
|
|
|
/// https://developers.cloudflare.com/api/operations/zones-get
|
|
|
|
@JsonSerializable()
|
|
|
|
class CloudflareZone {
|
|
|
|
CloudflareZone({
|
|
|
|
required this.id,
|
|
|
|
required this.name,
|
|
|
|
});
|
|
|
|
|
|
|
|
/// Zone identifier
|
|
|
|
///
|
|
|
|
/// `<= 32 characters`
|
|
|
|
///
|
|
|
|
/// Example: 023e105f4ecef8ad9ca31a8372d0c353
|
|
|
|
final String id;
|
|
|
|
|
|
|
|
/// The domain name
|
|
|
|
///
|
|
|
|
/// `<= 253 characters`
|
|
|
|
///
|
|
|
|
/// Example: example.com
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
static CloudflareZone fromJson(final Map<String, dynamic> json) =>
|
|
|
|
_$CloudflareZoneFromJson(json);
|
2023-11-09 13:21:56 +00:00
|
|
|
ServerDomain toServerDomain() => _toServerDomain(this);
|
2023-08-01 02:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// https://developers.cloudflare.com/api/operations/dns-records-for-a-zone-list-dns-records
|
|
|
|
@JsonSerializable()
|
|
|
|
class CloudflareDnsRecord {
|
|
|
|
CloudflareDnsRecord({
|
|
|
|
required this.type,
|
|
|
|
required this.name,
|
|
|
|
required this.content,
|
|
|
|
required this.zoneName,
|
|
|
|
this.ttl = 3600,
|
|
|
|
this.priority = 10,
|
|
|
|
this.id,
|
|
|
|
});
|
|
|
|
|
2023-11-09 13:21:56 +00:00
|
|
|
factory CloudflareDnsRecord.fromDnsRecord(
|
|
|
|
final DnsRecord dnsRecord,
|
|
|
|
final String rootDomain,
|
|
|
|
) =>
|
|
|
|
_fromDnsRecord(dnsRecord, rootDomain);
|
|
|
|
|
2023-08-01 02:40:25 +00:00
|
|
|
/// Record identifier
|
|
|
|
///
|
|
|
|
/// `<= 32 characters`
|
|
|
|
/// Example: 023e105f4ecef8ad9ca31a8372d0c353
|
|
|
|
final String? id;
|
|
|
|
|
|
|
|
/// Record type.
|
|
|
|
///
|
|
|
|
/// Example: A
|
|
|
|
final String type;
|
|
|
|
|
|
|
|
/// DNS record name (or @ for the zone apex) in Punycode.
|
|
|
|
///
|
|
|
|
/// `<= 255 characters`
|
|
|
|
///
|
|
|
|
/// Example: example.com
|
|
|
|
final String? name;
|
|
|
|
|
|
|
|
/// Valid DNS Record string content.
|
|
|
|
///
|
|
|
|
/// Example: A valid IPv4 address "198.51.100.4"
|
|
|
|
final String? content;
|
|
|
|
|
|
|
|
/// The domain of the record.
|
|
|
|
///
|
|
|
|
/// Example: example.com
|
|
|
|
@JsonKey(name: 'zone_name')
|
|
|
|
final String zoneName;
|
|
|
|
|
|
|
|
/// Time To Live (TTL) of the DNS record in seconds. Setting to 1 means 'automatic'.
|
|
|
|
///
|
|
|
|
/// Value must be between 60 and 86400, with the minimum reduced to 30 for Enterprise zones.
|
|
|
|
final int ttl;
|
|
|
|
|
|
|
|
/// Required for MX, SRV and URI records; unused by other record types. Records with lower priorities are preferred.
|
|
|
|
///
|
|
|
|
/// `>= 0 <= 65535`
|
|
|
|
final int priority;
|
|
|
|
|
|
|
|
static CloudflareDnsRecord fromJson(final Map<String, dynamic> json) =>
|
|
|
|
_$CloudflareDnsRecordFromJson(json);
|
|
|
|
Map<String, dynamic> toJson() => _$CloudflareDnsRecordToJson(this);
|
2023-11-09 13:21:56 +00:00
|
|
|
DnsRecord toDnsRecord() => _toDnsRecord(this);
|
2023-08-01 02:40:25 +00:00
|
|
|
}
|