diff --git a/dump_things_service/abstract_config.py b/dump_things_service/abstract_config.py index 9f79bb6..384d90c 100644 --- a/dump_things_service/abstract_config.py +++ b/dump_things_service/abstract_config.py @@ -430,17 +430,6 @@ def get_default_token_config( return get_token_config_by_name(abstract_config, default_token_name) -def get_default_token_representation( - abstract_config: Configuration, - collection: str, -) -> str | None: - default_token_config = get_default_token_config( - abstract_config, - collection, - ) - return default_token_config.representation if default_token_config else None - - def get_mapping_function(record_dir_backend_config: RecordDirBackendConfig): return mapping_functions[MappingMethod(record_dir_backend_config.mapping_method)] diff --git a/dump_things_service/collection.py b/dump_things_service/collection.py index 1ef648d..d670cbc 100644 --- a/dump_things_service/collection.py +++ b/dump_things_service/collection.py @@ -22,7 +22,6 @@ from starlette.responses import ( JSONResponse, PlainTextResponse, ) -from starlette.status import HTTP_401_UNAUTHORIZED from dump_things_service import ( Format, @@ -39,7 +38,6 @@ from dump_things_service.abstract_config import ( SQLiteBackendConfig, read_config, check_collection, - get_default_token_representation, ) from dump_things_service.audit.gitaudit import GitAuditBackend from dump_things_service.auth.config import ConfigAuthenticationSource @@ -554,27 +552,22 @@ def store_record( abstract_config = read_config(instance_state.store_path) check_collection(abstract_config, collection) - token_representation = get_default_token_representation( - abstract_config, - collection, - ) if api_key is None else api_key - - if not token_representation: - raise HTTPException( - status_code=HTTP_401_UNAUTHORIZED, - detail=f'Not authorized to submit to collection "{collection}"', - ) - # Get the token permissions and extend them by the default permissions. # This call will also convert plaintext tokens into the hashed version of # the token, if the token is hashed. This is necessary because we do not # store the plaintext token, so all token-information is associated with # the hashed representation of the token. + token_representation = ( + abstract_config.collections[collection].default_token + if api_key is None + else api_key + ) store, token_permissions, user_id = get_token_store( abstract_config, instance_state, collection, token_representation, + is_token_name=api_key is None, ) final_permissions = join_default_token_permissions( abstract_config,