def _replace_local_codeuri()

in samcli/lib/translate/sam_template_validator.py [0:0]


    def _replace_local_codeuri(self):
        """
        Replaces the CodeUri in AWS::Serverless::Function and DefinitionUri in AWS::Serverless::Api and
        AWS::Serverless::HttpApi to a fake S3 Uri. This is to support running the SAM Translator with
        valid values for these fields. If this in not done, the template is invalid in the eyes of SAM
        Translator (the translator does not support local paths)
        """

        all_resources = self.sam_template.get("Resources", {})
        global_settings = self.sam_template.get("Globals", {})

        for resource_type, properties in global_settings.items():
            if resource_type == "Function":
                if all(
                    [
                        _properties.get("Properties", {}).get("PackageType", ZIP) == ZIP
                        for _, _properties in all_resources.items()
                    ]
                    + [_properties.get("PackageType", ZIP) == ZIP for _, _properties in global_settings.items()]
                ):
                    SamTemplateValidator._update_to_s3_uri("CodeUri", properties)

        for _, resource in all_resources.items():
            resource_type = resource.get("Type")
            resource_dict = resource.get("Properties", {})

            if resource_type == "AWS::Serverless::Function" and resource_dict.get("PackageType", ZIP) == ZIP:
                SamTemplateValidator._update_to_s3_uri("CodeUri", resource_dict)

            if resource_type == "AWS::Serverless::LayerVersion":
                SamTemplateValidator._update_to_s3_uri("ContentUri", resource_dict)

            if resource_type == "AWS::Serverless::Api":
                if "DefinitionUri" in resource_dict:
                    SamTemplateValidator._update_to_s3_uri("DefinitionUri", resource_dict)

            if resource_type == "AWS::Serverless::HttpApi":
                if "DefinitionUri" in resource_dict:
                    SamTemplateValidator._update_to_s3_uri("DefinitionUri", resource_dict)

            if resource_type == "AWS::Serverless::StateMachine":
                if "DefinitionUri" in resource_dict:
                    SamTemplateValidator._update_to_s3_uri("DefinitionUri", resource_dict)