-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce 'infection' logic (#512)
Co-authored-by: Alan Christie <[email protected]>
- Loading branch information
1 parent
f496abe
commit 9c74317
Showing
4 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# infections.py | ||
# | ||
# A utility that provides a list of infections (forced internal errors). | ||
# Infections are injected into the application via the environment variable | ||
# 'INFECTIONS', a comma-separated list of infection names. | ||
|
||
import os | ||
from typing import Dict, Set | ||
|
||
from api.utils import deployment_mode_is_production | ||
|
||
# The built-in set of infections. | ||
# Must be lowercase, but user can use any case in the environment variable. | ||
# Define every name as a constant, and add it and a description to the _CATALOGUE. | ||
INFECTION_STRUCTURE_DOWNLOAD: str = 'structure-download' | ||
|
||
# The index is the short-form name of the infection, and the value is the | ||
# description of the infection. | ||
_CATALOGUE: Dict[str, str] = { | ||
INFECTION_STRUCTURE_DOWNLOAD: 'An error in the DownloadStructures view' | ||
} | ||
|
||
# What infection have been set? | ||
_INFECTIONS: str = os.environ.get('INFECTIONS', '').lower() | ||
|
||
|
||
def have_infection(name: str) -> bool: | ||
"""Returns True if we've been given the named infection. | ||
Infections are never present in production mode.""" | ||
return False if deployment_mode_is_production() else name in _get_infections() | ||
|
||
|
||
def _get_infections() -> Set[str]: | ||
if _INFECTIONS == '': | ||
return set() | ||
infections: set[str] = { | ||
infection for infection in _INFECTIONS.split(',') if infection in _CATALOGUE | ||
} | ||
return infections |
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