Skip to content

Commit

Permalink
Metadata blacklist (#279)
Browse files Browse the repository at this point in the history
* bugfix blacklist=None and add respecting blacklist

* adding how to circumvent blacklisting

* Update docs/source/faq.rst

Co-authored-by: qubixes <44498096+qubixes@users.noreply.github.com>

* refined

---------

Co-authored-by: qubixes <44498096+qubixes@users.noreply.github.com>
  • Loading branch information
chStaiger and qubixes authored Oct 31, 2024
1 parent 2258a4b commit ad70ef4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 16 additions & 3 deletions docs/source/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,23 @@ Warnings can also be switched off through python's `warnings` package:

.. code-block:: python
import warnings
warnings.filterwarnings("ignore")
import warnings
warnings.filterwarnings("ignore")
**My metadata with keys starting with `org_` do not show up in the iBridges metadata.**
---------------------------------------------------------------------------------------

iBridges **does not show** metadata that contain a key starting with the prefix `org_`. This is due to data security reasons on `Yoda systems <https://github.com/iBridges-for-iRODS/yoda>`__.
By default, iBridges **does not show** metadata that contain a key starting with the prefix `org_`. This is due to data security reasons on `Yoda systems <https://github.com/UtrechtUniversity/yoda>`__.

You can omit this by the following code:

.. code-block:: python
from ibridges.meta import MetaData
# collections
meta = MetaData(IrodsPath(session, "~", "my_coll").collection, blacklist=None)
# data objects
meta = MetaData(IrodsPath(session, "~", "my_obj").dataobject, blacklist=None)
print(meta)
6 changes: 5 additions & 1 deletion ibridges/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ def __iter__(self) -> Iterator:
"""Iterate over all metadata key/value/units triplets."""
if self.blacklist is None:
yield from self.item.metadata.items()
return
for meta in self.item.metadata.items():
if re.match(self.blacklist, meta.name) is None:
if self.blacklist and re.match(self.blacklist, meta.name) is None:
yield meta
else:
warnings.warn(f"Ignoring metadata entry with value {meta.name}, because it matches "
Expand Down Expand Up @@ -148,6 +149,9 @@ def add(self, key: str, value: str, units: Optional[str] = None):
try:
if (key, value, units) in self:
raise ValueError("ADD META: Metadata already present")
if self.blacklist:
if re.match(self.blacklist, key):
raise ValueError(f"ADD META: Key must not start with {self.blacklist}.")
self.item.metadata.add(key, value, units)
except irods.exception.CAT_NO_ACCESS_PERMISSION as error:
raise PermissionError("UPDATE META: no permissions") from error
Expand Down

0 comments on commit ad70ef4

Please sign in to comment.