mirror of
https://github.com/certbot/certbot.git
synced 2026-06-07 15:52:08 -04:00
Changes to satisfy pylint
This commit is contained in:
parent
db93b7b3c6
commit
5a85e1e46e
7 changed files with 25 additions and 25 deletions
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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:")]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Reference in a new issue