55
66"""
77import collections
8+ import copy
89import json
910import logging
1011from datetime import datetime
@@ -128,9 +129,7 @@ def _ensure_tls_listener(self):
128129 if "*:443" not in self ._configuration ["listeners" ]:
129130 if "*:80" not in self ._configuration ["listeners" ]:
130131 raise errors .PluginError ("No '*:80' default listeners configured" )
131- self ._configuration ["listeners" ]["*:443" ] = self ._configuration ["listeners" ]["*:80" ]
132- new_route = self ._ensure_acme_route (self ._configuration ["listeners" ]["*:443" ]["pass" ])
133- self ._configuration ["listeners" ]["*:80" ] = {"pass" : new_route }
132+ self ._configuration ["listeners" ]["*:443" ] = copy .deepcopy (self ._configuration ["listeners" ]["*:80" ])
134133
135134 if "tls" not in self ._configuration ["listeners" ]["*:443" ]:
136135 self ._configuration ["listeners" ]["*:443" ]["tls" ] = {}
@@ -157,12 +156,11 @@ def _ensure_challenge_listener(self):
157156 self .unitc .put (listener_route , default_route .encode (), success_message , error_message )
158157
159158 def _ensure_acme_route (self , actual_route : str ) -> str :
160- acme_challenge_url = "/.well-known/acme-challenge/*"
161- acme_base_path = "/srv/www/unit"
159+ acme_challenge_url = "/" + challenges .HTTP01 .URI_ROOT_PATH + "/*"
162160 acme_route = [
163161 {
164162 "match" : {"uri" : acme_challenge_url },
165- "action" : {"share" : acme_base_path + "/$uri" },
163+ "action" : {"share" : self . _challenge_path + "/$uri" },
166164 }
167165 ]
168166 if actual_route != "routes" and actual_route != "routes/acme" :
@@ -190,8 +188,8 @@ def _ensure_acme_route(self, actual_route: str) -> str:
190188 raise errors .PluginError ("Cannot configure the routes: unknown route[0] type" )
191189
192190 first_route = self ._configuration ["routes" ][0 ]
193- if "match" in first_route and "uri" in first_route ["match" ] and first_route [ "match" ][
194- " uri" ] == acme_challenge_url :
191+ if ( "match" in first_route and "uri" in first_route ["match" ]
192+ and first_route [ "match" ][ " uri" ] == acme_challenge_url ) :
195193 return "routes"
196194
197195 routes = acme_route + self ._configuration ["routes" ]
@@ -255,9 +253,9 @@ def get_chall_pref(self, domain: str) -> Iterable[Type[challenges.Challenge]]:
255253 # pylint: disable=unused-argument,missing-function-docstring
256254 return [challenges .HTTP01 ]
257255
258- def perform (self , achalls : List [AnnotatedChallenge ]) -> List [
259- challenges .ChallengeResponse ]: # pylint: disable=missing-function-docstring
256+ def perform (self , achalls : List [AnnotatedChallenge ]) -> List [challenges .ChallengeResponse ]:
260257
258+ self .prepare ()
261259 self ._set_webroot (achalls )
262260 self ._create_challenge_dir ()
263261
@@ -268,7 +266,7 @@ def perform(self, achalls: List[AnnotatedChallenge]) -> List[
268266 def _set_webroot (self , achalls : Iterable [AnnotatedChallenge ]) -> None :
269267 webroot_path = '/srv/www/unit/'
270268 if self .conf ("path" ):
271- webroot_path = self .conf ("path" )[ - 1 ]
269+ webroot_path = self .conf ("path" )
272270
273271 logger .info ("Using the webroot path %s for all domains." , webroot_path )
274272
0 commit comments