Skip to content

Commit

Permalink
always remove links added by API
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Dec 16, 2024
1 parent 97593a6 commit a9c00a2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion wis2box-management/wis2box/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit a9c00a2

Please sign in to comment.