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