Skip to content

Commit 9c6b717

Browse files
committed
Version 3.13.0
1 parent 2feee22 commit 9c6b717

File tree

5 files changed

+78
-57
lines changed

5 files changed

+78
-57
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Changelog
22

33
## master - CURRENT
4+
5+
## 3.13.0 - 07/08/2023
46
### Added
57
* Add `wedos` provider (#1675)
68

lexicon/providers/easydns.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def __init__(self, config):
3333
def _authenticate(self):
3434
payload = self._get(f"/domain/{self.domain}")
3535
if "error" in payload:
36-
raise AuthenticationError(f'{payload["error"]["code"]} {payload["error"]["message"]}')
36+
raise AuthenticationError(
37+
f'{payload["error"]["code"]} {payload["error"]["message"]}'
38+
)
3739

3840
if payload["data"]["exists"] == "N":
3941
raise AuthenticationError("No domain found")

lexicon/providers/wedos.py

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
import datetime
22
import hashlib
33
import json
4-
from typing import Optional, Dict, List
4+
from typing import Dict, List, Optional
55

66
import requests
77

88
from lexicon.exceptions import AuthenticationError, LexiconError
99
from lexicon.providers.base import Provider as BaseProvider
1010

11-
NAMESERVER_DOMAINS = [
12-
"wedos.net",
13-
"wedos.eu",
14-
"wedos.cz",
15-
"wedos.com"]
11+
NAMESERVER_DOMAINS = ["wedos.net", "wedos.eu", "wedos.cz", "wedos.com"]
1612

1713

1814
def provider_parser(subparser):
@@ -55,13 +51,12 @@ def __init__(self, config):
5551

5652
@staticmethod
5753
def _auth_hash(login, password):
58-
passhash = hashlib.sha1(password.encode('utf8')).hexdigest()
59-
phrase = login + passhash + datetime.datetime.now().strftime('%H')
60-
return hashlib.sha1(phrase.encode('utf8')).hexdigest()
54+
passhash = hashlib.sha1(password.encode("utf8")).hexdigest()
55+
phrase = login + passhash + datetime.datetime.now().strftime("%H")
56+
return hashlib.sha1(phrase.encode("utf8")).hexdigest()
6157

6258
def _authenticate(self):
63-
64-
payload = self._post(data=self._create_payload('dns-domains-list', ''))
59+
payload = self._post(data=self._create_payload("dns-domains-list", ""))
6560
domains = payload["response"]["data"]["domain"]
6661
for record in domains:
6762
if record["name"] == self.domain:
@@ -73,28 +68,33 @@ def _authenticate(self):
7368
self.domain_id = self.domain
7469

7570
def _create_payload(self, command, payload_data):
76-
data = {'request': {'user': self._get_provider_option("auth_username"),
77-
'auth': self._auth_hash(self._get_provider_option("auth_username"),
78-
self._get_provider_option("auth_pass")),
79-
'command': command,
80-
'data': payload_data
81-
}}
82-
return {'request': json.dumps(data)}
71+
data = {
72+
"request": {
73+
"user": self._get_provider_option("auth_username"),
74+
"auth": self._auth_hash(
75+
self._get_provider_option("auth_username"),
76+
self._get_provider_option("auth_pass"),
77+
),
78+
"command": command,
79+
"data": payload_data,
80+
}
81+
}
82+
return {"request": json.dumps(data)}
8383

8484
def _create_record(self, rtype: str, name: str, content: str) -> bool:
8585
records = self._list_records(rtype, name, content)
8686
if len(records) == 1:
8787
return True
8888
data = {
89-
'type': rtype,
90-
'name': self._full_name(name),
91-
'rdata': content,
92-
'domain': self.domain_id
89+
"type": rtype,
90+
"name": self._full_name(name),
91+
"rdata": content,
92+
"domain": self.domain_id,
9393
}
9494
if self._get_lexicon_option("ttl"):
9595
data["ttl"] = self._get_lexicon_option("ttl")
9696

97-
payload = self._post(data=self._create_payload('dns-row-add', data))
97+
payload = self._post(data=self._create_payload("dns-row-add", data))
9898
code = payload["response"]["code"]
9999
if code == 1000:
100100
validation = self._commit_changes()
@@ -105,9 +105,13 @@ def _create_record(self, rtype: str, name: str, content: str) -> bool:
105105
else:
106106
raise LexiconError("Cannot create records")
107107

108-
def _list_records(self, rtype: Optional[str] = None, name: Optional[str] = None, content: Optional[str] = None) -> \
109-
List[Dict]:
110-
data = self._create_payload('dns-rows-list', {'domain': self.domain_id})
108+
def _list_records(
109+
self,
110+
rtype: Optional[str] = None,
111+
name: Optional[str] = None,
112+
content: Optional[str] = None,
113+
) -> List[Dict]:
114+
data = self._create_payload("dns-rows-list", {"domain": self.domain_id})
111115
payload = self._post(data=data)
112116
records = []
113117
dns_records = payload["response"]["data"]["row"]
@@ -123,14 +127,21 @@ def _list_records(self, rtype: Optional[str] = None, name: Optional[str] = None,
123127
if rtype is not None:
124128
records = list(rec for rec in records if _filter_rtype(rtype, rec))
125129
if name is not None:
126-
records = list(rec for rec in records if _filter_name(self._full_name(name), rec))
130+
records = list(
131+
rec for rec in records if _filter_name(self._full_name(name), rec)
132+
)
127133
if content is not None:
128134
records = list(rec for rec in records if _filter_content(content, rec))
129135

130136
return records
131137

132-
def _update_record(self, identifier: Optional[str] = None, rtype: Optional[str] = None, name: Optional[str] = None,
133-
content: Optional[str] = None) -> bool:
138+
def _update_record(
139+
self,
140+
identifier: Optional[str] = None,
141+
rtype: Optional[str] = None,
142+
name: Optional[str] = None,
143+
content: Optional[str] = None,
144+
) -> bool:
134145
if not identifier:
135146
records = self._list_records(rtype, name, content)
136147
identifiers = [record["id"] for record in records]
@@ -142,17 +153,18 @@ def _update_record(self, identifier: Optional[str] = None, rtype: Optional[str]
142153
payloads = []
143154
for record_id in identifiers:
144155
data = {
145-
'type': rtype,
146-
147-
'rdata': content,
148-
'domain': self.domain_id,
149-
'row_id': record_id
156+
"type": rtype,
157+
"rdata": content,
158+
"domain": self.domain_id,
159+
"row_id": record_id,
150160
}
151161
if name:
152-
data['name'] = self._full_name(name)
162+
data["name"] = self._full_name(name)
153163
if self._get_lexicon_option("ttl"):
154164
data["ttl"] = self._get_lexicon_option("ttl")
155-
payloads.append(self._post(data=self._create_payload('dns-row-update', data)))
165+
payloads.append(
166+
self._post(data=self._create_payload("dns-row-update", data))
167+
)
156168

157169
if all(payload["response"]["code"] == 1000 for payload in payloads):
158170
validation = self._commit_changes()
@@ -163,8 +175,13 @@ def _update_record(self, identifier: Optional[str] = None, rtype: Optional[str]
163175
else:
164176
raise LexiconError("Cannot update records")
165177

166-
def _delete_record(self, identifier: Optional[str] = None, rtype: Optional[str] = None, name: Optional[str] = None,
167-
content: Optional[str] = None) -> bool:
178+
def _delete_record(
179+
self,
180+
identifier: Optional[str] = None,
181+
rtype: Optional[str] = None,
182+
name: Optional[str] = None,
183+
content: Optional[str] = None,
184+
) -> bool:
168185
if not identifier:
169186
records = self._list_records(rtype, name, content)
170187
identifiers = [record["id"] for record in records]
@@ -175,11 +192,10 @@ def _delete_record(self, identifier: Optional[str] = None, rtype: Optional[str]
175192
return True
176193
payloads = []
177194
for record_id in identifiers:
178-
data = {
179-
'domain': self.domain_id,
180-
'row_id': record_id
181-
}
182-
payloads.append(self._post(data=self._create_payload('dns-row-delete', data)))
195+
data = {"domain": self.domain_id, "row_id": record_id}
196+
payloads.append(
197+
self._post(data=self._create_payload("dns-row-delete", data))
198+
)
183199

184200
if all(payload["response"]["code"] == 1000 for payload in payloads):
185201
validation = self._commit_changes()
@@ -191,11 +207,9 @@ def _delete_record(self, identifier: Optional[str] = None, rtype: Optional[str]
191207
raise LexiconError("Cannot delete records")
192208

193209
def _commit_changes(self) -> bool:
194-
data = {
195-
'name': self.domain_id
196-
}
210+
data = {"name": self.domain_id}
197211

198-
payload = self._post(data=self._create_payload('dns-domain-commit', data))
212+
payload = self._post(data=self._create_payload("dns-domain-commit", data))
199213
code = payload["response"]["code"]
200214
if code == 1000:
201215
return True

lexicon/tests/providers/test_wedos.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,33 @@
22
import json
33
import re
44
import urllib.parse
5+
from unittest import TestCase
56

67
from lexicon.tests.providers.integration_tests import IntegrationTestsV2
7-
from unittest import TestCase
88

99

1010
# Hook into testing framework by inheriting unittest.TestCase and reuse
1111
# the tests which *each and every* implementation of the interface must
1212
# pass, by inheritance from integration_tests.IntegrationTests
1313
class WedosProviderTests(TestCase, IntegrationTestsV2):
1414
"""Integration tests for wedos provider"""
15-
provider_name = 'wedos'
16-
domain = 'kaniok.com'
15+
16+
provider_name = "wedos"
17+
domain = "kaniok.com"
1718

1819
def _filter_request(self, request):
19-
request_start_string = 'request='
20+
request_start_string = "request="
2021
try:
21-
body = urllib.parse.unquote_plus(urllib.parse.unquote(request.body.decode()))
22-
body = re.sub(r'request=', '', body)
22+
body = urllib.parse.unquote_plus(
23+
urllib.parse.unquote(request.body.decode())
24+
)
25+
body = re.sub(r"request=", "", body)
2326
data = json.loads(body)
2427
except ValueError:
2528
pass
2629
else:
27-
data['request']['user'] = 'username'
28-
data['request']['auth'] = 'password'
30+
data["request"]["user"] = "username"
31+
data["request"]["auth"] = "password"
2932
body = request_start_string + json.dumps(data)
3033
body = urllib.parse.quote(urllib.parse.quote_plus(body.encode()))
3134
request.body = body

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "dns-lexicon"
7-
version = "3.12.0"
7+
version = "3.13.0"
88
description = "Manipulate DNS records on various DNS providers in a standardized/agnostic way"
99
license = "MIT"
1010
keywords = [

0 commit comments

Comments
 (0)