Skip to content

Commit

Permalink
add security to WCMP2 output
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Aug 22, 2024
1 parent 1a39be1 commit b553050
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/integration/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,17 @@ def test_metadata_discovery_publish():
r = r.json()
assert r['conformsTo'][0] == 'http://wis.wmo.int/spec/wcmp/2/conf/core'

r = SESSION.get(f'{API_URL}/collections/discovery-metadata/items/urn:wmo:md:cd-brazza_met_centre:surface-weather-observations').json() # noqa
id_ = 'urn:wmo:md:cd-brazza_met_centre:surface-weather-observations'
r = SESSION.get(f'{API_URL}/collections/discovery-metadata/items/{id_}').json() # noqa

assert 'has_auth' in r['wis2box']
assert r['wis2box']['has_auth']

for link in r['links']:
if link['rel'] == 'collection' and link['title'] == id_:
assert link['security']['default']['type'] == 'http'
assert link['security']['default']['scheme'] == 'bearer'


def test_data_ingest():
"""Test data ingest/process publish"""
Expand Down
14 changes: 14 additions & 0 deletions wis2box-management/wis2box/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ def add_token(ctx, metadata_id, path, yes, token):
record = oar.collection_item('discovery-metadata', metadata_id)
record['wis2box']['has_auth'] = True

for link in record['links']:
if link['rel'] == 'collection' and link['title'] == metadata_id:
LOGGER.debug('Adding security object to link')
link['security'] = {
'default': {
'type': 'http',
'scheme': 'bearer',
'description': 'Please contact the data provider for access' # noqa
}
}

upsert_collection_item('discovery-metadata', record)


Expand Down Expand Up @@ -212,6 +223,9 @@ def remove_token(ctx, metadata_id, path, token):

record = oar.collection_item('discovery-metadata', metadata_id)
record['wis2box'].pop('has_auth', None)
for link in record['links']:
if 'security' in link:
link.pop('security', None)

upsert_collection_item('discovery-metadata', record)

Expand Down

0 comments on commit b553050

Please sign in to comment.