From 2178315f8a94bebbfd8ef01f07e9b7aec1fe1391 Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Thu, 28 May 2015 15:17:55 +0000 Subject: [PATCH 1/2] Various docstring fixes. - Use r""" \* """ - transform plugins note to ..warning - ' -> ` for cross-reference - fix some "more than one target found for cross-reference" warnings --- docs/plugins.rst | 16 ++++++++-------- letsencrypt/auth_handler.py | 10 +++++----- letsencrypt/interfaces.py | 2 +- letsencrypt_nginx/obj.py | 23 +++++++++++++---------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/docs/plugins.rst b/docs/plugins.rst index c4df1180a..33d63e84f 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -4,16 +4,16 @@ Plugins Let's Encrypt client supports dynamic discovery of plugins through the `setuptools entry points`_. This way you can, for example, create a -custom implementation of -`~letsencrypt.interfaces.IAuthenticator` or the -'~letsencrypt.interfaces.IInstaller' without having to -merge it with the core upstream source code. An example is provided in +custom implementation of `~letsencrypt.interfaces.IAuthenticator` or +the `~letsencrypt.interfaces.IInstaller` without having to merge it +with the core upstream source code. An example is provided in ``examples/plugins/`` directory. -Please be aware though that as this client is still in a developer-preview -stage, the API may undergo a few changes. If you believe the plugin will be -beneficial to the community, please consider submitting a pull request to the -repo and we will update it with any necessary API changes. +.. warning:: Please be aware though that as this client is still in a + developer-preview stage, the API may undergo a few changes. If you + believe the plugin will be beneficial to the community, please + consider submitting a pull request to the repo and we will update + it with any necessary API changes. .. _`setuptools entry points`: https://pythonhosted.org/setuptools/setuptools.html#dynamic-discovery-of-services-and-plugins diff --git a/letsencrypt/auth_handler.py b/letsencrypt/auth_handler.py index e83cdd717..37d818dbe 100644 --- a/letsencrypt/auth_handler.py +++ b/letsencrypt/auth_handler.py @@ -53,12 +53,12 @@ class AuthHandler(object): """Retrieve all authorizations for challenges. :param set domains: Domains for authorization - :param bool best_effort: Whether or not all authorizations are required - (this is useful in renewal) + :param bool best_effort: Whether or not all authorizations are + required (this is useful in renewal) - :returns: tuple of lists of authorization resources. Takes the form of - (`completed`, `failed`) - rtype: tuple + :returns: tuple of lists of authorization resources. Takes the + form of (`completed`, `failed`) + :rtype: tuple :raises AuthorizationError: If unable to retrieve all authorizations diff --git a/letsencrypt/interfaces.py b/letsencrypt/interfaces.py index e154bd5d3..7c61dc554 100644 --- a/letsencrypt/interfaces.py +++ b/letsencrypt/interfaces.py @@ -49,7 +49,7 @@ class IPluginFactory(zope.interface.Interface): """Inject argument parser options (flags). 1. Be nice and prepend all options and destinations with - `~.option_namespace` and `~.dest_namespace`. + `~.common.option_namespace` and `~common.dest_namespace`. 2. Inject options (flags) only. Positional arguments are not allowed, as this would break the CLI. diff --git a/letsencrypt_nginx/obj.py b/letsencrypt_nginx/obj.py index 9b3fa2e42..9e1f78e48 100644 --- a/letsencrypt_nginx/obj.py +++ b/letsencrypt_nginx/obj.py @@ -5,22 +5,25 @@ from letsencrypt_apache.obj import Addr as ApacheAddr class Addr(ApacheAddr): - """Represents an Nginx address, i.e. what comes after the 'listen' + r"""Represents an Nginx address, i.e. what comes after the 'listen' directive. - According to http://nginx.org/en/docs/http/ngx_http_core_module.html#listen, - this may be address[:port], port, or unix:path. The latter is ignored here. + According to the `documentation`_, this may be address[:port], port, + or unix:path. The latter is ignored here. - The default value if no directive is specified is *:80 (superuser) or - *:8000 (otherwise). If no port is specified, the default is 80. If no - address is specified, listen on all addresses. + The default value if no directive is specified is \*:80 (superuser) + or \*:8000 (otherwise). If no port is specified, the default is + 80. If no address is specified, listen on all addresses. - .. todo:: Old-style nginx configs define SSL vhosts in a separate block - instead of using 'ssl' in the listen directive + .. _documentation: + http://nginx.org/en/docs/http/ngx_http_core_module.html#listen + + .. todo:: Old-style nginx configs define SSL vhosts in a separate + block instead of using 'ssl' in the listen directive. :param str addr: addr part of vhost address, may be hostname, IPv4, IPv6, - "", or "*" - :param str port: port number or "*" or "" + "", or "\*" + :param str port: port number or "\*" or "" :param bool ssl: Whether the directive includes 'ssl' :param bool default: Whether the directive includes 'default_server' From a3d452c112a63fc9b9b2eb543037e46017a4c30d Mon Sep 17 00:00:00 2001 From: Jakub Warmuz Date: Thu, 28 May 2015 19:27:30 +0000 Subject: [PATCH 2/2] storage.config_with_defaults --- letsencrypt/constants.py | 5 ++--- letsencrypt/renewer.py | 7 +------ letsencrypt/storage.py | 18 +++++++++--------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/letsencrypt/constants.py b/letsencrypt/constants.py index 4b3b79e36..088f92aea 100644 --- a/letsencrypt/constants.py +++ b/letsencrypt/constants.py @@ -1,5 +1,4 @@ """Let's Encrypt constants.""" -import configobj import logging from acme import challenges @@ -27,7 +26,7 @@ CLI_DEFAULTS = dict( """Defaults for CLI flags and `.IConfig` attributes.""" -RENEWER_DEFAULTS = configobj.ConfigObj(dict( +RENEWER_DEFAULTS = dict( renewer_config_file="/etc/letsencrypt/renewer.conf", renewal_configs_dir="/etc/letsencrypt/configs", archive_dir="/etc/letsencrypt/archive", @@ -35,7 +34,7 @@ RENEWER_DEFAULTS = configobj.ConfigObj(dict( renewer_enabled="yes", renew_before_expiry="30 days", deploy_before_expiry="20 days", -)) +) """Defaults for renewer script.""" diff --git a/letsencrypt/renewer.py b/letsencrypt/renewer.py index 834a69548..d95fb7d95 100644 --- a/letsencrypt/renewer.py +++ b/letsencrypt/renewer.py @@ -7,13 +7,11 @@ within lineages of successor certificates, according to configuration. .. todo:: Call new installer API to restart servers after deployment """ -import copy import os import configobj from letsencrypt import configuration -from letsencrypt import constants from letsencrypt import client from letsencrypt import crypto_util from letsencrypt import notify @@ -102,10 +100,7 @@ def main(config=None): # turned it off. (The boolean parameter should probably be # called renewer_enabled.) - # Merge supplied config, if provided, on top of builtin defaults - defaults_copy = copy.deepcopy(constants.RENEWER_DEFAULTS) - defaults_copy.merge(config if config is not None else configobj.ConfigObj()) - config = defaults_copy + config = storage.config_with_defaults(config) # Now attempt to read the renewer config file and augment or replace # the renewer defaults with any options contained in that file. If # renewer_config_file is undefined or if the file is nonexistent or diff --git a/letsencrypt/storage.py b/letsencrypt/storage.py index 3b2cd58b0..2648be3ba 100644 --- a/letsencrypt/storage.py +++ b/letsencrypt/storage.py @@ -1,5 +1,4 @@ """Renewable certificates storage.""" -import copy import datetime import os import re @@ -17,6 +16,13 @@ from letsencrypt import le_util ALL_FOUR = ("cert", "privkey", "chain", "fullchain") +def config_with_defaults(config=None): + """Merge supplied config, if provided, on top of builtin defaults.""" + defaults_copy = configobj.ConfigObj(constants.RENEWER_DEFAULTS) + defaults_copy.merge(config if config is not None else configobj.ConfigObj()) + return defaults_copy + + def parse_time_interval(interval, textparser=parsedatetime.Calendar()): """Parse the time specified time interval. @@ -103,10 +109,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes # TODO: Do we actually use anything from defaults and do we want to # read further defaults from the systemwide renewal configuration # file at this stage? - defaults_copy = copy.deepcopy(constants.RENEWER_DEFAULTS) - defaults_copy.merge(config_opts if config_opts is not None - else configobj.ConfigObj()) - self.configuration = defaults_copy + self.configuration = config_with_defaults(config_opts) self.configuration.merge(self.configfile) if not all(x in self.configuration for x in ALL_FOUR): @@ -528,10 +531,7 @@ class RenewableCert(object): # pylint: disable=too-many-instance-attributes :returns: the newly-created RenewalCert object :rtype: :class:`storage.renewableCert`""" - defaults_copy = copy.deepcopy(constants.RENEWER_DEFAULTS) - defaults_copy.merge(config if config is not None - else configobj.ConfigObj()) - config = defaults_copy + config = config_with_defaults(config) # This attempts to read the renewer config file and augment or replace # the renewer defaults with any options contained in that file. If # renewer_config_file is undefined or if the file is nonexistent or