forked from p15670423/monkey
Island: Rename FlaskResourceManager -> FlaskDIWrapper
This commit is contained in:
parent
98033c96c0
commit
54d34d1816
|
@ -113,8 +113,7 @@ def init_app_url_rules(app):
|
||||||
app.add_url_rule("/<path:static_path>", "serve_static_file", serve_static_file)
|
app.add_url_rule("/<path:static_path>", "serve_static_file", serve_static_file)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Come up with a better name than FlaskResourceManager
|
class FlaskDIWrapper:
|
||||||
class FlaskResourceManager:
|
|
||||||
def __init__(self, api: flask_restful.Api, container: DIContainer):
|
def __init__(self, api: flask_restful.Api, container: DIContainer):
|
||||||
self._api = api
|
self._api = api
|
||||||
self._container = container
|
self._container = container
|
||||||
|
@ -124,76 +123,66 @@ class FlaskResourceManager:
|
||||||
self._api.add_resource(resource, *urls, resource_class_args=dependencies)
|
self._api.add_resource(resource, *urls, resource_class_args=dependencies)
|
||||||
|
|
||||||
|
|
||||||
def init_api_resources(flask_resource_manager: FlaskResourceManager):
|
def init_api_resources(api: FlaskDIWrapper):
|
||||||
flask_resource_manager.add_resource(Root, "/api")
|
api.add_resource(Root, "/api")
|
||||||
flask_resource_manager.add_resource(Registration, "/api/registration")
|
api.add_resource(Registration, "/api/registration")
|
||||||
flask_resource_manager.add_resource(Authenticate, "/api/auth")
|
api.add_resource(Authenticate, "/api/auth")
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(
|
||||||
Monkey,
|
Monkey,
|
||||||
"/api/agent",
|
"/api/agent",
|
||||||
"/api/agent/<string:guid>",
|
"/api/agent/<string:guid>",
|
||||||
"/api/agent/<string:guid>/<string:config_format>",
|
"/api/agent/<string:guid>/<string:config_format>",
|
||||||
)
|
)
|
||||||
flask_resource_manager.add_resource(LocalRun, "/api/local-monkey")
|
api.add_resource(LocalRun, "/api/local-monkey")
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(Telemetry, "/api/telemetry", "/api/telemetry/<string:monkey_guid>")
|
||||||
Telemetry, "/api/telemetry", "/api/telemetry/<string:monkey_guid>"
|
|
||||||
)
|
|
||||||
|
|
||||||
flask_resource_manager.add_resource(IslandMode, "/api/island-mode")
|
api.add_resource(IslandMode, "/api/island-mode")
|
||||||
flask_resource_manager.add_resource(IslandConfiguration, "/api/configuration/island")
|
api.add_resource(IslandConfiguration, "/api/configuration/island")
|
||||||
flask_resource_manager.add_resource(ConfigurationExport, "/api/configuration/export")
|
api.add_resource(ConfigurationExport, "/api/configuration/export")
|
||||||
flask_resource_manager.add_resource(ConfigurationImport, "/api/configuration/import")
|
api.add_resource(ConfigurationImport, "/api/configuration/import")
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(
|
||||||
MonkeyDownload,
|
MonkeyDownload,
|
||||||
"/api/agent/download/<string:host_os>",
|
"/api/agent/download/<string:host_os>",
|
||||||
)
|
)
|
||||||
flask_resource_manager.add_resource(NetMap, "/api/netmap")
|
api.add_resource(NetMap, "/api/netmap")
|
||||||
flask_resource_manager.add_resource(Edge, "/api/netmap/edge")
|
api.add_resource(Edge, "/api/netmap/edge")
|
||||||
flask_resource_manager.add_resource(Node, "/api/netmap/node")
|
api.add_resource(Node, "/api/netmap/node")
|
||||||
flask_resource_manager.add_resource(NodeStates, "/api/netmap/node-states")
|
api.add_resource(NodeStates, "/api/netmap/node-states")
|
||||||
|
|
||||||
flask_resource_manager.add_resource(SecurityReport, "/api/report/security")
|
api.add_resource(SecurityReport, "/api/report/security")
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(ZeroTrustReport, "/api/report/zero-trust/<string:report_data>")
|
||||||
ZeroTrustReport, "/api/report/zero-trust/<string:report_data>"
|
api.add_resource(AttackReport, "/api/report/attack")
|
||||||
)
|
api.add_resource(RansomwareReport, "/api/report/ransomware")
|
||||||
flask_resource_manager.add_resource(AttackReport, "/api/report/attack")
|
api.add_resource(ManualExploitation, "/api/exploitations/manual")
|
||||||
flask_resource_manager.add_resource(RansomwareReport, "/api/report/ransomware")
|
api.add_resource(MonkeyExploitation, "/api/exploitations/monkey")
|
||||||
flask_resource_manager.add_resource(ManualExploitation, "/api/exploitations/manual")
|
|
||||||
flask_resource_manager.add_resource(MonkeyExploitation, "/api/exploitations/monkey")
|
|
||||||
|
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(ZeroTrustFindingEvent, "/api/zero-trust/finding-event/<string:finding_id>")
|
||||||
ZeroTrustFindingEvent, "/api/zero-trust/finding-event/<string:finding_id>"
|
api.add_resource(TelemetryFeed, "/api/telemetry-feed")
|
||||||
)
|
api.add_resource(Log, "/api/log")
|
||||||
flask_resource_manager.add_resource(TelemetryFeed, "/api/telemetry-feed")
|
api.add_resource(IslandLog, "/api/log/island/download")
|
||||||
flask_resource_manager.add_resource(Log, "/api/log")
|
|
||||||
flask_resource_manager.add_resource(IslandLog, "/api/log/island/download")
|
|
||||||
|
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(
|
||||||
PBAFileDownload,
|
PBAFileDownload,
|
||||||
"/api/pba/download/<string:filename>",
|
"/api/pba/download/<string:filename>",
|
||||||
)
|
)
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(
|
||||||
FileUpload,
|
FileUpload,
|
||||||
"/api/file-upload/<string:target_os>",
|
"/api/file-upload/<string:target_os>",
|
||||||
"/api/file-upload/<string:target_os>?load=<string:filename>",
|
"/api/file-upload/<string:target_os>?load=<string:filename>",
|
||||||
"/api/file-upload/<string:target_os>?restore=<string:filename>",
|
"/api/file-upload/<string:target_os>?restore=<string:filename>",
|
||||||
)
|
)
|
||||||
|
|
||||||
flask_resource_manager.add_resource(
|
api.add_resource(PropagationCredentials, "/api/propagation-credentials/<string:guid>")
|
||||||
PropagationCredentials, "/api/propagation-credentials/<string:guid>"
|
api.add_resource(RemoteRun, "/api/remote-monkey")
|
||||||
)
|
api.add_resource(VersionUpdate, "/api/version-update")
|
||||||
flask_resource_manager.add_resource(RemoteRun, "/api/remote-monkey")
|
api.add_resource(StopAgentCheck, "/api/monkey-control/needs-to-stop/<int:monkey_guid>")
|
||||||
flask_resource_manager.add_resource(VersionUpdate, "/api/version-update")
|
api.add_resource(StopAllAgents, "/api/monkey-control/stop-all-agents")
|
||||||
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")
|
|
||||||
|
|
||||||
# Resources used by black box tests
|
# Resources used by black box tests
|
||||||
flask_resource_manager.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey")
|
api.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey")
|
||||||
flask_resource_manager.add_resource(ClearCaches, "/api/test/clear-caches")
|
api.add_resource(ClearCaches, "/api/test/clear-caches")
|
||||||
flask_resource_manager.add_resource(LogBlackboxEndpoint, "/api/test/log")
|
api.add_resource(LogBlackboxEndpoint, "/api/test/log")
|
||||||
flask_resource_manager.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry")
|
api.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry")
|
||||||
|
|
||||||
|
|
||||||
def init_app(mongo_url: str, container: DIContainer):
|
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_services(app)
|
||||||
init_app_url_rules(app)
|
init_app_url_rules(app)
|
||||||
|
|
||||||
flask_resource_manager = FlaskResourceManager(api, container)
|
flask_resource_manager = FlaskDIWrapper(api, container)
|
||||||
init_api_resources(flask_resource_manager)
|
init_api_resources(flask_resource_manager)
|
||||||
|
|
||||||
return app
|
return app
|
||||||
|
|
|
@ -40,7 +40,7 @@ def mock_init_app(container):
|
||||||
api.representations = {"application/json": output_json}
|
api.representations = {"application/json": output_json}
|
||||||
|
|
||||||
monkey_island.cc.app.init_app_url_rules(app)
|
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)
|
monkey_island.cc.app.init_api_resources(flask_resource_manager)
|
||||||
|
|
||||||
flask_jwt_extended.JWTManager(app)
|
flask_jwt_extended.JWTManager(app)
|
||||||
|
|
Loading…
Reference in New Issue