From b6cf3a6839e3480131d2c78d1a672e6839722ade Mon Sep 17 00:00:00 2001 From: siddharth Date: Wed, 5 May 2021 20:18:22 -0400 Subject: acmens.py: move `_cmd` out of `sign_csr` and `revoke_crt` --- acmens.py | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'acmens.py') diff --git a/acmens.py b/acmens.py index 0529c7d..cf7424a 100644 --- a/acmens.py +++ b/acmens.py @@ -25,6 +25,17 @@ def _b64(b): return base64.urlsafe_b64encode(b).decode().replace("=", "") +def _cmd(cmd_list, stdin=None, cmd_input=None, err_msg="Command Line Error"): + "Runs external commands" + proc = subprocess.Popen( + cmd_list, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + out, err = proc.communicate(cmd_input) + if proc.returncode != 0: + raise IOError("{0}\n{1}".format(err_msg, err)) + return out + + 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. @@ -43,16 +54,6 @@ def sign_csr(ca_url, account_key, csr, email=None, challenge_type="http"): """ DIRECTORY = json.loads(urlopen(ca_url + "/directory").read().decode("utf8")) - # helper function - run external commands - def _cmd(cmd_list, stdin=None, cmd_input=None, err_msg="Command Line Error"): - proc = subprocess.Popen( - cmd_list, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - out, err = proc.communicate(cmd_input) - if proc.returncode != 0: - raise IOError("{0}\n{1}".format(err_msg, err)) - return out - # helper function - make request and automatically parse json response def _do_request(url, data=None, err_msg="Error", depth=0): try: @@ -349,16 +350,6 @@ def revoke_crt(ca_url, account_key, crt): "Shortcut function to go from jwt base64 string to bytes" return base64.urlsafe_b64decode(str(a + ("=" * (len(a) % 4)))) - # helper function - run external commands - def _cmd(cmd_list, stdin=None, cmd_input=None, err_msg="Command Line Error"): - proc = subprocess.Popen( - cmd_list, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - out, err = proc.communicate(cmd_input) - if proc.returncode != 0: - raise IOError("{0}\n{1}".format(err_msg, err)) - return out - # helper function - make request and automatically parse json response def _do_request(url, data=None, err_msg="Error", depth=0): try: -- cgit v1.2.3