Cleaner connection error handling
This commit is contained in:
parent
3e1706ecbd
commit
2bbf64c6d7
@ -161,9 +161,9 @@ def certidude_enroll(fork, no_wait, kerberos):
|
|||||||
headers={"Accept": "application/x-x509-ca-cert,application/x-pem-file"})
|
headers={"Accept": "application/x-x509-ca-cert,application/x-pem-file"})
|
||||||
header, _, certificate_der_bytes = pem.unarmor(r.content)
|
header, _, certificate_der_bytes = pem.unarmor(r.content)
|
||||||
authority_certificate = x509.Certificate.load(certificate_der_bytes)
|
authority_certificate = x509.Certificate.load(certificate_der_bytes)
|
||||||
except: # TODO: catch correct exceptions
|
except requests.exceptions.ConnectionError:
|
||||||
raise
|
click.echo("Connection error while attempting to fetch %s" % authority_url)
|
||||||
# raise ValueError("Failed to parse PEM: %s" % r.text)
|
continue
|
||||||
authority_partial = authority_path + ".part"
|
authority_partial = authority_path + ".part"
|
||||||
with open(authority_partial, "wb") as oh:
|
with open(authority_partial, "wb") as oh:
|
||||||
oh.write(r.content)
|
oh.write(r.content)
|
||||||
@ -186,7 +186,12 @@ def certidude_enroll(fork, no_wait, kerberos):
|
|||||||
else:
|
else:
|
||||||
bootstrap_url = "http://%s/api/bootstrap/" % authority_name
|
bootstrap_url = "http://%s/api/bootstrap/" % authority_name
|
||||||
click.echo("Attempting to bootstrap connection from %s" % bootstrap_url)
|
click.echo("Attempting to bootstrap connection from %s" % bootstrap_url)
|
||||||
|
try:
|
||||||
r = requests.get(bootstrap_url)
|
r = requests.get(bootstrap_url)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
click.echo("Connection error while attempting to fetch %s" % bootstrap_url)
|
||||||
|
continue
|
||||||
|
else:
|
||||||
if r.status_code != 200:
|
if r.status_code != 200:
|
||||||
raise ValueError("Bootstrap API endpoint returned %s" % r.content)
|
raise ValueError("Bootstrap API endpoint returned %s" % r.content)
|
||||||
bootstrap = r.json()
|
bootstrap = r.json()
|
||||||
@ -314,7 +319,12 @@ def certidude_enroll(fork, no_wait, kerberos):
|
|||||||
request_url = "https://%s:8443/api/request/" % authority_name
|
request_url = "https://%s:8443/api/request/" % authority_name
|
||||||
if request_params:
|
if request_params:
|
||||||
request_url = request_url + "?" + "&".join(request_params)
|
request_url = request_url + "?" + "&".join(request_params)
|
||||||
|
|
||||||
|
try:
|
||||||
submission = requests.post(request_url, **kwargs)
|
submission = requests.post(request_url, **kwargs)
|
||||||
|
except requests.exceptions.ConnectionError:
|
||||||
|
click.echo("Connection error while attempting to submit request to %s" % request_url)
|
||||||
|
continue
|
||||||
|
|
||||||
# Destroy service ticket
|
# Destroy service ticket
|
||||||
if os.path.exists("/tmp/ca.ticket"):
|
if os.path.exists("/tmp/ca.ticket"):
|
||||||
|
Loading…
Reference in New Issue
Block a user