use correct authentication calls in store_record #239

Merged
cmo merged 2 commits from fix-auth-in-store into master 2026-06-29 07:18:58 +00:00
2 changed files with 6 additions and 24 deletions

View file

@ -430,17 +430,6 @@ def get_default_token_config(
return get_token_config_by_name(abstract_config, default_token_name) 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): def get_mapping_function(record_dir_backend_config: RecordDirBackendConfig):
return mapping_functions[MappingMethod(record_dir_backend_config.mapping_method)] return mapping_functions[MappingMethod(record_dir_backend_config.mapping_method)]

View file

@ -22,7 +22,6 @@ from starlette.responses import (
JSONResponse, JSONResponse,
PlainTextResponse, PlainTextResponse,
) )
from starlette.status import HTTP_401_UNAUTHORIZED
from dump_things_service import ( from dump_things_service import (
Format, Format,
@ -39,7 +38,6 @@ from dump_things_service.abstract_config import (
SQLiteBackendConfig, SQLiteBackendConfig,
read_config, read_config,
check_collection, check_collection,
get_default_token_representation,
) )
from dump_things_service.audit.gitaudit import GitAuditBackend from dump_things_service.audit.gitaudit import GitAuditBackend
from dump_things_service.auth.config import ConfigAuthenticationSource from dump_things_service.auth.config import ConfigAuthenticationSource
@ -554,27 +552,22 @@ def store_record(
abstract_config = read_config(instance_state.store_path) abstract_config = read_config(instance_state.store_path)
check_collection(abstract_config, collection) 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. # Get the token permissions and extend them by the default permissions.
# This call will also convert plaintext tokens into the hashed version of # 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 # 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 # store the plaintext token, so all token-information is associated with
# the hashed representation of the token. # 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( store, token_permissions, user_id = get_token_store(
abstract_config, abstract_config,
instance_state, instance_state,
collection, collection,
token_representation, token_representation,
is_token_name=api_key is None,
) )
final_permissions = join_default_token_permissions( final_permissions = join_default_token_permissions(
abstract_config, abstract_config,