Add Redis password support

This commit is contained in:
allegroai 2022-02-13 19:37:52 +02:00
parent 17cd48dada
commit 970a32287a

View File

@ -21,6 +21,11 @@ OVERRIDE_PORT_ENV_KEY = (
"TRAINS_REDIS_SERVICE_PORT",
"REDIS_SERVICE_PORT",
)
OVERRIDE_PASSWORD_ENV_KEY = (
"CLEARML_REDIS_SERVICE_PASSWORD",
"TRAINS_REDIS_SERVICE_PASSWORD",
"REDIS_SERVICE_PASSWORD",
)
OVERRIDE_HOST = first(filter(None, map(getenv, OVERRIDE_HOST_ENV_KEY)))
if OVERRIDE_HOST:
@ -30,6 +35,8 @@ OVERRIDE_PORT = first(filter(None, map(getenv, OVERRIDE_PORT_ENV_KEY)))
if OVERRIDE_PORT:
log.info(f"Using override redis port {OVERRIDE_PORT}")
OVERRIDE_PASSWORD = first(filter(None, map(getenv, OVERRIDE_PASSWORD_ENV_KEY)))
class MyPubSubWorkerThread(threading.Thread):
def __init__(self, sentinel, on_new_master, msg_sleep_time, daemon=True):
@ -131,6 +138,7 @@ class RedisManager(object):
for alias, alias_config in redis_config_dict.items():
alias_config = alias_config.as_plain_ordered_dict()
alias_config["password"] = config.get(f"secure.redis.{alias}.password", None)
is_cluster = alias_config.get("cluster", False)
@ -142,6 +150,10 @@ class RedisManager(object):
if port:
alias_config["port"] = port
password = OVERRIDE_PASSWORD or alias_config.get("password", None)
if password:
alias_config["password"] = password
db = alias_config.get("db", 0)
sentinels = alias_config.get("sentinels", None)