From 6991214fc2a16a9b94398fe13d2ee8a5ff770c2e Mon Sep 17 00:00:00 2001 From: Christian Monch Date: Fri, 26 Jun 2026 12:33:21 +0200 Subject: [PATCH 1/2] use correct authentication calls in `store_record` This commit fixes a bug where collection writes with a hashed default token would fail. --- dump_things_service/collection.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) 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, -- 2.52.0 From 6f00f3e26d1fef2a7d218dd5215b8dda94a854ab Mon Sep 17 00:00:00 2001 From: Christian Monch Date: Fri, 26 Jun 2026 12:38:38 +0200 Subject: [PATCH 2/2] remove unused code --- dump_things_service/abstract_config.py | 11 ----------- 1 file changed, 11 deletions(-) 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)] -- 2.52.0