def get_actions_matching_arn(arn): """ Given a user-supplied ARN, get a list of all actions that correspond to that ARN. Arguments: arn: A user-supplied arn Returns: List: A list of all actions that can match it. """ raw_arns = get_matching_raw_arns(arn) results = [] for raw_arn in raw_arns: resource_type_name = get_resource_type_name_with_raw_arn(raw_arn) service_prefix = get_service_from_arn(raw_arn) service_prefix_data = get_service_prefix_data(service_prefix) for action_name, action_data in service_prefix_data[ "privileges"].items(): # for some_action in service_prefix_data["privileges"]: for resource_name, resource_data in action_data[ "resource_types"].items(): this_resource_type = resource_data["resource_type"].strip("*") if this_resource_type.lower() == resource_type_name.lower(): results.append( f"{service_prefix}:{action_data['privilege']}") results = list(dict.fromkeys(results)) results.sort() return results
def test_get_matching_raw_arn(self): """querying.arns.get_matching_raw_arns""" self.assertEqual(get_matching_raw_arns("arn:aws:s3:::bucket_name"), ["arn:${Partition}:s3:::${BucketName}"]) self.assertEqual(get_matching_raw_arns("arn:aws:codecommit:us-east-1:123456789012:MyDemoRepo"), ["arn:${Partition}:codecommit:${Region}:${Account}:${RepositoryName}"]) self.assertEqual(get_matching_raw_arns("arn:aws:ssm:us-east-1:123456789012:parameter/test"), ["arn:${Partition}:ssm:${Region}:${Account}:parameter/${ParameterNameWithoutLeadingSlash}"]) self.assertEqual(get_matching_raw_arns("arn:aws:batch:region:account-id:job-definition/job-name:revision"), ["arn:${Partition}:batch:${Region}:${Account}:job-definition/${JobDefinitionName}:${Revision}"]) self.assertEqual(get_matching_raw_arns("arn:aws:states:region:account-id:stateMachine:stateMachineName"), ["arn:${Partition}:states:${Region}:${Account}:stateMachine:${StateMachineName}"]) self.assertEqual(get_matching_raw_arns("arn:aws:states:region:account-id:execution:stateMachineName:executionName"), ["arn:${Partition}:states:${Region}:${Account}:execution:${StateMachineName}:${ExecutionId}"]) # self.assertEqual(get_matching_raw_arns("arn:aws:greengrass:region:account-id:/greengrass/definition/devices/1234567/versions/1"), ["arn:aws:greengrass:${Region}:${Account}:/greengrass/definition/devices/${DeviceDefinitionId}/versions/${VersionId}"]) self.assertEqual(get_matching_raw_arns("arn:${Partition}:rds:region:account-id:db:mydatabase"), ["arn:${Partition}:rds:${Region}:${Account}:db:${DbInstanceName}"]) self.assertIn("arn:${Partition}:rds:${Region}:${Account}:db:${DbInstanceName}", get_matching_raw_arns("arn:${Partition}:rds:region:account-id:*:*")) self.assertEqual(get_matching_raw_arns("arn:${Partition}:rds:region:account-id:invalid-resource:*"), [])