Skip to content

Commit 97d1c44

Browse files
committed
Update conftest helper and SQL for creating test user, switching from password to private key
1 parent a44fe35 commit 97d1c44

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

test/_sql/account_setup.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
-- SQL script to set up a new Snowflake account for tests and GitHub workflows
2-
-- Replace <password> placeholder statement with an actual password of your choice
2+
-- Replace <public_key> placeholder statement with an actual public key
3+
-- https://docs.snowflake.com/en/user-guide/key-pair-auth#configuring-key-pair-authentication
34

45
-- Replace <aws_role_arn> with ARN of AWS role
56
-- https://docs.snowflake.com/en/user-guide/data-load-s3-config-storage-integration
67

7-
SET PASSWORD = '<password>';
8+
SET RSA_PUBLIC_KEY = '<public_key>';
89
SET STORAGE_AWS_ROLE_ARN = '<storage_aws_role_arn>';
910

1011
---
@@ -32,7 +33,8 @@ CREATE ROLE SNOWDDL_ADMIN_TEST;
3233
GRANT ROLE ACCOUNTADMIN TO ROLE SNOWDDL_ADMIN_TEST;
3334

3435
CREATE USER SNOWDDL_TEST
35-
PASSWORD = $PASSWORD
36+
TYPE = SERVICE
37+
RSA_PUBLIC_KEY = $RSA_PUBLIC_KEY
3638
DEFAULT_ROLE = SNOWDDL_ADMIN_TEST;
3739

3840
GRANT ROLE SNOWDDL_ADMIN_TEST TO USER SNOWDDL_TEST;

test/conftest.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from cryptography.hazmat.primitives import serialization
12
from json import loads
23
from itertools import groupby
34
from os import environ
@@ -538,10 +539,17 @@ def __exit__(self, exc_type, exc_val, exc_tb):
538539
self.connection.close()
539540

540541
def _init_connection(self):
542+
key_bytes = str(environ["SNOWFLAKE_PRIVATE_KEY"]).encode("utf-8")
543+
pk = serialization.load_pem_private_key(data=key_bytes, password=None)
544+
541545
options = {
542546
"account": environ.get("SNOWFLAKE_ACCOUNT"),
543547
"user": environ.get("SNOWFLAKE_USER"),
544-
"password": environ.get("SNOWFLAKE_PASSWORD"),
548+
"private_key": pk.private_bytes(
549+
encoding=serialization.Encoding.DER,
550+
format=serialization.PrivateFormat.PKCS8,
551+
encryption_algorithm=serialization.NoEncryption(),
552+
)
545553
}
546554

547555
return connect(**options)

0 commit comments

Comments
 (0)