mirror of
https://github.com/certbot/certbot.git
synced 2026-08-03 00:22:04 +02:00
network2: _get, improve netwrok error handling
This commit is contained in:
@@ -32,17 +32,49 @@ class Network(object):
|
|||||||
return jose.JWS.sign(
|
return jose.JWS.sign(
|
||||||
payload=dumps, key=self.key, alg=self.alg).json_dumps()
|
payload=dumps, key=self.key, alg=self.alg).json_dumps()
|
||||||
|
|
||||||
def _post(self, uri, data):
|
def _get(self, uri, **kwargs):
|
||||||
"""Send POST data.
|
"""Send GET request.
|
||||||
|
|
||||||
:raises letsencrypt.acme.messages2.Error:
|
:raises letsencrypt.client.errors.NetworkError:
|
||||||
|
|
||||||
|
:returns: HTTP Response
|
||||||
|
:rtype: `requests.Response`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
logging.debug('Sending data: %s', data)
|
try:
|
||||||
response = requests.post(uri, data)
|
return requests.get(uri, **kwargs)
|
||||||
|
except requests.exception.RequestException as error:
|
||||||
|
raise errors.NetworkError(error)
|
||||||
|
|
||||||
|
def _post(self, uri, data, content_type='application/json', **kwargs):
|
||||||
|
"""Send POST data.
|
||||||
|
|
||||||
|
:param str content_type: Expected Content-Type, fails if not set.
|
||||||
|
|
||||||
|
:raises letsencrypt.acme.messages2.NetworkError:
|
||||||
|
|
||||||
|
:returns: HTTP Response
|
||||||
|
:rtype: `requests.Response`
|
||||||
|
|
||||||
|
"""
|
||||||
|
logging.debug('Sending POST data: %s', data)
|
||||||
|
try:
|
||||||
|
response = requests.post(uri, data=data, **kwargs)
|
||||||
|
except requests.exception.RequestException as error:
|
||||||
|
raise errors.NetworkError(error)
|
||||||
logging.debug('Received response %s: %s', response, response.text)
|
logging.debug('Received response %s: %s', response, response.text)
|
||||||
|
|
||||||
if not response.ok:
|
if not response.ok:
|
||||||
raise messages2.Error.from_json(response.json())
|
if response.content_type == 'application/json':
|
||||||
|
raise messages2.Error.from_json(response.json())
|
||||||
|
else:
|
||||||
|
raise errors.NetworkError(response)
|
||||||
|
|
||||||
|
# TODO: Boulder messes up Content-Type #56
|
||||||
|
#if response.headers['content-type'] != content_type:
|
||||||
|
# raise errors.NetworkError(
|
||||||
|
# 'Server returned unexpected content-type header')
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def _regr_from_response(self, response, uri=None, new_authz_uri=None):
|
def _regr_from_response(self, response, uri=None, new_authz_uri=None):
|
||||||
@@ -188,7 +220,7 @@ class Network(object):
|
|||||||
:rtype: (`.AuthorizationResource`, `int`)
|
:rtype: (`.AuthorizationResource`, `int`)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
response = requests.get(authzr.uri)
|
response = self._get(authzr.uri)
|
||||||
retry_after = 0 # TODO, get it from response.headers.get('Retry-After')
|
retry_after = 0 # TODO, get it from response.headers.get('Retry-After')
|
||||||
|
|
||||||
updated_authzr = self._authzr_from_response(
|
updated_authzr = self._authzr_from_response(
|
||||||
@@ -247,7 +279,7 @@ class Network(object):
|
|||||||
"""
|
"""
|
||||||
# TODO: acme-spec 5.1 table action should be renamed to
|
# TODO: acme-spec 5.1 table action should be renamed to
|
||||||
# "refresh cert", and this method integrated with self.refresh
|
# "refresh cert", and this method integrated with self.refresh
|
||||||
return requests.get(certr.uri)
|
return self._get(certr.uri)
|
||||||
|
|
||||||
def refresh(self, certr):
|
def refresh(self, certr):
|
||||||
"""Refresh certificate."""
|
"""Refresh certificate."""
|
||||||
|
|||||||
Reference in New Issue
Block a user