freqtrade_origin/freqtrade/configuration/config_secrets.py

37 lines
1022 B
Python
Raw Normal View History

2024-03-20 06:22:12 +00:00
from copy import deepcopy
2024-03-19 18:30:35 +00:00
from freqtrade.constants import Config
2024-03-20 06:06:24 +00:00
def sanitize_config(config: Config, *, show_sensitive: bool = False) -> Config:
2024-03-19 18:30:35 +00:00
"""
Remove sensitive information from the config.
:param config: Configuration
2024-03-20 06:06:24 +00:00
:param show_sensitive: Show sensitive information
2024-03-19 18:30:35 +00:00
:return: Configuration
"""
2024-03-20 06:06:24 +00:00
if show_sensitive:
return config
2024-03-19 18:30:35 +00:00
keys_to_remove = [
"exchange.key",
"exchange.secret",
"exchange.password",
"exchange.uid",
"telegram.token",
"telegram.chat_id",
"discord.webhook_url",
"api_server.password",
]
2024-03-20 06:22:12 +00:00
config = deepcopy(config)
2024-03-19 18:30:35 +00:00
for key in keys_to_remove:
2024-05-12 14:29:24 +00:00
if "." in key:
nested_keys = key.split(".")
2024-03-19 18:30:35 +00:00
nested_config = config
for nested_key in nested_keys[:-1]:
nested_config = nested_config.get(nested_key, {})
2024-05-12 14:29:24 +00:00
nested_config[nested_keys[-1]] = "REDACTED"
2024-03-19 18:30:35 +00:00
else:
2024-05-12 14:29:24 +00:00
config[key] = "REDACTED"
2024-03-19 18:30:35 +00:00
return config