Skip to content

Commit

Permalink
validate dns recrods prio for supported dns types
Browse files Browse the repository at this point in the history
  • Loading branch information
infinityofspace committed Aug 20, 2024
1 parent 74af55a commit 57fdadd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pkb_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import requests

from pkb_client.dns import DNSRecord, DNSRestoreMode, DNSRecordType
from pkb_client.dns import DNSRecord, DNSRestoreMode, DNSRecordType, DNS_RECORDS_WITH_PRIORITY
from pkb_client.domain import DomainInfo
from pkb_client.forwarding import URLForwarding, URLForwardingType
from pkb_client.ssl_cert import SSLCertBundle
Expand Down Expand Up @@ -103,6 +103,9 @@ def dns_create(self,
if ttl > 86400 or ttl < self.default_ttl:
raise ValueError(f"ttl must be between {self.default_ttl} and 86400")

if prio is not None and record_type not in DNS_RECORDS_WITH_PRIORITY:
raise ValueError(f"Priority can only be set for {DNS_RECORDS_WITH_PRIORITY}")

url = urljoin(self.api_endpoint, f"dns/create/{domain}")
req_json = {
**self._get_auth_request_json(),
Expand Down Expand Up @@ -149,6 +152,9 @@ def dns_edit(self,
if ttl > 86400 or ttl < self.default_ttl:
raise ValueError(f"ttl must be between {self.default_ttl} and 86400")

if prio is not None and record_type not in DNS_RECORDS_WITH_PRIORITY:
raise ValueError(f"Priority can only be set for {DNS_RECORDS_WITH_PRIORITY}")

url = urljoin(self.api_endpoint, f"dns/edit/{domain}/{record_id}")
req_json = {
**self._get_auth_request_json(),
Expand Down Expand Up @@ -191,6 +197,9 @@ def dns_edit_all(self,
if ttl > 86400 or ttl < self.default_ttl:
raise ValueError(f"ttl must be between {self.default_ttl} and 86400")

if prio is not None and record_type not in DNS_RECORDS_WITH_PRIORITY:
raise ValueError(f"Priority can only be set for {DNS_RECORDS_WITH_PRIORITY}")

url = urljoin(self.api_endpoint, f"dns/editByNameType/{domain}/{record_type}/{subdomain}")
req_json = {
**self._get_auth_request_json(),
Expand Down

0 comments on commit 57fdadd

Please sign in to comment.