From 54d34d18160630dc9f1917620e12651d9c6820b2 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Tue, 26 Apr 2022 19:19:24 -0400 Subject: [PATCH] Island: Rename FlaskResourceManager -> FlaskDIWrapper --- monkey/monkey_island/cc/app.py | 89 ++++++++----------- .../monkey_island/cc/resources/conftest.py | 2 +- 2 files changed, 40 insertions(+), 51 deletions(-) diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index 404f5731b..7cb34a5a3 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -113,8 +113,7 @@ def init_app_url_rules(app): app.add_url_rule("/", "serve_static_file", serve_static_file) -# TODO: Come up with a better name than FlaskResourceManager -class FlaskResourceManager: +class FlaskDIWrapper: def __init__(self, api: flask_restful.Api, container: DIContainer): self._api = api self._container = container @@ -124,76 +123,66 @@ class FlaskResourceManager: self._api.add_resource(resource, *urls, resource_class_args=dependencies) -def init_api_resources(flask_resource_manager: FlaskResourceManager): - flask_resource_manager.add_resource(Root, "/api") - flask_resource_manager.add_resource(Registration, "/api/registration") - flask_resource_manager.add_resource(Authenticate, "/api/auth") - flask_resource_manager.add_resource( +def init_api_resources(api: FlaskDIWrapper): + api.add_resource(Root, "/api") + api.add_resource(Registration, "/api/registration") + api.add_resource(Authenticate, "/api/auth") + api.add_resource( Monkey, "/api/agent", "/api/agent/", "/api/agent//", ) - flask_resource_manager.add_resource(LocalRun, "/api/local-monkey") - flask_resource_manager.add_resource( - Telemetry, "/api/telemetry", "/api/telemetry/" - ) + api.add_resource(LocalRun, "/api/local-monkey") + api.add_resource(Telemetry, "/api/telemetry", "/api/telemetry/") - flask_resource_manager.add_resource(IslandMode, "/api/island-mode") - flask_resource_manager.add_resource(IslandConfiguration, "/api/configuration/island") - flask_resource_manager.add_resource(ConfigurationExport, "/api/configuration/export") - flask_resource_manager.add_resource(ConfigurationImport, "/api/configuration/import") - flask_resource_manager.add_resource( + api.add_resource(IslandMode, "/api/island-mode") + api.add_resource(IslandConfiguration, "/api/configuration/island") + api.add_resource(ConfigurationExport, "/api/configuration/export") + api.add_resource(ConfigurationImport, "/api/configuration/import") + api.add_resource( MonkeyDownload, "/api/agent/download/", ) - flask_resource_manager.add_resource(NetMap, "/api/netmap") - flask_resource_manager.add_resource(Edge, "/api/netmap/edge") - flask_resource_manager.add_resource(Node, "/api/netmap/node") - flask_resource_manager.add_resource(NodeStates, "/api/netmap/node-states") + api.add_resource(NetMap, "/api/netmap") + api.add_resource(Edge, "/api/netmap/edge") + api.add_resource(Node, "/api/netmap/node") + api.add_resource(NodeStates, "/api/netmap/node-states") - flask_resource_manager.add_resource(SecurityReport, "/api/report/security") - flask_resource_manager.add_resource( - ZeroTrustReport, "/api/report/zero-trust/" - ) - flask_resource_manager.add_resource(AttackReport, "/api/report/attack") - flask_resource_manager.add_resource(RansomwareReport, "/api/report/ransomware") - flask_resource_manager.add_resource(ManualExploitation, "/api/exploitations/manual") - flask_resource_manager.add_resource(MonkeyExploitation, "/api/exploitations/monkey") + api.add_resource(SecurityReport, "/api/report/security") + api.add_resource(ZeroTrustReport, "/api/report/zero-trust/") + api.add_resource(AttackReport, "/api/report/attack") + api.add_resource(RansomwareReport, "/api/report/ransomware") + api.add_resource(ManualExploitation, "/api/exploitations/manual") + api.add_resource(MonkeyExploitation, "/api/exploitations/monkey") - flask_resource_manager.add_resource( - ZeroTrustFindingEvent, "/api/zero-trust/finding-event/" - ) - flask_resource_manager.add_resource(TelemetryFeed, "/api/telemetry-feed") - flask_resource_manager.add_resource(Log, "/api/log") - flask_resource_manager.add_resource(IslandLog, "/api/log/island/download") + api.add_resource(ZeroTrustFindingEvent, "/api/zero-trust/finding-event/") + api.add_resource(TelemetryFeed, "/api/telemetry-feed") + api.add_resource(Log, "/api/log") + api.add_resource(IslandLog, "/api/log/island/download") - flask_resource_manager.add_resource( + api.add_resource( PBAFileDownload, "/api/pba/download/", ) - flask_resource_manager.add_resource( + api.add_resource( FileUpload, "/api/file-upload/", "/api/file-upload/?load=", "/api/file-upload/?restore=", ) - flask_resource_manager.add_resource( - PropagationCredentials, "/api/propagation-credentials/" - ) - flask_resource_manager.add_resource(RemoteRun, "/api/remote-monkey") - flask_resource_manager.add_resource(VersionUpdate, "/api/version-update") - flask_resource_manager.add_resource( - StopAgentCheck, "/api/monkey-control/needs-to-stop/" - ) - flask_resource_manager.add_resource(StopAllAgents, "/api/monkey-control/stop-all-agents") + api.add_resource(PropagationCredentials, "/api/propagation-credentials/") + api.add_resource(RemoteRun, "/api/remote-monkey") + api.add_resource(VersionUpdate, "/api/version-update") + api.add_resource(StopAgentCheck, "/api/monkey-control/needs-to-stop/") + api.add_resource(StopAllAgents, "/api/monkey-control/stop-all-agents") # Resources used by black box tests - flask_resource_manager.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey") - flask_resource_manager.add_resource(ClearCaches, "/api/test/clear-caches") - flask_resource_manager.add_resource(LogBlackboxEndpoint, "/api/test/log") - flask_resource_manager.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry") + api.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey") + api.add_resource(ClearCaches, "/api/test/clear-caches") + api.add_resource(LogBlackboxEndpoint, "/api/test/log") + api.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry") def init_app(mongo_url: str, container: DIContainer): @@ -206,7 +195,7 @@ def init_app(mongo_url: str, container: DIContainer): init_app_services(app) init_app_url_rules(app) - flask_resource_manager = FlaskResourceManager(api, container) + flask_resource_manager = FlaskDIWrapper(api, container) init_api_resources(flask_resource_manager) return app diff --git a/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py b/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py index db58ed173..723c777b8 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py +++ b/monkey/tests/unit_tests/monkey_island/cc/resources/conftest.py @@ -40,7 +40,7 @@ def mock_init_app(container): api.representations = {"application/json": output_json} monkey_island.cc.app.init_app_url_rules(app) - flask_resource_manager = monkey_island.cc.app.FlaskResourceManager(api, container) + flask_resource_manager = monkey_island.cc.app.FlaskDIWrapper(api, container) monkey_island.cc.app.init_api_resources(flask_resource_manager) flask_jwt_extended.JWTManager(app)