Skip to content

Commit 1e64b8b

Browse files
Scribbdgruebel
authored andcommitted
feat: expand capability of '*' querying action table
1 parent ba6cdf7 commit 1e64b8b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

policy_sentry/querying/actions.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ def get_action_data(service: str, action_name: str) -> dict[str, list[dict[str,
6262
action_data_results = {}
6363
try:
6464
service_prefix_data = get_service_prefix_data(service)
65-
if action_name == "*":
65+
if action_name.endswith("*"):
66+
stripped_action_name = action_name.removesuffix("*")
6667
results = []
6768
for this_action_name, this_action_data in service_prefix_data["privileges"].items():
69+
if not this_action_name.startswith(stripped_action_name):
70+
continue
6871
if this_action_data:
6972
entries = create_action_data_entries(
7073
service_prefix_data=service_prefix_data,

test/querying/test_query_actions.py

+27
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,33 @@ def test_get_action_data(self):
181181
self.maxDiff = None
182182
self.assertDictEqual(desired_output, output)
183183

184+
def test_get_action_data_with_glob(self):
185+
"""Query action-table with glob."""
186+
desired_output = {
187+
"sns": [
188+
{
189+
"action": "sns:ListSubscriptions",
190+
"description": "Grants permission to return a list of the requester's subscriptions",
191+
"access_level": "List",
192+
"api_documentation_link": "https://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptions.html",
193+
"resource_arn_format": "*",
194+
"condition_keys": [],
195+
"dependent_actions": [],
196+
},
197+
{
198+
"action": "sns:ListSubscriptionsByTopic",
199+
"description": "Grants permission to return a list of the subscriptions to a specific topic",
200+
"access_level": "List",
201+
"api_documentation_link": "https://docs.aws.amazon.com/sns/latest/api/API_ListSubscriptionsByTopic.html",
202+
"resource_arn_format": "arn:${Partition}:sns:${Region}:${Account}:${TopicName}",
203+
"condition_keys": ["aws:ResourceTag/${TagKey}"],
204+
"dependent_actions": [],
205+
},
206+
]
207+
}
208+
results = get_action_data("sns", "ListSubscriptions*")
209+
self.assertDictEqual(desired_output, results)
210+
184211
def test_get_actions_that_support_wildcard_arns_only(self):
185212
"""querying.actions.get_actions_that_support_wildcard_arns_only"""
186213
# Variant 1: Secrets manager

0 commit comments

Comments
 (0)