diff --git a/monkey/common/cloud/aws/aws_instance.py b/monkey/common/cloud/aws/aws_instance.py index b1c2c174d..8f00cc399 100644 --- a/monkey/common/cloud/aws/aws_instance.py +++ b/monkey/common/cloud/aws/aws_instance.py @@ -35,10 +35,11 @@ class AwsInstance(CloudInstance): def __init__(self): self._is_instance, instance_info = AwsInstance._fetch_instance_info() - self.instance_id = instance_info.instance_id - self.region = instance_info.region - self.account_id = instance_info.account_id + self._instance_id = instance_info.instance_id + self._region = instance_info.region + self._account_id = instance_info.account_id + @property def is_instance(self) -> bool: return self._is_instance @@ -93,10 +94,10 @@ class AwsInstance(CloudInstance): return None def get_instance_id(self): - return self.instance_id + return self._instance_id def get_region(self): - return self.region + return self._region @staticmethod def _extract_account_id(instance_identity_document_response): @@ -116,4 +117,4 @@ class AwsInstance(CloudInstance): :return: the AWS account ID which "owns" this instance. See https://docs.aws.amazon.com/general/latest/gr/acct-identifiers.html """ - return self.account_id + return self._account_id diff --git a/monkey/infection_monkey/utils/aws_environment_check.py b/monkey/infection_monkey/utils/aws_environment_check.py index aa60e0a55..af84354e8 100644 --- a/monkey/infection_monkey/utils/aws_environment_check.py +++ b/monkey/infection_monkey/utils/aws_environment_check.py @@ -11,7 +11,7 @@ logger = logging.getLogger(__name__) def _running_on_aws(aws_instance: AwsInstance) -> bool: - return aws_instance.is_instance() + return aws_instance.is_instance def _report_aws_environment(telemetry_messenger: LegacyTelemetryMessengerAdapter): diff --git a/monkey/monkey_island/cc/services/remote_run_aws.py b/monkey/monkey_island/cc/services/remote_run_aws.py index 7b2bdbf90..1e1ac5b78 100644 --- a/monkey/monkey_island/cc/services/remote_run_aws.py +++ b/monkey/monkey_island/cc/services/remote_run_aws.py @@ -49,14 +49,14 @@ class RemoteRunAwsService: @staticmethod def is_running_on_aws(): with aws_lock: - return RemoteRunAwsService.aws_instance.is_instance() + return RemoteRunAwsService.aws_instance.is_instance @staticmethod def update_aws_region_authless(): """ Updates the AWS region without auth params (via IAM role) """ - AwsService.set_region(RemoteRunAwsService.aws_instance.region) + AwsService.set_region(RemoteRunAwsService.aws_instance._region) @staticmethod def _run_aws_monkey_cmd_async(instance_id, is_linux, island_ip): diff --git a/monkey/monkey_island/monkey_island.spec b/monkey/monkey_island/monkey_island.spec index 80335d346..4e1ff825c 100644 --- a/monkey/monkey_island/monkey_island.spec +++ b/monkey/monkey_island/monkey_island.spec @@ -4,7 +4,6 @@ import platform import sys - block_cipher = None @@ -13,7 +12,8 @@ def main(): # The format of the tuples is (src, dest_dir). See https://pythonhosted.org/PyInstaller/spec-files.html#adding-data-files added_datas = [ ("../common/BUILD", "/common"), - ("../monkey_island/cc/setup/mongo/attack_mitigations.json", "/monkey_island/cc/setup/mongo/attack_mitigations.json") + ("../monkey_island/cc/setup/mongo/attack_mitigations.json", + "/monkey_island/cc/setup/mongo/attack_mitigations.json") ] a = Analysis(['main.py'], 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 04421920f..2981a7bd1 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 @@ -74,7 +74,7 @@ def good_data_mock_instance(): def test_is_instance_good_data(good_data_mock_instance): - assert good_data_mock_instance.is_instance() + assert good_data_mock_instance.is_instance def test_get_instance_id_good_data(good_data_mock_instance): @@ -102,7 +102,7 @@ def bad_region_data_mock_instance(): def test_is_instance_bad_region_data(bad_region_data_mock_instance): - assert bad_region_data_mock_instance.is_instance() + assert bad_region_data_mock_instance.is_instance def test_get_instance_id_bad_region_data(bad_region_data_mock_instance): @@ -130,7 +130,7 @@ def bad_account_id_data_mock_instance(): def test_is_instance_bad_account_id_data(bad_account_id_data_mock_instance): - assert bad_account_id_data_mock_instance.is_instance() + assert bad_account_id_data_mock_instance.is_instance def test_get_instance_id_bad_account_id_data(bad_account_id_data_mock_instance): @@ -160,7 +160,7 @@ def bad_instance_id_request_mock_instance(instance_id_exception): @pytest.mark.parametrize("instance_id_exception", [requests.RequestException, IOError]) def test_is_instance_bad_instance_id_request(bad_instance_id_request_mock_instance): - assert bad_instance_id_request_mock_instance.is_instance() is False + assert bad_instance_id_request_mock_instance.is_instance is False @pytest.mark.parametrize("instance_id_exception", [requests.RequestException, IOError]) @@ -193,7 +193,7 @@ def bad_region_request_mock_instance(region_exception): @pytest.mark.parametrize("region_exception", [requests.RequestException, IOError]) def test_is_instance_bad_region_request(bad_region_request_mock_instance): - assert bad_region_request_mock_instance.is_instance() + assert bad_region_request_mock_instance.is_instance @pytest.mark.parametrize("region_exception", [requests.RequestException, IOError]) @@ -226,7 +226,7 @@ def bad_account_id_request_mock_instance(account_id_exception): @pytest.mark.parametrize("account_id_exception", [requests.RequestException, IOError]) def test_is_instance_bad_account_id_request(bad_account_id_request_mock_instance): - assert bad_account_id_request_mock_instance.is_instance() + assert bad_account_id_request_mock_instance.is_instance @pytest.mark.parametrize("account_id_exception", [requests.RequestException, IOError]) @@ -265,7 +265,7 @@ def not_found_request_mock_instance(): def test_is_instance_not_found_request(not_found_request_mock_instance): - assert not_found_request_mock_instance.is_instance() is False + assert not_found_request_mock_instance.is_instance is False def test_get_instance_id_not_found_request(not_found_request_mock_instance):