-
Notifications
You must be signed in to change notification settings - Fork 27
[mock_uss] Move mock_uss webapp to app module #1219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BenjaminPelletier
merged 5 commits into
interuss:main
from
BenjaminPelletier:mock_uss-webapp
Oct 15, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cc93998
Move mock_uss webapp to app module
BenjaminPelletier 3f66518
Re-add CERT_BASE_PATH check
BenjaminPelletier c8d2c56
Merge remote-tracking branch 'interuss/main' into mock_uss-webapp
BenjaminPelletier e940fd2
Merge remote-tracking branch 'interuss/main' into mock_uss-webapp
BenjaminPelletier 499f56d
Re-remove broken message signing content
BenjaminPelletier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,142 +0,0 @@ | ||
import inspect | ||
import os | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
# Because mock_uss uses gevent, we need to monkey-patch before anything else is loaded. | ||
# https://www.gevent.org/intro.html#monkey-patching | ||
from gevent import monkey | ||
|
||
monkey.patch_all() | ||
|
||
from loguru import logger # noqa E402 | ||
from werkzeug.middleware.proxy_fix import ProxyFix # noqa E402 | ||
|
||
from monitoring.mock_uss.server import MockUSS # noqa E402 | ||
|
||
SERVICE_GEOAWARENESS = "geoawareness" | ||
SERVICE_RIDSP = "ridsp" | ||
SERVICE_RIDDP = "riddp" | ||
SERVICE_SCDSC = "scdsc" | ||
SERVICE_MESSAGESIGNING = "msgsigning" | ||
SERVICE_TRACER = "tracer" | ||
SERVICE_INTERACTION_LOGGING = "interaction_logging" | ||
SERVICE_VERSIONING = "versioning" | ||
SERVICE_FLIGHT_PLANNING = "flight_planning" | ||
|
||
webapp = MockUSS(__name__) | ||
webapp.secret_key = os.environ.get("SECRET_KEY") or os.urandom(24) | ||
if os.environ.get("MOCK_USS_PROXY_VALUES"): | ||
values = os.environ.get("MOCK_USS_PROXY_VALUES").split(",") | ||
kwargs = {v.split("=")[0].strip(): int(v.split("=")[1]) for v in values} | ||
webapp.wsgi_app = ProxyFix(webapp.wsgi_app, **kwargs) | ||
enabled_services = set() | ||
|
||
|
||
def import_environment_variable( | ||
var_name: str, | ||
required: bool = True, | ||
default: str | None = None, | ||
mutator: Callable[[str], Any] | None = None, | ||
) -> None: | ||
"""Import a value from a named environment variable into the webapp configuration. | ||
|
||
Args: | ||
var_name: Environment variable name (key). Also used as the webapp configuration key for that variable. | ||
required: Whether the variable must be specified by the user. If True, a ValueError will be raised if the | ||
variable is not specified by the user. If False, the webapp configuration will not be populated if no | ||
default is provided. If default is specified, the default value is treated as specification by the user. | ||
default: If the variable is not required, then use this value when it is not specified by the user. The default | ||
value should be the string from the environment variable rather than the output of the mutator, if present. | ||
mutator: If specified, apply this function to the string value of the environment variable to obtain the | ||
variable to actually store in the configuration. | ||
""" | ||
if var_name in os.environ: | ||
str_value = os.environ[var_name] | ||
elif default is not None: | ||
str_value = default | ||
elif required: | ||
stack = inspect.stack() | ||
raise ValueError( | ||
f"System cannot proceed because required environment variable '{var_name}' was not found. Required from {stack[1].filename}:{stack[1].lineno}" | ||
) | ||
else: | ||
str_value = None | ||
|
||
if str_value is not None: | ||
webapp.config[var_name] = str_value if mutator is None else mutator(str_value) | ||
|
||
|
||
def require_config_value(config_key: str) -> None: | ||
if config_key not in webapp.config: | ||
stack = inspect.stack() | ||
raise ValueError( | ||
f"System cannot proceed because required configuration key '{config_key}' was not found. Required from {stack[1].filename}:{stack[1].lineno}" | ||
) | ||
|
||
|
||
from monitoring.mock_uss import config # noqa E402 | ||
from monitoring.mock_uss import logging as logging # noqa E402 | ||
from monitoring.mock_uss import routes as basic_routes # noqa F401,F402 | ||
|
||
if SERVICE_GEOAWARENESS in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_GEOAWARENESS) | ||
from monitoring.mock_uss import geoawareness as geoawareness | ||
from monitoring.mock_uss.geoawareness import ( | ||
routes as geoawareness_routes, # noqa F401 | ||
) | ||
|
||
if SERVICE_RIDSP in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_RIDSP) | ||
from monitoring.mock_uss import ridsp as ridsp | ||
from monitoring.mock_uss.ridsp import routes as ridsp_routes # noqa F401 | ||
|
||
if SERVICE_RIDDP in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_RIDDP) | ||
from monitoring.mock_uss import riddp as riddp | ||
from monitoring.mock_uss.riddp import routes as riddp_routes # noqa F401 | ||
|
||
if SERVICE_SCDSC in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_SCDSC) | ||
from monitoring.mock_uss.f3548v21 import routes_scd as routes_scd | ||
from monitoring.mock_uss.scd_injection import ( | ||
routes as scd_injection_routes, # noqa F401 | ||
) | ||
|
||
if SERVICE_MESSAGESIGNING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_MESSAGESIGNING) | ||
from monitoring.mock_uss import msgsigning as msgsigning # noqa F401 | ||
from monitoring.mock_uss.msgsigning import routes as msgsigning_routes # noqa F401 | ||
|
||
if SERVICE_INTERACTION_LOGGING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_INTERACTION_LOGGING) | ||
from monitoring.mock_uss.interaction_logging import logger as interactions_logger # noqa F401 | ||
from monitoring.mock_uss.interaction_logging import ( | ||
routes_interactions_log as routes_interactions_log, | ||
) | ||
|
||
logger.info("Interaction logging enabled") | ||
else: | ||
logger.info("Interaction logging disabled") | ||
|
||
if SERVICE_TRACER in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_TRACER) | ||
from monitoring.mock_uss import tracer as tracer | ||
from monitoring.mock_uss.tracer import routes as tracer_routes # noqa F401 | ||
|
||
if SERVICE_VERSIONING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_VERSIONING) | ||
from monitoring.mock_uss.versioning import routes as versioning_routes # noqa F401 | ||
|
||
if SERVICE_FLIGHT_PLANNING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_FLIGHT_PLANNING) | ||
from monitoring.mock_uss.flight_planning import routes as flight_planning_routes # noqa F401 | ||
|
||
msg = ( | ||
"################################################################################\n" | ||
+ "################################ Configuration ################################\n" | ||
+ "\n".join(f"## {key}: {webapp.config[key]}" for key in webapp.config) | ||
+ "\n" | ||
+ "################################################################################" | ||
) | ||
logger.info("Configuration:\n" + msg) | ||
This file contains hidden or 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,142 @@ | ||
import inspect | ||
import os | ||
from collections.abc import Callable | ||
from typing import Any | ||
|
||
# Because mock_uss uses gevent, we need to monkey-patch before anything else is loaded. | ||
# https://www.gevent.org/intro.html#monkey-patching | ||
from gevent import monkey | ||
|
||
monkey.patch_all() | ||
|
||
from loguru import logger # noqa E402 | ||
from werkzeug.middleware.proxy_fix import ProxyFix # noqa E402 | ||
|
||
from monitoring.mock_uss.server import MockUSS # noqa E402 | ||
|
||
SERVICE_GEOAWARENESS = "geoawareness" | ||
SERVICE_RIDSP = "ridsp" | ||
SERVICE_RIDDP = "riddp" | ||
SERVICE_SCDSC = "scdsc" | ||
SERVICE_MESSAGESIGNING = "msgsigning" | ||
SERVICE_TRACER = "tracer" | ||
SERVICE_INTERACTION_LOGGING = "interaction_logging" | ||
SERVICE_VERSIONING = "versioning" | ||
SERVICE_FLIGHT_PLANNING = "flight_planning" | ||
|
||
webapp = MockUSS(__name__) | ||
webapp.secret_key = os.environ.get("SECRET_KEY") or os.urandom(24) | ||
if os.environ.get("MOCK_USS_PROXY_VALUES"): | ||
values = os.environ.get("MOCK_USS_PROXY_VALUES", "").split(",") | ||
kwargs = {v.split("=")[0].strip(): int(v.split("=")[1]) for v in values} | ||
webapp.wsgi_app = ProxyFix(webapp.wsgi_app, **kwargs) | ||
enabled_services = set() | ||
|
||
|
||
def import_environment_variable( | ||
var_name: str, | ||
required: bool = True, | ||
default: str | None = None, | ||
mutator: Callable[[str], Any] | None = None, | ||
) -> None: | ||
"""Import a value from a named environment variable into the webapp configuration. | ||
|
||
Args: | ||
var_name: Environment variable name (key). Also used as the webapp configuration key for that variable. | ||
required: Whether the variable must be specified by the user. If True, a ValueError will be raised if the | ||
variable is not specified by the user. If False, the webapp configuration will not be populated if no | ||
default is provided. If default is specified, the default value is treated as specification by the user. | ||
default: If the variable is not required, then use this value when it is not specified by the user. The default | ||
value should be the string from the environment variable rather than the output of the mutator, if present. | ||
mutator: If specified, apply this function to the string value of the environment variable to obtain the | ||
variable to actually store in the configuration. | ||
""" | ||
if var_name in os.environ: | ||
str_value = os.environ[var_name] | ||
elif default is not None: | ||
str_value = default | ||
elif required: | ||
stack = inspect.stack() | ||
raise ValueError( | ||
f"System cannot proceed because required environment variable '{var_name}' was not found. Required from {stack[1].filename}:{stack[1].lineno}" | ||
) | ||
else: | ||
str_value = None | ||
|
||
if str_value is not None: | ||
webapp.config[var_name] = str_value if mutator is None else mutator(str_value) | ||
|
||
|
||
def require_config_value(config_key: str) -> None: | ||
if config_key not in webapp.config: | ||
stack = inspect.stack() | ||
raise ValueError( | ||
f"System cannot proceed because required configuration key '{config_key}' was not found. Required from {stack[1].filename}:{stack[1].lineno}" | ||
) | ||
|
||
|
||
from monitoring.mock_uss import config # noqa E402 | ||
from monitoring.mock_uss import logging as logging # noqa E402 | ||
from monitoring.mock_uss import routes as basic_routes # noqa F401,F402 | ||
|
||
if SERVICE_GEOAWARENESS in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_GEOAWARENESS) | ||
from monitoring.mock_uss import geoawareness as geoawareness | ||
from monitoring.mock_uss.geoawareness import ( | ||
routes as geoawareness_routes, # noqa F401 | ||
) | ||
|
||
if SERVICE_RIDSP in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_RIDSP) | ||
from monitoring.mock_uss import ridsp as ridsp | ||
from monitoring.mock_uss.ridsp import routes as ridsp_routes # noqa F401 | ||
|
||
if SERVICE_RIDDP in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_RIDDP) | ||
from monitoring.mock_uss import riddp as riddp | ||
from monitoring.mock_uss.riddp import routes as riddp_routes # noqa F401 | ||
|
||
if SERVICE_SCDSC in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_SCDSC) | ||
from monitoring.mock_uss.f3548v21 import routes_scd as routes_scd | ||
from monitoring.mock_uss.scd_injection import ( | ||
routes as scd_injection_routes, # noqa F401 | ||
) | ||
|
||
if SERVICE_MESSAGESIGNING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_MESSAGESIGNING) | ||
from monitoring.mock_uss import msgsigning as msgsigning # noqa F401 | ||
from monitoring.mock_uss.msgsigning import routes as msgsigning_routes # noqa F401 | ||
|
||
if SERVICE_INTERACTION_LOGGING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_INTERACTION_LOGGING) | ||
from monitoring.mock_uss.interaction_logging import logger as interactions_logger # noqa F401 | ||
from monitoring.mock_uss.interaction_logging import ( | ||
routes_interactions_log as routes_interactions_log, | ||
) | ||
|
||
logger.info("Interaction logging enabled") | ||
else: | ||
logger.info("Interaction logging disabled") | ||
|
||
if SERVICE_TRACER in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_TRACER) | ||
from monitoring.mock_uss import tracer as tracer | ||
from monitoring.mock_uss.tracer import routes as tracer_routes # noqa F401 | ||
|
||
if SERVICE_VERSIONING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_VERSIONING) | ||
from monitoring.mock_uss.versioning import routes as versioning_routes # noqa F401 | ||
|
||
if SERVICE_FLIGHT_PLANNING in webapp.config[config.KEY_SERVICES]: | ||
enabled_services.add(SERVICE_FLIGHT_PLANNING) | ||
from monitoring.mock_uss.flight_planning import routes as flight_planning_routes # noqa F401 | ||
|
||
msg = ( | ||
"################################################################################\n" | ||
+ "################################ Configuration ################################\n" | ||
+ "\n".join(f"## {key}: {webapp.config[key]}" for key in webapp.config) | ||
+ "\n" | ||
+ "################################################################################" | ||
) | ||
logger.info("Configuration:\n" + msg) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR: checked this change