def test_get_default_policy_template_json_must_work(self, _read_file_mock): expected = "something" _read_file_mock.return_value = expected result = PolicyTemplatesProcessor.get_default_policy_templates_json() self.assertEquals(result, expected) _read_file_mock.assert_called_once_with(PolicyTemplatesProcessor.DEFAULT_POLICY_TEMPLATES_FILE)
def make_policy_template_for_function_plugin(): """ Constructs an instance of policy templates processing plugin using default policy templates JSON data :return plugins.policies.policy_templates_plugin.PolicyTemplatesForFunctionPlugin: Instance of the plugin """ policy_templates = PolicyTemplatesProcessor.get_default_policy_templates_json() processor = PolicyTemplatesProcessor(policy_templates) return PolicyTemplatesForFunctionPlugin(processor)
def make_policy_template_for_function_plugin(): """ Constructs an instance of policy templates processing plugin using default policy templates JSON data :return plugins.policies.policy_templates_plugin.PolicyTemplatesForFunctionPlugin: Instance of the plugin """ policy_templates = PolicyTemplatesProcessor.get_default_policy_templates_json() processor = PolicyTemplatesProcessor(policy_templates) return PolicyTemplatesForFunctionPlugin(processor)
"""Shim for calling SAM translator""" #pylint: disable = line-too-long,import-error import argparse from ast import literal_eval from typing import Dict import sys import yaml from samtranslator.policy_template_processor.processor import PolicyTemplatesProcessor import samtranslator.policy_template_processor.exceptions as translator_errors # This is the set of policy templates that Amazon provides for serverless apps: # https://github.com/aws/serverless-application-model/blob/develop/samtranslator/policy_templates_data/policy_templates.json # Lucky for us, the class has a utility method to load and validate the JSON document. aws_templates = PolicyTemplatesProcessor.get_default_policy_templates_json() ptp = PolicyTemplatesProcessor(aws_templates) def get_policy(policy_name : str, parameters: Dict[str, any]) -> Dict[str, any]: """ Get a completed IAM policy statement from the named policy ready for inclusion in a CloudFormation template. Args: policy_name (str): The SAM policy template name parameters (Dict[str, any]): The policy arguments Returns: Dict[str, any]: An IAM policy statement. Raises: InsufficientParameterValues: If the parameter values do not have values for all required parameters TemplateNotFoundException: If the policy_name is not present in the set of SAM policy templates