mirror of
https://github.com/certbot/certbot.git
synced 2026-07-28 16:15:42 +02:00
Move webroot processing to webroot.py
This commit is contained in:
@@ -38,9 +38,21 @@ to serve all files under specified web root ({0})."""
|
||||
|
||||
@classmethod
|
||||
def add_parser_arguments(cls, add):
|
||||
# --webroot-path and --webroot-map are added in cli.py because they
|
||||
# are parsed in conjunction with --domains
|
||||
pass
|
||||
add("path", "-w", default=[], action=_WebrootPathAction,
|
||||
help="public_html / webroot path. This can be specified multiple "
|
||||
"times to handle different domains; each domain will have "
|
||||
"the webroot path that preceded it. For instance: `-w "
|
||||
"/var/www/example -d example.com -d www.example.com -w "
|
||||
"/var/www/thing -d thing.net -d m.thing.net`")
|
||||
add("map", default={}, action=_WebrootMapAction,
|
||||
help="JSON dictionary mapping domains to webroot paths; this "
|
||||
"implies -d for each entry. You may need to escape this from "
|
||||
"your shell. E.g.: --webroot-map "
|
||||
'\'{"eg1.is,m.eg1.is":"/www/eg1/", "eg2.is":"/www/eg2"}\' '
|
||||
"This option is merged with, but takes precedence over, -w / "
|
||||
"-d entries. At present, if you put webroot-map in a config "
|
||||
"file, it needs to be on a single line, like: webroot-map = "
|
||||
'{"example.com":"/var/www"}.')
|
||||
|
||||
def get_chall_pref(self, domain): # pragma: no cover
|
||||
# pylint: disable=missing-docstring,no-self-use,unused-argument
|
||||
@@ -52,8 +64,10 @@ to serve all files under specified web root ({0})."""
|
||||
self.performed = defaultdict(set)
|
||||
|
||||
def prepare(self): # pylint: disable=missing-docstring
|
||||
path_map = self.conf("map")
|
||||
if self.conf("path"):
|
||||
_match_webroot_with_domains(self.config)
|
||||
|
||||
path_map = self.conf("map")
|
||||
if not path_map:
|
||||
raise errors.PluginError(
|
||||
"Missing parts of webroot configuration; please set either "
|
||||
@@ -173,6 +187,7 @@ class _WebrootMapAction(argparse.Action):
|
||||
|
||||
class _WebrootPathAction(argparse.Action):
|
||||
"""Action class for parsing webroot_path."""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(_WebrootPathAction, self).__init__(*args, **kwargs)
|
||||
self._domain_before_webroot = False
|
||||
@@ -218,4 +233,4 @@ def _match_webroot_with_domains(args_or_config):
|
||||
"""
|
||||
webroot_path = args_or_config.webroot_path[-1]
|
||||
for domain in args_or_config.domains:
|
||||
args_or_config.webroot_map.set_default(domain, webroot_path)
|
||||
args_or_config.webroot_map.setdefault(domain, webroot_path)
|
||||
|
||||
@@ -53,7 +53,7 @@ class AuthenticatorTest(unittest.TestCase):
|
||||
def test_add_parser_arguments(self):
|
||||
add = mock.MagicMock()
|
||||
self.auth.add_parser_arguments(add)
|
||||
self.assertEqual(0, add.call_count) # args moved to cli.py!
|
||||
self.assertEqual(2, add.call_count)
|
||||
|
||||
def test_prepare_missing_root(self):
|
||||
self.config.webroot_path = None
|
||||
|
||||
Reference in New Issue
Block a user