"""SSH Utilities.""" from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization def get_private_key(key_path, passphrase): """Parse key files for snowflake ssh access.""" with open(key_path, 'rb') as key: p_key = serialization.load_pem_private_key( key.read(), password=passphrase.encode(), backend=default_backend() ) return p_key.private_bytes( encoding=serialization.Encoding.DER, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption(), )