mirror of
https://github.com/certbot/certbot.git
synced 2026-07-30 18:04:31 +02:00
Allow runtime to determine directory structure
This commit is contained in:
@@ -124,14 +124,20 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
|||||||
:ivar dict assoc: Mapping between domains and vhosts
|
:ivar dict assoc: Mapping between domains and vhosts
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, server_root=CONFIG.SERVER_ROOT, save_dir=None, version=None):
|
def __init__(self, server_root=CONFIG.SERVER_ROOT, dir=None, version=None):
|
||||||
"""Initialize an Apache Configurator."""
|
"""Initialize an Apache Configurator."""
|
||||||
if not save_dir:
|
# The top 3 are the only ones that need to be
|
||||||
save_dir={"backup": CONFIG.BACKUP_DIR,
|
# defined for Augeas Configurator
|
||||||
"temp": CONFIG.TEMP_CHECKPOINT_DIR,
|
if dir:
|
||||||
"progress": CONFIG.IN_PROGRESS_DIR}
|
self.dir = dir
|
||||||
|
else:
|
||||||
|
self.dir = {"backup": CONFIG.BACKUP_DIR,
|
||||||
|
"temp": CONFIG.TEMP_CHECKPOINT_DIR,
|
||||||
|
"progress": CONFIG.IN_PROGRESS_DIR,
|
||||||
|
"config": CONFIG.CONFIG_DIR,
|
||||||
|
"work": CONFIG.WORK_DIR}
|
||||||
|
|
||||||
super(ApacheConfigurator, self).__init__(save_dir)
|
super(ApacheConfigurator, self).__init__(dir)
|
||||||
|
|
||||||
self.server_root = server_root
|
self.server_root = server_root
|
||||||
|
|
||||||
@@ -167,7 +173,7 @@ class ApacheConfigurator(augeas_configurator.AugeasConfigurator):
|
|||||||
# Add name_server association dict
|
# Add name_server association dict
|
||||||
self.assoc = dict()
|
self.assoc = dict()
|
||||||
# Verify that all directories and files exist with proper permissions
|
# Verify that all directories and files exist with proper permissions
|
||||||
verify_setup()
|
self.verify_setup()
|
||||||
|
|
||||||
# Enable mod_ssl if it isn't already enabled
|
# Enable mod_ssl if it isn't already enabled
|
||||||
# This is Let's Encrypt... we enable mod_ssl on initialization :)
|
# This is Let's Encrypt... we enable mod_ssl on initialization :)
|
||||||
@@ -1327,6 +1333,19 @@ LogLevel warn \n\
|
|||||||
|
|
||||||
return tuple(matches[0].split('.'))
|
return tuple(matches[0].split('.'))
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
"""
|
||||||
|
uid = os.geteuid()
|
||||||
|
le_util.make_or_verify_dir(self.dir["config"], 0o755, uid)
|
||||||
|
le_util.make_or_verify_dir(self.dir["work"], 0o755, uid)
|
||||||
|
le_util.make_or_verify_dir(self.dir["backup"], 0o755, uid)
|
||||||
|
|
||||||
###########################################################################
|
###########################################################################
|
||||||
# Challenges Section
|
# Challenges Section
|
||||||
###########################################################################
|
###########################################################################
|
||||||
@@ -1572,19 +1591,6 @@ def apache_restart():
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def verify_setup():
|
|
||||||
"""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
|
|
||||||
|
|
||||||
"""
|
|
||||||
le_util.make_or_verify_dir(CONFIG.CONFIG_DIR, 0o755)
|
|
||||||
le_util.make_or_verify_dir(CONFIG.WORK_DIR, 0o755)
|
|
||||||
le_util.make_or_verify_dir(CONFIG.BACKUP_DIR, 0o755)
|
|
||||||
|
|
||||||
|
|
||||||
def case_i(string):
|
def case_i(string):
|
||||||
"""Returns case insensitive regex.
|
"""Returns case insensitive regex.
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,9 @@ class AugeasConfigurator(configurator.Configurator):
|
|||||||
super(AugeasConfigurator, self).__init__()
|
super(AugeasConfigurator, self).__init__()
|
||||||
|
|
||||||
if not dir:
|
if not dir:
|
||||||
dir={"backup": CONFIG.BACKUP_DIR,
|
dir = {"backup": CONFIG.BACKUP_DIR,
|
||||||
"temp": CONFIG.TEMP_CHECKPOINT_DIR,
|
"temp": CONFIG.TEMP_CHECKPOINT_DIR,
|
||||||
"progress": CONFIG.IN_PROGRESS_DIR}
|
"progress": CONFIG.IN_PROGRESS_DIR}
|
||||||
|
|
||||||
self.dir = dir
|
self.dir = dir
|
||||||
# TODO: this instantiation can be optimized to only load
|
# TODO: this instantiation can be optimized to only load
|
||||||
|
|||||||
@@ -53,11 +53,14 @@ class TwoVhost80(unittest.TestCase):
|
|||||||
|
|
||||||
# Using a new configurator every time allows the Configurator to clean
|
# Using a new configurator every time allows the Configurator to clean
|
||||||
# up after itself
|
# up after itself
|
||||||
backup = os.path.join(TESTING_DIR, "backups")
|
|
||||||
temp = os.path.join(TESTING_DIR, "temp_checkpoint")
|
|
||||||
progress = os.path.join(backup, "IN_PROGRESS")
|
|
||||||
self.config = apache_configurator.ApacheConfigurator(
|
self.config = apache_configurator.ApacheConfigurator(
|
||||||
self.config_path, {"backup": backup, "temp": temp, "progress": progress}, (2, 4, 7))
|
self.config_path,
|
||||||
|
{"backup": os.path.join(TESTING_DIR, "backups"),
|
||||||
|
"temp": os.path.join(TESTING_DIR, "temp_checkpoint"),
|
||||||
|
"progress": os.path.join(TESTING_DIR, "backups", "IN_PROGRESS"),
|
||||||
|
"config": os.path.join(TESTING_DIR, "config"),
|
||||||
|
"work": os.path.join(TESTING_DIR, "work")},
|
||||||
|
(2, 4, 7))
|
||||||
|
|
||||||
self.aug_path = "/files" + self.config_path
|
self.aug_path = "/files" + self.config_path
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user