Skip to content

Add method to get links to all AWS Actions #317

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

Merged
merged 2 commits into from
Dec 28, 2020
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
25 changes: 24 additions & 1 deletion policy_sentry/querying/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import functools
from policy_sentry.shared.iam_data import iam_definition, get_service_prefix_data
from policy_sentry.querying.all import get_all_service_prefixes
from policy_sentry.querying.all import get_all_service_prefixes, get_all_actions
from policy_sentry.querying.arns import get_matching_raw_arns, get_resource_type_name_with_raw_arn
from policy_sentry.util.arns import get_service_from_arn

Expand Down Expand Up @@ -469,3 +469,26 @@ def get_api_documentation_link_for_action(service_prefix, action_name):
if row.get("api_documentation_link"):
result = row.get("api_documentation_link")
return result


@functools.lru_cache(maxsize=1024)
def get_all_action_links():
"""
Gets a huge list of the links to all AWS IAM actions. This is meant for use by Cloudsplaining.

:return: A dictionary of all actions present in the database, with the values being the API documentation links.
"""
all_actions = get_all_actions()
results = {}
for action in all_actions:
try:
service_prefix, action_name = action.split(":")
except ValueError as v_e:
logger.debug(f"{v_e} - for action {action}")
continue
link = get_api_documentation_link_for_action(service_prefix, action_name)
result = {
action: link
}
results.update(result)
return results
8 changes: 7 additions & 1 deletion test/querying/test_query_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
get_actions_matching_condition_key,
get_actions_matching_arn,
get_actions_matching_arn_type,
get_api_documentation_link_for_action
get_api_documentation_link_for_action,
get_all_action_links
# get_actions_matching_condition_crud_and_arn
)
from policy_sentry.writing.validate import check
Expand Down Expand Up @@ -528,3 +529,8 @@ def test_get_api_documentation_link_for_action(self):
# Link should be: https://docs.aws.amazon.com/cloud9/latest/APIReference/API_CreateEnvironmentEC2.html
# We will just check the https and subdomain.domain in case they change the format in the future.
self.assertTrue("https://docs.aws.amazon.com" in result)

def test_get_all_links(self):
"""querying.actions.get_all_action_links"""
results = get_all_action_links()
self.assertTrue(len(results.keys()) > 8000)