diff --git a/redash/query_runner/snowflake.py b/redash/query_runner/snowflake.py index bb67c20d68..023d7bf3f7 100644 --- a/redash/query_runner/snowflake.py +++ b/redash/query_runner/snowflake.py @@ -1,3 +1,9 @@ +import os +import tempfile + +from cryptography.hazmat.backends import default_backend +from cryptography.hazmat.primitives import serialization + try: import snowflake.connector @@ -96,16 +102,31 @@ def _get_connection(self): else: host = "{}.snowflakecomputing.com".format(account) - connection = snowflake.connector.connect( - user=self.configuration["user"], - password=self.configuration["password"], - account=account, - region=region, - host=host, - application="Redash/{} (Snowflake)".format(__version__.split("-")[0]), - ) + connection_parameters = { + "user": self.configuration["user"], + "password": self.configuration["password"], + "account": account, + "region": region, + "host": host, + "application": "Redash/{} (Snowflake)".format(__version__.split("-")[0]), + } + + private_key_content = os.getenv("SNOWFLAKE_PRIVATE_KEY") + private_key_password = os.getenv("SNOWFLAKE_KEY_PASSWORD") + + if private_key_content and private_key_password: + + key_file = tempfile.NamedTemporaryFile(delete=False) + key_file.write(private_key_content.encode('UTF-8')) + key_file.close() + + connection_parameters['private_key_file'] = key_file.name + connection_parameters["private_key_file_pwd"] = private_key_password + + # password is not needed + connection_parameters.pop('password') - return connection + return snowflake.connector.connect(**connection_parameters) def _column_name(self, column_name): if self.configuration.get("lower_case_columns", False): diff --git a/requirements_ds_obmedia.txt b/requirements_ds_obmedia.txt new file mode 100644 index 0000000000..969f530457 --- /dev/null +++ b/requirements_ds_obmedia.txt @@ -0,0 +1,15 @@ +google-api-python-client==1.7.11 +protobuf==3.17.3 +gspread==3.1.0 +mysqlclient==2.1.1 +oauth2client==4.1.3 +boto3>=1.10.0,<1.11.0 +botocore>=1.13,<1.14.0 +sasl>=0.1.3 +requests_aws_sign==0.1.5 +snowflake-connector-python==3.0.4 +python-rapidjson==0.8.0 +pandas==1.3.4 +nzpy>=1.15 +nzalchemy +pyarrow==10.0.0