diff --git a/oidc-controller/api/authSessions/models.py b/oidc-controller/api/authSessions/models.py index 67e84c15..017010da 100644 --- a/oidc-controller/api/authSessions/models.py +++ b/oidc-controller/api/authSessions/models.py @@ -4,7 +4,7 @@ from api.core.acapy.client import AcapyClient from api.core.models import UUIDModel -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from ..core.config import settings @@ -27,8 +27,7 @@ class AuthSessionBase(BaseModel): response_url: str presentation_request_msg: Optional[dict] = None - class Config: - allow_population_by_field_name = True + model_config = ConfigDict(populate_by_name=True) class AuthSession(AuthSessionBase, UUIDModel): diff --git a/oidc-controller/api/clientConfigurations/models.py b/oidc-controller/api/clientConfigurations/models.py index 295a88f5..b35c3588 100644 --- a/oidc-controller/api/clientConfigurations/models.py +++ b/oidc-controller/api/clientConfigurations/models.py @@ -1,7 +1,7 @@ from enum import Enum from typing import List, Optional -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from ..core.config import settings from .examples import ex_client_config @@ -27,9 +27,7 @@ class ClientConfigurationBase(BaseModel): client_secret: str = Field(default=settings.OIDC_CLIENT_SECRET) - class Config: - allow_population_by_field_name = True - schema_extra = {"example": ex_client_config} + model_config = ConfigDict(populate_by_name=True, json_schema_extra={"example": ex_client_config}) class ClientConfiguration(ClientConfigurationBase): @@ -41,11 +39,11 @@ class ClientConfigurationRead(ClientConfigurationBase): class ClientConfigurationPatch(ClientConfigurationBase): - client_id: Optional[str] - client_name: Optional[str] - response_types: Optional[List[str]] - redirect_uris: Optional[List[str]] - token_endpoint_auth_method: Optional[TOKENENDPOINTAUTHMETHODS] - client_secret: Optional[str] + client_id: Optional[str] = None + client_name: Optional[str] = None + response_types: Optional[List[str]] = None + redirect_uris: Optional[List[str]] = None + token_endpoint_auth_method: Optional[TOKENENDPOINTAUTHMETHODS] = None + client_secret: Optional[str] = None pass diff --git a/oidc-controller/api/core/acapy/models.py b/oidc-controller/api/core/acapy/models.py index da48a16d..7b4df94c 100644 --- a/oidc-controller/api/core/acapy/models.py +++ b/oidc-controller/api/core/acapy/models.py @@ -10,7 +10,7 @@ class WalletDid(BaseModel): class WalletDidPublicResponse(BaseModel): - result: Optional[WalletDid] + result: Optional[WalletDid] = None class CreatePresentationResponse(BaseModel): diff --git a/oidc-controller/api/core/aries/out_of_band.py b/oidc-controller/api/core/aries/out_of_band.py index 6c17ab99..c24f3478 100644 --- a/oidc-controller/api/core/aries/out_of_band.py +++ b/oidc-controller/api/core/aries/out_of_band.py @@ -1,5 +1,5 @@ from typing import Dict, List, Union -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from .service_decorator import OOBServiceDecorator @@ -8,8 +8,7 @@ class OutOfBandPresentProofAttachment(BaseModel): mime_type: str = Field(default="application/json", alias="mime-type") data: Dict - class Config: - allow_population_by_field_name = True + model_config = ConfigDict(populate_by_name=True) class OutOfBandMessage(BaseModel): @@ -28,5 +27,4 @@ class OutOfBandMessage(BaseModel): ) services: List[Union[OOBServiceDecorator, str]] = Field(alias="services") - class Config: - allow_population_by_field_name = True + model_config = ConfigDict(populate_by_name=True) diff --git a/oidc-controller/api/core/aries/present_proof_presentation.py b/oidc-controller/api/core/aries/present_proof_presentation.py index 1bf383ce..95b01b5e 100644 --- a/oidc-controller/api/core/aries/present_proof_presentation.py +++ b/oidc-controller/api/core/aries/present_proof_presentation.py @@ -2,7 +2,7 @@ import base64 from typing import Optional, List -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from api.core.aries import PresentProofv10Attachment, ServiceDecorator @@ -17,10 +17,9 @@ class PresentationRequestMessage(BaseModel): alias="request_presentations~attach" ) comment: Optional[str] = None - service: Optional[ServiceDecorator] = Field(alias="~service") + service: Optional[ServiceDecorator] = Field(None, alias="~service") - class Config: - allow_population_by_field_name = True + model_config = ConfigDict(populate_by_name=True) def b64_str(self): # object->dict->jsonString->ascii->ENCODE->ascii diff --git a/oidc-controller/api/core/aries/service_decorator.py b/oidc-controller/api/core/aries/service_decorator.py index 7a64ae6a..937edc18 100644 --- a/oidc-controller/api/core/aries/service_decorator.py +++ b/oidc-controller/api/core/aries/service_decorator.py @@ -1,25 +1,23 @@ from typing import List, Optional -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field class ServiceDecorator(BaseModel): # https://github.com/hyperledger/aries-rfcs/tree/main/features/0056-service-decorator - recipient_keys: Optional[List[str]] = Field(alias="recipientKeys") - routing_keys: Optional[List[str]] = Field(alias="routingKeys") - service_endpoint: Optional[str] = Field(alias="serviceEndpoint") + recipient_keys: Optional[List[str]] = Field(default=None, alias="recipientKeys") + routing_keys: Optional[List[str]] = Field(default=None, alias="routingKeys") + service_endpoint: Optional[str] = Field(default=None, alias="serviceEndpoint") - class Config: - allow_population_by_field_name = True + model_config = ConfigDict(populate_by_name=True) class OOBServiceDecorator(ServiceDecorator): # ServiceDecorator - recipient_keys: Optional[List[str]] + recipient_keys: Optional[List[str]] = None routing_keys: Optional[List[str]] = Field(default=[]) - service_endpoint: Optional[str] + service_endpoint: Optional[str] = None id: str = Field(default="did:vc-authn-oidc:123456789zyxwvutsr#did-communication") type: str = Field(default="did-communication") priority: int = 0 - class Config: - allow_population_by_field_name = True + model_config = ConfigDict(populate_by_name=True) diff --git a/oidc-controller/api/core/config.py b/oidc-controller/api/core/config.py index c9087e96..04e49300 100644 --- a/oidc-controller/api/core/config.py +++ b/oidc-controller/api/core/config.py @@ -7,9 +7,10 @@ from functools import lru_cache from pathlib import Path from typing import Optional, Union +from pydantic_settings import BaseSettings +from pydantic import ConfigDict import structlog -from pydantic import BaseSettings # Removed in later versions of python @@ -162,7 +163,7 @@ class GlobalConfig(BaseSettings): "CONTROLLER_CAMERA_REDIRECT_URL" ) # The number of seconds to wait for a presentation to be verified, Default: 10 - CONTROLLER_PRESENTATION_EXPIRE_TIME: Union[int, str] = os.environ.get( + CONTROLLER_PRESENTATION_EXPIRE_TIME: int = os.environ.get( "CONTROLLER_PRESENTATION_EXPIRE_TIME", 10 ) @@ -188,11 +189,11 @@ class GlobalConfig(BaseSettings): DEFAULT_PAGE_SIZE: Union[int, str] = os.environ.get("DEFAULT_PAGE_SIZE", 10) # openssl rand -hex 32 - SIGNING_KEY_SIZE = os.environ.get("SIGNING_KEY_SIZE", 2048) + SIGNING_KEY_SIZE: int = os.environ.get("SIGNING_KEY_SIZE", 2048) # SIGNING_KEY_FILEPATH expects complete path including filename and extension. SIGNING_KEY_FILEPATH: Optional[str] = os.environ.get("SIGNING_KEY_FILEPATH") SIGNING_KEY_ALGORITHM: str = os.environ.get("SIGNING_KEY_ALGORITHM", "RS256") - SUBJECT_ID_HASH_SALT = os.environ.get("SUBJECT_ID_HASH_SALT", "test_hash_salt") + SUBJECT_ID_HASH_SALT: str = os.environ.get("SUBJECT_ID_HASH_SALT", "test_hash_salt") # OIDC Client Settings OIDC_CLIENT_ID: str = os.environ.get("OIDC_CLIENT_ID", "keycloak") @@ -213,15 +214,14 @@ class GlobalConfig(BaseSettings): ) SET_NON_REVOKED: bool = strtobool(os.environ.get("SET_NON_REVOKED", True)) - class Config: - case_sensitive = True + model_config = ConfigDict(case_sensitive=True) class LocalConfig(GlobalConfig): """Local configurations.""" DEBUG: bool = True - DB_ECHO_LOG = True + DB_ECHO_LOG: bool = True ENVIRONMENT: EnvironmentEnum = EnvironmentEnum.LOCAL diff --git a/oidc-controller/api/core/models.py b/oidc-controller/api/core/models.py index 519d2456..12d11bc4 100644 --- a/oidc-controller/api/core/models.py +++ b/oidc-controller/api/core/models.py @@ -2,23 +2,24 @@ from typing import TypedDict from bson import ObjectId -from pydantic import BaseModel, Field +from pydantic import BaseModel, ConfigDict, Field from pyop.userinfo import Userinfo +from pydantic_core import core_schema class PyObjectId(ObjectId): @classmethod - def __get_validators__(cls): - yield cls.validate + def __get_pydantic_core_schema__(cls, source_type, handler) -> core_schema.CoreSchema: + return core_schema.general_plain_validator_function(cls.validate) @classmethod - def validate(cls, v): + def validate(cls, v, info): if not ObjectId.is_valid(v): raise ValueError("Invalid objectid") return ObjectId(v) @classmethod - def __modify_schema__(cls, field_schema): + def __get_pydantic_json_schema__(cls, field_schema): field_schema.update(type="string") @@ -36,8 +37,7 @@ class StatusMessage(BaseModel): class UUIDModel(BaseModel): id: PyObjectId = Field(default_factory=PyObjectId, alias="_id") - class Config: - json_encoders = {ObjectId: str} + model_config = ConfigDict(json_encoders={ObjectId: str}) class TimestampModel(BaseModel): diff --git a/oidc-controller/api/routers/quick-socket/app.py b/oidc-controller/api/routers/quick-socket/app.py deleted file mode 100755 index 833d52a5..00000000 --- a/oidc-controller/api/routers/quick-socket/app.py +++ /dev/null @@ -1,65 +0,0 @@ -import uvicorn -from fastapi import FastAPI -from fastapi.responses import HTMLResponse -import socketio # Installed with 'pip install python-socketio` - -html = """ - - -
- -