From a102060e8e0db531f835550fa6c6a62e39b91f71 Mon Sep 17 00:00:00 2001 From: Hagen Wierstorf Date: Mon, 30 Sep 2024 15:35:51 +0200 Subject: [PATCH] Add support for owner() --- audbackend/core/backend/minio.py | 27 +++++++++++++++++++++++---- tests/conftest.py | 5 ----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/audbackend/core/backend/minio.py b/audbackend/core/backend/minio.py index 408c92c0..05b3e5da 100644 --- a/audbackend/core/backend/minio.py +++ b/audbackend/core/backend/minio.py @@ -1,4 +1,5 @@ import configparser +import getpass import os import tempfile import typing @@ -212,6 +213,7 @@ def _copy_file( self.repository, dst_path, minio.commonconfig.CopySource(self.repository, src_path), + metadata=_metadata(), ) def _create( @@ -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( @@ -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 @@ -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()} diff --git a/tests/conftest.py b/tests/conftest.py index 3395d5e2..9598f5c4 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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"