Move constants.py to _internal (#7534)

* Don't call core constants from nginx plugin

* Move constants.py to _internal/

* Move ENHANCEMENTS from now-internal constants to public plugins.enhancements

* Update display.enhancements.ask from its 2015 comment
This commit is contained in:
ohemorange
2019-11-11 15:41:40 -08:00
committed by Brad Warren
parent 08c1de34bd
commit 4792e1ee21
30 changed files with 47 additions and 73 deletions
@@ -1612,9 +1612,9 @@ class ApacheConfigurator(common.Installer):
:param str domain: domain to enhance :param str domain: domain to enhance
:param str enhancement: enhancement type defined in :param str enhancement: enhancement type defined in
:const:`~certbot.constants.ENHANCEMENTS` :const:`~certbot.plugins.enhancements.ENHANCEMENTS`
:param options: options for the enhancement :param options: options for the enhancement
See :const:`~certbot.constants.ENHANCEMENTS` See :const:`~certbot.plugins.enhancements.ENHANCEMENTS`
documentation for appropriate parameter. documentation for appropriate parameter.
:raises .errors.PluginError: If Enhancement is not supported, or if :raises .errors.PluginError: If Enhancement is not supported, or if
@@ -4,7 +4,7 @@ import os
import shutil import shutil
import tempfile import tempfile
from certbot import constants from certbot._internal import constants
from certbot_compatibility_test import errors from certbot_compatibility_test import errors
from certbot_compatibility_test import util from certbot_compatibility_test import util
@@ -9,7 +9,7 @@ import tarfile
import josepy as jose import josepy as jose
from certbot.tests import util as test_util from certbot.tests import util as test_util
from certbot import constants from certbot._internal import constants
from certbot_compatibility_test import errors from certbot_compatibility_test import errors
+2 -18
View File
@@ -17,7 +17,6 @@ from acme import challenges
from acme import crypto_util as acme_crypto_util from acme import crypto_util as acme_crypto_util
from acme.magic_typing import List, Dict, Set # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import List, Dict, Set # pylint: disable=unused-import, no-name-in-module
from certbot import constants as core_constants
from certbot import crypto_util from certbot import crypto_util
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
@@ -101,9 +100,6 @@ class NginxConfigurator(common.Installer):
openssl_version = kwargs.pop("openssl_version", None) openssl_version = kwargs.pop("openssl_version", None)
super(NginxConfigurator, self).__init__(*args, **kwargs) super(NginxConfigurator, self).__init__(*args, **kwargs)
# Verify that all directories and files exist with proper permissions
self._verify_setup()
# Files to save # Files to save
self.save_notes = "" self.save_notes = ""
@@ -708,9 +704,9 @@ class NginxConfigurator(common.Installer):
:param str domain: domain to enhance :param str domain: domain to enhance
:param str enhancement: enhancement type defined in :param str enhancement: enhancement type defined in
:const:`~certbot.constants.ENHANCEMENTS` :const:`~certbot.plugins.enhancements.ENHANCEMENTS`
:param options: options for the enhancement :param options: options for the enhancement
See :const:`~certbot.constants.ENHANCEMENTS` See :const:`~certbot.plugins.enhancements.ENHANCEMENTS`
documentation for appropriate parameter. documentation for appropriate parameter.
""" """
@@ -929,18 +925,6 @@ class NginxConfigurator(common.Installer):
except errors.SubprocessError as err: except errors.SubprocessError as err:
raise errors.MisconfigurationError(str(err)) raise errors.MisconfigurationError(str(err))
def _verify_setup(self):
"""Verify the setup to ensure safe operating environment.
Make sure that files/directories are setup with appropriate permissions
Aim for defensive coding... make sure all input files
have permissions of root.
"""
util.make_or_verify_dir(self.config.work_dir, core_constants.CONFIG_DIRS_MODE)
util.make_or_verify_dir(self.config.backup_dir, core_constants.CONFIG_DIRS_MODE)
util.make_or_verify_dir(self.config.config_dir, core_constants.CONFIG_DIRS_MODE)
def _nginx_version(self): def _nginx_version(self):
"""Return results of nginx -V """Return results of nginx -V
+1 -1
View File
@@ -16,7 +16,7 @@ from cryptography.hazmat.primitives import serialization
from acme import fields as acme_fields from acme import fields as acme_fields
from acme import messages from acme import messages
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
from certbot import util from certbot import util
+1 -1
View File
@@ -21,7 +21,7 @@ import certbot
from certbot._internal import account from certbot._internal import account
from certbot._internal import auth_handler from certbot._internal import auth_handler
from certbot import cli from certbot import cli
from certbot import constants from certbot._internal import constants
from certbot import crypto_util from certbot import crypto_util
from certbot._internal import eff from certbot._internal import eff
from certbot._internal import error_handler from certbot._internal import error_handler
@@ -147,18 +147,6 @@ RENEWER_DEFAULTS = dict(
) )
"""Defaults for renewer script.""" """Defaults for renewer script."""
ENHANCEMENTS = ["redirect", "ensure-http-header", "ocsp-stapling"]
"""List of possible :class:`certbot.interfaces.IInstaller`
enhancements.
List of expected options parameters:
- redirect: None
- ensure-http-header: name of header (i.e. Strict-Transport-Security)
- ocsp-stapling: certificate chain file path
"""
ARCHIVE_DIR = "archive" ARCHIVE_DIR = "archive"
"""Archive directory, relative to `IConfig.config_dir`.""" """Archive directory, relative to `IConfig.config_dir`."""
+1 -1
View File
@@ -18,7 +18,7 @@ def ask(enhancement):
"""Display the enhancement to the user. """Display the enhancement to the user.
:param str enhancement: One of the :param str enhancement: One of the
:class:`certbot.CONFIG.ENHANCEMENTS` enhancements :const:`~certbot.plugins.enhancements.ENHANCEMENTS` enhancements
:returns: True if feature is desired, False otherwise :returns: True if feature is desired, False otherwise
:rtype: bool :rtype: bool
+1 -1
View File
@@ -4,7 +4,7 @@ import logging
import requests import requests
import zope.component import zope.component
from certbot import constants from certbot._internal import constants
from certbot import interfaces from certbot import interfaces
+2 -2
View File
@@ -24,7 +24,7 @@ import traceback
from acme import messages from acme import messages
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot import util from certbot import util
from certbot.compat import os from certbot.compat import os
@@ -41,7 +41,7 @@ def pre_arg_parse_setup():
"""Setup logging before command line arguments are parsed. """Setup logging before command line arguments are parsed.
Terminal logging is setup using Terminal logging is setup using
`certbot.constants.QUIET_LOGGING_LEVEL` so Certbot is as quiet as `certbot._internal.constants.QUIET_LOGGING_LEVEL` so Certbot is as quiet as
possible. File logging is setup so that logging messages are possible. File logging is setup so that logging messages are
buffered in memory. If Certbot exits before `post_arg_parse_setup` buffered in memory. If Certbot exits before `post_arg_parse_setup`
is called, these buffered messages are written to a temporary file. is called, these buffered messages are written to a temporary file.
+1 -1
View File
@@ -19,7 +19,7 @@ from certbot._internal import cert_manager
from certbot import cli from certbot import cli
from certbot._internal import client from certbot._internal import client
from certbot import configuration from certbot import configuration
from certbot import constants from certbot._internal import constants
from certbot import crypto_util from certbot import crypto_util
from certbot._internal import eff from certbot._internal import eff
from certbot import errors from certbot import errors
+1 -1
View File
@@ -10,7 +10,7 @@ import zope.interface
import zope.interface.verify import zope.interface.verify
from acme.magic_typing import Dict # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import Dict # pylint: disable=unused-import, no-name-in-module
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
+1 -1
View File
@@ -13,7 +13,7 @@ import six
import certbot import certbot
from certbot import cli from certbot import cli
from certbot import constants from certbot._internal import constants
from certbot import crypto_util from certbot import crypto_util
from certbot._internal import error_handler from certbot._internal import error_handler
from certbot import errors from certbot import errors
+1 -1
View File
@@ -22,7 +22,7 @@ from acme.magic_typing import Any, Dict, Optional
import certbot import certbot
import certbot.plugins.enhancements as enhancements import certbot.plugins.enhancements as enhancements
import certbot._internal.plugins.selection as plugin_selection import certbot._internal.plugins.selection as plugin_selection
from certbot import constants from certbot._internal import constants
from certbot import crypto_util from certbot import crypto_util
from certbot import errors from certbot import errors
from certbot import hooks from certbot import hooks
+3 -3
View File
@@ -4,7 +4,7 @@ import copy
import zope.interface import zope.interface
from six.moves.urllib import parse # pylint: disable=relative-import from six.moves.urllib import parse # pylint: disable=relative-import
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
from certbot import util from certbot import util
@@ -20,7 +20,7 @@ class NamespaceConfig(object):
:class:`certbot.interfaces.IConfig`. However, note that :class:`certbot.interfaces.IConfig`. However, note that
the following attributes are dynamically resolved using the following attributes are dynamically resolved using
:attr:`~certbot.interfaces.IConfig.work_dir` and relative :attr:`~certbot.interfaces.IConfig.work_dir` and relative
paths defined in :py:mod:`certbot.constants`: paths defined in :py:mod:`certbot._internal.constants`:
- `accounts_dir` - `accounts_dir`
- `csr_dir` - `csr_dir`
@@ -30,7 +30,7 @@ class NamespaceConfig(object):
And the following paths are dynamically resolved using And the following paths are dynamically resolved using
:attr:`~certbot.interfaces.IConfig.config_dir` and relative :attr:`~certbot.interfaces.IConfig.config_dir` and relative
paths defined in :py:mod:`certbot.constants`: paths defined in :py:mod:`certbot._internal.constants`:
- `default_archive_dir` - `default_archive_dir`
- `live_dir` - `live_dir`
+1 -1
View File
@@ -5,7 +5,7 @@ import textwrap
import zope.interface import zope.interface
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
from certbot.compat import misc from certbot.compat import misc
+3 -3
View File
@@ -295,10 +295,10 @@ class IInstaller(IPlugin):
:param str domain: domain for which to provide enhancement :param str domain: domain for which to provide enhancement
:param str enhancement: An enhancement as defined in :param str enhancement: An enhancement as defined in
:const:`~certbot.constants.ENHANCEMENTS` :const:`~certbot.plugins.enhancements.ENHANCEMENTS`
:param options: Flexible options parameter for enhancement. :param options: Flexible options parameter for enhancement.
Check documentation of Check documentation of
:const:`~certbot.constants.ENHANCEMENTS` :const:`~certbot.plugins.enhancements.ENHANCEMENTS`
for expected options for each enhancement. for expected options for each enhancement.
:raises .PluginError: If Enhancement is not supported, or if :raises .PluginError: If Enhancement is not supported, or if
@@ -310,7 +310,7 @@ class IInstaller(IPlugin):
"""Returns a `collections.Iterable` of supported enhancements. """Returns a `collections.Iterable` of supported enhancements.
:returns: supported enhancements which should be a subset of :returns: supported enhancements which should be a subset of
:const:`~certbot.constants.ENHANCEMENTS` :const:`~certbot.plugins.enhancements.ENHANCEMENTS`
:rtype: :class:`collections.Iterable` of :class:`str` :rtype: :class:`collections.Iterable` of :class:`str`
""" """
+1 -1
View File
@@ -14,7 +14,7 @@ from josepy import util as jose_util
from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import List # pylint: disable=unused-import, no-name-in-module
from certbot import achallenges # pylint: disable=unused-import from certbot import achallenges # pylint: disable=unused-import
from certbot import constants from certbot._internal import constants
from certbot import crypto_util from certbot import crypto_util
from certbot import errors from certbot import errors
from certbot import interfaces from certbot import interfaces
+2 -2
View File
@@ -167,11 +167,11 @@ class InstallerTest(test_util.ConfigTestCase):
self.assertTrue(os.path.isfile(self.installer.ssl_dhparams)) self.assertTrue(os.path.isfile(self.installer.ssl_dhparams))
def _current_ssl_dhparams_hash(self): def _current_ssl_dhparams_hash(self):
from certbot.constants import SSL_DHPARAMS_SRC from certbot._internal.constants import SSL_DHPARAMS_SRC
return crypto_util.sha256sum(SSL_DHPARAMS_SRC) return crypto_util.sha256sum(SSL_DHPARAMS_SRC)
def test_current_file_hash_in_all_hashes(self): def test_current_file_hash_in_all_hashes(self):
from certbot.constants import ALL_SSL_DHPARAMS_HASHES from certbot._internal.constants import ALL_SSL_DHPARAMS_HASHES
self.assertTrue(self._current_ssl_dhparams_hash() in ALL_SSL_DHPARAMS_HASHES, self.assertTrue(self._current_ssl_dhparams_hash() in ALL_SSL_DHPARAMS_HASHES,
"Constants.ALL_SSL_DHPARAMS_HASHES must be appended" "Constants.ALL_SSL_DHPARAMS_HASHES must be appended"
" with the sha256 hash of self.config.ssl_dhparams when it is updated.") " with the sha256 hash of self.config.ssl_dhparams when it is updated.")
+12 -1
View File
@@ -2,10 +2,21 @@
import abc import abc
import six import six
from certbot import constants from certbot._internal import constants
from acme.magic_typing import Dict, List, Any # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import Dict, List, Any # pylint: disable=unused-import, no-name-in-module
ENHANCEMENTS = ["redirect", "ensure-http-header", "ocsp-stapling"]
"""List of possible :class:`certbot.interfaces.IInstaller`
enhancements.
List of expected options parameters:
- redirect: None
- ensure-http-header: name of header (i.e. Strict-Transport-Security)
- ocsp-stapling: certificate chain file path
"""
def enabled_enhancements(config): def enabled_enhancements(config):
""" """
Generator to yield the enabled new style enhancements. Generator to yield the enabled new style enhancements.
+1 -1
View File
@@ -9,7 +9,7 @@ import traceback
import six import six
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot import util from certbot import util
from certbot.compat import os from certbot.compat import os
+1 -1
View File
@@ -278,7 +278,7 @@ class AccountFileStorageTest(test_util.ConfigTestCase):
self._set_server('https://acme-staging.api.letsencrypt.org/directory') self._set_server('https://acme-staging.api.letsencrypt.org/directory')
self.storage.save(self.acc, self.mock_client) self.storage.save(self.acc, self.mock_client)
# ensure v2 isn't already linked to it # ensure v2 isn't already linked to it
with mock.patch('certbot.constants.LE_REUSE_SERVERS', {}): with mock.patch('certbot._internal.constants.LE_REUSE_SERVERS', {}):
self._set_server('https://acme-staging-v02.api.letsencrypt.org/directory') self._set_server('https://acme-staging-v02.api.letsencrypt.org/directory')
self.assertRaises(errors.AccountNotFound, self.storage.load, self.acc.id) self.assertRaises(errors.AccountNotFound, self.storage.load, self.acc.id)
+1 -1
View File
@@ -12,7 +12,7 @@ from acme import challenges
import certbot.tests.util as test_util import certbot.tests.util as test_util
from certbot import cli from certbot import cli
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot.compat import os from certbot.compat import os
from certbot.compat import filesystem from certbot.compat import filesystem
+1 -1
View File
@@ -3,7 +3,7 @@ import unittest
import mock import mock
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot.compat import misc from certbot.compat import misc
from certbot.compat import os from certbot.compat import os
+1 -1
View File
@@ -4,7 +4,7 @@ import unittest
import mock import mock
import requests import requests
from certbot import constants from certbot._internal import constants
import certbot.tests.util as test_util import certbot.tests.util as test_util
+1 -1
View File
@@ -11,7 +11,7 @@ import six
from acme import messages from acme import messages
from acme.magic_typing import Optional # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import Optional # pylint: disable=unused-import, no-name-in-module
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot import util from certbot import util
from certbot.compat import filesystem from certbot.compat import filesystem
+1 -1
View File
@@ -24,7 +24,7 @@ import certbot.tests.util as test_util
from certbot._internal import account from certbot._internal import account
from certbot import cli from certbot import cli
from certbot import configuration from certbot import configuration
from certbot import constants from certbot._internal import constants
from certbot import crypto_util from certbot import crypto_util
from certbot import errors from certbot import errors
from certbot import interfaces # pylint: disable=unused-import from certbot import interfaces # pylint: disable=unused-import
+1 -1
View File
@@ -20,7 +20,7 @@ from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives import serialization
from certbot import configuration from certbot import configuration
from certbot import constants from certbot._internal import constants
from certbot import interfaces from certbot import interfaces
from certbot._internal import lock from certbot._internal import lock
from certbot._internal import storage from certbot._internal import storage
+1 -1
View File
@@ -19,7 +19,7 @@ import six
from acme.magic_typing import Tuple, Union # pylint: disable=unused-import, no-name-in-module from acme.magic_typing import Tuple, Union # pylint: disable=unused-import, no-name-in-module
from certbot import constants from certbot._internal import constants
from certbot import errors from certbot import errors
from certbot._internal import lock from certbot._internal import lock
from certbot.compat import os from certbot.compat import os
-9
View File
@@ -1,9 +0,0 @@
:mod:`certbot.constants`
-----------------------------------
.. automodule:: certbot.constants
:members:
:exclude-members: SSL_DHPARAMS_SRC
.. autodata:: SSL_DHPARAMS_SRC
:annotation: = '/path/to/certbot/ssl-dhparams.pem'