Select Git revision
      
  monkeypatches.py
 
   
              Mohammad Torkashvand authored 
   monkeypatches.py  1.09 KiB 
"""Override certain classes and settings in the oauth2_lib.fastapi package with custom implementations.
This adjustment is typically done to extend or modify the functionality of the original
oauth2_lib package to meet specific requirements of the gso application.
"""
from datetime import datetime
from ipaddress import IPv4Address, IPv6Address
import oauth2_lib.fastapi
import oauth2_lib.settings
from pydantic import BaseModel
from gso.auth.oidc_policy_helper import HTTPX_SSL_CONTEXT, OIDCUser, OIDCUserModel, opa_decision
from gso.auth.settings import oauth2lib_settings
oauth2_lib.fastapi.OIDCUser = OIDCUser  # type: ignore[assignment, misc]
oauth2_lib.fastapi.OIDCUserModel = OIDCUserModel  # type: ignore[assignment, misc]
oauth2_lib.fastapi.opa_decision = opa_decision  # type: ignore[assignment]
oauth2_lib.fastapi.HTTPX_SSL_CONTEXT = HTTPX_SSL_CONTEXT
oauth2_lib.settings.oauth2lib_settings = oauth2lib_settings  # type: ignore[assignment]
BaseModel.model_config["json_encoders"] = {
    datetime: lambda dt: dt.timestamp(),
    IPv4Address: lambda v: str(v),
    IPv6Address: lambda v: str(v),
}