authority.v2: optimize code paths (raw_result, nonce)

raw_result does not need an extra return, dicarding the nonce at that
point would discard the newer nonce from the response and also the first
nonce is gotten implicitly with the first request acme anyway
This commit is contained in:
Kishi85 2019-03-27 12:49:41 +01:00
parent 44aeda6915
commit 7da3c266a7
1 changed files with 2 additions and 8 deletions

View File

@ -42,7 +42,7 @@ class ACMEAuthority(AbstractACMEAuthority):
"newOrder": "{}/acme/new-order".format(self.ca),
}
print("API directory retrieval failed ({}). Guessed necessary values: {}".format(code, self.directory))
self._request_endpoint('newNonce') # cache the first nonce
self.nonce = None
# @todo: Add support for key-types other than RSA
numbers = key.public_key().public_numbers()
@ -69,11 +69,8 @@ class ACMEAuthority(AbstractACMEAuthority):
if 'Replay-Nonce' in resp.headers:
self.nonce = resp.headers['Replay-Nonce']
if raw_result:
return resp.getcode(), resp.read(), resp.headers
body = resp.read()
if len(body) > 0:
if not raw_result and len(body) > 0:
try:
body = json.loads(body.decode('utf-8'))
except json.JSONDecodeError as e:
@ -110,9 +107,6 @@ class ACMEAuthority(AbstractACMEAuthority):
return self._request_url(url, data, raw_result)
except IOError as e:
return getattr(e, "code", None), getattr(e, "read", e.__str__)(), {}
finally:
# Dispose of nonce after it was used
self.nonce = None
# @brief send a request to authority
def _request_endpoint(self, request, data=None, raw_result=False):