Repository: salesforce/policy_sentry
Pull request #317 (2020-12-28 19:17:42)

Add method to get links to all AWS Actions
## What does this PR do?

Added `get_all_action_links` method to `policy_sentry.querying.actions`

## Completion checklist

- [x] Additions and changes have unit tests
- [x] [Unit tests, Pylint, security testing, and Integration tests are passing.](https://github.com/salesforce/policy_sentry/actions). GitHub actions does this automatically
- [x] The pull request has been appropriately labeled using the provided PR labels



Patch:
diff --git a/policy_sentry/querying/actions.py b/policy_sentry/querying/actions.py
index fbeb2767..acd80b01 100644
--- a/policy_sentry/querying/actions.py
+++ b/policy_sentry/querying/actions.py
@@ -5,7 +5,7 @@ This supports the Policy Sentry query functionality
 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
 
@@ -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


Test patch:
diff --git a/test/querying/test_query_actions.py b/test/querying/test_query_actions.py
index 6762572d..37546c51 100644
--- a/test/querying/test_query_actions.py
+++ b/test/querying/test_query_actions.py
@@ -17,7 +17,8 @@ from policy_sentry.querying.actions import (
     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
@@ -528,3 +529,8 @@ class QueryActionsTestCase(unittest.TestCase):
         # 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)