forked from p15670423/monkey
Island, Common: Change AwsInstance properties to private, add getter
This commit is contained in:
parent
f63bc77df0
commit
fead7f602e
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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'],
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue