Skip to content

Commit a08b4e5

Browse files
add support for deleting dnssec records closes #54
1 parent 4ff0cbc commit a08b4e5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

pkb_client/client/client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,29 @@ def create_dnssec_record(
926926
response_json.get("message", "Unknown message"),
927927
)
928928

929+
def delete_dnssec_record(self, domain: str, key_tag: int) -> bool:
930+
"""
931+
API DNSSEC delete method: delete an existing DNSSEC record for the given domain.
932+
See https://porkbun.com/api/json/v3/documentation#DNSSEC%20Delete%20Record for more info.
933+
934+
:param domain: the domain for which the DNSSEC record should be deleted
935+
:param key_tag: the key tag of the DNSSEC record
936+
:return: True if everything went well
937+
"""
938+
939+
url = urljoin(self.api_endpoint, f"dns/deleteDnssecRecord/{domain}/{key_tag}")
940+
req_json = self._get_auth_request_json()
941+
r = requests.post(url=url, json=req_json)
942+
943+
if r.status_code == 200:
944+
return True
945+
else:
946+
response_json = json.loads(r.text)
947+
raise PKBClientException(
948+
response_json.get("status", "Unknown status"),
949+
response_json.get("message", "Unknown message"),
950+
)
951+
929952
@staticmethod
930953
def __handle_error_backup__(dns_records):
931954
# merge the single DNS records into one single dict with the record id as key

tests/client.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,23 @@ def test_create_dnssec_record(self):
11581158
)
11591159
self.assertTrue(success)
11601160

1161+
@responses.activate
1162+
def delete_dnssec_record(self):
1163+
pkb_client = PKBClient("key", "secret")
1164+
1165+
responses.post(
1166+
url=urljoin(API_ENDPOINT, "dns/deleteDnssecRecord/example.com/123456"),
1167+
json={"status": "SUCCESS"},
1168+
match=[
1169+
matchers.json_params_matcher(
1170+
{"apikey": "key", "secretapikey": "secret"}
1171+
)
1172+
],
1173+
)
1174+
1175+
success = pkb_client.delete_dnssec_record("example.com", 123456)
1176+
self.assertTrue(success)
1177+
11611178

11621179
if __name__ == "__main__":
11631180
unittest.main()

0 commit comments

Comments
 (0)