From 23a1dd9549a26cc649f51f6eb8027aa450417f1d Mon Sep 17 00:00:00 2001 From: ILCDIRAC Date: Wed, 31 Jul 2024 09:25:00 +0200 Subject: [PATCH] feat(FC): Add function getFileUserMetadata to get user metadata for list of lfns add DB internal getFileDetailsPublic to add permission check before getFileDetails --- .../DataManagementSystem/DB/FileCatalogDB.py | 17 +++++++++++++++++ .../Service/FileCatalogHandler.py | 6 ++++++ .../Resources/Catalog/FileCatalogClient.py | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/src/DIRAC/DataManagementSystem/DB/FileCatalogDB.py b/src/DIRAC/DataManagementSystem/DB/FileCatalogDB.py index 92f8ac056ea..6ce5a569ef2 100755 --- a/src/DIRAC/DataManagementSystem/DB/FileCatalogDB.py +++ b/src/DIRAC/DataManagementSystem/DB/FileCatalogDB.py @@ -769,6 +769,23 @@ def getFileDescendents(self, lfns, depths, credDict): successful = res["Value"]["Successful"] return S_OK({"Successful": successful, "Failed": failed}) + def getFileDetailsPublic(self, lfns, credDict): + """Return all the metadata, including user defined, for those lfns that exist. + + :return: S_OK with a dictionary of LFNs to detailed information + """ + + res = self._checkPathPermissions("getFileMetadata", lfns, credDict) + if not res["OK"]: + return res + failed = res["Value"]["Failed"] + + # if no successful, just return empty dict + if not res["Value"]["Successful"]: + return S_OK({}) + + return self.getFileDetails(res["Value"]["Successful"], credDict) + def getFileDetails(self, lfnList, credDict): """Get all the metadata for the given files""" connection = False diff --git a/src/DIRAC/DataManagementSystem/Service/FileCatalogHandler.py b/src/DIRAC/DataManagementSystem/Service/FileCatalogHandler.py index 3a0995ac6c3..75a00b6f420 100644 --- a/src/DIRAC/DataManagementSystem/Service/FileCatalogHandler.py +++ b/src/DIRAC/DataManagementSystem/Service/FileCatalogHandler.py @@ -261,6 +261,12 @@ def export_getFileMetadata(self, lfns): """Get the metadata associated to supplied lfns""" return self.fileCatalogDB.getFileMetadata(lfns, self.getRemoteCredentials()) + types_getFileUserMetadata = [[list, dict, str]] + + def export_getFileUserMetadata(self, lfns): + """Get all the metadata associated to supplied lfns, including user metadata""" + return self.fileCatalogDB.getFileDetailsPublic(lfns, self.getRemoteCredentials()) + types_getReplicas = [[list, dict, str], bool] def export_getReplicas(self, lfns, allStatus=False): diff --git a/src/DIRAC/Resources/Catalog/FileCatalogClient.py b/src/DIRAC/Resources/Catalog/FileCatalogClient.py index ddd4fbf755c..87aa7771980 100644 --- a/src/DIRAC/Resources/Catalog/FileCatalogClient.py +++ b/src/DIRAC/Resources/Catalog/FileCatalogClient.py @@ -18,6 +18,7 @@ class FileCatalogClient(FileCatalogClientBase): READ_METHODS = FileCatalogClientBase.READ_METHODS + [ "isFile", "getFileMetadata", + "getFileUserMetadata", "getReplicas", "getReplicaStatus", "getFileSize", @@ -472,6 +473,11 @@ def getFileMetadata(self, lfns, timeout=120): """Get the metadata associated to supplied lfns""" return self._getRPC(timeout=timeout).getFileMetadata(lfns) + @checkCatalogArguments + def getFileUserMetadata(self, lfns, timeout=120): + """Get the (user) metadata associated to supplied lfns""" + return self._getRPC(timeout=timeout).getFileUserMetadata(lfns) + @checkCatalogArguments def getReplicaStatus(self, lfns, timeout=120): """Get the status for the supplied replicas"""