Skip to content

Commit 3da9bce

Browse files
authored
Merge pull request #317 from kmcquade/fix/query-all-action-links
Add method to get links to all AWS Actions
2 parents 7733d99 + 06c0db9 commit 3da9bce

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

policy_sentry/querying/actions.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import functools
77
from policy_sentry.shared.iam_data import iam_definition, get_service_prefix_data
8-
from policy_sentry.querying.all import get_all_service_prefixes
8+
from policy_sentry.querying.all import get_all_service_prefixes, get_all_actions
99
from policy_sentry.querying.arns import get_matching_raw_arns, get_resource_type_name_with_raw_arn
1010
from policy_sentry.util.arns import get_service_from_arn
1111

@@ -469,3 +469,26 @@ def get_api_documentation_link_for_action(service_prefix, action_name):
469469
if row.get("api_documentation_link"):
470470
result = row.get("api_documentation_link")
471471
return result
472+
473+
474+
@functools.lru_cache(maxsize=1024)
475+
def get_all_action_links():
476+
"""
477+
Gets a huge list of the links to all AWS IAM actions. This is meant for use by Cloudsplaining.
478+
479+
:return: A dictionary of all actions present in the database, with the values being the API documentation links.
480+
"""
481+
all_actions = get_all_actions()
482+
results = {}
483+
for action in all_actions:
484+
try:
485+
service_prefix, action_name = action.split(":")
486+
except ValueError as v_e:
487+
logger.debug(f"{v_e} - for action {action}")
488+
continue
489+
link = get_api_documentation_link_for_action(service_prefix, action_name)
490+
result = {
491+
action: link
492+
}
493+
results.update(result)
494+
return results

test/querying/test_query_actions.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
get_actions_matching_condition_key,
1818
get_actions_matching_arn,
1919
get_actions_matching_arn_type,
20-
get_api_documentation_link_for_action
20+
get_api_documentation_link_for_action,
21+
get_all_action_links
2122
# get_actions_matching_condition_crud_and_arn
2223
)
2324
from policy_sentry.writing.validate import check
@@ -528,3 +529,8 @@ def test_get_api_documentation_link_for_action(self):
528529
# Link should be: https://docs.aws.amazon.com/cloud9/latest/APIReference/API_CreateEnvironmentEC2.html
529530
# We will just check the https and subdomain.domain in case they change the format in the future.
530531
self.assertTrue("https://docs.aws.amazon.com" in result)
532+
533+
def test_get_all_links(self):
534+
"""querying.actions.get_all_action_links"""
535+
results = get_all_action_links()
536+
self.assertTrue(len(results.keys()) > 8000)

0 commit comments

Comments
 (0)