freqtrade_origin/freqtrade/configuration/config_secrets.py

45 lines
1.2 KiB
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",
2024-08-02 05:05:45 +00:00
"exchange.api_key",
"exchange.apiKey",
2024-03-19 18:30:35 +00:00
"exchange.secret",
"exchange.password",
"exchange.uid",
2024-08-02 05:05:45 +00:00
"exchange.account_id",
2024-07-16 16:26:51 +00:00
"exchange.accountId",
2024-08-02 05:05:45 +00:00
"exchange.wallet_address",
"exchange.walletAddress",
2024-08-02 05:05:45 +00:00
"exchange.private_key",
"exchange.privateKey",
2024-03-19 18:30:35 +00:00
"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