Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only query sgs owned by the account #535

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion awslimitchecker/services/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,9 @@ def _find_usage_networking_sgs(self):
logger.debug("Getting usage for EC2 VPC resources")
sg_count = 0
rules_per_sg = defaultdict(int)
for sg in self.resource_conn.security_groups.all():
for sg in self.resource_conn.security_groups.filter(
owner_id=self.current_account_id
):
if sg.vpc_id is None:
continue
sg_count += 1
Expand Down
5 changes: 3 additions & 2 deletions awslimitchecker/tests/services/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,10 @@ def test_simple(self):
mocks = fixtures.test_find_usage_networking_sgs

mock_conn = Mock()
mock_conn.security_groups.all.return_value = mocks
mock_conn.security_groups.filter.return_value = mocks

cls = _Ec2Service(21, 43, {}, None)
cls._current_account_id = "1234567890"
cls.resource_conn = mock_conn

with patch('awslimitchecker.services.ec2.logger') as mock_logger:
Expand Down Expand Up @@ -802,7 +803,7 @@ def test_simple(self):
# egress: IPv4 = 22; IPv6 = 29
assert sorted_usage[2].get_value() == 29
assert mock_conn.mock_calls == [
call.security_groups.all()
call.security_groups.filter(owner_id='1234567890')
]


Expand Down