Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1296805 Remove option tmpdir from SnowflakeEncryptionUtil.decrypt_file #1987

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/snowflake/connector/encryption_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,23 @@ def decrypt_file(
encryption_material: SnowflakeFileEncryptionMaterial,
in_filename: str,
chunk_size: int = 64 * kilobyte,
tmp_dir: str | None = None,
) -> str:
"""Decrypts a file and stores the output in the temporary directory.
"""Decrypts a file and stores the output in the same dierctory of the incoming file.
sfc-gh-stan marked this conversation as resolved.
Show resolved Hide resolved

Args:
metadata: The file's metadata input.
encryption_material: The file's encryption material.
in_filename: The name of the input file.
chunk_size: The size of read chunks (Default value = block_size * 4 * 1024).
tmp_dir: Temporary directory to use, optional (Default value = None).

Returns:
The decrypted file's location.
"""
temp_output_file = f"{os.path.basename(in_filename)}#{random_string()}"
if tmp_dir:
temp_output_file = os.path.join(tmp_dir, temp_output_file)
# writing in same directory as in_filename
temp_output_file = os.path.join(
os.path.dirname(in_filename),
f"{os.path.basename(in_filename)}#{random_string()}",
)

logger.debug("encrypted file: %s, tmp file: %s", in_filename, temp_output_file)
with open(in_filename, "rb") as infile:
Expand Down
1 change: 0 additions & 1 deletion src/snowflake/connector/storage_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ def finish_download(self) -> None:
self.encryption_metadata,
meta.encryption_material,
str(self.intermediate_dst_path),
tmp_dir=self.tmp_dir,
)
shutil.move(tmp_dst_file_name, self.full_dst_file_name)
self.intermediate_dst_path.unlink()
Expand Down
6 changes: 3 additions & 3 deletions test/unit/test_encryption_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_encrypt_decrypt_file(tmp_path):
encryption_material, input_file, tmp_dir=str(tmp_path)
)
decrypted_file = SnowflakeEncryptionUtil.decrypt_file(
metadata, encryption_material, encrypted_file, tmp_dir=str(tmp_path)
metadata, encryption_material, encrypted_file
)

contents = ""
Expand Down Expand Up @@ -98,10 +98,10 @@ def test_encrypt_decrypt_large_file(tmpdir):
)

(metadata, encrypted_file) = SnowflakeEncryptionUtil.encrypt_file(
encryption_material, input_file, tmp_dir=str(tmpdir)
encryption_material, input_file
)
decrypted_file = SnowflakeEncryptionUtil.decrypt_file(
metadata, encryption_material, encrypted_file, tmp_dir=str(tmpdir)
metadata, encryption_material, encrypted_file
)

digest_dec, size_dec = SnowflakeFileUtil.get_digest_and_size_for_file(
Expand Down
Loading