Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kasserver: Respect flood delay #11

Merged
merged 1 commit into from
Jul 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions kasserver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,13 @@
class KasServer:
"""Manage domains hosted on All-Inkl.com through the KAS server API"""

FLOOD_TIMEOUT = 1

def __init__(self):
wsdl_file = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "KasApi.wsdl"
)
self._client = zeep.Client(wsdl_file)
self._get_credentials()
self._flood_timeout = 0

def _get_credentials(self):
self._username = os.environ.get("KASSERVER_USER", None)
Expand Down Expand Up @@ -76,15 +75,14 @@ def _request(self, request, params):
}

def _send_request(request):
time.sleep(self._flood_timeout)
try:
result = self._client.service.KasApi(json.dumps(request))
time.sleep(KasServer.FLOOD_TIMEOUT)
self._flood_timeout = result[1]["value"]["item"][0]["value"]
return result
except zeep.exceptions.Fault as exc:
if exc.message == "flood_protection":
timeout = (
math.ceil(float(exc.detail.text)) + KasServer.FLOOD_TIMEOUT
)
timeout = math.ceil(float(exc.detail.text))
LOGGER.warning("Hit flood protection, retrying in %ds", timeout)
time.sleep(timeout)
return _send_request(request)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_kasserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class TestKasServer:
"key": "Response",
"value": {
"item": [
{},
{"key": "KasFloodDelay", "value": 0},
{},
{
"key": "ReturnInfo",
Expand Down