Skip to content

Commit

Permalink
factor out location_directive_for_achall (#5794)
Browse files Browse the repository at this point in the history
  • Loading branch information
ohemorange committed Mar 26, 2018
1 parent 8cdb213 commit 804fd4b
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions certbot-nginx/certbot_nginx/http_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,17 +159,23 @@ def _make_server_block(self, achall):
document_root = os.path.join(
self.configurator.config.work_dir, "http_01_nonexistent")

validation = achall.validation(achall.account_key)
validation_path = self._get_validation_path(achall)

block.extend([['server_name', ' ', achall.domain],
['root', ' ', document_root],
[['location', ' ', '=', ' ', validation_path],
[['default_type', ' ', 'text/plain'],
['return', ' ', '200', ' ', validation]]]])
self._location_directive_for_achall(achall)
])
# TODO: do we want to return something else if they otherwise access this block?
return [['server'], block]

def _location_directive_for_achall(self, achall):
validation = achall.validation(achall.account_key)
validation_path = self._get_validation_path(achall)

location_directive = [['location', ' ', '=', ' ', validation_path],
[['default_type', ' ', 'text/plain'],
['return', ' ', '200', ' ', validation]]]
return location_directive


def _make_or_mod_server_block(self, achall):
"""Modifies a server block to respond to a challenge.
Expand All @@ -191,12 +197,7 @@ def _make_or_mod_server_block(self, achall):
vhost = vhosts[0]

# Modify existing server block
validation = achall.validation(achall.account_key)
validation_path = self._get_validation_path(achall)

location_directive = [[['location', ' ', '=', ' ', validation_path],
[['default_type', ' ', 'text/plain'],
['return', ' ', '200', ' ', validation]]]]
location_directive = [self._location_directive_for_achall(achall)]

self.configurator.parser.add_server_directives(vhost,
location_directive)
Expand Down

0 comments on commit 804fd4b

Please sign in to comment.