@@ -47,6 +47,7 @@ class Configurator(common.Installer, interfaces.Authenticator):
4747
4848 def __init__ (self , * args : Any , ** kwargs : Any ):
4949 super ().__init__ (* args , ** kwargs )
50+ self ._prepared = False
5051 self ._configuration = None
5152 self .unitc = Unitc ()
5253 self ._entropy = datetime .now ().strftime ("%Y%m%d%H%M%S" )
@@ -55,6 +56,8 @@ def __init__(self, *args: Any, **kwargs: Any):
5556 self ._full_root : str = ""
5657 self ._performed : DefaultDict [str , Set [AnnotatedChallenge ]] = collections .defaultdict (set )
5758 self ._created_dirs : List [str ] = []
59+ self ._to_remove : List [str ] = []
60+ self ._backup_routes : List [str ] = []
5861
5962 def get_all_names (self ) -> Iterable [str ]:
6063 return []
@@ -140,11 +143,13 @@ def _ensure_challenge_listener(self):
140143 if "listeners" not in self ._configuration :
141144 raise errors .PluginError ("No listeners configured" )
142145 if "*:80" not in self ._configuration ["listeners" ]:
143- raise errors .PluginError ("No '*:80' default listeners configured" )
146+ self ._configuration ["listeners" ]["*:80" ] = {"pass" : "routes" }
147+ self ._to_remove .append ("/config/listeners/*:80" )
144148 if "pass" not in self ._configuration ["listeners" ]["*:80" ]:
145149 raise errors .PluginError ("Cannot configure the route for the *:80 listener" )
146150
147151 actual_route = self ._configuration ["listeners" ]["*:80" ]["pass" ]
152+ self ._backup_routes = self ._configuration .get ("routes" , [])
148153 default_route = self ._ensure_acme_route (actual_route )
149154 if actual_route == default_route :
150155 return
@@ -237,7 +242,10 @@ def prepare(self) -> None:
237242 """Prepare the authenticator/installer."""
238243 # @todo verify "unitc" executable
239244 # @todo lock to prevent concurrent multi update
245+ if self ._prepared :
246+ return
240247 self ._configuration = self ._get_unit_configuration ("/config" )
248+ self ._prepared = True
241249
242250 def more_info (self ) -> str : # pylint: disable=missing-function-docstring
243251 return self .MORE_INFO .format (self .conf ("path" ))
@@ -339,6 +347,12 @@ def _perform_single(self, achall: AnnotatedChallenge) -> challenges.ChallengeRes
339347 return response
340348
341349 def cleanup (self , achalls : List [AnnotatedChallenge ]) -> None : # pylint: disable=missing-function-docstring
350+ for config_path in self ._to_remove :
351+ self .unitc .delete (config_path , None , "Delete tmp configuration failed" )
352+
353+ if self ._configuration ["routes" ] != self ._backup_routes :
354+ self .unitc .put ("/config/routes" , json .dumps (self ._backup_routes ).encode ())
355+
342356 for achall in achalls :
343357 root_path = self ._full_root
344358 if root_path is not None :
0 commit comments