Skip to content

Commit

Permalink
SNOW-1728000 Go back to previous config
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mbobowski committed Nov 7, 2024
1 parent 146a659 commit 24e7a89
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Binary file modified .github/scripts/profile.json.gpg
Binary file not shown.
12 changes: 8 additions & 4 deletions test/test_suit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,26 @@ def __init__(self, msg=""):
self.msg = msg


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

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

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

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

Expand Down
11 changes: 9 additions & 2 deletions test/test_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ def __init__(self, kafkaAddress, schemaRegistryAddress, kafkaConnectAddress, cre
testDatabase = credentialJson["database"]
testSchema = credentialJson["schema"]
testWarehouse = credentialJson["warehouse"]
pk = credentialJson["private_key"]
pk = credentialJson["encrypted_private_key"]
pk_passphrase = credentialJson["private_key_passphrase"]

self.TEST_DATA_FOLDER = "./test_data/"
self.httpHeader = {'Content-type': 'application/json', 'Accept': 'application/json'}
Expand Down Expand Up @@ -102,9 +103,10 @@ 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= parsePrivateKey(pk),
private_key=pkb,
account=account[0][:-19],
warehouse=testWarehouse,
database=testDatabase,
Expand Down Expand Up @@ -397,6 +399,8 @@ 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 @@ -409,6 +413,9 @@ 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 24e7a89

Please sign in to comment.