def jsonify_config(config): # check exchange keys encryption for exchange in config[CONFIG_EXCHANGES]: try: try: decrypt(config[CONFIG_EXCHANGES][exchange] [CONFIG_EXCHANGE_KEY], silent_on_invalid_token=True) except Exception: config[CONFIG_EXCHANGES][exchange][ CONFIG_EXCHANGE_KEY] = encrypt( config[CONFIG_EXCHANGES][exchange] [CONFIG_EXCHANGE_KEY]).decode() try: decrypt(config[CONFIG_EXCHANGES][exchange] [CONFIG_EXCHANGE_SECRET], silent_on_invalid_token=True) except Exception: config[CONFIG_EXCHANGES][exchange][ CONFIG_EXCHANGE_SECRET] = encrypt( config[CONFIG_EXCHANGES][exchange] [CONFIG_EXCHANGE_SECRET]).decode() except Exception: config[CONFIG_EXCHANGES][exchange] = { CONFIG_EXCHANGE_KEY: "", CONFIG_EXCHANGE_SECRET: "" } return json.dumps(config, indent=4, sort_keys=True)
def jsonify_config(config): # check exchange keys encryption for exchange in config[CONFIG_EXCHANGES]: key = config[CONFIG_EXCHANGES][exchange][CONFIG_EXCHANGE_KEY] secret = config[CONFIG_EXCHANGES][exchange][CONFIG_EXCHANGE_SECRET] try: if not ConfigManager.has_invalid_default_config_value(key): try: decrypt(key, silent_on_invalid_token=True) except Exception: config[CONFIG_EXCHANGES][exchange][ CONFIG_EXCHANGE_KEY] = encrypt(key).decode() if not ConfigManager.has_invalid_default_config_value(secret): try: decrypt(secret, silent_on_invalid_token=True) except Exception: config[CONFIG_EXCHANGES][exchange][ CONFIG_EXCHANGE_SECRET] = encrypt(secret).decode() except Exception: config[CONFIG_EXCHANGES][exchange] = { CONFIG_EXCHANGE_KEY: "", CONFIG_EXCHANGE_SECRET: "" } return json.dumps(config, indent=4, sort_keys=True)
def exchange_keys_encrypter(catch=False): try: api_key_crypted = encrypt(input("ENTER YOUR API-KEY : ")).decode() api_secret_crypted = encrypt(input("ENTER YOUR API-SECRET : ")).decode() print(f"Here are your encrypted exchanges keys : \n " f"\t- API-KEY : {api_key_crypted}\n" f"\t- API-SECRET : {api_secret_crypted}\n\n" f"Your new exchange key configuration is : \n" f'\t"api-key": "{api_key_crypted}",\n' f'\t"api-secret": "{api_secret_crypted}"\n') except Exception as e: if not catch: get_logger(Commands.__name__).error(f"Fail to encrypt your exchange keys, please try again ({e}).") raise e
def _handle_encrypted_value(value_key, config_element, verbose=False): if value_key in config_element: key = config_element[value_key] if not ConfigManager.has_invalid_default_config_value(key): try: decrypt(key, silent_on_invalid_token=True) return True except Exception: config_element[value_key] = encrypt(key).decode() if verbose: get_logger().warning( f"Non encrypted secret info found in config ({value_key}): replaced " f"value with encrypted equivalent.") return False return True