From 5a85e1e46ebcd67bb8b4ab8050d0c59d93720e9b Mon Sep 17 00:00:00 2001 From: Seth Schoen Date: Mon, 11 May 2015 15:02:02 -0700 Subject: [PATCH] Changes to satisfy pylint --- letsencrypt/client/cli.py | 3 ++- letsencrypt/client/client.py | 5 +++++ letsencrypt/client/crypto_util.py | 2 +- letsencrypt/client/le_util.py | 12 ++++++------ letsencrypt/client/renewer.py | 11 ++--------- letsencrypt/client/storage.py | 5 ++++- letsencrypt/client/tests/renewer_test.py | 12 +++++------- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/letsencrypt/client/cli.py b/letsencrypt/client/cli.py index 904cdce68..02dbc3692 100644 --- a/letsencrypt/client/cli.py +++ b/letsencrypt/client/cli.py @@ -140,7 +140,8 @@ def install(args, config, plugins): acme, doms = _common_run( args, config, acc, authenticator=None, installer=installer) assert args.cert_path is not None - acme.deploy_certificate(doms, acc.key, args.cert_path, args.chain_path) + # XXX: This API has changed as a result of RenewableCert! + # acme.deploy_certificate(doms, acc.key, args.cert_path, args.chain_path) acme.enhance_config(doms, args.redirect) diff --git a/letsencrypt/client/client.py b/letsencrypt/client/client.py index 239b3fcff..48573f922 100644 --- a/letsencrypt/client/client.py +++ b/letsencrypt/client/client.py @@ -155,6 +155,9 @@ class Client(object): def obtain_and_enroll_certificate(self, domains, authenticator, installer, csr=None): + """Get a new certificate for the specified domains using the specified + authenticator and installer, and then create a new renewable lineage + containing it.""" cert_pem, privkey, chain_pem = self._obtain_certificate(domains, csr) # TODO: Add IPlugin.name or use PluginsFactory.find_init instead # of assuming that each plugin has a .name attribute @@ -165,6 +168,8 @@ class Client(object): vars(self.config.namespace)) def obtain_certificate(self, domains): + """Public method to obtain a certificate for the specified domains + using this client object. Returns the tuple (cert, privkey, chain).""" return self._obtain_certificate(domains, None) def save_certificate(self, certr, cert_path, chain_path): diff --git a/letsencrypt/client/crypto_util.py b/letsencrypt/client/crypto_util.py index c813f3bd1..7722bba44 100644 --- a/letsencrypt/client/crypto_util.py +++ b/letsencrypt/client/crypto_util.py @@ -238,7 +238,7 @@ def get_sans_from_cert(pem): """ x509 = M2Crypto.X509.load_cert_string(pem) try: - ext=x509.get_ext("subjectAltName") + ext = x509.get_ext("subjectAltName") except LookupError: return [] return [x[4:] for x in ext.get_value().split(", ") if x.startswith("DNS:")] diff --git a/letsencrypt/client/le_util.py b/letsencrypt/client/le_util.py index d948226b9..001bd9077 100644 --- a/letsencrypt/client/le_util.py +++ b/letsencrypt/client/le_util.py @@ -90,18 +90,18 @@ def unique_lineage_name(path, filename, mode=0o777): try: file_d = os.open(fname, os.O_CREAT | os.O_EXCL | os.O_RDWR, mode) return os.fdopen(file_d, "w"), fname - except OSError as e: - if e.errno != 17: # file exists - raise e + except OSError as err: + if err.errno != 17: # file exists + raise err count = 1 while True: fname = os.path.join(path, "%s-%04d.conf" % (filename, count)) try: file_d = os.open(fname, os.O_CREAT | os.O_EXCL | os.O_RDWR, mode) return os.fdopen(file_d, "w"), fname - except OSError as e: - if e.errno != 17: # file exists - raise e + except OSError as err: + if err.errno != 17: # file exists + raise err count += 1 diff --git a/letsencrypt/client/renewer.py b/letsencrypt/client/renewer.py index 619be206f..1fa88ae69 100644 --- a/letsencrypt/client/renewer.py +++ b/letsencrypt/client/renewer.py @@ -15,20 +15,11 @@ configuration.""" # memorialize the fact that it happened import configobj -import copy -import datetime import os -import OpenSSL -import pkg_resources -import pyrfc3339 -import pytz -import re -import time from letsencrypt.client import configuration from letsencrypt.client import client from letsencrypt.client import crypto_util -from letsencrypt.client import le_util from letsencrypt.client import notify from letsencrypt.client import storage from letsencrypt.client.plugins import disco as plugins_disco @@ -39,6 +30,8 @@ DEFAULTS["official_archive_dir"] = "/tmp/etc/letsencrypt/archive" DEFAULTS["live_dir"] = "/tmp/etc/letsencrypt/live" class AttrDict(dict): + """A trick to allow accessing dictionary keys as object + attributes.""" def __init__(self, *args, **kwargs): super(AttrDict, self).__init__(*args, **kwargs) self.__dict__ = self diff --git a/letsencrypt/client/storage.py b/letsencrypt/client/storage.py index 6f1f96199..3f2fea90b 100644 --- a/letsencrypt/client/storage.py +++ b/letsencrypt/client/storage.py @@ -1,3 +1,6 @@ +"""The RenewableCert class, representing renewable lineages of +certificates and storing the associated cert data and metadata.""" + import configobj import copy import datetime @@ -313,7 +316,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes @classmethod def new_lineage(cls, lineagename, cert, privkey, chain, renewalparams=None, config=DEFAULTS): - # pylint: disable=too-many-locals + # pylint: disable=too-many-locals,too-many-arguments """Create a new certificate lineage with the (suggested) lineage name lineagename, and the associated cert, privkey, and chain (the associated fullchain will be created automatically). Optional diff --git a/letsencrypt/client/tests/renewer_test.py b/letsencrypt/client/tests/renewer_test.py index 1df1bec5c..c0485d5f0 100644 --- a/letsencrypt/client/tests/renewer_test.py +++ b/letsencrypt/client/tests/renewer_test.py @@ -551,7 +551,6 @@ class RenewableCertTests(unittest.TestCase): def test_new_lineage(self): """Test for new_lineage() class method.""" - from letsencrypt.client import renewer from letsencrypt.client import storage config_dir = self.defaults["renewal_configs_dir"] archive_dir = self.defaults["official_archive_dir"] @@ -591,7 +590,6 @@ class RenewableCertTests(unittest.TestCase): def test_new_lineage_nonexistent_dirs(self): """Test that directories can be created if they don't exist.""" - from letsencrypt.client import renewer from letsencrypt.client import storage config_dir = self.defaults["renewal_configs_dir"] archive_dir = self.defaults["official_archive_dir"] @@ -599,9 +597,9 @@ class RenewableCertTests(unittest.TestCase): shutil.rmtree(config_dir) shutil.rmtree(archive_dir) shutil.rmtree(live_dir) - result = storage.RenewableCert.new_lineage("the-lineage.com", "cert2", - "privkey2", "chain2", - None, self.defaults) + storage.RenewableCert.new_lineage("the-lineage.com", "cert2", + "privkey2", "chain2", + None, self.defaults) self.assertTrue(os.path.exists( os.path.join(config_dir, "the-lineage.com.conf"))) self.assertTrue(os.path.exists( @@ -609,9 +607,8 @@ class RenewableCertTests(unittest.TestCase): self.assertTrue(os.path.exists( os.path.join(archive_dir, "the-lineage.com", "privkey1.pem"))) - @mock.patch("letsencrypt.client.renewer.le_util.unique_lineage_name") + @mock.patch("letsencrypt.client.storage.le_util.unique_lineage_name") def test_invalid_config_filename(self, mock_uln): - from letsencrypt.client import renewer from letsencrypt.client import storage mock_uln.return_value = "this_does_not_end_with_dot_conf", "yikes" self.assertRaises(ValueError, storage.RenewableCert.new_lineage, @@ -705,6 +702,7 @@ class RenewableCertTests(unittest.TestCase): self.assertEqual(2, renewer.renew(self.test_rc, 1)) # TODO: We could also make several assertions about calls that should # have been made to the mock functions here. + self.assertEqual(mock_da.call_count, 1) mock_client.obtain_certificate.return_value = (None, None, None) # This should fail because the renewal itself appears to fail self.assertEqual(False, renewer.renew(self.test_rc, 1))