diff --git a/src/fides/api/ctl/routes/health.py b/src/fides/api/ctl/routes/health.py index f011f32deae..0113a149d62 100644 --- a/src/fides/api/ctl/routes/health.py +++ b/src/fides/api/ctl/routes/health.py @@ -67,7 +67,7 @@ def get_cache_health() -> str: }, ) async def health() -> Dict: - "Confirm that the API is running and healthy." + """Confirm that the API is running and healthy.""" database_health = get_db_health(CONFIG.database.sync_database_uri) cache_health = get_cache_health() response = { diff --git a/src/fides/api/ctl/routes/user.py b/src/fides/api/ctl/routes/user.py deleted file mode 100644 index d020515fed8..00000000000 --- a/src/fides/api/ctl/routes/user.py +++ /dev/null @@ -1,111 +0,0 @@ -from fastapi import Depends, HTTPException, Security -from fideslib.cryptography.cryptographic_util import b64_str_to_str -from fideslib.models.client import ClientDetail -from fideslib.models.fides_user import FidesUser -from fideslib.oauth.api import urn_registry -from fideslib.oauth.schemas.user import UserPasswordReset, UserResponse, UserUpdate -from fideslib.oauth.scopes import USER_PASSWORD_RESET, USER_UPDATE -from sqlalchemy.orm import Session -from starlette.status import ( - HTTP_200_OK, - HTTP_204_NO_CONTENT, - HTTP_401_UNAUTHORIZED, - HTTP_404_NOT_FOUND, -) - -from fides.api.ctl.deps import get_current_user, get_db, verify_oauth_client -from fides.api.ctl.routes.util import API_PREFIX -from fides.api.ctl.utils.api_router import APIRouter -from fides.ctl.core.config import FidesConfig, get_config - -CONFIG = get_config() -router = APIRouter(tags=["Users"], prefix=f"{API_PREFIX}") - - -def _validate_current_user(user_id: str, user_from_token: FidesUser) -> None: - if not user_from_token: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, - detail=f"User with id {user_id} does not exist.", - ) - - if user_id != user_from_token.id: - raise HTTPException( - status_code=HTTP_401_UNAUTHORIZED, - detail="You are only authorised to update your own user data.", - ) - - -@router.put( - urn_registry.USER_DETAIL, - dependencies=[Security(verify_oauth_client, scopes=[USER_UPDATE])], - status_code=HTTP_200_OK, - response_model=UserResponse, -) -def update_user( - *, - db: Session = Depends(get_db), # pylint: disable=invalid-name - user_id: str, - data: UserUpdate, -) -> FidesUser: - """ - Update a user given a `user_id`. By default this is limited to users - updating their own data. - """ - user = FidesUser.get(db=db, object_id=user_id) - if not user: - raise HTTPException( - status_code=HTTP_404_NOT_FOUND, detail=f"user with id {user_id} not found." - ) - - user.update(db=db, data=data.dict()) - return user - - -@router.post( - urn_registry.USER_PASSWORD_RESET, - dependencies=[Security(verify_oauth_client, scopes=[USER_PASSWORD_RESET])], - status_code=HTTP_200_OK, - response_model=UserResponse, -) -def update_user_password( - *, - db: Session = Depends(get_db), # pylint: disable=invalid-name - current_user: FidesUser = Depends(get_current_user), - user_id: str, - data: UserPasswordReset, - config: FidesConfig = Depends(get_config), -) -> FidesUser: - """ - Update a user's password given a `user_id`. By default this is limited to users - updating their own data. - """ - _validate_current_user(user_id, current_user) - - if not current_user.credentials_valid( - b64_str_to_str(data.old_password), CONFIG.security.encoding - ): - raise HTTPException( - status_code=HTTP_401_UNAUTHORIZED, detail="Incorrect password." - ) - - current_user.update_password(db=db, new_password=b64_str_to_str(data.new_password)) - - return current_user - - -@router.post( - "/logout", - status_code=HTTP_204_NO_CONTENT, -) -def user_logout( - *, - client: ClientDetail = Security( - verify_oauth_client, - scopes=[], - ), - db: Session = Depends(get_db), # pylint: disable=invalid-name -) -> None: - """logout the user by deleting its client""" - - client.delete(db) diff --git a/src/fides/api/main.py b/src/fides/api/main.py index c52650d39e7..fa55b59c792 100644 --- a/src/fides/api/main.py +++ b/src/fides/api/main.py @@ -30,7 +30,6 @@ datamap, generate, health, - user, validate, visualize, ) @@ -82,7 +81,6 @@ datamap.router, generate.router, health.router, - user.router, validate.router, view.router, ] diff --git a/tests/ops/api/v1/endpoints/test_health_endpoints.py b/tests/ops/api/v1/endpoints/test_health_endpoints.py index 97be5d60434..f51bfbf8c8b 100644 --- a/tests/ops/api/v1/endpoints/test_health_endpoints.py +++ b/tests/ops/api/v1/endpoints/test_health_endpoints.py @@ -1,12 +1,13 @@ from starlette.testclient import TestClient +import fides from fides.api.ops.api.v1.urn_registry import HEALTH def test_health(api_client: TestClient) -> None: response = api_client.get(HEALTH) - assert response.json() == { - "webserver": "healthy", - "database": "healthy", - "cache": "healthy", - } + json = response.json() + assert json["webserver"] == "healthy" + assert json["database"] == "healthy" + assert json["cache"] == "healthy" + assert json["version"] == str(fides.__version__) diff --git a/tests/ops/integration_test_config.toml b/tests/ops/integration_test_config.toml index 4dbcb4e410b..d75a71269ee 100644 --- a/tests/ops/integration_test_config.toml +++ b/tests/ops/integration_test_config.toml @@ -45,3 +45,10 @@ user="mariadb_user" password="mariadb_pw" db="mariadb_example" port=3306 + +[timescale_example] +server="timescale_example" +user="postgres" +password="postgres" +db="timescale_example" +port=5432 diff --git a/tests/ops/integration_tests/test_execution.py b/tests/ops/integration_tests/test_execution.py index 3bc40293b65..702bbbcc9d7 100644 --- a/tests/ops/integration_tests/test_execution.py +++ b/tests/ops/integration_tests/test_execution.py @@ -30,6 +30,8 @@ get_privacy_request_results, ) +CONFIG = get_config() + def get_sorted_execution_logs(db, privacy_request: PrivacyRequest): return [ @@ -134,7 +136,7 @@ def delete_connection_config(_): Delete the mongo connection in a separate session, for testing purposes, while the privacy request is in progress. Arbitrarily hooks into the log_start method to do this. """ - SessionLocal = get_db_session(config) + SessionLocal = get_db_session(CONFIG) new_session = SessionLocal() try: reloaded_config = new_session.query(ConnectionConfig).get( @@ -405,7 +407,7 @@ def disable_connection_config(_): in a new session, to mimic the ConnectionConfig being disabled by a separate request while request is in progress. """ - SessionLocal = get_db_session(config) + SessionLocal = get_db_session(CONFIG) new_session = SessionLocal() reloaded_config = new_session.query(ConnectionConfig).get( mongo_connection_config.id diff --git a/tests/ops/integration_tests/test_sql_task.py b/tests/ops/integration_tests/test_sql_task.py index c18d8c9b6dc..5d1a83f133b 100644 --- a/tests/ops/integration_tests/test_sql_task.py +++ b/tests/ops/integration_tests/test_sql_task.py @@ -41,6 +41,8 @@ str_converter, ) +CONFIG = get_config() + logger = logging.getLogger(__name__) sample_postgres_configuration_policy = erasure_policy( "system.operations", @@ -1060,9 +1062,9 @@ async def test_retry_access_request( policy, integration_postgres_config, ): - config.execution.task_retry_count = 1 - config.execution.task_retry_delay = 0.1 - config.execution.task_retry_backoff = 0.01 + CONFIG.execution.task_retry_count = 1 + CONFIG.execution.task_retry_delay = 0.1 + CONFIG.execution.task_retry_backoff = 0.01 dataset = FidesopsDataset(**example_datasets[0]) graph = convert_dataset_to_graph(dataset, integration_postgres_config.key) @@ -1113,9 +1115,9 @@ async def test_retry_erasure( policy, integration_postgres_config, ): - config.execution.task_retry_count = 2 - config.execution.task_retry_delay = 0.1 - config.execution.task_retry_backoff = 0.01 + CONFIG.execution.task_retry_count = 2 + CONFIG.execution.task_retry_delay = 0.1 + CONFIG.execution.task_retry_backoff = 0.01 dataset = FidesopsDataset(**example_datasets[0]) graph = convert_dataset_to_graph(dataset, integration_postgres_config.key) @@ -1172,7 +1174,7 @@ async def test_retry_erasure( @pytest.mark.integration_timescale @pytest.mark.integration @pytest.mark.asyncio -async def test_postgres_access_request_task( +async def test_timescale_access_request_task( db, policy, timescale_connection_config, diff --git a/tests/ops/service/connectors/test_saas_queryconfig.py b/tests/ops/service/connectors/test_saas_queryconfig.py index 9b05ab9bd94..0209c9e78fc 100644 --- a/tests/ops/service/connectors/test_saas_queryconfig.py +++ b/tests/ops/service/connectors/test_saas_queryconfig.py @@ -341,7 +341,7 @@ def test_get_masking_request( method="DELETE", path="/api/0///" ) # Delete endpoint not used because masking_strict is True - assert config.execution.masking_strict is True + assert CONFIG.execution.masking_strict is True query_config = SaaSQueryConfig(conversations, endpoints, {}) saas_request = query_config.get_masking_request()