Skip to content

Commit

Permalink
Merge pull request #40 from materials-data-facility/toolbox-dev
Browse files Browse the repository at this point in the history
URN formatting for Search
  • Loading branch information
jgaff authored Apr 9, 2019
2 parents d806e7e + b707b63 commit 2a4ac2b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
16 changes: 15 additions & 1 deletion mdf_toolbox/toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ def format_gmeta(data, acl=None, identifier=None):
acl (list of str): The list of Globus UUIDs allowed to view the document,
or the special value ``["public"]`` to allow anyone access.
Required if data is a dict. Ignored if data is a list.
Will be formatted into URNs if required.
identifier (str): A unique identifier for this document. If this value is not unique,
ingests into Globus Search may merge entries.
Required is data is a dict. Ignored if data is a list.
Expand All @@ -501,11 +502,24 @@ def format_gmeta(data, acl=None, identifier=None):
raise ValueError("acl and identifier are required when formatting a GMetaEntry.")
if isinstance(acl, str):
acl = [acl]
# "Correctly" format ACL entries into URNs
prefixed_acl = []
for uuid in acl:
# If entry is not special value "public" and is not a URN, make URN
# It is not known what the type of UUID is, so use both
# This solution is known to be hacky
if uuid != "public" and not uuid.lower().startswith("urn:"):
prefixed_acl.append("urn:globus:auth:identity:"+uuid.lower())
prefixed_acl.append("urn:globus:groups:id:"+uuid.lower())
# Otherwise, no modification
else:
prefixed_acl.append(uuid)

return {
"@datatype": "GMetaEntry",
"@version": "2016-11-09",
"subject": identifier,
"visible_to": acl,
"visible_to": prefixed_acl,
"content": data
}

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='mdf_toolbox',
version='0.4.3',
version='0.4.4',
packages=['mdf_toolbox'],
description='Materials Data Facility Python utilities',
long_description=("Toolbox is the Materials Data Facility Python package"
Expand Down
4 changes: 2 additions & 2 deletions tests/test_toolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ def test_format_gmeta():
}
}
}
gme2 = mdf_toolbox.format_gmeta(md2, ["ABCD"], "https://example.com/123456")
gme2 = mdf_toolbox.format_gmeta(md2, ["abcd"], "https://example.com/123456")
assert gme2 == {
"@datatype": "GMetaEntry",
"@version": "2016-11-09",
"subject": "https://example.com/123456",
"visible_to": ["ABCD"],
"visible_to": ["urn:globus:auth:identity:abcd", "urn:globus:groups:id:abcd"],
"content": {
"mdf": {
"title": "test",
Expand Down

0 comments on commit 2a4ac2b

Please sign in to comment.