Skip to content

Commit

Permalink
[Windows] Change default paths for Certbot when run on Windows (certb…
Browse files Browse the repository at this point in the history
…ot#6416)

Defaults path of Certbot are the following:

config: /etc/letsencrypt
workdir: /var/letsencrypt/lib
logs: /var/letsencrypt/log
On Windows, this translate into:

config: C:\etc\letsencrypt
workdir: C:\var\letsencrypt\lib
logs: C:\var\letsencrypt\log
As Windows does not follow the standard POSIX filesystem layout, theses paths do not have a lot of sense in this case.

This PR sets the following default paths when Certbot is run on Windows:

config: C:\Certbot
workdir: C:\Certbot\lib
logs: C:\Certbot\log
Better to decide the default paths for Certbot before users start to run it on Windows, to avoid future migration procedures.
  • Loading branch information
adferrand authored and bmw committed Nov 20, 2018
1 parent 1dd7db1 commit a23d76b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
27 changes: 27 additions & 0 deletions certbot/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,30 @@ def compare_file_modes(mode1, mode2):
# Windows specific: most of mode bits are ignored on Windows. Only check user R/W rights.
return (stat.S_IMODE(mode1) & stat.S_IREAD == stat.S_IMODE(mode2) & stat.S_IREAD
and stat.S_IMODE(mode1) & stat.S_IWRITE == stat.S_IMODE(mode2) & stat.S_IWRITE)

WINDOWS_DEFAULT_FOLDERS = {
'config': 'C:\\Certbot',
'work': 'C:\\Certbot\\lib',
'logs': 'C:\\Certbot\\log',
}
LINUX_DEFAULT_FOLDERS = {
'config': '/etc/letsencrypt',
'work': '/var/letsencrypt/lib',
'logs': '/var/letsencrypt/log',
}

def get_default_folder(folder_type):
"""
Return the relevant default folder for the current OS
:param str folder_type: The type of folder to retrieve (config, work or logs)
:returns: The relevant default folder.
:rtype: str
"""
if 'fcntl' in sys.modules:
# Linux specific
return LINUX_DEFAULT_FOLDERS[folder_type]
# Windows specific
return WINDOWS_DEFAULT_FOLDERS[folder_type]
10 changes: 5 additions & 5 deletions certbot/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pkg_resources

from acme import challenges

from certbot import compat

SETUPTOOLS_PLUGINS_ENTRY_POINT = "certbot.plugins"
"""Setuptools entry point group name for plugins."""
Expand All @@ -14,7 +14,7 @@

CLI_DEFAULTS = dict(
config_files=[
"/etc/letsencrypt/cli.ini",
os.path.join(compat.get_default_folder('config'), 'cli.ini'),
# http://freedesktop.org/wiki/Software/xdg-user-dirs/
os.path.join(os.environ.get("XDG_CONFIG_HOME", "~/.config"),
"letsencrypt", "cli.ini"),
Expand Down Expand Up @@ -85,9 +85,9 @@
auth_cert_path="./cert.pem",
auth_chain_path="./chain.pem",
key_path=None,
config_dir="/etc/letsencrypt",
work_dir="/var/lib/letsencrypt",
logs_dir="/var/log/letsencrypt",
config_dir=compat.get_default_folder('config'),
work_dir=compat.get_default_folder('work'),
logs_dir=compat.get_default_folder('logs'),
server="https://acme-v02.api.letsencrypt.org/directory",

# Plugins parsers
Expand Down
5 changes: 4 additions & 1 deletion certbot/display/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

import zope.component

from certbot import compat
from certbot import errors
from certbot import interfaces
from certbot import util

from certbot.display import util as display_util

logger = logging.getLogger(__name__)
Expand All @@ -33,7 +35,8 @@ def get_email(invalid=False, optional=True):
unsafe_suggestion = ("\n\nIf you really want to skip this, you can run "
"the client with --register-unsafely-without-email "
"but make sure you then backup your account key from "
"/etc/letsencrypt/accounts\n\n")
"{0}\n\n".format(os.path.join(
compat.get_default_folder('config'), 'accounts')))
if optional:
if invalid:
msg += unsafe_suggestion
Expand Down
7 changes: 4 additions & 3 deletions certbot/tests/main_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,8 @@ def test_certonly_dry_run_new_request_success(self, mock_get_utility):
@mock.patch('certbot.crypto_util.notAfter')
@test_util.patch_get_utility()
def test_certonly_new_request_success(self, mock_get_utility, mock_notAfter):
cert_path = '/etc/letsencrypt/live/foo.bar'
key_path = '/etc/letsencrypt/live/baz.qux'
cert_path = os.path.normpath(os.path.join(self.config.config_dir, 'live/foo.bar'))
key_path = os.path.normpath(os.path.join(self.config.config_dir, 'live/baz.qux'))
date = '1970-01-01'
mock_notAfter().date.return_value = date

Expand Down Expand Up @@ -975,7 +975,8 @@ def _test_renewal_common(self, due_for_renewal, extra_args, log_out=None,
reuse_key=False):
# pylint: disable=too-many-locals,too-many-arguments,too-many-branches
cert_path = test_util.vector_path('cert_512.pem')
chain_path = '/etc/letsencrypt/live/foo.bar/fullchain.pem'
chain_path = os.path.normpath(os.path.join(self.config.config_dir,
'live/foo.bar/fullchain.pem'))
mock_lineage = mock.MagicMock(cert=cert_path, fullchain=chain_path,
cert_path=cert_path, fullchain_path=chain_path)
mock_lineage.should_autorenew.return_value = due_for_renewal
Expand Down

0 comments on commit a23d76b

Please sign in to comment.