Skip to content

Commit

Permalink
fix IAM permissions bug for EC2 DescribeAccountAttributes, and ignore…
Browse files Browse the repository at this point in the history
… AccountLimits objects from pagination
  • Loading branch information
jantman committed Nov 29, 2015
1 parent e93cf0a commit 18d96d3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions awslimitchecker/services/ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ def required_iam_permissions(self):
:rtype: list
"""
return [
"ec2:DescribeAccountAttributes",
"ec2:DescribeAddresses",
"ec2:DescribeInstances",
"ec2:DescribeInternetGateways",
Expand Down
3 changes: 2 additions & 1 deletion awslimitchecker/tests/services/test_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,9 @@ def test_find_usage_instances_key_error(self):

def test_required_iam_permissions(self):
cls = _Ec2Service(21, 43)
assert len(cls.required_iam_permissions()) == 12
assert len(cls.required_iam_permissions()) == 13
assert cls.required_iam_permissions() == [
"ec2:DescribeAccountAttributes",
"ec2:DescribeAddresses",
"ec2:DescribeInstances",
"ec2:DescribeInternetGateways",
Expand Down
22 changes: 22 additions & 0 deletions awslimitchecker/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

from boto.exception import BotoServerError
from boto.resultset import ResultSet
from boto.ec2.autoscale.limits import AccountLimits

from awslimitchecker.utils import (
StoreKeyValuePair, dict2cols, invoke_with_throttling_retries,
Expand Down Expand Up @@ -421,6 +422,27 @@ def test_dict_missing_params(self):
"Query returned a dict, but does not have _paginate_dict params "
"set; cannot paginate (<Mock id='") is True

def test_result_AccountLimits(self):
func = Mock()
result = AccountLimits()

with patch.multiple(
pbm,
invoke_with_throttling_retries=DEFAULT,
_paginate_resultset=DEFAULT,
_paginate_dict=DEFAULT,
logger=DEFAULT,
) as mocks:
mocks['invoke_with_throttling_retries'].return_value = result
res = paginate_query(func, 'foo', bar='barval')
assert res == result
assert mocks['invoke_with_throttling_retries'].mock_calls == [
call(func, 'foo', bar='barval')
]
assert mocks['_paginate_resultset'].mock_calls == []
assert mocks['_paginate_dict'].mock_calls == []
assert mocks['logger'].mock_calls == []

def test_other_type(self):
func = Mock()

Expand Down
4 changes: 4 additions & 0 deletions awslimitchecker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import logging
from boto.exception import BotoServerError
from boto.resultset import ResultSet
from boto.ec2.autoscale.limits import AccountLimits
from copy import deepcopy

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -184,6 +185,9 @@ def paginate_query(function_ref, *argv, **kwargs):
return result
elif isinstance(result, ResultSet) and result.next_token is not None:
return _paginate_resultset(result, function_ref, *argv, **kwargs)
elif isinstance(result, AccountLimits):
# cannot be paginated
return result
elif isinstance(result, dict):
if set(paginate_dict_params).issubset(kwargs):
return _paginate_dict(result, function_ref, *argv, **kwargs)
Expand Down

0 comments on commit 18d96d3

Please sign in to comment.