Island: Rename FlaskResourceManager -> FlaskDIWrapper

This commit is contained in:
Mike Salvatore 2022-04-26 19:19:24 -04:00
parent 98033c96c0
commit 54d34d1816
2 changed files with 40 additions and 51 deletions

View File

@ -113,8 +113,7 @@ def init_app_url_rules(app):
app.add_url_rule("/<path:static_path>", "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/<string:guid>",
"/api/agent/<string:guid>/<string:config_format>",
)
flask_resource_manager.add_resource(LocalRun, "/api/local-monkey")
flask_resource_manager.add_resource(
Telemetry, "/api/telemetry", "/api/telemetry/<string:monkey_guid>"
)
api.add_resource(LocalRun, "/api/local-monkey")
api.add_resource(Telemetry, "/api/telemetry", "/api/telemetry/<string:monkey_guid>")
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/<string:host_os>",
)
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/<string:report_data>"
)
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/<string:report_data>")
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/<string:finding_id>"
)
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/<string:finding_id>")
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/<string:filename>",
)
flask_resource_manager.add_resource(
api.add_resource(
FileUpload,
"/api/file-upload/<string:target_os>",
"/api/file-upload/<string:target_os>?load=<string:filename>",
"/api/file-upload/<string:target_os>?restore=<string:filename>",
)
flask_resource_manager.add_resource(
PropagationCredentials, "/api/propagation-credentials/<string:guid>"
)
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/<int:monkey_guid>"
)
flask_resource_manager.add_resource(StopAllAgents, "/api/monkey-control/stop-all-agents")
api.add_resource(PropagationCredentials, "/api/propagation-credentials/<string:guid>")
api.add_resource(RemoteRun, "/api/remote-monkey")
api.add_resource(VersionUpdate, "/api/version-update")
api.add_resource(StopAgentCheck, "/api/monkey-control/needs-to-stop/<int:monkey_guid>")
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

View File

@ -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)