This repository has been archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
environment variables to disable app db and cache. some related clean…
…up (#550) * environment variables to disable app db and cache. some related cleanup * update changelog.md * add tests db and redis disabled configs. add tests for endpoint exception handlers. make exception handler a static method. Co-authored-by: Adam Sachs <adam@Adams-MacBook-Pro.local>
- Loading branch information
Showing
13 changed files
with
202 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
services: | ||
fidesops: | ||
container_name: fidesops | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
expose: | ||
- 8080 | ||
healthcheck: | ||
test: [ "CMD", "curl", "-f", "http://0.0.0.0:8080/health" ] | ||
interval: 30s | ||
timeout: 10s | ||
retries: 3 | ||
start_period: 1s | ||
ports: | ||
- "8080:8080" | ||
volumes: | ||
- type: bind | ||
source: ./ | ||
target: /fidesops | ||
read_only: False | ||
- /fidesops/src/fidesops.egg-info | ||
environment: | ||
- FIDESOPS__DEV_MODE=${FIDESOPS__DEV_MODE} | ||
- FIDESOPS__LOG_PII=${FIDESOPS__LOG_PII} | ||
- FIDESOPS__HOT_RELOAD=${FIDESOPS__HOT_RELOAD} | ||
- FIDESOPS__DATABASE__ENABLED=false | ||
- FIDESOPS__REDIS__ENABLED=false | ||
docs: | ||
build: | ||
context: docs/fidesops/ | ||
dockerfile: Dockerfile | ||
volumes: | ||
- ./docs/fidesops:/docs | ||
expose: | ||
- 8000 | ||
ports: | ||
- "8000:8000" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Callable, List | ||
|
||
from fastapi import Request | ||
from fastapi.responses import JSONResponse, Response | ||
from starlette.status import HTTP_500_INTERNAL_SERVER_ERROR | ||
|
||
from fidesops.common_exceptions import FunctionalityNotConfigured | ||
|
||
|
||
class ExceptionHandlers: | ||
@staticmethod | ||
def functionality_not_configured_handler( | ||
request: Request, exc: FunctionalityNotConfigured | ||
) -> JSONResponse: | ||
return JSONResponse( | ||
status_code=HTTP_500_INTERNAL_SERVER_ERROR, content={"message": str(exc)} | ||
) | ||
|
||
@classmethod | ||
def get_handlers(cls) -> List[Callable[[Request, Exception], Response]]: | ||
return [ExceptionHandlers.functionality_not_configured_handler] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
|
||
from fidesops.api.deps import get_cache, get_db | ||
from fidesops.common_exceptions import FunctionalityNotConfigured | ||
from fidesops.core import config | ||
|
||
|
||
@pytest.fixture | ||
def mock_config(): | ||
db_enabled = config.config.database.ENABLED | ||
redis_enabled = config.config.redis.ENABLED | ||
config.config.database.ENABLED = False | ||
config.config.redis.ENABLED = False | ||
yield | ||
config.config.database.ENABLED = db_enabled | ||
config.config.redis.ENABLED = redis_enabled | ||
|
||
|
||
@pytest.mark.usefixtures("mock_config") | ||
def test_get_cache_not_enabled(): | ||
with pytest.raises(FunctionalityNotConfigured): | ||
next(get_cache()) | ||
|
||
|
||
@pytest.mark.usefixtures("mock_config") | ||
def test_get_db_not_enabled(): | ||
with pytest.raises(FunctionalityNotConfigured): | ||
next(get_db()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import json | ||
|
||
import pytest | ||
from starlette.testclient import TestClient | ||
|
||
from fidesops.api.v1.scope_registry import CLIENT_CREATE | ||
from fidesops.api.v1.urn_registry import CLIENT, HEALTH, PRIVACY_REQUESTS, V1_URL_PREFIX | ||
from fidesops.core import config | ||
|
||
|
||
@pytest.fixture | ||
def mock_config_db_disabled(): | ||
db_enabled = config.config.database.ENABLED | ||
config.config.database.ENABLED = False | ||
yield | ||
config.config.database.ENABLED = db_enabled | ||
|
||
@pytest.fixture | ||
def mock_config_redis_disabled(): | ||
redis_enabled = config.config.redis.ENABLED | ||
config.config.redis.ENABLED = False | ||
yield | ||
config.config.redis.ENABLED = redis_enabled | ||
|
||
|
||
class TestExceptionHandlers: | ||
@pytest.mark.usefixtures("mock_config_db_disabled") | ||
def test_db_disabled(self, api_client: TestClient, generate_auth_header): | ||
auth_header = generate_auth_header([CLIENT_CREATE]) | ||
# oauth endpoint should not work | ||
expected_response = {"message": "Application database required, but it is currently disabled! Please update your application configuration to enable integration with an application database."} | ||
response = api_client.post(V1_URL_PREFIX + CLIENT, headers=auth_header) | ||
response_body = json.loads(response.text) | ||
assert 500 == response.status_code | ||
assert expected_response == response_body | ||
|
||
# health endpoint should still work | ||
expected_response = {"healthy": True} | ||
response = api_client.get(HEALTH) | ||
response_body = json.loads(response.text) | ||
assert 200 == response.status_code | ||
assert expected_response == response_body | ||
|
||
@pytest.mark.usefixtures("mock_config_redis_disabled") | ||
def test_redis_disabled(self, api_client: TestClient, generate_auth_header): | ||
auth_header = generate_auth_header([CLIENT_CREATE]) | ||
# Privacy requests endpoint should not work | ||
request_body = [ | ||
{ | ||
"requested_at": "2021-08-30T16:09:37.359Z", | ||
"identity": { "email": "customer-1@example.com" }, | ||
"policy_key": "my_separate_policy" | ||
} | ||
] | ||
expected_response = {"message": "Application redis cache required, but it is currently disabled! Please update your application configuration to enable integration with a redis cache."} | ||
response = api_client.post(V1_URL_PREFIX + PRIVACY_REQUESTS, headers=auth_header, json=request_body) | ||
response_body = json.loads(response.text) | ||
assert 500 == response.status_code | ||
assert expected_response == response_body | ||
|
||
# health endpoint should still work | ||
expected_response = {"healthy": True} | ||
response = api_client.get(HEALTH) | ||
response_body = json.loads(response.text) | ||
assert 200 == response.status_code | ||
assert expected_response == response_body |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters