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

feat(filesystem): use only netloc and scheme for fingerprint #1516

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 13 additions & 2 deletions dlt/common/storages/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,19 @@ def resolve_credentials_type(self) -> Type[CredentialsConfiguration]:
return self.PROTOCOL_CREDENTIALS.get(self.protocol) or Optional[CredentialsConfiguration] # type: ignore[return-value]

def fingerprint(self) -> str:
"""Returns a fingerprint of bucket_url"""
return digest128(self.bucket_url) if self.bucket_url else ""
"""Returns a fingerprint of bucket schema and netloc.

Returns:
str: Fingerprint.
"""
if not self.bucket_url:
return ""

if self.is_local_path(self.bucket_url):
return digest128("")

uri = urlparse(self.bucket_url)
return digest128(self.bucket_url.replace(uri.path, ""))

def __str__(self) -> str:
"""Return displayable destination location"""
Expand Down
16 changes: 11 additions & 5 deletions tests/load/filesystem/test_filesystem_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,17 @@ def logger_autouse() -> None:
]


def test_filesystem_destination_configuration() -> None:
assert FilesystemDestinationClientConfiguration().fingerprint() == ""
assert FilesystemDestinationClientConfiguration(
bucket_url="s3://cool"
).fingerprint() == digest128("s3://cool")
@pytest.mark.parametrize(
"url, exp",
(
(None, ""),
("/path/path2", digest128("")),
("s3://cool", digest128("s3://cool")),
("s3://cool.domain/path/path2", digest128("s3://cool.domain")),
),
)
def test_filesystem_destination_configuration(url, exp) -> None:
assert FilesystemDestinationClientConfiguration(bucket_url=url).fingerprint() == exp


def test_filesystem_factory_buckets(with_gdrive_buckets_env: str) -> None:
Expand Down
Loading