@@ -293,19 +293,30 @@ def _warn_empty_username(self):
293
293
)
294
294
return ""
295
295
296
- traefik_api_hashed_password = Unicode ()
296
+ traefik_api_hashed_password = Unicode (
297
+ config = True ,
298
+ help = """
299
+ Set the hashed password to use for the API
300
+
301
+ If unspecified, `traefik_api_password` will be hashed with bcrypt.
302
+ ref: https://doc.traefik.io/traefik/middlewares/http/basicauth/
303
+ """ ,
304
+ )
305
+
306
+ @default ("traefik_api_hashed_password" )
307
+ def _generate_htpassword (self ):
308
+ import bcrypt
309
+
310
+ return bcrypt .hashpw (
311
+ self .traefik_api_password .encode ("utf8" ), bcrypt .gensalt ()
312
+ ).decode ("ascii" )
297
313
298
314
check_route_timeout = Integer (
299
315
30 ,
300
316
config = True ,
301
317
help = """Timeout (in seconds) when waiting for traefik to register an updated route.""" ,
302
318
)
303
319
304
- def _generate_htpassword (self ):
305
- from passlib .hash import apr_md5_crypt
306
-
307
- self .traefik_api_hashed_password = apr_md5_crypt .hash (self .traefik_api_password )
308
-
309
320
async def _check_for_traefik_service (self , routespec , kind ):
310
321
"""Check for an expected router or service in the Traefik API.
311
322
@@ -508,7 +519,6 @@ async def _setup_traefik_static_config(self):
508
519
509
520
async def _setup_traefik_dynamic_config (self ):
510
521
self .log .debug ("Setting up traefik's dynamic config..." )
511
- self ._generate_htpassword ()
512
522
api_url = urlparse (self .traefik_api_url )
513
523
api_path = api_url .path if api_url .path .strip ("/" ) else '/api'
514
524
api_credentials = (
0 commit comments