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:
if '.' in key:
nested_keys = key.split('.')
nested_config = config
for nested_key in nested_keys[:-1]:
nested_config = nested_config.get(nested_key, {})
nested_config[nested_keys[-1]] = 'REDACTED'
else:
config[key] = 'REDACTED'
return config