mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 21:44:18 +02:00
Clean up settings
This commit is contained in:
parent
db18baa24f
commit
0824b3783d
3 changed files with 26 additions and 15 deletions
|
|
@ -1,15 +1,10 @@
|
|||
from enum import Enum
|
||||
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
from fastmcp.server.auth.providers.bearer import BearerAuthProvider
|
||||
|
||||
|
||||
class NotSet(Enum):
|
||||
sentinel = 0
|
||||
|
||||
|
||||
NOTSET = NotSet.sentinel
|
||||
class NotSet:
|
||||
pass
|
||||
|
||||
|
||||
class EnvBearerAuthProviderSettings(BaseSettings):
|
||||
|
|
@ -35,11 +30,11 @@ class EnvBearerAuthProvider(BearerAuthProvider):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
public_key: str | None | NotSet = NOTSET,
|
||||
jwks_uri: str | None | NotSet = NOTSET,
|
||||
issuer: str | None | NotSet = NOTSET,
|
||||
audience: str | None | NotSet = NOTSET,
|
||||
required_scopes: list[str] | None | NotSet = NOTSET,
|
||||
public_key: str | None | type[NotSet] = NotSet,
|
||||
jwks_uri: str | None | type[NotSet] = NotSet,
|
||||
issuer: str | None | type[NotSet] = NotSet,
|
||||
audience: str | None | type[NotSet] = NotSet,
|
||||
required_scopes: list[str] | None | type[NotSet] = NotSet,
|
||||
):
|
||||
kwargs = {
|
||||
"public_key": public_key,
|
||||
|
|
@ -49,6 +44,6 @@ class EnvBearerAuthProvider(BearerAuthProvider):
|
|||
"required_scopes": required_scopes,
|
||||
}
|
||||
settings = EnvBearerAuthProviderSettings(
|
||||
**{k: v for k, v in kwargs.items() if v is not NOTSET}
|
||||
**{k: v for k, v in kwargs.items() if v is not NotSet}
|
||||
)
|
||||
super().__init__(**settings.model_dump())
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ class FastMCP(Generic[LifespanResultT]):
|
|||
lifespan=_lifespan_wrapper(self, lifespan),
|
||||
)
|
||||
|
||||
if auth is None and self.settings.auth_provider == "bearer_env":
|
||||
if auth is None and self.settings.default_auth_provider == "bearer_env":
|
||||
auth = EnvBearerAuthProvider()
|
||||
self.auth = auth
|
||||
|
||||
|
|
|
|||
|
|
@ -180,7 +180,23 @@ class ServerSettings(BaseSettings):
|
|||
)
|
||||
|
||||
# Auth settings
|
||||
auth_provider: Literal["bearer_env"] | None = None
|
||||
default_auth_provider: Annotated[
|
||||
Literal["bearer_env"] | None,
|
||||
Field(
|
||||
description=inspect.cleandoc(
|
||||
"""
|
||||
Configure the authentication provider. This setting is intended only to
|
||||
be used for remote confirugation of providers that fully support
|
||||
environment variable configuration.
|
||||
|
||||
If None, no automatic configuration will take place.
|
||||
|
||||
This setting is *always* overriden by any auth provider passed to the
|
||||
FastMCP constructor.
|
||||
"""
|
||||
),
|
||||
),
|
||||
] = None
|
||||
|
||||
|
||||
settings = Settings()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue