3
3
4
4
import pydantic_settings
5
5
from fastapi import Depends , HTTPException , Query , Request , Security
6
+ from fastapi .security import SecurityScopes
6
7
from starlette .status import HTTP_403_FORBIDDEN , HTTP_404_NOT_FOUND
7
8
9
+ from tiled .adapters .mapping import MapAdapter
10
+ from tiled .structures .core import StructureFamily
11
+
8
12
from ..media_type_registration import (
9
13
default_deserialization_registry ,
10
14
default_serialization_registry ,
11
15
)
12
16
from ..query_registration import default_query_registry
13
17
from ..validation_registration import default_validation_registry
14
- from .authentication import get_current_principal , get_session_state
18
+ from .authentication import check_scopes , get_current_principal , get_session_state
15
19
from .core import NoEntry
16
20
from .utils import filter_for_access , record_timing
17
21
@@ -53,14 +57,16 @@ def get_root_tree():
53
57
)
54
58
55
59
56
- def SecureEntry ( scopes , structure_families = None ):
60
+ def get_entry ( structure_families : Optional [ set [ StructureFamily ]] = None ):
57
61
async def inner (
58
62
path : str ,
59
63
request : Request ,
64
+ security_scopes : SecurityScopes ,
60
65
principal : str = Depends (get_current_principal ),
61
66
root_tree : pydantic_settings .BaseSettings = Depends (get_root_tree ),
62
67
session_state : dict = Depends (get_session_state ),
63
- ):
68
+ _ = Security (check_scopes )
69
+ ) -> MapAdapter :
64
70
"""
65
71
Obtain a node in the tree from its path.
66
72
@@ -131,7 +137,7 @@ async def inner(
131
137
allowed_scopes = await access_policy .allowed_scopes (
132
138
entry_with_access_policy , principal , path_parts_relative
133
139
)
134
- if not set (scopes ).issubset (allowed_scopes ):
140
+ if not set (security_scopes . scopes ).issubset (allowed_scopes ):
135
141
if "read:metadata" not in allowed_scopes :
136
142
# If you can't read metadata, it does not exist for you.
137
143
raise NoEntry (path_parts )
@@ -142,7 +148,7 @@ async def inner(
142
148
status_code = HTTP_403_FORBIDDEN ,
143
149
detail = (
144
150
"Not enough permissions to perform this action on this node. "
145
- f"Requires scopes { scopes } . "
151
+ f"Requires scopes { security_scopes . scopes } . "
146
152
f"Principal had scopes { list (allowed_scopes )} on this node."
147
153
),
148
154
)
@@ -164,7 +170,7 @@ async def inner(
164
170
),
165
171
)
166
172
167
- return Security ( inner , scopes = scopes )
173
+ return inner
168
174
169
175
170
176
def block (
0 commit comments