import os from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives.asymmetric import dsa from cryptography.hazmat.primitives import serialization from conf import config if config.ENV == 'dev' and config.SNOWFLAKE_KEY_PASSPHRASE: # Snowflake key if not config.SNOWFLAKE_PRIVATE_KEY_PATH: SNOWFLAKE_PRIVATE_KEY_PATH = '{}/.ssh/snowflake/rsa_key.p8'.format(os.environ['HOME']) with open(SNOWFLAKE_PRIVATE_KEY_PATH, 'rb') as key: p_key = serialization.load_pem_private_key( key.read(), password=config.SNOWFLAKE_KEY_PASSPHRASE.encode(), backend=default_backend() ) PRIVATE_KEY = p_key.private_bytes( encoding=serialization.Encoding.DER, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption()) else: PRIVATE_KEY = None