Skip to content

Commit

Permalink
Refactor the disguised counting loop in check_authorization_status me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
rozgonik committed Mar 15, 2020
1 parent ee0f259 commit a35a833
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions sewer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,15 +463,13 @@ def check_authorization_status(self, authorization_url, desired_status=None):
"""
self.logger.info("check_authorization_status")
desired_status = desired_status or ["pending", "valid"]
number_of_checks = 0
while True:
for _ in range(self.ACME_AUTH_STATUS_MAX_CHECKS):
time.sleep(self.ACME_AUTH_STATUS_WAIT_PERIOD)
headers = {"User-Agent": self.User_Agent}
check_authorization_status_response = requests.get(
authorization_url, timeout=self.ACME_REQUEST_TIMEOUT, headers=headers
)
authorization_status = check_authorization_status_response.json()["status"]
number_of_checks = number_of_checks + 1
self.logger.debug(
"check_authorization_status_response. status_code={0}. response={1}".format(
check_authorization_status_response.status_code,
Expand All @@ -480,14 +478,13 @@ def check_authorization_status(self, authorization_url, desired_status=None):
)
if authorization_status in desired_status:
break
if number_of_checks == self.ACME_AUTH_STATUS_MAX_CHECKS:
raise StopIteration(
"Checks done={0}. Max checks allowed={1}. Interval between checks={2}seconds.".format(
number_of_checks,
self.ACME_AUTH_STATUS_MAX_CHECKS,
self.ACME_AUTH_STATUS_WAIT_PERIOD,
)
else:
raise StopIteration(
"Checks done={0}. Max checks allowed={0}. Interval between checks={1}seconds.".format(
self.ACME_AUTH_STATUS_MAX_CHECKS,
self.ACME_AUTH_STATUS_WAIT_PERIOD,
)
)

self.logger.info("check_authorization_status_success")
return check_authorization_status_response
Expand Down

0 comments on commit a35a833

Please # to comment.