diff --git a/dump_things_service/commands/download_config.py b/dump_things_service/commands/download_config.py index 4c35271..f63b098 100644 --- a/dump_things_service/commands/download_config.py +++ b/dump_things_service/commands/download_config.py @@ -4,8 +4,6 @@ import json import os import sys from argparse import ArgumentParser -from itertools import count -from pathlib import Path import requests import yaml @@ -53,6 +51,11 @@ def main(): else ['admin_tokens', 'collections', 'tokens'] ) + if arguments.server_api.endswith('/'): + server_api = arguments.server_api[:-1] + else: + server_api = arguments.server_api + admin_token = os.environ.get('DTS_ADMIN_TOKEN') if not admin_token: print( @@ -63,7 +66,7 @@ def main(): return 1 configuration = get_configuration( - arguments.server_api, + server_api, admin_token, entities, ) @@ -167,7 +170,7 @@ def _get_data( ) -> list: result = requests.get(url, headers={'x-dumpthings-token': token}) if result.status_code >= 300: - msg = f'Error downloading {content_class}: {result.text}' + msg = f'Error downloading {content_class} from {url}: {result.text}' raise RuntimeError(msg) return result.json() diff --git a/dump_things_service/tests/test_collection_administration.py b/dump_things_service/tests/test_collection_administration.py index f98b02a..5dc2f39 100644 --- a/dump_things_service/tests/test_collection_administration.py +++ b/dump_things_service/tests/test_collection_administration.py @@ -122,6 +122,8 @@ def test_collection_adding(fastapi_client_simple): 'name': new_token_request.name, 'user_id': new_token_request.user_id, 'collections': new_token_request.model_dump(mode='json')['collections'], + 'hashed': new_token_request.hashed, + 'representation': new_token_request.representation } new_record = { diff --git a/dump_things_service/token_endpoints.py b/dump_things_service/token_endpoints.py index 59822d9..06d2d0f 100644 --- a/dump_things_service/token_endpoints.py +++ b/dump_things_service/token_endpoints.py @@ -1,7 +1,6 @@ import logging import random import re -from os import name from urllib.parse import quote from fastapi import ( @@ -205,7 +204,7 @@ def create_or_replace_token( ) async def get_tokens( api_key: str = Depends(api_key_header_scheme), -) -> list[TokenResponse]: +) -> list[TokenRequest]: instance_state = get_instance_state() abstract_config = read_config(store_path=instance_state.store_path) @@ -213,10 +212,12 @@ async def get_tokens( authenticate_admin(instance_state, abstract_config, api_key) return [ - TokenResponse( + TokenRequest( name=n, user_id=t.user_id, collections=t.collections, + hashed=t.hashed, + representation=t.representation, ) for n, t in abstract_config.tokens.items() ] @@ -230,7 +231,7 @@ async def get_tokens( async def get_token_with_name( token_name: str, api_key: str = Depends(api_key_header_scheme), -) -> TokenResponse: +) -> TokenRequest: instance_state = get_instance_state() abstract_config = get_config() @@ -243,10 +244,12 @@ async def get_token_with_name( raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail=detail) t = abstract_config.tokens[token_name] - return TokenResponse( + return TokenRequest( name=token_name, user_id=t.user_id, collections=t.collections, + hashed=t.hashed, + representation=t.representation, ) @@ -320,7 +323,7 @@ def create_or_replace_admin_token( if body.name == '__bootstrap__': raise HTTPException( status_code=HTTP_409_CONFLICT, - detail=f"The admin token name '{body.name}' is reserved and cannot be used.", + detail=f"The admin token name '{body.name}' is reserved and cannot be used", ) # Check for token content @@ -389,11 +392,6 @@ async def get_admin_token( } ] ) - return list(abstract_config.admin_tokens) + ( - [] - if instance_state.bootstrap_token is None - else ['__bootstrap__'] - ) @router.delete(