Skip to content

Commit 8f46234

Browse files
committed
Move authenticators to settings and call as such
1 parent 202d43a commit 8f46234

File tree

7 files changed

+27
-21
lines changed

7 files changed

+27
-21
lines changed

tiled/_tests/test_access_control.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def context(tmpdir_module):
7676
config = {
7777
"allow_anonymous_access": True,
7878
"secret_keys": ["SECRET"],
79-
"providers": [
79+
"authenticators": [
8080
{
8181
"provider": "toy",
8282
"authenticator": "tiled.authenticators:DictionaryAuthenticator",
@@ -355,7 +355,7 @@ def test_service_principal_access(tmpdir):
355355
"Test that a service principal can work with SimpleAccessPolicy."
356356
config = {
357357
"secret_keys": ["SECRET"],
358-
"providers": [
358+
"authenticators": [
359359
{
360360
"provider": "toy",
361361
"authenticator": "tiled.authenticators:DictionaryAuthenticator",

tiled/_tests/test_authentication.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def config(sqlite_or_postgresql_database_uri):
4040
)
4141
return {
4242
"secret_keys": ["SECRET"],
43-
"providers": [
43+
"authenticators": [
4444
{
4545
"provider": "toy",
4646
"authenticator": "tiled.authenticators:DictionaryAuthenticator",
@@ -256,7 +256,7 @@ def test_multiple_providers(enter_username_password, config, monkeypatch):
256256
257257
This mechanism is used to support "Login with ORCID or Google or ...."
258258
"""
259-
config["authentication"]["providers"].extend(
259+
config["authenticators"].extend(
260260
[
261261
{
262262
"provider": "second",
@@ -289,7 +289,7 @@ def test_multiple_providers_name_collision(config):
289289
"""
290290
Check that we enforce unique provider names.
291291
"""
292-
config["authentication"]["providers"] = [
292+
config["authenticators"] = [
293293
{
294294
"provider": "some_name",
295295
"authenticator": "tiled.authenticators:DictionaryAuthenticator",

tiled/_tests/test_catalog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ async def test_access_control(tmpdir):
372372
config = {
373373
"allow_anonymous_access": True,
374374
"secret_keys": ["SECRET"],
375-
"providers": [
375+
"authenticators": [
376376
{
377377
"provider": "toy",
378378
"authenticator": "tiled.authenticators:DictionaryAuthenticator",

tiled/_tests/test_openapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
tree = MapAdapter({})
1010
config = {
1111
"secret_keys": ["SECRET"],
12-
"providers": [
12+
"authenticators": [
1313
{
1414
"provider": "toy",
1515
"authenticator": "tiled.authenticators:DictionaryAuthenticator",

tiled/_tests/test_server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def multiuser_server(tmpdir):
8989
)
9090
config = {
9191
"secret_keys": ["SECRET"],
92-
"providers": [
92+
"authenticators": [
9393
{
9494
"provider": "toy",
9595
"authenticator": "tiled.authenticators:DictionaryAuthenticator",
@@ -152,17 +152,17 @@ def test_internal_authentication_mode_with_password_clients(multiuser_server):
152152
response = httpx.get(
153153
multiuser_server + "/api/v1/", headers={"user-agent": "python-tiled/0.1.0b16"}
154154
)
155-
actual_mode = response.json()["authentication"]["providers"][0]["mode"]
155+
actual_mode = response.json()["authenticators"][0]["mode"]
156156
assert actual_mode == "password"
157157

158158
# Mock new client
159159
response = httpx.get(
160160
multiuser_server + "/api/v1/", headers={"user-agent": "python-tiled/0.1.0b17"}
161161
)
162-
actual_mode = response.json()["authentication"]["providers"][0]["mode"]
162+
actual_mode = response.json()["authenticators"][0]["mode"]
163163
assert actual_mode == "internal"
164164

165165
# Mock unknown client
166166
response = httpx.get(multiuser_server + "/api/v1/", headers={})
167-
actual_mode = response.json()["authentication"]["providers"][0]["mode"]
167+
actual_mode = response.json()["authenticators"][0]["mode"]
168168
assert actual_mode == "internal"

tiled/server/app.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,15 @@ def custom_openapi(app):
105105

106106

107107
def build_app(
108-
tree,
109-
authentication=None,
108+
tree: MapAdapter,
110109
server_settings: Optional[Settings] = None,
111110
query_registry: Optional[QueryRegistry] = None,
112111
serialization_registry: Optional[SerializationRegistry] = None,
113112
deserialization_registry: Optional[SerializationRegistry] = None,
114113
compression_registry: Optional[CompressionRegistry] = None,
115114
validation_registry: Optional[ValidationRegistry] = None,
116115
tasks=None,
117-
scalable=False,
116+
scalable: bool = False,
118117
):
119118
"""
120119
Serve a Tree
@@ -125,12 +124,7 @@ def build_app(
125124
server_settings: Settings, optional
126125
Dict of other server configuration.
127126
"""
128-
authentication = authentication or {}
129-
authenticators: dict[str, Union[ExternalAuthenticator, InternalAuthenticator]] = {
130-
spec["provider"]: spec["authenticator"]
131-
for spec in authentication.get("providers", [])
132-
}
133-
server_settings = server_settings or {}
127+
server_settings = server_settings or get_settings()
134128
query_registry = query_registry or default_query_registry
135129
serialization_registry = serialization_registry or default_serialization_registry
136130
deserialization_registry = (

tiled/server/settings.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77
from pydantic.dataclasses import dataclass
88
from pydantic_settings import BaseSettings, SettingsConfigDict
99

10+
from tiled.server.protocols import ExternalAuthenticator, InternalAuthenticator
11+
12+
13+
class Admin(BaseModel):
14+
provider: str
15+
id: str
16+
17+
18+
class AuthenticatorInfo(BaseModel):
19+
provider: str
20+
authenticator: InternalAuthenticator | ExternalAuthenticator
21+
1022

1123
# hashable cache key for use in tiled.authn_database.connection_pool
1224
@dataclass(unsafe_hash=True)
@@ -31,7 +43,7 @@ class Settings(BaseSettings):
3143
tree: Any = None
3244
allow_anonymous_access: bool = False
3345
allow_origins: List[str] = Field(default_factory=list)
34-
authenticator: Any = None
46+
authenticators: list[AuthenticatorInfo] = Field(default_factory=list)
3547
# These 'single user' settings are only applicable if authenticator is None.
3648
single_user_api_key: str = secrets.token_hex(32)
3749
# The first key will be used for encryption. Each key will be tried in turn for decryption.

0 commit comments

Comments
 (0)