From 3676a6d87ab0930c67bfd212c77d01c2b96ff1e3 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Tue, 24 Mar 2015 19:05:09 +0000 Subject: [PATCH] network2: Update poll() --- examples/restified.py | 2 ++ letsencrypt/client/network2.py | 31 +++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/examples/restified.py b/examples/restified.py index 99d07a067..b68b3b047 100644 --- a/examples/restified.py +++ b/examples/restified.py @@ -32,6 +32,8 @@ authzr = net.request_challenges( regr=regr) logging.debug(authzr) +authzr = net.poll(authzr) + csr = M2Crypto.X509.load_request_string(pkg_resources.resource_string( 'letsencrypt.client.tests', os.path.join('testdata', 'csr.pem'))) try: diff --git a/letsencrypt/client/network2.py b/letsencrypt/client/network2.py index 3c68a17c7..34419c209 100644 --- a/letsencrypt/client/network2.py +++ b/letsencrypt/client/network2.py @@ -108,6 +108,23 @@ class Network(object): #raise errors.UnexpectedUpdate(regr) return updated_regr + def _authzr_from_response(self, response, identifier, + uri=None, new_cert_uri=None): + if new_cert_uri is None: + try: + new_cert_uri = response.links['next']['url'] + except KeyError: + raise errors.NetworkError('"next" link missing') + + authzr = messages2.AuthorizationResource( + body=messages2.Authorization.from_json(response.json()), + uri=response.headers.get('location', uri), + new_cert_uri=new_cert_uri) + if (authzr.body.key != self.key.public() + or authzr.body.identifier != identifier): + raise errors.UnexpectedUpdate(authzr) + return authzr + def request_challenges(self, identifier, regr): """Request challenges. @@ -121,14 +138,7 @@ class Network(object): new_authz = messages2.Authorization(identifier=identifier) response = self._post(regr.new_authz_uri, self._wrap_in_jws(new_authz)) assert response.status_code == httplib.CREATED # TODO: handle errors - authzr = messages2.AuthorizationResource( - body=messages2.Authorization.from_json(response.json()), - uri=response.headers['location'], - new_cert_uri=response.links['next']['url']) - if (authzr.body.key != self.key.public() - or authzr.body.identifier != identifier): - raise errors.UnexpectedUpdate(authzr) - return authzr + return self._authzr_from_response(response, identifier) # TODO: anything below is also stub, bot not working, not tested at all @@ -178,6 +188,11 @@ class Network(object): :rtype: (`.AuthorizationResource`, `int`) """ + response = requests.get(authzr.uri) + updated_authzr = self._authzr_from_response( + response, authzr.body.identifier, authzr.uri, authzr.new_cert_uri) + # TODO check UnexpectedUpdate + return updated_authzr def request_issuance(self, csr, authzrs): """Request issuance.