From ebc0d84a1dc9e9acb64444916db845d52fc5e5ad Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sat, 30 Nov 2024 04:04:33 -0500 Subject: [PATCH 1/3] do not apply security to WCMP2 records on API (#775) --- wis2box-management/wis2box/auth.py | 39 +----------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/wis2box-management/wis2box/auth.py b/wis2box-management/wis2box/auth.py index 6d4f4696..0728e875 100644 --- a/wis2box-management/wis2box/auth.py +++ b/wis2box-management/wis2box/auth.py @@ -24,12 +24,9 @@ import requests from secrets import token_hex -from owslib.ogcapi.records import Records - from wis2box import cli_helpers -from wis2box.api import upsert_collection_item from wis2box.data_mappings import get_data_mappings -from wis2box.env import AUTH_URL, DOCKER_API_URL +from wis2box.env import AUTH_URL LOGGER = logging.getLogger(__name__) @@ -173,27 +170,6 @@ def add_token(ctx, metadata_id, path, yes, token): if create_token(path, token): click.echo('Token successfully created') - if metadata_id is not None: - click.echo('Adding access control object to discovery metadata') - - oar = Records(DOCKER_API_URL) - - 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) - @click.command() @click.pass_context @@ -216,19 +192,6 @@ def remove_token(ctx, metadata_id, path, token): if delete_token(path, token): click.echo('Token successfully deleted') - if metadata_id is not None: - click.echo('Removing access control object to discovery metadata') - - oar = Records(DOCKER_API_URL) - - 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) - auth.add_command(add_token) auth.add_command(remove_token) From 97593a657bf369bf13d024169e93293353cc24af Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sat, 30 Nov 2024 04:06:30 -0500 Subject: [PATCH 2/3] do not apply security to WCMP2 records on API (#775) --- tests/integration/test_workflow.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/integration/test_workflow.py b/tests/integration/test_workflow.py index 176cbd59..25d6a8a8 100644 --- a/tests/integration/test_workflow.py +++ b/tests/integration/test_workflow.py @@ -205,11 +205,6 @@ def test_metadata_discovery_publish(): 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""" From a9c00a25eccbad6117ef036a3a66c3e687b9987a Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Mon, 16 Dec 2024 09:46:34 -0500 Subject: [PATCH 3/3] always remove links added by API --- wis2box-management/wis2box/auth.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/wis2box-management/wis2box/auth.py b/wis2box-management/wis2box/auth.py index 0728e875..e6f51ffd 100644 --- a/wis2box-management/wis2box/auth.py +++ b/wis2box-management/wis2box/auth.py @@ -24,9 +24,12 @@ import requests from secrets import token_hex +from owslib.ogcapi.records import Records + from wis2box import cli_helpers +from wis2box.api import upsert_collection_item from wis2box.data_mappings import get_data_mappings -from wis2box.env import AUTH_URL +from wis2box.env import AUTH_URL, DOCKER_API_URL LOGGER = logging.getLogger(__name__) @@ -170,6 +173,18 @@ def add_token(ctx, metadata_id, path, yes, token): if create_token(path, token): click.echo('Token successfully created') + if metadata_id is not None: + click.echo('Adding access control object to discovery metadata') + + oar = Records(DOCKER_API_URL) + + record = oar.collection_item('discovery-metadata', metadata_id) + record['wis2box']['has_auth'] = True + + del record['links'][-6:] + + upsert_collection_item('discovery-metadata', record) + @click.command() @click.pass_context @@ -192,6 +207,18 @@ def remove_token(ctx, metadata_id, path, token): if delete_token(path, token): click.echo('Token successfully deleted') + if metadata_id is not None: + click.echo('Removing access control object to discovery metadata') + + oar = Records(DOCKER_API_URL) + + record = oar.collection_item('discovery-metadata', metadata_id) + record['wis2box'].pop('has_auth', None) + + del record['links'][-6:] + + upsert_collection_item('discovery-metadata', record) + auth.add_command(add_token) auth.add_command(remove_token)