From 7b2ff1e159d7b1c23da6a5dcd5ec15c1f44326c7 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Mon, 2 May 2022 11:05:18 +0300 Subject: [PATCH] Common: Remove CloudInstance since aws is the only cloud supported This change simplifies the codebase by removing unnecessary inheritance and nested directory structure --- monkey/common/{cloud => aws}/__init__.py | 0 monkey/common/{cloud => }/aws/aws_instance.py | 3 +-- monkey/common/{cloud => }/aws/aws_service.py | 2 +- monkey/common/cloud/aws/__init__.py | 0 monkey/common/cloud/instance.py | 9 --------- monkey/common/cmd/aws/aws_cmd_runner.py | 2 +- monkey/infection_monkey/utils/aws_environment_check.py | 2 +- monkey/monkey_island/cc/resources/remote_run.py | 2 +- monkey/monkey_island/cc/services/remote_run_aws.py | 4 ++-- .../monkey_island/cc/services/reporting/aws_exporter.py | 2 +- .../unit_tests/common/cloud/aws/test_aws_instance.py | 2 +- .../unit_tests/common/cloud/aws/test_aws_service.py | 2 +- 12 files changed, 10 insertions(+), 20 deletions(-) rename monkey/common/{cloud => aws}/__init__.py (100%) rename monkey/common/{cloud => }/aws/aws_instance.py (97%) rename monkey/common/{cloud => }/aws/aws_service.py (97%) delete mode 100644 monkey/common/cloud/aws/__init__.py delete mode 100644 monkey/common/cloud/instance.py diff --git a/monkey/common/cloud/__init__.py b/monkey/common/aws/__init__.py similarity index 100% rename from monkey/common/cloud/__init__.py rename to monkey/common/aws/__init__.py diff --git a/monkey/common/cloud/aws/aws_instance.py b/monkey/common/aws/aws_instance.py similarity index 97% rename from monkey/common/cloud/aws/aws_instance.py rename to monkey/common/aws/aws_instance.py index ced7d6ab5..9f7b81180 100644 --- a/monkey/common/cloud/aws/aws_instance.py +++ b/monkey/common/aws/aws_instance.py @@ -6,7 +6,6 @@ from typing import Optional, Tuple import requests -from common.cloud.instance import CloudInstance from common.utils.code_utils import Singleton AWS_INSTANCE_METADATA_LOCAL_IP_ADDRESS = "169.254.169.254" @@ -25,7 +24,7 @@ class AwsInstanceInfo: account_id: Optional[str] = None -class AwsInstance(CloudInstance): +class AwsInstance: """ Class which gives useful information about the current instance you're on. """ diff --git a/monkey/common/cloud/aws/aws_service.py b/monkey/common/aws/aws_service.py similarity index 97% rename from monkey/common/cloud/aws/aws_service.py rename to monkey/common/aws/aws_service.py index 3cacc1a8f..84710f839 100644 --- a/monkey/common/cloud/aws/aws_service.py +++ b/monkey/common/aws/aws_service.py @@ -3,7 +3,7 @@ import logging import boto3 import botocore -from common.cloud.aws.aws_instance import AwsInstance +from common.aws.aws_instance import AwsInstance INSTANCE_INFORMATION_LIST_KEY = "InstanceInformationList" INSTANCE_ID_KEY = "InstanceId" diff --git a/monkey/common/cloud/aws/__init__.py b/monkey/common/cloud/aws/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/monkey/common/cloud/instance.py b/monkey/common/cloud/instance.py deleted file mode 100644 index 77376ee8e..000000000 --- a/monkey/common/cloud/instance.py +++ /dev/null @@ -1,9 +0,0 @@ -class CloudInstance(object): - """ - This is an abstract class which represents a cloud instance. - - The current machine can be a cloud instance (for example EC2 instance or Azure VM). - """ - - def is_instance(self) -> bool: - raise NotImplementedError() diff --git a/monkey/common/cmd/aws/aws_cmd_runner.py b/monkey/common/cmd/aws/aws_cmd_runner.py index c1c65ecb9..03d4e9e4f 100644 --- a/monkey/common/cmd/aws/aws_cmd_runner.py +++ b/monkey/common/cmd/aws/aws_cmd_runner.py @@ -1,7 +1,7 @@ import logging import time -from common.cloud.aws.aws_service import AwsService +from common.aws.aws_service import AwsService from common.cmd.aws.aws_cmd_result import AwsCmdResult from common.cmd.cmd_runner import CmdRunner from common.cmd.cmd_status import CmdStatus diff --git a/monkey/infection_monkey/utils/aws_environment_check.py b/monkey/infection_monkey/utils/aws_environment_check.py index f508135ca..6bdbb5c85 100644 --- a/monkey/infection_monkey/utils/aws_environment_check.py +++ b/monkey/infection_monkey/utils/aws_environment_check.py @@ -1,6 +1,6 @@ import logging -from common.cloud.aws.aws_instance import AwsInstance +from common.aws.aws_instance import AwsInstance from infection_monkey.telemetry.aws_instance_telem import AWSInstanceTelemetry from infection_monkey.telemetry.messengers.legacy_telemetry_messenger_adapter import ( LegacyTelemetryMessengerAdapter, diff --git a/monkey/monkey_island/cc/resources/remote_run.py b/monkey/monkey_island/cc/resources/remote_run.py index 0e6e6df10..864fb4848 100644 --- a/monkey/monkey_island/cc/resources/remote_run.py +++ b/monkey/monkey_island/cc/resources/remote_run.py @@ -4,7 +4,7 @@ import flask_restful from botocore.exceptions import ClientError, NoCredentialsError from flask import jsonify, make_response, request -from common.cloud.aws.aws_service import AwsService +from common.aws.aws_service import AwsService from monkey_island.cc.resources.auth.auth import jwt_required from monkey_island.cc.services.remote_run_aws import RemoteRunAwsService diff --git a/monkey/monkey_island/cc/services/remote_run_aws.py b/monkey/monkey_island/cc/services/remote_run_aws.py index 26ec58e5c..dd15bff07 100644 --- a/monkey/monkey_island/cc/services/remote_run_aws.py +++ b/monkey/monkey_island/cc/services/remote_run_aws.py @@ -1,8 +1,8 @@ import logging from threading import Event -from common.cloud.aws.aws_instance import AwsInstance -from common.cloud.aws.aws_service import AwsService +from common.aws.aws_instance import AwsInstance +from common.aws.aws_service import AwsService from common.cmd.aws.aws_cmd_runner import AwsCmdRunner from common.cmd.cmd import Cmd from common.cmd.cmd_runner import CmdRunner diff --git a/monkey/monkey_island/cc/services/reporting/aws_exporter.py b/monkey/monkey_island/cc/services/reporting/aws_exporter.py index ce3f6a953..ed8925985 100644 --- a/monkey/monkey_island/cc/services/reporting/aws_exporter.py +++ b/monkey/monkey_island/cc/services/reporting/aws_exporter.py @@ -5,7 +5,7 @@ from datetime import datetime import boto3 from botocore.exceptions import UnknownServiceError -from common.cloud.aws.aws_instance import AwsInstance +from common.aws.aws_instance import AwsInstance from monkey_island.cc.services.reporting.exporter import Exporter __authors__ = ["maor.rayzin", "shay.nehmad"] diff --git a/monkey/tests/unit_tests/common/cloud/aws/test_aws_instance.py b/monkey/tests/unit_tests/common/cloud/aws/test_aws_instance.py index 30cc0ce08..d36c92ac0 100644 --- a/monkey/tests/unit_tests/common/cloud/aws/test_aws_instance.py +++ b/monkey/tests/unit_tests/common/cloud/aws/test_aws_instance.py @@ -2,7 +2,7 @@ import pytest import requests import requests_mock -from common.cloud.aws.aws_instance import AWS_LATEST_METADATA_URI_PREFIX, AwsInstance +from common.aws.aws_instance import AWS_LATEST_METADATA_URI_PREFIX, AwsInstance INSTANCE_ID_RESPONSE = "i-1234567890abcdef0" diff --git a/monkey/tests/unit_tests/common/cloud/aws/test_aws_service.py b/monkey/tests/unit_tests/common/cloud/aws/test_aws_service.py index dc5ec3831..f66646b34 100644 --- a/monkey/tests/unit_tests/common/cloud/aws/test_aws_service.py +++ b/monkey/tests/unit_tests/common/cloud/aws/test_aws_service.py @@ -1,7 +1,7 @@ import json from unittest import TestCase -from common.cloud.aws.aws_service import filter_instance_data_from_aws_response +from common.aws.aws_service import filter_instance_data_from_aws_response class TestAwsService(TestCase):