-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #246 from CloudWanderer-io/feature/improve-account…
…-id-and-region-fetching Allow the setting of account_id and enabled_regions in CloudWandererA…
- Loading branch information
Showing
7 changed files
with
148 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
"""The CloudWanderer AWS Interface.""" | ||
from .interface import CloudWandererAWSInterface | ||
from .session import CloudWandererBoto3Session | ||
from .models import AWSResourceTypeFilter | ||
from .session import CloudWandererBoto3Session, CloudWandererBoto3SessionGetterClientConfig | ||
|
||
__all__ = ["CloudWandererAWSInterface", "CloudWandererBoto3Session", "AWSResourceTypeFilter"] | ||
__all__ = [ | ||
"CloudWandererAWSInterface", | ||
"CloudWandererBoto3Session", | ||
"AWSResourceTypeFilter", | ||
"CloudWandererBoto3SessionGetterClientConfig", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from cloudwanderer.aws_interface import CloudWandererAWSInterface | ||
|
||
|
||
def test_get_account_id(): | ||
subject = CloudWandererAWSInterface( | ||
cloudwanderer_boto3_session=MagicMock(**{"get_account_id.return_value": "0123456789012"}) | ||
) | ||
|
||
assert subject.get_account_id() == "0123456789012" | ||
|
||
|
||
def test_get_account_id_init_arg(): | ||
subject = CloudWandererAWSInterface(account_id="0123456789012") | ||
|
||
assert subject.get_account_id() == "0123456789012" | ||
|
||
|
||
def test_get_enabled_regions(): | ||
subject = CloudWandererAWSInterface( | ||
cloudwanderer_boto3_session=MagicMock(**{"get_enabled_regions.return_value": ["eu-west-1"]}) | ||
) | ||
|
||
assert subject.get_enabled_regions() == ["eu-west-1"] | ||
|
||
|
||
def test_get_enabled_regions_init_arg(): | ||
subject = CloudWandererAWSInterface(enabled_regions=["eu-west-1"]) | ||
|
||
assert subject.get_enabled_regions() == ["eu-west-1"] |
59 changes: 59 additions & 0 deletions
59
tests/unit/aws_interface/test_cloudwanderer_boto3_session.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from unittest.mock import MagicMock | ||
|
||
from cloudwanderer.aws_interface import CloudWandererBoto3Session, CloudWandererBoto3SessionGetterClientConfig | ||
|
||
|
||
def test_get_account_id(): | ||
botocore_session = MagicMock() | ||
subject = CloudWandererBoto3Session( | ||
aws_access_key_id="A", | ||
aws_secret_access_key="A", | ||
aws_session_token="A", | ||
botocore_session=botocore_session, | ||
getter_client_config=CloudWandererBoto3SessionGetterClientConfig( | ||
sts={"endpoint_url": "sts.eu-west-1.amazonaws.com"} | ||
), | ||
) | ||
|
||
subject.get_account_id() | ||
|
||
botocore_session.create_client.assert_called_with( | ||
"sts", | ||
region_name=None, | ||
api_version=None, | ||
use_ssl=True, | ||
verify=None, | ||
endpoint_url="sts.eu-west-1.amazonaws.com", | ||
aws_access_key_id=None, | ||
aws_secret_access_key=None, | ||
aws_session_token=None, | ||
config=None, | ||
) | ||
|
||
|
||
def test_get_enabled_regions(): | ||
botocore_session = MagicMock() | ||
subject = CloudWandererBoto3Session( | ||
aws_access_key_id="A", | ||
aws_secret_access_key="A", | ||
aws_session_token="A", | ||
botocore_session=botocore_session, | ||
getter_client_config=CloudWandererBoto3SessionGetterClientConfig( | ||
ec2={"endpoint_url": "ec2.eu-west-1.amazonaws.com"} | ||
), | ||
) | ||
|
||
subject.get_enabled_regions() | ||
|
||
botocore_session.create_client.assert_called_with( | ||
"ec2", | ||
region_name=None, | ||
api_version=None, | ||
use_ssl=True, | ||
verify=None, | ||
endpoint_url="ec2.eu-west-1.amazonaws.com", | ||
aws_access_key_id=None, | ||
aws_secret_access_key=None, | ||
aws_session_token=None, | ||
config=None, | ||
) |