mirror of
https://github.com/certbot/certbot.git
synced 2026-07-30 16:14:44 +02:00
Refactor path logic in webroot plugin
This commit is contained in:
@@ -97,7 +97,7 @@ to serve all files under specified web root ({0})."""
|
|||||||
assert self.full_roots, "Webroot plugin appears to be missing webroot map"
|
assert self.full_roots, "Webroot plugin appears to be missing webroot map"
|
||||||
return [self._perform_single(achall) for achall in achalls]
|
return [self._perform_single(achall) for achall in achalls]
|
||||||
|
|
||||||
def _path_for_achall(self, achall):
|
def _get_root_path(self, achall):
|
||||||
try:
|
try:
|
||||||
path = self.full_roots[achall.domain]
|
path = self.full_roots[achall.domain]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -106,19 +106,23 @@ to serve all files under specified web root ({0})."""
|
|||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise errors.PluginError("Mysteriously missing path {0} for domain: {1}"
|
raise errors.PluginError("Mysteriously missing path {0} for domain: {1}"
|
||||||
.format(path, achall.domain))
|
.format(path, achall.domain))
|
||||||
return os.path.join(path, achall.chall.encode("token"))
|
return path
|
||||||
|
|
||||||
|
def _get_validation_path(self, root_path, achall):
|
||||||
|
return os.path.join(root_path, achall.chall.encode("token"))
|
||||||
|
|
||||||
def _perform_single(self, achall):
|
def _perform_single(self, achall):
|
||||||
response, validation = achall.response_and_validation()
|
response, validation = achall.response_and_validation()
|
||||||
|
|
||||||
path = self._path_for_achall(achall)
|
root_path = self._get_root_path(achall)
|
||||||
logger.debug("Attempting to save validation to %s", path)
|
validation_path = self._get_validation_path(root_path, achall)
|
||||||
|
logger.debug("Attempting to save validation to %s", validation_path)
|
||||||
|
|
||||||
# Change permissions to be world-readable, owner-writable (GH #1795)
|
# Change permissions to be world-readable, owner-writable (GH #1795)
|
||||||
old_umask = os.umask(0o022)
|
old_umask = os.umask(0o022)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(path, "w") as validation_file:
|
with open(validation_path, "w") as validation_file:
|
||||||
validation_file.write(validation.encode())
|
validation_file.write(validation.encode())
|
||||||
finally:
|
finally:
|
||||||
os.umask(old_umask)
|
os.umask(old_umask)
|
||||||
@@ -127,6 +131,7 @@ to serve all files under specified web root ({0})."""
|
|||||||
|
|
||||||
def cleanup(self, achalls): # pylint: disable=missing-docstring
|
def cleanup(self, achalls): # pylint: disable=missing-docstring
|
||||||
for achall in achalls:
|
for achall in achalls:
|
||||||
path = self._path_for_achall(achall)
|
root_path = self._get_root_path(achall)
|
||||||
logger.debug("Removing %s", path)
|
validation_path = self._get_validation_path(root_path, achall)
|
||||||
os.remove(path)
|
logger.debug("Removing %s", validation_path)
|
||||||
|
os.remove(validation_path)
|
||||||
|
|||||||
Reference in New Issue
Block a user