forked from p15670423/monkey
Island: Use AWSService in RemoteRun resource
This commit is contained in:
parent
144506c32d
commit
528ca76c32
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue