3 D\@s8dZddlZddlmZddlmZGdddeZdS)a Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. N)CloudFormationLintRule) RuleMatchc@s@eZdZdZdZdZdZdZddgZdd Z d d Z d d Z dS)Elbz Check if Elb Resource PropertiesZE2503zResource ELB Propertiesz^See if Elb Resource Properties are set correctly HTTPS has certificate HTTP has no certificatezchttps://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-elb-listener.html propertiesZelbc Ksg}t|tjr|j|dkrTd}|jt||jdj|ddjtt |n>|j|dkr|dsd}|jt||jdjtt ||S)z* Check Protocol Value accepted_protocolsz&Protocol must be {0} is invalid at {1}z, /certificate_protocols certificatesz9Certificates should be specified when using HTTPS for {0}) isinstancesix string_typesupperappendrformatjoinmapstr)selfvaluepathkwargsmatchesmessagery/private/var/folders/pf/wv4htv3x0qs2c2mp0dnn0kchsvlck3/T/pip-install-emcbgzcf/cfn-lint/cfnlint/rules/resources/elb/Elb.pycheck_protocol_values 0"zElb.check_protocol_valuecCsg}|jd}|dkr|jd}t|trPt|dkrP|dg}|jt|d|jd}t|trt|dkr|dg}|jt|d|S)z( Validate at least two subnets with ALBsTypeZ applicationZSubnetszPYou must specify at least two Subnets for load balancers with type "application"ZSubnetMappingszWYou must specify at least two SubnetMappings for load balancers with type "application")getr listlenrr)rpropsrrelb_typesubnetsZsubnet_mappingsrrrcheck_alb_subnets/s         zElb.check_alb_subnetsc CsTg}|jdg}xJ|D]B}|j|j|dd|d|jddddgddg|djd d qW|jd d g}xp|D]h}t|dtrpxTt|dD]D\}}|j|j|d|d|g|jdddd gdd g|jdd qWqpW|jdg}xf|D]^}|d}|jd}|dkr6d|kr6|ddg} |jt | d|j|j ||dqW|S)zCheck ELB Resource Parametersz%AWS::ElasticLoadBalancingV2::ListenerValueZProtocolPathHTTPHTTPSZTCPZTLSZ Certificates) check_valuerrr z'AWS::ElasticLoadBalancing::LoadBalancerZ ListenersZSSLZSSLCertificateIdz)AWS::ElasticLoadBalancingV2::LoadBalancerrnetworkZSecurityGroupszHSecurity groups are not supported for load balancers with type "network") Zget_resource_propertiesextendr)rrr r enumeraterrr$) rZcfnrresultsresultindexlistenerrr"rrrrmatchAs>          z Elb.matchN) __name__ __module__ __qualname____doc__idZ shortdesc descriptionZ source_urltagsrr$r1rrrrrsr)r5r Zcfnlintrrrrrrrs