From 27dd0d047333b4ac4fb59f6e0ad6bdc2cb44069e Mon Sep 17 00:00:00 2001 From: siddharth Date: Wed, 5 May 2021 23:00:46 -0400 Subject: acmens.py: move `_poll_unitl_not` out of `sign_csr` --- acmens.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/acmens.py b/acmens.py index 3e82729..3e2fd79 100644 --- a/acmens.py +++ b/acmens.py @@ -108,6 +108,18 @@ def _send_signed_request(url, payload, nonce_url, auth, account_key, err_msg, de ) +def _poll_until_not(url, pending_statuses, nonce_url, auth, account_key, err_msg): + """Poll until status is not in pending_statuses""" + result, t0 = None, time.time() + while result is None or result["status"] in pending_statuses: + assert time.time() - t0 < 3600, "Polling timeout" # 1 hour timeout + time.sleep(0 if result is None else 2) + result, _, _ = _send_signed_request( + url, None, nonce_url, auth, account_key, err_msg + ) + return result + + def sign_csr(ca_url, account_key, csr, email=None, challenge_type="http"): """Use the ACME protocol to get an ssl certificate signed by a certificate authority. @@ -125,17 +137,6 @@ def sign_csr(ca_url, account_key, csr, email=None, challenge_type="http"): """ - # helper function - poll until complete - def _poll_until_not(url, pending_statuses, nonce_url, auth, account_key, err_msg): - result, t0 = None, time.time() - while result is None or result["status"] in pending_statuses: - assert time.time() - t0 < 3600, "Polling timeout" # 1 hour timeout - time.sleep(0 if result is None else 2) - result, _, _ = _send_signed_request( - url, None, nonce_url, auth, account_key, err_msg - ) - return result - # helper function - do challenge def _do_challenge(authz_url, nonce_url, auth, account_key, thumbprint): # Request challenges -- cgit v1.2.3