We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
AWS::Serverless::StateMachine.DefinitionUri support for local files
*cfn-lint version: 0.32.1*

*Description of issue.*

The recent release of SAM support for Step Functions has added the ability to use a non-S3 URL for the [`DefinitionUri`](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html#sam-statemachine-definitionuri) in order to reference local files that get included during a deploy. The linter is currently throwing an error for all non-S3 values, though.

```
[cfn-lint] E0001: Error transforming template: Resource with id [StateMachine] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `setup.py`
Content:
```
1 """
2 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 SPDX-License-Identifier: MIT-0
4 """
5 import codecs
6 import re
7 from setuptools import find_packages
8 from setuptools import setup
9 
10 
11 def get_version(filename):
12     with codecs.open(filename, 'r', 'utf-8') as fp:
13         contents = fp.read()
14     return re.search(r"__version__ = ['\"]([^'\"]+)['\"]", contents).group(1)
15 
16 
17 version = get_version('src/cfnlint/version.py')
18 
19 
20 with open('README.md') as f:
21     readme = f.read()
22 
23 setup(
24     name='cfn-lint',
25     version=version,
26     description=('Checks CloudFormation templates for practices and behaviour \
27 that could potentially be improved'),
28     long_description=readme,
29     long_description_content_type="text/markdown",
30     keywords='aws, lint',
31     author='kddejong',
32     author_email='kddejong@amazon.com',
33     url='https://github.com/aws-cloudformation/cfn-python-lint',
34     package_dir={'': 'src'},
35     package_data={'cfnlint': [
36         'data/CloudSpecs/*.json',
37         'data/AdditionalSpecs/*.json',
38         'data/Serverless/*.json',
39         'data/ExtendedSpecs/*/*.json',
40         'data/CfnLintCli/config/schema.json'
41     ]},
42     packages=find_packages('src'),
43     zip_safe=False,
44     install_requires=[
45         'pyyaml<=5.2;python_version=="3.4"',
46         'pyyaml;python_version!="3.4"',
47         'six~=1.11',
48         'aws-sam-translator>=1.23.0',
49         'jsonpatch;python_version!="3.4"',
50         'jsonpatch<=1.24;python_version=="3.4"',
51         'jsonschema~=3.0',
52         'pathlib2>=2.3.0;python_version<="3.4"',
53         'importlib_resources~=1.0.2;python_version=="3.4"',
54         'importlib_resources~=1.4;python_version<"3.7" and python_version!="3.4"',
55         'networkx~=2.4;python_version>="3.5"',
56         'networkx<=2.2;python_version<"3.5"',
57         'junit-xml~=1.9',
58     ],
59     python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
60     entry_points={
61         'console_scripts': [
62             'cfn-lint = cfnlint.__main__:main'
63         ]
64     },
65     license='MIT no attribution',
66     test_suite="unittest",
67     classifiers=[
68         'Development Status :: 5 - Production/Stable',
69         'Intended Audience :: Developers',
70         'License :: OSI Approved :: MIT License',
71         'Natural Language :: English',
72         'Operating System :: OS Independent',
73         'Programming Language :: Python :: 2',
74         'Programming Language :: Python :: 2.7',
75         'Programming Language :: Python :: 3',
76         'Programming Language :: Python :: 3.4',
77         'Programming Language :: Python :: 3.5',
78         'Programming Language :: Python :: 3.6',
79         'Programming Language :: Python :: 3.7',
80         'Programming Language :: Python :: 3.8',
81     ],
82 )
83
```

Path: `src/cfnlint/transform.py`
Content:
```
1 """
2 Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 SPDX-License-Identifier: MIT-0
4 """
5 import os
6 import logging
7 import six
8 import samtranslator
9 from samtranslator.parser import parser
10 from samtranslator.translator.translator import Translator
11 from samtranslator.public.exceptions import InvalidDocumentException
12 
13 from cfnlint.helpers import load_resource, convert_dict, format_json_string
14 from cfnlint.data import Serverless
15 from cfnlint.rules import Match, TransformError
16 LOGGER = logging.getLogger('cfnlint')
17 
18 
19 class Transform(object):
20     """
21     Application Serverless Module tranform Wrapper.
22     Based on code from AWS SAM CLI:
23     https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/commands/validate/lib/sam_template_validator.py
24     """
25 
26     def __init__(self, filename, template, region):
27         """
28         Initialize Transform class
29         """
30         self._filename = filename
31         self._template = template
32         self._region = region
33         self._parameters = {}
34 
35         self._managed_policy_map = self.load_managed_policies()
36         self._sam_parser = parser.Parser()
37 
38     def template(self):
39         """Get the template"""
40         return self._template
41 
42     def load_managed_policies(self):
43         """
44         Load the ManagedPolicies locally, based on the AWS-CLI:
45         https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/lib/samlib/default_managed_policies.json
46         """
47         return load_resource(Serverless, 'ManagedPolicies.json')
48 
49     def _replace_local_codeuri(self):
50         """
51         Replaces the CodeUri in AWS::Serverless::Function and DefinitionUri in
52         AWS::Serverless::Api to a fake S3 Uri. This is to support running the
53         SAM Translator with valid values for these fields. If this is not done,
54         the template is invalid in the eyes of SAM Translator (the translator
55         does not support local paths)
56         """
57 
58         all_resources = self._template.get('Resources', {})
59 
60         for _, resource in all_resources.items():
61 
62             resource_type = resource.get('Type')
63             resource_dict = resource.get('Properties')
64 
65             if resource_type == 'AWS::Serverless::Function':
66 
67                 Transform._update_to_s3_uri('CodeUri', resource_dict)
68                 auto_publish_alias = resource_dict.get('AutoPublishAlias')
69                 if isinstance(auto_publish_alias, dict):
70                     if len(auto_publish_alias) == 1:
71                         for k, v in auto_publish_alias.items():
72                             if k == 'Ref':
73                                 if v in self._template.get('Parameters'):
74                                     self._parameters[v] = 'Alias'
75             if resource_type in ['AWS::Serverless::LayerVersion']:
76                 if resource_dict.get('ContentUri'):
77                     Transform._update_to_s3_uri('ContentUri', resource_dict)
78             if resource_type == 'AWS::Serverless::Application':
79                 if resource_dict.get('Location'):
80                     resource_dict['Location'] = ''
81                     Transform._update_to_s3_uri('Location', resource_dict)
82             if resource_type == 'AWS::Serverless::Api':
83                 if ('DefinitionBody' not in resource_dict and
84                         'Auth' not in resource_dict and 'Cors' not in resource_dict):
85                     Transform._update_to_s3_uri('DefinitionUri', resource_dict)
86                 else:
87                     resource_dict['DefinitionBody'] = ''
88 
89     def transform_template(self):
90         """
91         Transform the Template using the Serverless Application Model.
92         """
93         matches = []
94 
95         try:
96             # Output the SAM Translator version in debug mode
97             LOGGER.info('SAM Translator: %s', samtranslator.__version__)
98 
99             sam_translator = Translator(
100                 managed_policy_map=self._managed_policy_map,
101                 sam_parser=self._sam_parser)
102 
103             self._replace_local_codeuri()
104 
105             # Tell SAM to use the region we're linting in, this has to be
106             # controlled using the default AWS mechanisms, see also:
107             # https://github.com/awslabs/serverless-application-model/blob/master/samtranslator/translator/arn_generator.py
108             LOGGER.info('Setting AWS_DEFAULT_REGION to %s', self._region)
109             os.environ['AWS_DEFAULT_REGION'] = self._region
110 
111             self._template = convert_dict(
112                 sam_translator.translate(sam_template=self._template,
113                                          parameter_values=self._parameters))
114 
115             LOGGER.info('Transformed template: \n%s',
116                         format_json_string(self._template))
117         except InvalidDocumentException as e:
118             message = 'Error transforming template: {0}'
119             for cause in e.causes:
120                 matches.append(Match(
121                     1, 1,
122                     1, 1,
123                     self._filename,
124                     TransformError(), message.format(cause.message)))
125         except Exception as e:  # pylint: disable=W0703
126             LOGGER.debug('Error transforming template: %s', str(e))
127             LOGGER.debug('Stack trace: %s', e, exc_info=True)
128             message = 'Error transforming template: {0}'
129             matches.append(Match(
130                 1, 1,
131                 1, 1,
132                 self._filename,
133                 TransformError(), message.format(str(e))))
134 
135         return matches
136 
137     @staticmethod
138     def is_s3_uri(uri):
139         """
140         Checks the uri and determines if it is a valid S3 Uri
141         Parameters
142         ----------
143         uri str, required
144             Uri to check
145         Returns
146         -------
147         bool
148             Returns True if the uri given is an S3 uri, otherwise False
149         """
150         return isinstance(uri, six.string_types) and uri.startswith('s3://')
151 
152     @staticmethod
153     def _update_to_s3_uri(
154             property_key, resource_property_dict,
155             s3_uri_value='s3://bucket/value'):
156         """
157         Updates the 'property_key' in the 'resource_property_dict' to the
158         value of 's3_uri_value'
159         Note: The function will mutate the resource_property_dict that is pass
160         in Parameters
161         ----------
162         property_key str, required
163             Key in the resource_property_dict
164         resource_property_dict dict, required
165             Property dictionary of a Resource in the template to replace
166         s3_uri_value str, optional
167             Value to update the value of the property_key to
168         """
169         uri_property = resource_property_dict.get(property_key, '.')
170 
171         # ignore if dict or already an S3 Uri
172         if isinstance(uri_property, dict) or Transform.is_s3_uri(uri_property):
173             return
174 
175         resource_property_dict[property_key] = s3_uri_value
176
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -45,7 +45,7 @@
         'pyyaml<=5.2;python_version=="3.4"',
         'pyyaml;python_version!="3.4"',
         'six~=1.11',
-        'aws-sam-translator>=1.23.0',
+        'aws-sam-translator>=1.24.0',
         'jsonpatch;python_version!="3.4"',
         'jsonpatch<=1.24;python_version=="3.4"',
         'jsonschema~=3.0',
diff --git a/src/cfnlint/transform.py b/src/cfnlint/transform.py
--- a/src/cfnlint/transform.py
+++ b/src/cfnlint/transform.py
@@ -85,6 +85,8 @@
                     Transform._update_to_s3_uri('DefinitionUri', resource_dict)
                 else:
                     resource_dict['DefinitionBody'] = ''
+            if resource_type == 'AWS::Serverless::StateMachine':
+                Transform._update_to_s3_uri('DefinitionUri', resource_dict)
 
     def transform_template(self):
         """

{"golden_diff": "diff --git a/setup.py b/setup.py\n--- a/setup.py\n+++ b/setup.py\n@@ -45,7 +45,7 @@\n         'pyyaml<=5.2;python_version==\"3.4\"',\n         'pyyaml;python_version!=\"3.4\"',\n         'six~=1.11',\n-        'aws-sam-translator>=1.23.0',\n+        'aws-sam-translator>=1.24.0',\n         'jsonpatch;python_version!=\"3.4\"',\n         'jsonpatch<=1.24;python_version==\"3.4\"',\n         'jsonschema~=3.0',\ndiff --git a/src/cfnlint/transform.py b/src/cfnlint/transform.py\n--- a/src/cfnlint/transform.py\n+++ b/src/cfnlint/transform.py\n@@ -85,6 +85,8 @@\n                     Transform._update_to_s3_uri('DefinitionUri', resource_dict)\n                 else:\n                     resource_dict['DefinitionBody'] = ''\n+            if resource_type == 'AWS::Serverless::StateMachine':\n+                Transform._update_to_s3_uri('DefinitionUri', resource_dict)\n \n     def transform_template(self):\n         \"\"\"\n", "issue": "AWS::Serverless::StateMachine.DefinitionUri support for local files\n*cfn-lint version: 0.32.1*\r\n\r\n*Description of issue.*\r\n\r\nThe recent release of SAM support for Step Functions has added the ability to use a non-S3 URL for the [`DefinitionUri`](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-statemachine.html#sam-statemachine-definitionuri) in order to reference local files that get included during a deploy. The linter is currently throwing an error for all non-S3 values, though.\r\n\r\n```\r\n[cfn-lint] E0001: Error transforming template: Resource with id [StateMachine] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.\r\n```\n", "before_files": [{"content": "\"\"\"\nCopyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nimport codecs\nimport re\nfrom setuptools import find_packages\nfrom setuptools import setup\n\n\ndef get_version(filename):\n    with codecs.open(filename, 'r', 'utf-8') as fp:\n        contents = fp.read()\n    return re.search(r\"__version__ = ['\\\"]([^'\\\"]+)['\\\"]\", contents).group(1)\n\n\nversion = get_version('src/cfnlint/version.py')\n\n\nwith open('README.md') as f:\n    readme = f.read()\n\nsetup(\n    name='cfn-lint',\n    version=version,\n    description=('Checks CloudFormation templates for practices and behaviour \\\nthat could potentially be improved'),\n    long_description=readme,\n    long_description_content_type=\"text/markdown\",\n    keywords='aws, lint',\n    author='kddejong',\n    author_email='kddejong@amazon.com',\n    url='https://github.com/aws-cloudformation/cfn-python-lint',\n    package_dir={'': 'src'},\n    package_data={'cfnlint': [\n        'data/CloudSpecs/*.json',\n        'data/AdditionalSpecs/*.json',\n        'data/Serverless/*.json',\n        'data/ExtendedSpecs/*/*.json',\n        'data/CfnLintCli/config/schema.json'\n    ]},\n    packages=find_packages('src'),\n    zip_safe=False,\n    install_requires=[\n        'pyyaml<=5.2;python_version==\"3.4\"',\n        'pyyaml;python_version!=\"3.4\"',\n        'six~=1.11',\n        'aws-sam-translator>=1.23.0',\n        'jsonpatch;python_version!=\"3.4\"',\n        'jsonpatch<=1.24;python_version==\"3.4\"',\n        'jsonschema~=3.0',\n        'pathlib2>=2.3.0;python_version<=\"3.4\"',\n        'importlib_resources~=1.0.2;python_version==\"3.4\"',\n        'importlib_resources~=1.4;python_version<\"3.7\" and python_version!=\"3.4\"',\n        'networkx~=2.4;python_version>=\"3.5\"',\n        'networkx<=2.2;python_version<\"3.5\"',\n        'junit-xml~=1.9',\n    ],\n    python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',\n    entry_points={\n        'console_scripts': [\n            'cfn-lint = cfnlint.__main__:main'\n        ]\n    },\n    license='MIT no attribution',\n    test_suite=\"unittest\",\n    classifiers=[\n        'Development Status :: 5 - Production/Stable',\n        'Intended Audience :: Developers',\n        'License :: OSI Approved :: MIT License',\n        'Natural Language :: English',\n        'Operating System :: OS Independent',\n        'Programming Language :: Python :: 2',\n        'Programming Language :: Python :: 2.7',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.4',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Programming Language :: Python :: 3.8',\n    ],\n)\n", "path": "setup.py"}, {"content": "\"\"\"\nCopyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nimport os\nimport logging\nimport six\nimport samtranslator\nfrom samtranslator.parser import parser\nfrom samtranslator.translator.translator import Translator\nfrom samtranslator.public.exceptions import InvalidDocumentException\n\nfrom cfnlint.helpers import load_resource, convert_dict, format_json_string\nfrom cfnlint.data import Serverless\nfrom cfnlint.rules import Match, TransformError\nLOGGER = logging.getLogger('cfnlint')\n\n\nclass Transform(object):\n    \"\"\"\n    Application Serverless Module tranform Wrapper.\n    Based on code from AWS SAM CLI:\n    https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/commands/validate/lib/sam_template_validator.py\n    \"\"\"\n\n    def __init__(self, filename, template, region):\n        \"\"\"\n        Initialize Transform class\n        \"\"\"\n        self._filename = filename\n        self._template = template\n        self._region = region\n        self._parameters = {}\n\n        self._managed_policy_map = self.load_managed_policies()\n        self._sam_parser = parser.Parser()\n\n    def template(self):\n        \"\"\"Get the template\"\"\"\n        return self._template\n\n    def load_managed_policies(self):\n        \"\"\"\n        Load the ManagedPolicies locally, based on the AWS-CLI:\n        https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/lib/samlib/default_managed_policies.json\n        \"\"\"\n        return load_resource(Serverless, 'ManagedPolicies.json')\n\n    def _replace_local_codeuri(self):\n        \"\"\"\n        Replaces the CodeUri in AWS::Serverless::Function and DefinitionUri in\n        AWS::Serverless::Api to a fake S3 Uri. This is to support running the\n        SAM Translator with valid values for these fields. If this is not done,\n        the template is invalid in the eyes of SAM Translator (the translator\n        does not support local paths)\n        \"\"\"\n\n        all_resources = self._template.get('Resources', {})\n\n        for _, resource in all_resources.items():\n\n            resource_type = resource.get('Type')\n            resource_dict = resource.get('Properties')\n\n            if resource_type == 'AWS::Serverless::Function':\n\n                Transform._update_to_s3_uri('CodeUri', resource_dict)\n                auto_publish_alias = resource_dict.get('AutoPublishAlias')\n                if isinstance(auto_publish_alias, dict):\n                    if len(auto_publish_alias) == 1:\n                        for k, v in auto_publish_alias.items():\n                            if k == 'Ref':\n                                if v in self._template.get('Parameters'):\n                                    self._parameters[v] = 'Alias'\n            if resource_type in ['AWS::Serverless::LayerVersion']:\n                if resource_dict.get('ContentUri'):\n                    Transform._update_to_s3_uri('ContentUri', resource_dict)\n            if resource_type == 'AWS::Serverless::Application':\n                if resource_dict.get('Location'):\n                    resource_dict['Location'] = ''\n                    Transform._update_to_s3_uri('Location', resource_dict)\n            if resource_type == 'AWS::Serverless::Api':\n                if ('DefinitionBody' not in resource_dict and\n                        'Auth' not in resource_dict and 'Cors' not in resource_dict):\n                    Transform._update_to_s3_uri('DefinitionUri', resource_dict)\n                else:\n                    resource_dict['DefinitionBody'] = ''\n\n    def transform_template(self):\n        \"\"\"\n        Transform the Template using the Serverless Application Model.\n        \"\"\"\n        matches = []\n\n        try:\n            # Output the SAM Translator version in debug mode\n            LOGGER.info('SAM Translator: %s', samtranslator.__version__)\n\n            sam_translator = Translator(\n                managed_policy_map=self._managed_policy_map,\n                sam_parser=self._sam_parser)\n\n            self._replace_local_codeuri()\n\n            # Tell SAM to use the region we're linting in, this has to be\n            # controlled using the default AWS mechanisms, see also:\n            # https://github.com/awslabs/serverless-application-model/blob/master/samtranslator/translator/arn_generator.py\n            LOGGER.info('Setting AWS_DEFAULT_REGION to %s', self._region)\n            os.environ['AWS_DEFAULT_REGION'] = self._region\n\n            self._template = convert_dict(\n                sam_translator.translate(sam_template=self._template,\n                                         parameter_values=self._parameters))\n\n            LOGGER.info('Transformed template: \\n%s',\n                        format_json_string(self._template))\n        except InvalidDocumentException as e:\n            message = 'Error transforming template: {0}'\n            for cause in e.causes:\n                matches.append(Match(\n                    1, 1,\n                    1, 1,\n                    self._filename,\n                    TransformError(), message.format(cause.message)))\n        except Exception as e:  # pylint: disable=W0703\n            LOGGER.debug('Error transforming template: %s', str(e))\n            LOGGER.debug('Stack trace: %s', e, exc_info=True)\n            message = 'Error transforming template: {0}'\n            matches.append(Match(\n                1, 1,\n                1, 1,\n                self._filename,\n                TransformError(), message.format(str(e))))\n\n        return matches\n\n    @staticmethod\n    def is_s3_uri(uri):\n        \"\"\"\n        Checks the uri and determines if it is a valid S3 Uri\n        Parameters\n        ----------\n        uri str, required\n            Uri to check\n        Returns\n        -------\n        bool\n            Returns True if the uri given is an S3 uri, otherwise False\n        \"\"\"\n        return isinstance(uri, six.string_types) and uri.startswith('s3://')\n\n    @staticmethod\n    def _update_to_s3_uri(\n            property_key, resource_property_dict,\n            s3_uri_value='s3://bucket/value'):\n        \"\"\"\n        Updates the 'property_key' in the 'resource_property_dict' to the\n        value of 's3_uri_value'\n        Note: The function will mutate the resource_property_dict that is pass\n        in Parameters\n        ----------\n        property_key str, required\n            Key in the resource_property_dict\n        resource_property_dict dict, required\n            Property dictionary of a Resource in the template to replace\n        s3_uri_value str, optional\n            Value to update the value of the property_key to\n        \"\"\"\n        uri_property = resource_property_dict.get(property_key, '.')\n\n        # ignore if dict or already an S3 Uri\n        if isinstance(uri_property, dict) or Transform.is_s3_uri(uri_property):\n            return\n\n        resource_property_dict[property_key] = s3_uri_value\n", "path": "src/cfnlint/transform.py"}], "after_files": [{"content": "\"\"\"\nCopyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nimport codecs\nimport re\nfrom setuptools import find_packages\nfrom setuptools import setup\n\n\ndef get_version(filename):\n    with codecs.open(filename, 'r', 'utf-8') as fp:\n        contents = fp.read()\n    return re.search(r\"__version__ = ['\\\"]([^'\\\"]+)['\\\"]\", contents).group(1)\n\n\nversion = get_version('src/cfnlint/version.py')\n\n\nwith open('README.md') as f:\n    readme = f.read()\n\nsetup(\n    name='cfn-lint',\n    version=version,\n    description=('Checks CloudFormation templates for practices and behaviour \\\nthat could potentially be improved'),\n    long_description=readme,\n    long_description_content_type=\"text/markdown\",\n    keywords='aws, lint',\n    author='kddejong',\n    author_email='kddejong@amazon.com',\n    url='https://github.com/aws-cloudformation/cfn-python-lint',\n    package_dir={'': 'src'},\n    package_data={'cfnlint': [\n        'data/CloudSpecs/*.json',\n        'data/AdditionalSpecs/*.json',\n        'data/Serverless/*.json',\n        'data/ExtendedSpecs/*/*.json',\n        'data/CfnLintCli/config/schema.json'\n    ]},\n    packages=find_packages('src'),\n    zip_safe=False,\n    install_requires=[\n        'pyyaml<=5.2;python_version==\"3.4\"',\n        'pyyaml;python_version!=\"3.4\"',\n        'six~=1.11',\n        'aws-sam-translator>=1.24.0',\n        'jsonpatch;python_version!=\"3.4\"',\n        'jsonpatch<=1.24;python_version==\"3.4\"',\n        'jsonschema~=3.0',\n        'pathlib2>=2.3.0;python_version<=\"3.4\"',\n        'importlib_resources~=1.0.2;python_version==\"3.4\"',\n        'importlib_resources~=1.4;python_version<\"3.7\" and python_version!=\"3.4\"',\n        'networkx~=2.4;python_version>=\"3.5\"',\n        'networkx<=2.2;python_version<\"3.5\"',\n        'junit-xml~=1.9',\n    ],\n    python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',\n    entry_points={\n        'console_scripts': [\n            'cfn-lint = cfnlint.__main__:main'\n        ]\n    },\n    license='MIT no attribution',\n    test_suite=\"unittest\",\n    classifiers=[\n        'Development Status :: 5 - Production/Stable',\n        'Intended Audience :: Developers',\n        'License :: OSI Approved :: MIT License',\n        'Natural Language :: English',\n        'Operating System :: OS Independent',\n        'Programming Language :: Python :: 2',\n        'Programming Language :: Python :: 2.7',\n        'Programming Language :: Python :: 3',\n        'Programming Language :: Python :: 3.4',\n        'Programming Language :: Python :: 3.5',\n        'Programming Language :: Python :: 3.6',\n        'Programming Language :: Python :: 3.7',\n        'Programming Language :: Python :: 3.8',\n    ],\n)\n", "path": "setup.py"}, {"content": "\"\"\"\nCopyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nimport os\nimport logging\nimport six\nimport samtranslator\nfrom samtranslator.parser import parser\nfrom samtranslator.translator.translator import Translator\nfrom samtranslator.public.exceptions import InvalidDocumentException\n\nfrom cfnlint.helpers import load_resource, convert_dict, format_json_string\nfrom cfnlint.data import Serverless\nfrom cfnlint.rules import Match, TransformError\nLOGGER = logging.getLogger('cfnlint')\n\n\nclass Transform(object):\n    \"\"\"\n    Application Serverless Module tranform Wrapper.\n    Based on code from AWS SAM CLI:\n    https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/commands/validate/lib/sam_template_validator.py\n    \"\"\"\n\n    def __init__(self, filename, template, region):\n        \"\"\"\n        Initialize Transform class\n        \"\"\"\n        self._filename = filename\n        self._template = template\n        self._region = region\n        self._parameters = {}\n\n        self._managed_policy_map = self.load_managed_policies()\n        self._sam_parser = parser.Parser()\n\n    def template(self):\n        \"\"\"Get the template\"\"\"\n        return self._template\n\n    def load_managed_policies(self):\n        \"\"\"\n        Load the ManagedPolicies locally, based on the AWS-CLI:\n        https://github.com/awslabs/aws-sam-cli/blob/develop/samcli/lib/samlib/default_managed_policies.json\n        \"\"\"\n        return load_resource(Serverless, 'ManagedPolicies.json')\n\n    def _replace_local_codeuri(self):\n        \"\"\"\n        Replaces the CodeUri in AWS::Serverless::Function and DefinitionUri in\n        AWS::Serverless::Api to a fake S3 Uri. This is to support running the\n        SAM Translator with valid values for these fields. If this is not done,\n        the template is invalid in the eyes of SAM Translator (the translator\n        does not support local paths)\n        \"\"\"\n\n        all_resources = self._template.get('Resources', {})\n\n        for _, resource in all_resources.items():\n\n            resource_type = resource.get('Type')\n            resource_dict = resource.get('Properties')\n\n            if resource_type == 'AWS::Serverless::Function':\n\n                Transform._update_to_s3_uri('CodeUri', resource_dict)\n                auto_publish_alias = resource_dict.get('AutoPublishAlias')\n                if isinstance(auto_publish_alias, dict):\n                    if len(auto_publish_alias) == 1:\n                        for k, v in auto_publish_alias.items():\n                            if k == 'Ref':\n                                if v in self._template.get('Parameters'):\n                                    self._parameters[v] = 'Alias'\n            if resource_type in ['AWS::Serverless::LayerVersion']:\n                if resource_dict.get('ContentUri'):\n                    Transform._update_to_s3_uri('ContentUri', resource_dict)\n            if resource_type == 'AWS::Serverless::Application':\n                if resource_dict.get('Location'):\n                    resource_dict['Location'] = ''\n                    Transform._update_to_s3_uri('Location', resource_dict)\n            if resource_type == 'AWS::Serverless::Api':\n                if ('DefinitionBody' not in resource_dict and\n                        'Auth' not in resource_dict and 'Cors' not in resource_dict):\n                    Transform._update_to_s3_uri('DefinitionUri', resource_dict)\n                else:\n                    resource_dict['DefinitionBody'] = ''\n            if resource_type == 'AWS::Serverless::StateMachine':\n                Transform._update_to_s3_uri('DefinitionUri', resource_dict)\n\n    def transform_template(self):\n        \"\"\"\n        Transform the Template using the Serverless Application Model.\n        \"\"\"\n        matches = []\n\n        try:\n            # Output the SAM Translator version in debug mode\n            LOGGER.info('SAM Translator: %s', samtranslator.__version__)\n\n            sam_translator = Translator(\n                managed_policy_map=self._managed_policy_map,\n                sam_parser=self._sam_parser)\n\n            self._replace_local_codeuri()\n\n            # Tell SAM to use the region we're linting in, this has to be\n            # controlled using the default AWS mechanisms, see also:\n            # https://github.com/awslabs/serverless-application-model/blob/master/samtranslator/translator/arn_generator.py\n            LOGGER.info('Setting AWS_DEFAULT_REGION to %s', self._region)\n            os.environ['AWS_DEFAULT_REGION'] = self._region\n\n            self._template = convert_dict(\n                sam_translator.translate(sam_template=self._template,\n                                         parameter_values=self._parameters))\n\n            LOGGER.info('Transformed template: \\n%s',\n                        format_json_string(self._template))\n        except InvalidDocumentException as e:\n            message = 'Error transforming template: {0}'\n            for cause in e.causes:\n                matches.append(Match(\n                    1, 1,\n                    1, 1,\n                    self._filename,\n                    TransformError(), message.format(cause.message)))\n        except Exception as e:  # pylint: disable=W0703\n            LOGGER.debug('Error transforming template: %s', str(e))\n            LOGGER.debug('Stack trace: %s', e, exc_info=True)\n            message = 'Error transforming template: {0}'\n            matches.append(Match(\n                1, 1,\n                1, 1,\n                self._filename,\n                TransformError(), message.format(str(e))))\n\n        return matches\n\n    @staticmethod\n    def is_s3_uri(uri):\n        \"\"\"\n        Checks the uri and determines if it is a valid S3 Uri\n        Parameters\n        ----------\n        uri str, required\n            Uri to check\n        Returns\n        -------\n        bool\n            Returns True if the uri given is an S3 uri, otherwise False\n        \"\"\"\n        return isinstance(uri, six.string_types) and uri.startswith('s3://')\n\n    @staticmethod\n    def _update_to_s3_uri(\n            property_key, resource_property_dict,\n            s3_uri_value='s3://bucket/value'):\n        \"\"\"\n        Updates the 'property_key' in the 'resource_property_dict' to the\n        value of 's3_uri_value'\n        Note: The function will mutate the resource_property_dict that is pass\n        in Parameters\n        ----------\n        property_key str, required\n            Key in the resource_property_dict\n        resource_property_dict dict, required\n            Property dictionary of a Resource in the template to replace\n        s3_uri_value str, optional\n            Value to update the value of the property_key to\n        \"\"\"\n        uri_property = resource_property_dict.get(property_key, '.')\n\n        # ignore if dict or already an S3 Uri\n        if isinstance(uri_property, dict) or Transform.is_s3_uri(uri_property):\n            return\n\n        resource_property_dict[property_key] = s3_uri_value\n", "path": "src/cfnlint/transform.py"}]}