From e8cd88420bf0f6ae10bd45a6071714041e962bfe Mon Sep 17 00:00:00 2001 From: vakarisz Date: Fri, 8 Jul 2022 17:05:16 +0300 Subject: [PATCH] Island: Add ConfiguredPropagationCredentials resource --- monkey/monkey_island/cc/app.py | 5 ++++ .../configured_propagation_credentials.py | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 monkey/monkey_island/cc/resources/credentials/configured_propagation_credentials.py diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index 408839b6c..df8497f65 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -28,6 +28,9 @@ from monkey_island.cc.resources.blackbox.monkey_blackbox_endpoint import MonkeyB from monkey_island.cc.resources.blackbox.telemetry_blackbox_endpoint import ( TelemetryBlackboxEndpoint, ) +from monkey_island.cc.resources.credentials.configured_propagation_credentials import ( + ConfiguredPropagationCredentials, +) from monkey_island.cc.resources.edge import Edge from monkey_island.cc.resources.exploitations.manual_exploitation import ManualExploitation from monkey_island.cc.resources.exploitations.monkey_exploitation import MonkeyExploitation @@ -185,6 +188,8 @@ def init_restful_endpoints(api: FlaskDIWrapper): api.add_resource(FileUpload) api.add_resource(PropagationCredentials) + api.add_resource(ConfiguredPropagationCredentials) + api.add_resource(RemoteRun) api.add_resource(VersionUpdate) api.add_resource(StopAgentCheck) diff --git a/monkey/monkey_island/cc/resources/credentials/configured_propagation_credentials.py b/monkey/monkey_island/cc/resources/credentials/configured_propagation_credentials.py new file mode 100644 index 000000000..0794e979c --- /dev/null +++ b/monkey/monkey_island/cc/resources/credentials/configured_propagation_credentials.py @@ -0,0 +1,27 @@ +import logging + +from flask import jsonify, request + +from common.credentials import Credentials +from monkey_island.cc.repository import ICredentialsRepository +from monkey_island.cc.resources.AbstractResource import AbstractResource + +logger = logging.getLogger(__name__) + + +class ConfiguredPropagationCredentials(AbstractResource): + # API Spec: Resource name should be plural + urls = ["/api/propagation-credentials/configured"] + + def __init__(self, credentials_repository: ICredentialsRepository): + self._credentials_repository = credentials_repository + + def get(self): + return jsonify(self._credentials_repository.get_configured_credentials()) + + def post(self): + credentials = Credentials.from_mapping(request.json) + self._credentials_repository.save_configured_credentials(credentials) + + def delete(self): + self._credentials_repository.remove_configured_credentials()