prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Single-subnet ELB detection
  *cfn-lint version: 0.10.3*
  
  *Description of issue.*
  
  When configuring `AWS::ElasticLoadBalancingV2::LoadBalancer`, if you specify only 1 subnet, you get back from AWS:
  
  > 2019-02-05 12:22:39 +1100 Elb AWS::ElasticLoadBalancingV2::LoadBalancer CREATE_FAILED At least two subnets in two different Availability Zones must be specified (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Request ID: ...)
  
  This could be covered by a cfn-lint check.
  
  </issue>
  <code>
  [start of src/cfnlint/rules/resources/elb/Elb.py]
  1 """
  2   Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3 
  4   Permission is hereby granted, free of charge, to any person obtaining a copy of this
  5   software and associated documentation files (the "Software"), to deal in the Software
  6   without restriction, including without limitation the rights to use, copy, modify,
  7   merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  8   permit persons to whom the Software is furnished to do so.
  9 
  10   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  11   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  12   PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  13   HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  14   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  15   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16 """
  17 import six
  18 from cfnlint import CloudFormationLintRule
  19 from cfnlint import RuleMatch
  20 
  21 
  22 class Elb(CloudFormationLintRule):
  23     """Check if Elb Resource Properties"""
  24     id = 'E2503'
  25     shortdesc = 'Resource ELB Properties'
  26     description = 'See if Elb Resource Properties are set correctly \
  27 HTTPS has certificate HTTP has no certificate'
  28     source_url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-elb-listener.html'
  29     tags = ['properties', 'elb']
  30 
  31     def check_protocol_value(self, value, path, **kwargs):
  32         """
  33             Check Protocol Value
  34         """
  35         matches = []
  36         if isinstance(value, six.string_types):
  37             if value.upper() not in kwargs['accepted_protocols']:
  38                 message = 'Protocol must be {0} is invalid at {1}'
  39                 matches.append(RuleMatch(path, message.format((', '.join(kwargs['accepted_protocols'])), ('/'.join(map(str, path))))))
  40             elif value.upper() in kwargs['certificate_protocols']:
  41                 if not kwargs['certificates']:
  42                     message = 'Certificates should be specified when using HTTPS for {0}'
  43                     matches.append(RuleMatch(path, message.format(('/'.join(map(str, path))))))
  44 
  45         return matches
  46 
  47     def match(self, cfn):
  48         """Check ELB Resource Parameters"""
  49 
  50         matches = []
  51 
  52         results = cfn.get_resource_properties(['AWS::ElasticLoadBalancingV2::Listener'])
  53         for result in results:
  54             matches.extend(
  55                 cfn.check_value(
  56                     result['Value'], 'Protocol', result['Path'],
  57                     check_value=self.check_protocol_value,
  58                     accepted_protocols=['HTTP', 'HTTPS', 'TCP', 'TLS'],
  59                     certificate_protocols=['HTTPS', 'TLS'],
  60                     certificates=result['Value'].get('Certificates')))
  61 
  62         results = cfn.get_resource_properties(['AWS::ElasticLoadBalancing::LoadBalancer', 'Listeners'])
  63         for result in results:
  64             if isinstance(result['Value'], list):
  65                 for index, listener in enumerate(result['Value']):
  66                     matches.extend(
  67                         cfn.check_value(
  68                             listener, 'Protocol', result['Path'] + [index],
  69                             check_value=self.check_protocol_value,
  70                             accepted_protocols=['HTTP', 'HTTPS', 'TCP', 'SSL'],
  71                             certificate_protocols=['HTTPS', 'SSL'],
  72                             certificates=listener.get('SSLCertificateId')))
  73 
  74         results = cfn.get_resource_properties(['AWS::ElasticLoadBalancingV2::LoadBalancer'])
  75         for result in results:
  76             properties = result['Value']
  77             if 'Type' in properties and properties['Type'] == 'network':
  78                 if 'SecurityGroups' in properties:
  79                     path = result['Path'] + ['SecurityGroups']
  80                     matches.append(RuleMatch(path, 'Security groups are not supported for load balancers with type "network"'))
  81 
  82         return matches
  83
  [end of src/cfnlint/rules/resources/elb/Elb.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/src/cfnlint/rules/resources/elb/Elb.py b/src/cfnlint/rules/resources/elb/Elb.py
  --- a/src/cfnlint/rules/resources/elb/Elb.py
  +++ b/src/cfnlint/rules/resources/elb/Elb.py
  @@ -44,6 +44,24 @@
   
           return matches
   
  +    def check_alb_subnets(self, props, path):
  +        """ Validate at least two subnets with ALBs"""
  +        matches = []
  +        elb_type = props.get('Type')
  +        if elb_type == 'application':
  +            subnets = props.get('Subnets')
  +            if isinstance(subnets, list):
  +                if len(subnets) < 2:
  +                    path = path + ['Subnets']
  +                    matches.append(RuleMatch(path, 'You must specify at least two Subnets for load balancers with type "application"'))
  +            subnet_mappings = props.get('SubnetMappings')
  +            if isinstance(subnet_mappings, list):
  +                if len(subnet_mappings) < 2:
  +                    path = path + ['SubnetMappings']
  +                    matches.append(RuleMatch(path, 'You must specify at least two SubnetMappings for load balancers with type "application"'))
  +
  +        return matches
  +
       def match(self, cfn):
           """Check ELB Resource Parameters"""
   
  @@ -74,9 +92,12 @@
           results = cfn.get_resource_properties(['AWS::ElasticLoadBalancingV2::LoadBalancer'])
           for result in results:
               properties = result['Value']
  -            if 'Type' in properties and properties['Type'] == 'network':
  +            elb_type = properties.get('Type')
  +            if elb_type == 'network':
                   if 'SecurityGroups' in properties:
                       path = result['Path'] + ['SecurityGroups']
                       matches.append(RuleMatch(path, 'Security groups are not supported for load balancers with type "network"'))
   
  +            matches.extend(self.check_alb_subnets(properties, result['Path']))
  +
           return matches
  
verification_info: {"golden_diff": "diff --git a/src/cfnlint/rules/resources/elb/Elb.py b/src/cfnlint/rules/resources/elb/Elb.py\n--- a/src/cfnlint/rules/resources/elb/Elb.py\n+++ b/src/cfnlint/rules/resources/elb/Elb.py\n@@ -44,6 +44,24 @@\n \n         return matches\n \n+    def check_alb_subnets(self, props, path):\n+        \"\"\" Validate at least two subnets with ALBs\"\"\"\n+        matches = []\n+        elb_type = props.get('Type')\n+        if elb_type == 'application':\n+            subnets = props.get('Subnets')\n+            if isinstance(subnets, list):\n+                if len(subnets) < 2:\n+                    path = path + ['Subnets']\n+                    matches.append(RuleMatch(path, 'You must specify at least two Subnets for load balancers with type \"application\"'))\n+            subnet_mappings = props.get('SubnetMappings')\n+            if isinstance(subnet_mappings, list):\n+                if len(subnet_mappings) < 2:\n+                    path = path + ['SubnetMappings']\n+                    matches.append(RuleMatch(path, 'You must specify at least two SubnetMappings for load balancers with type \"application\"'))\n+\n+        return matches\n+\n     def match(self, cfn):\n         \"\"\"Check ELB Resource Parameters\"\"\"\n \n@@ -74,9 +92,12 @@\n         results = cfn.get_resource_properties(['AWS::ElasticLoadBalancingV2::LoadBalancer'])\n         for result in results:\n             properties = result['Value']\n-            if 'Type' in properties and properties['Type'] == 'network':\n+            elb_type = properties.get('Type')\n+            if elb_type == 'network':\n                 if 'SecurityGroups' in properties:\n                     path = result['Path'] + ['SecurityGroups']\n                     matches.append(RuleMatch(path, 'Security groups are not supported for load balancers with type \"network\"'))\n \n+            matches.extend(self.check_alb_subnets(properties, result['Path']))\n+\n         return matches\n", "issue": "Single-subnet ELB detection\n*cfn-lint version: 0.10.3*\r\n\r\n*Description of issue.*\r\n\r\nWhen configuring `AWS::ElasticLoadBalancingV2::LoadBalancer`, if you specify only 1 subnet, you get back from AWS:\r\n\r\n> 2019-02-05 12:22:39 +1100 Elb AWS::ElasticLoadBalancingV2::LoadBalancer CREATE_FAILED At least two subnets in two different Availability Zones must be specified (Service: AmazonElasticLoadBalancingV2; Status Code: 400; Error Code: ValidationError; Request ID: ...)\r\n\r\nThis could be covered by a cfn-lint check.\n", "before_files": [{"content": "\"\"\"\n  Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n\n  Permission is hereby granted, free of charge, to any person obtaining a copy of this\n  software and associated documentation files (the \"Software\"), to deal in the Software\n  without restriction, including without limitation the rights to use, copy, modify,\n  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n  permit persons to whom the Software is furnished to do so.\n\n  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,\n  INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A\n  PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\n  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\"\"\"\nimport six\nfrom cfnlint import CloudFormationLintRule\nfrom cfnlint import RuleMatch\n\n\nclass Elb(CloudFormationLintRule):\n    \"\"\"Check if Elb Resource Properties\"\"\"\n    id = 'E2503'\n    shortdesc = 'Resource ELB Properties'\n    description = 'See if Elb Resource Properties are set correctly \\\nHTTPS has certificate HTTP has no certificate'\n    source_url = 'https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-elb-listener.html'\n    tags = ['properties', 'elb']\n\n    def check_protocol_value(self, value, path, **kwargs):\n        \"\"\"\n            Check Protocol Value\n        \"\"\"\n        matches = []\n        if isinstance(value, six.string_types):\n            if value.upper() not in kwargs['accepted_protocols']:\n                message = 'Protocol must be {0} is invalid at {1}'\n                matches.append(RuleMatch(path, message.format((', '.join(kwargs['accepted_protocols'])), ('/'.join(map(str, path))))))\n            elif value.upper() in kwargs['certificate_protocols']:\n                if not kwargs['certificates']:\n                    message = 'Certificates should be specified when using HTTPS for {0}'\n                    matches.append(RuleMatch(path, message.format(('/'.join(map(str, path))))))\n\n        return matches\n\n    def match(self, cfn):\n        \"\"\"Check ELB Resource Parameters\"\"\"\n\n        matches = []\n\n        results = cfn.get_resource_properties(['AWS::ElasticLoadBalancingV2::Listener'])\n        for result in results:\n            matches.extend(\n                cfn.check_value(\n                    result['Value'], 'Protocol', result['Path'],\n                    check_value=self.check_protocol_value,\n                    accepted_protocols=['HTTP', 'HTTPS', 'TCP', 'TLS'],\n                    certificate_protocols=['HTTPS', 'TLS'],\n                    certificates=result['Value'].get('Certificates')))\n\n        results = cfn.get_resource_properties(['AWS::ElasticLoadBalancing::LoadBalancer', 'Listeners'])\n        for result in results:\n            if isinstance(result['Value'], list):\n                for index, listener in enumerate(result['Value']):\n                    matches.extend(\n                        cfn.check_value(\n                            listener, 'Protocol', result['Path'] + [index],\n                            check_value=self.check_protocol_value,\n                            accepted_protocols=['HTTP', 'HTTPS', 'TCP', 'SSL'],\n                            certificate_protocols=['HTTPS', 'SSL'],\n                            certificates=listener.get('SSLCertificateId')))\n\n        results = cfn.get_resource_properties(['AWS::ElasticLoadBalancingV2::LoadBalancer'])\n        for result in results:\n            properties = result['Value']\n            if 'Type' in properties and properties['Type'] == 'network':\n                if 'SecurityGroups' in properties:\n                    path = result['Path'] + ['SecurityGroups']\n                    matches.append(RuleMatch(path, 'Security groups are not supported for load balancers with type \"network\"'))\n\n        return matches\n", "path": "src/cfnlint/rules/resources/elb/Elb.py"}]}