Skip to content

Commit

Permalink
SNOW-1728000 Switch to key with no password
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mbobowski committed Nov 7, 2024
1 parent c33d196 commit dc8d9d4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 19 deletions.
Binary file modified .github/scripts/profile.json.gpg
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test_suit/iceberg_json_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def getConfigFileName(self):
def setup(self):
self.driver.create_iceberg_table_with_content(
table_name=self.topic,
external_volume="kafka_push_e2e_volume_aws", # volume created manually
external_volume="test_exvol", # volume created manually
)

def send(self):
Expand Down
12 changes: 4 additions & 8 deletions test/test_suit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,22 @@ def __init__(self, msg=""):
self.msg = msg


def parsePrivateKey(pk, pk_passphrase):
pkpass = None
if len(pk_passphrase) != 0:
pkpass = pk_passphrase.encode()

def parsePrivateKey(pk):
# remove header, footer, and line breaks
pk = re.sub("-+[A-Za-z ]+-+", "", pk)
pk = re.sub("\\s", "", pk)

pkBuilder = ""
pkBuilder += "-----BEGIN ENCRYPTED PRIVATE KEY-----"
pkBuilder += "-----BEGIN PRIVATE KEY-----"
for i, c in enumerate(pk):
if i % 64 == 0:
pkBuilder += "\n"
pkBuilder += c
pkBuilder += "\n-----END ENCRYPTED PRIVATE KEY-----"
pkBuilder += "\n-----END PRIVATE KEY-----"

p_key = serialization.load_pem_private_key(
pkBuilder.encode(),
password=pkpass,
password=None,
backend=default_backend()
)

Expand Down
13 changes: 3 additions & 10 deletions test/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import time

import test_suit
from test_suit.test_utils import parsePrivateKey, RetryableError
from test_suit . test_utils import parsePrivateKey , RetryableError

from cloud_platform import CloudPlatform

Expand Down Expand Up @@ -57,8 +57,7 @@ def __init__(self, kafkaAddress, schemaRegistryAddress, kafkaConnectAddress, cre
testDatabase = credentialJson["database"]
testSchema = credentialJson["schema"]
testWarehouse = credentialJson["warehouse"]
pk = credentialJson["encrypted_private_key"]
pk_passphrase = credentialJson["private_key_passphrase"]
pk = credentialJson["private_key"]

self.TEST_DATA_FOLDER = "./test_data/"
self.httpHeader = {'Content-type': 'application/json', 'Accept': 'application/json'}
Expand Down Expand Up @@ -103,10 +102,9 @@ def __init__(self, kafkaAddress, schemaRegistryAddress, kafkaConnectAddress, cre
print(datetime.now().strftime("%H:%M:%S "),
"Format error in 'host' field at profile.json, expecting account.snowflakecomputing.com:443")

pkb = parsePrivateKey(pk, pk_passphrase)
self.snowflake_conn = snowflake.connector.connect(
user=testUser,
private_key=pkb,
private_key= parsePrivateKey(pk),
account=account[0][:-19],
warehouse=testWarehouse,
database=testDatabase,
Expand Down Expand Up @@ -399,8 +397,6 @@ def createConnector(self, fileName, nameSalt):
testDatabase = credentialJson["database"]
testSchema = credentialJson["schema"]
pk = credentialJson["private_key"]
# Use Encrypted key if passphrase is non empty
pkEncrypted = credentialJson["encrypted_private_key"]

print(datetime.now().strftime("\n%H:%M:%S "),
"=== generate sink connector rest request from {} ===".format(rest_template_path))
Expand All @@ -413,9 +409,6 @@ def createConnector(self, fileName, nameSalt):
"=== Connector Config JSON: {}, Connector Name: {} ===".format(fileName, snowflake_connector_name))
with open("{}/{}".format(rest_template_path, fileName), 'r') as f:
fileContent = f.read()
# Template has passphrase, use the encrypted version of P8 Key
if fileContent.find("snowflake.private.key.passphrase") != -1:
pk = pkEncrypted

fileContent = fileContent \
.replace("SNOWFLAKE_PRIVATE_KEY", pk) \
Expand Down

0 comments on commit dc8d9d4

Please sign in to comment.