Skip to content

Commit 1ead655

Browse files
authored
Merge pull request #223 from duo-labs/lru_cache
Lru cache
2 parents dad4197 + ba58b69 commit 1ead655

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

parliament/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""
22
This library is a linter for AWS IAM policies.
33
"""
4-
__version__ = "1.6.0"
4+
__version__ = "1.6.1"
55

66
import fnmatch
77
import functools
@@ -229,7 +229,7 @@ def is_glob_match(s1, s2):
229229
return s1[0] == s2[0] and is_glob_match(s1[1:], s2[1:])
230230

231231

232-
@functools.lru_cache(maxsize=1024)
232+
@functools.lru_cache(maxsize=10240)
233233
def expand_action(action, raise_exceptions=True):
234234
"""
235235
Converts "iam:*List*" to

parliament/statement.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,16 @@ def is_valid_account_id(str):
147147
"aws:CalledViaLast": "String",
148148
"aws:CurrentTime": "Date",
149149
"aws:EpochTime": "Date", # This needs to accept Date or Numeric
150+
"aws:FederatedProvider": "String",
150151
"aws:MultiFactorAuthAge": "Numeric",
151152
"aws:MultiFactorAuthPresent": "Bool",
152153
"aws:PrincipalAccount": "String",
153154
"aws:PrincipalOrgID": "String",
154155
"aws:PrincipalArn": "Arn",
156+
"aws:PrincipalIsAWSService": "Bool",
155157
"aws:PrincipalOrgPaths": "String",
158+
"aws:PrincipalServiceName": "String",
159+
"aws:PrincipalServiceNamesList": "String",
156160
"aws:PrincipalTag": "String",
157161
"aws:PrincipalType": "String",
158162
"aws:RequestedRegion": "String",
@@ -162,11 +166,16 @@ def is_valid_account_id(str):
162166
"aws:PrincipalTag/*": "String",
163167
"aws:PrincipalType": "String",
164168
"aws:Referer": "String",
169+
"aws:RequestedRegion": "String",
165170
"aws:RequestTag/*": "String",
171+
"aws:ResourceAccount": "String",
172+
"aws:ResourceOrgID": "String",
173+
"aws:ResourceOrgPaths": "String",
166174
"aws:ResourceTag/*": "String",
167175
"aws:SecureTransport": "Bool",
168176
"aws:SourceAccount": "String",
169177
"aws:SourceArn": "Arn",
178+
"aws:SourceIdentity": "String",
170179
"aws:SourceIp": "Ip",
171180
"aws:SourceVpc": "String",
172181
"aws:SourceVpce": "String",

tests/unit/test_action_expansion.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,36 @@ class TestActionExpansion:
99

1010
def test_expand_action_no_expansion(self):
1111
expanded_actions = expand_action("s3:listallmybuckets")
12-
assert (
13-
len(expanded_actions),
14-
len([{"service": "s3", "action": "ListAllMyBuckets"}]),
12+
assert len(expanded_actions) == len(
13+
[{"service": "s3", "action": "ListAllMyBuckets"}]
1514
)
1615

1716
def test_expand_action_with_expansion(self):
1817
expanded_actions = expand_action("s3:listallmybucke*")
19-
assert (
20-
len(expanded_actions),
21-
len([{"service": "s3", "action": "ListAllMyBuckets"}]),
18+
assert len(expanded_actions) == len(
19+
[{"service": "s3", "action": "ListAllMyBuckets"}]
2220
)
2321

2422
def test_expand_action_with_casing(self):
2523
expanded_actions = expand_action("iAm:li*sTuS*rs")
26-
assert (len(expanded_actions), len([{"service": "iam", "action": "ListUsers"}]))
24+
assert len(expanded_actions) == len([{"service": "iam", "action": "ListUsers"}])
2725

2826
def test_expand_action_with_expansion_for_prefix_used_multiple_times(self):
2927
expanded_actions = expand_action("ses:Describe*")
30-
assert (
31-
len(expanded_actions),
32-
len(
33-
[
34-
{"service": "ses", "action": "DescribeActiveReceiptRuleSet"},
35-
{"service": "ses", "action": "DescribeConfigurationSet"},
36-
{"service": "ses", "action": "DescribeReceiptRule"},
37-
{"service": "ses", "action": "DescribeReceiptRuleSet"},
38-
]
39-
),
28+
assert len(expanded_actions) == len(
29+
[
30+
{"service": "ses", "action": "DescribeActiveReceiptRuleSet"},
31+
{"service": "ses", "action": "DescribeConfigurationSet"},
32+
{"service": "ses", "action": "DescribeReceiptRule"},
33+
{"service": "ses", "action": "DescribeReceiptRuleSet"},
34+
]
4035
)
4136

4237
def test_expand_action_with_permission_only_action(self):
4338
# There are 17 privileges list as "logs.CreateLogDelivery [permission only]"
4439
expanded_actions = expand_action("logs:GetLogDelivery")
45-
assert (
46-
len(expanded_actions),
47-
len([{"service": "logs", "action": "GetLogDelivery"}]),
40+
assert len(expanded_actions) == len(
41+
[{"service": "logs", "action": "GetLogDelivery"}]
4842
)
4943

5044
def test_exception_malformed(self):

0 commit comments

Comments
 (0)