Exception -> LetsEncryptClientError, doc fixes

This commit is contained in:
Jakub Warmuz
2014-11-29 13:00:28 +01:00
parent 73137b404a
commit 73eb8f8546
3 changed files with 37 additions and 23 deletions
+3 -2
View File
@@ -37,8 +37,9 @@ def acme_object_validate(json_string, schemata=None):
:type schemata: dict
:returns: None if validation was successful.
:raises: jsonschema.ValidationError if validation was unsuccessful
ValueError if the object cannot even be parsed as valid JSON
:raises jsonschema.ValidationError: if validation was unsuccessful
:raises ValueError: if the object cannot even be parsed as valid JSON
"""
schemata = SCHEMATA if schemata is None else schemata
+24 -16
View File
@@ -57,10 +57,10 @@ class Client(object):
# TODO: Figure out all exceptions from this function
try:
self._validate_csr_key_cli()
except Exception as e:
except errors.LetsEncryptClientError as e:
# TODO: Something nice here...
logger.fatal(("%s - until the programmers get their act together, "
"we are just going to exit" % str(e)))
logger.fatal("%s - until the programmers get their act together, "
"we are just going to exit" % e)
sys.exit(1)
self.server_url = "https://%s/acme/" % self.server
@@ -103,8 +103,8 @@ class Client(object):
# TODO: Handle this exception/problem
if not crypto_util.csr_matches_names(self.csr_file, self.names):
raise Exception(("CSR subject does not contain one of the "
"specified names"))
raise errrors.LetsEncryptClientError(
"CSR subject does not contain one of the specified names")
# Perform Challenges
responses, challenge_objs = self.verify_identity(challenge_msg)
@@ -211,10 +211,10 @@ class Client(object):
:param msg: ACME message (JSON serializable).
:type msg: dict
:raises: TypeError if `msg` is not JSON serializable or
jsonschema.ValidationError if not valid ACME message or
`errors.LetsEncryptClientError` in case of connection error
or if response from server is not a valid ACME message.
:raises TypeError: if `msg` is not JSON serializable
:raises jsonschema.ValidationError: if `msg` is not valid ACME message
:raises LetsEncryptClientError: in case of a connection error
or if a response from server is not a valid ACME message
:returns: Server response message.
:rtype: dict
@@ -281,7 +281,7 @@ class Client(object):
reponse message.
:type rounds: int
:raises: Exception
:raises LetsEncryptClientError: if server sent ACME "error" message
:returns: ACME response message from server.
:rtype: dict
@@ -668,6 +668,8 @@ class Client(object):
Verifies that the client key and csr arguments are valid and
correspond to one another.
:raises LetsEncryptClientError: if validation fails
"""
# TODO: Handle all of these problems appropriately
# The client can eventually do things like prompt the user
@@ -681,15 +683,19 @@ class Client(object):
# If CSR is provided, it must be readable and valid.
try:
if self.csr_file and not crypto_util.valid_csr(self.csr_file):
raise Exception("The provided CSR is not a valid CSR")
raise errors.LetsEncryptClientError(
"The provided CSR is not a valid CSR")
except IOError:
raise Exception("The provided CSR could not be read")
raise errors.LetsEncryptClientError(
"The provided CSR could not be read")
# If key is provided, it must be readable and valid.
try:
if self.key_file and not crypto_util.valid_privkey(self.key_file):
raise Exception("The provided key is not a valid key")
raise LetsEncryptClientError(
"The provided key is not a valid key")
except IOError:
raise Exception("The provided key could not be read")
raise raise LetsEncryptClientError(
"The provided key could not be read")
# If CSR and key are provided, the key must be the same key used
# in the CSR.
@@ -697,9 +703,11 @@ class Client(object):
try:
if not crypto_util.csr_matches_pubkey(
self.csr_file, self.key_file):
raise Exception("The key and CSR do not match")
raise errors.LetsEncryptClientError(
"The key and CSR do not match")
except IOError:
raise Exception("The key or CSR files could not be read")
raise errors.LetsEncryptClientError(
"The key or CSR files could not be read")
def get_all_names(self):
"""Return all valid names in the configuration."""
+10 -5
View File
@@ -4,6 +4,8 @@ import errno
import os
import stat
from letsencrypt.client import errors
def make_or_verify_dir(directory, mode=0o755, uid=0):
"""Make sure directory exists with proper permissions.
@@ -17,7 +19,8 @@ def make_or_verify_dir(directory, mode=0o755, uid=0):
:param uid: Directory owner.
:type uid: int
:raises: Exception -- TODO
:raises LetsEncryptClientError: if a directory already exists,
but has wrong permissions or owner
"""
try:
@@ -25,8 +28,9 @@ def make_or_verify_dir(directory, mode=0o755, uid=0):
except OSError as exception:
if exception.errno == errno.EEXIST:
if not check_permissions(directory, mode, uid):
raise Exception('%s exists and does not contain the proper '
'permissions or owner' % directory)
raise errors.LetsEncryptClientError(
'%s exists and does not contain the proper '
'permissions or owner' % directory)
else:
raise
@@ -80,7 +84,7 @@ def jose_b64encode(data):
:param data: Data to be encoded.
:type data: str or bytearray
:raises: TypeError
:raises TypeError: if input is of incorrect type
:returns: JOSE Base64 string.
:rtype: str
@@ -98,7 +102,8 @@ def jose_b64decode(data):
only ASCII characters are allowed.
:type data: str or unicode
:raises: ValueError, TypeError
:raises TypeError: if input is of incorrect type
:raises ValueError: if unput is unicode with non-ASCII characters
:returns: Decoded data.