Skip to content

Commit bb1e9d5

Browse files
authored
fix: Fail early if private_key_path doesn't exist (#326)
This pull request includes an important update to the `get_private_key` method in the `target_snowflake/connector.py` file. The changes enhance logging and error handling when reading the private key from a file. Enhancements to logging and error handling: * Added a debug log statement to indicate when the private key is being read from a file. * Introduced a check to verify if the private key file exists before attempting to read it, raising a `FileNotFoundError` with a descriptive error message if the file is not found.
1 parent 1dd2f17 commit bb1e9d5

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

target_snowflake/connector.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,13 @@ def get_private_key(self):
120120
phrase = self.config.get("private_key_passphrase")
121121
encoded_passphrase = phrase.encode() if phrase else None
122122
if "private_key_path" in self.config:
123-
with Path(self.config["private_key_path"]).open("rb") as key:
124-
key_content = key.read()
123+
self.logger.debug("Reading private key from file: %s", self.config["private_key_path"])
124+
key_path = Path(self.config["private_key_path"])
125+
if not key_path.is_file():
126+
error_message = f"Private key file not found: {key_path}"
127+
raise FileNotFoundError(error_message)
128+
with key_path.open("rb") as key_file:
129+
key_content = key_file.read()
125130
else:
126131
key_content = self.config["private_key"].encode()
127132

0 commit comments

Comments
 (0)