From 528ca76c3268d6eff27251fbcb5053c458a0be5e Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 9 May 2022 15:52:01 -0400 Subject: [PATCH] Island: Use AWSService in RemoteRun resource --- monkey/monkey_island/cc/resources/remote_run.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/monkey/monkey_island/cc/resources/remote_run.py b/monkey/monkey_island/cc/resources/remote_run.py index f918c9253..d1c1149b5 100644 --- a/monkey/monkey_island/cc/resources/remote_run.py +++ b/monkey/monkey_island/cc/resources/remote_run.py @@ -5,8 +5,7 @@ from botocore.exceptions import ClientError, NoCredentialsError from flask import jsonify, make_response, request from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.services import aws_service -from monkey_island.cc.services.remote_run_aws import RemoteRunAwsService +from monkey_island.cc.services import AWSService CLIENT_ERROR_FORMAT = ( "ClientError, error message: '{}'. Probably, the IAM role that has been associated with the " @@ -19,20 +18,24 @@ NO_CREDS_ERROR_FORMAT = ( class RemoteRun(flask_restful.Resource): + def __init__(self, aws_service: AWSService): + self._aws_service = aws_service + def run_aws_monkeys(self, request_body): instances = request_body.get("instances") island_ip = request_body.get("island_ip") - return RemoteRunAwsService.run_aws_monkeys(instances, island_ip) + + return self._aws_service.run_agents_on_managed_instances(instances, island_ip) @jwt_required def get(self): action = request.args.get("action") if action == "list_aws": - is_aws = aws_service.is_on_aws() + is_aws = self._aws_service.island_is_running_on_aws() resp = {"is_aws": is_aws} if is_aws: try: - resp["instances"] = aws_service.get_instances() + resp["instances"] = self._aws_service.get_managed_instances() except NoCredentialsError as e: resp["error"] = NO_CREDS_ERROR_FORMAT.format(e) return jsonify(resp)