def _validate(self, sam_template, parameter_values):
        """ Validates the template and parameter values and raises exceptions if there's an issue

        :param dict sam_template: SAM template
        :param dict parameter_values: Dictionary of parameter values provided by the user
        """
        if parameter_values is None:
            raise ValueError("`parameter_values` argument is required")

        if ("Resources" not in sam_template or not isinstance(sam_template["Resources"], dict) or not
                sam_template["Resources"]):
            raise InvalidDocumentException(
                [InvalidTemplateException("'Resources' section is required")])

        if (not all(isinstance(sam_resource, dict) for sam_resource in sam_template["Resources"].values())):
            raise InvalidDocumentException(
                [InvalidTemplateException(
                    "All 'Resources' must be Objects. If you're using YAML, this may be an "
                    "indentation issue."
                )])

        sam_template_instance = SamTemplate(sam_template)

        for resource_logical_id, sam_resource in sam_template_instance.iterate():
            # NOTE: Properties isn't required for SimpleTable, so we can't check
            # `not isinstance(sam_resources.get("Properties"), dict)` as this would be a breaking change.
            # sam_resource.properties defaults to {} in SamTemplate init
            if (not isinstance(sam_resource.properties, dict)):
                raise InvalidDocumentException(
                    [InvalidResourceException(resource_logical_id,
                                              "All 'Resources' must be Objects and have a 'Properties' Object. If "
                                              "you're using YAML, this may be an indentation issue."
                                              )])

        SamTemplateValidator.validate(sam_template)
Esempio n. 2
0
    def _validate(self, sam_template):
        """ Validates the template and parameter values and raises exceptions if there's an issue

        :param dict sam_template: SAM template
        """

        if "Resources" not in sam_template or not isinstance(sam_template["Resources"], dict) \
                or not sam_template["Resources"]:
            raise InvalidDocumentException(
                [InvalidTemplateException("'Resources' section is required")])

        SamTemplateValidator.validate(sam_template)
Esempio n. 3
0
def test_validate_template_success(testcase):
    # These templates are failing validation, will fix schema one at a time
    excluded = [
        'api_endpoint_configuration', 'api_with_binary_media_types',
        'api_with_cors', 'cloudwatch_logs_with_ref', 'sns',
        'sns_existing_other_subscription', 'sns_topic_outside_template',
        'alexa_skill', 'iot_rule', 'function_managed_inline_policy',
        'unsupported_resources', 'intrinsic_functions',
        'basic_function_with_tags', 'function_with_kmskeyarn',
        'function_with_alias', 'function_with_alias_intrinsics',
        'function_with_disabled_deployment_preference',
        'function_with_deployment_preference',
        'function_with_deployment_preference_all_parameters',
        'function_with_deployment_preference_multiple_combinations',
        'function_with_alias_and_event_sources', 'function_with_resource_refs',
        'function_with_policy_templates', 'globals_for_function',
        'all_policy_templates', 'simple_table_ref_parameter_intrinsic',
        'simple_table_with_table_name', 'function_concurrency',
        'simple_table_with_extra_tags'
    ]
    if testcase in excluded:
        return
    manifest = yaml_parse(
        open(os.path.join(input_folder, testcase + '.yaml'), 'r'))
    validation_errors = SamTemplateValidator.validate(manifest)
    has_errors = len(validation_errors)
    if has_errors:
        print("\nFailing template: {0}\n".format(testcase))
        print(validation_errors)
    assert len(validation_errors) == 0
Esempio n. 4
0
    def _validate(self, sam_template, parameter_values):
        """ Validates the template and parameter values and raises exceptions if there's an issue

        :param dict sam_template: SAM template
        :param dict parameter_values: Dictionary of parameter values provided by the user
        """
        if parameter_values is None:
            raise ValueError("`parameter_values` argument is required")

        if "Resources" not in sam_template or not isinstance(sam_template["Resources"], dict) or not sam_template["Resources"]:
            raise InvalidDocumentException(
                [InvalidTemplateException("'Resources' section is required")])

        validation_errors = SamTemplateValidator.validate(sam_template)
def test_validate_template_success(testcase):
    # These templates are failing validation, will fix schema one at a time
    excluded = [
        'api_endpoint_configuration',
        'api_with_binary_media_types',
        'api_with_minimum_compression_size',
        'api_with_cors',
        'cloudwatch_logs_with_ref',
        'sns',
        'sns_existing_other_subscription',
        'sns_topic_outside_template',
        'alexa_skill',
        'iot_rule',
        'function_managed_inline_policy',
        'unsupported_resources',
        'intrinsic_functions',
        'basic_function_with_tags',
        'function_with_kmskeyarn',
        'function_with_alias',
        'function_with_alias_intrinsics',
        'function_with_disabled_deployment_preference',
        'function_with_deployment_preference',
        'function_with_deployment_preference_all_parameters',
        'function_with_deployment_preference_multiple_combinations',
        'function_with_alias_and_event_sources',
        'function_with_resource_refs',
        'function_with_policy_templates',
        'globals_for_function',
        'all_policy_templates',
        'simple_table_ref_parameter_intrinsic',
        'simple_table_with_table_name',
        'function_concurrency',
        'simple_table_with_extra_tags'
    ]
    if testcase in excluded:
        return
    manifest = yaml_parse(open(os.path.join(INPUT_FOLDER, testcase + '.yaml'), 'r'))
    validation_errors = SamTemplateValidator.validate(manifest)
    has_errors = len(validation_errors)
    if has_errors:
        print("\nFailing template: {0}\n".format(testcase))
        print(validation_errors)
    assert len(validation_errors) == 0