From 2b8b7f1da4568c9c3140b1697003f4743e37fbf2 Mon Sep 17 00:00:00 2001 From: Andrew Jackson Date: Fri, 15 Sep 2023 16:03:14 -0400 Subject: [PATCH] DI app instance --- .../versions/f17f92237383_disable_inactive_notices.py | 1 - src/fides/api/api/v1/endpoints/config_endpoints.py | 5 +++-- src/fides/api/main.py | 2 +- src/fides/config/utils.py | 7 ++++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/fides/api/alembic/migrations/versions/f17f92237383_disable_inactive_notices.py b/src/fides/api/alembic/migrations/versions/f17f92237383_disable_inactive_notices.py index 07cd4dd120..a6758b8a70 100644 --- a/src/fides/api/alembic/migrations/versions/f17f92237383_disable_inactive_notices.py +++ b/src/fides/api/alembic/migrations/versions/f17f92237383_disable_inactive_notices.py @@ -13,7 +13,6 @@ from sqlalchemy.engine import Connection, ResultProxy from sqlalchemy.sql.elements import TextClause - # revision identifiers, used by Alembic. from fides.api.models.sql_models import DataUse diff --git a/src/fides/api/api/v1/endpoints/config_endpoints.py b/src/fides/api/api/v1/endpoints/config_endpoints.py index 9f62813308..92bc6c59f4 100644 --- a/src/fides/api/api/v1/endpoints/config_endpoints.py +++ b/src/fides/api/api/v1/endpoints/config_endpoints.py @@ -1,6 +1,6 @@ from typing import Any, Dict, Optional -from fastapi import Depends +from fastapi import Depends, Request from fastapi.params import Security from loguru import logger from sqlalchemy.orm import Session @@ -49,6 +49,7 @@ def get_config( def update_settings( *, db: Session = Depends(deps.get_db), + request: Request, data: ApplicationConfigSchema, ) -> ApplicationConfigSchema: """ @@ -66,7 +67,7 @@ def update_settings( "security" in pruned_data.keys() and "cors_origins" in pruned_data.get("security").keys() ): - load_updated_cors_domains(pruned_data["security"]["cors_origins"]) + load_updated_cors_domains(pruned_data["security"]["cors_origins"], request.app) return update_config.api_set diff --git a/src/fides/api/main.py b/src/fides/api/main.py index aea258858c..cec0e253c1 100644 --- a/src/fides/api/main.py +++ b/src/fides/api/main.py @@ -263,7 +263,7 @@ async def setup_server() -> None: db = get_api_session() config_proxy = ConfigProxy(db) - load_updated_cors_domains(config_proxy.security.cors_origins) + load_updated_cors_domains(config_proxy.security.cors_origins, app) check_redis() diff --git a/src/fides/config/utils.py b/src/fides/config/utils.py index 246be5ddd3..9ec9a1bad6 100644 --- a/src/fides/config/utils.py +++ b/src/fides/config/utils.py @@ -1,6 +1,7 @@ from os import getenv from typing import List +from fastapi.applications import FastAPI from starlette.middleware.cors import CORSMiddleware DEFAULT_CONFIG_PATH = ".fides/fides.toml" @@ -86,9 +87,9 @@ def get_dev_mode() -> bool: } -def load_updated_cors_domains(domains: List[str], resetDomains=False) -> None: - from fides.api.main import app - +def load_updated_cors_domains( + domains: List[str], app: FastAPI, resetDomains=False +) -> None: for mw in app.user_middleware: if mw.cls is CORSMiddleware: if resetDomains: