Skip to content

Commit

Permalink
Add support for owner()
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Sep 30, 2024
1 parent 1005c6b commit a102060
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
27 changes: 23 additions & 4 deletions audbackend/core/backend/minio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import configparser
import getpass
import os
import tempfile
import typing
Expand Down Expand Up @@ -212,6 +213,7 @@ def _copy_file(
self.repository,
dst_path,
minio.commonconfig.CopySource(self.repository, src_path),
metadata=_metadata(),
)

def _create(
Expand Down Expand Up @@ -329,9 +331,11 @@ def _owner(
) -> str:
r"""Get owner of file on backend."""
path = self.path(path)
# TODO: owner seems to be empty,
# need to check if we have to manage this ourselves?
owner = self._client.stat_object(self.repository, path).owner_name
# NOTE:
# we use a custom metadata entry to track the owner
# as stats.owner_name is always empty.
stats = self._client.stat_object(self.repository, path)
owner = stats.metadata["x-amz-meta-owner"]
return owner

def path(
Expand Down Expand Up @@ -369,7 +373,12 @@ def _put_file(
)
print(desc, end="\r")

self._client.fput_object(self.repository, dst_path, src_path)
self._client.fput_object(
self.repository,
dst_path,
src_path,
metadata=_metadata(),
)

if verbose: # pragma: no cover
# Clear progress line
Expand All @@ -391,3 +400,13 @@ def _size(
path = self.path(path)
size = self._client.stat_object(self.repository, path).size
return size


def _metadata():
"""Dictionary with owner entry.
When uploaded as metadata to MinIO,
it can be accessed under ``stat_object(...).metadata["x-amz-meta-owner"]``.
"""
return {"owner": getpass.getuser()}
5 changes: 0 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ def owner(request):
):
host_wo_https = pytest.HOSTS["artifactory"][8:]
owner = backend_cls.get_authentication(host_wo_https)[0]
elif (
hasattr(audbackend.backend, "Minio") and backend_cls == audbackend.backend.Minio
):
# There seems to be a MinIO bug here
owner = None
else:
if os.name == "nt":
owner = "Administrators"
Expand Down

0 comments on commit a102060

Please sign in to comment.