<s> """<STR_LIT>""" <EOL> import time <EOL> from security_monkey . watcher import Watcher <EOL> from security_monkey . watcher import ChangeItem <EOL> from security_monkey . constants import TROUBLE_REGIONS <EOL> from security_monkey . exceptions import BotoConnectionIssue <EOL> from security_monkey import app <EOL> from boto . ec2 . elb import regions <EOL> def parse_policy ( policy ) : <EOL> ret = { } <EOL> ret [ '<STR_LIT:name>' ] = policy [ '<STR_LIT:name>' ] <EOL> ret [ '<STR_LIT:type>' ] = policy [ '<STR_LIT:type>' ] <EOL> attrs = policy [ '<STR_LIT>' ] <EOL> if policy [ '<STR_LIT:type>' ] != '<STR_LIT>' : <EOL> return ret <EOL> ret [ '<STR_LIT>' ] = bool ( attrs . get ( '<STR_LIT>' ) ) <EOL> ret [ '<STR_LIT>' ] = bool ( attrs . get ( '<STR_LIT>' ) ) <EOL> ret [ '<STR_LIT>' ] = bool ( attrs . get ( '<STR_LIT>' ) ) <EOL> ret [ '<STR_LIT>' ] = bool ( attrs . get ( '<STR_LIT>' ) ) <EOL> ret [ '<STR_LIT>' ] = bool ( attrs . get ( '<STR_LIT>' ) ) <EOL> ret [ '<STR_LIT>' ] = bool ( attrs . get ( '<STR_LIT>' ) ) <EOL> ret [ '<STR_LIT>' ] = attrs . get ( '<STR_LIT>' , None ) <EOL> non_ciphers = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> ciphers = [ ] <EOL> for cipher in attrs : <EOL> if attrs [ cipher ] and cipher not in non_ciphers : <EOL> ciphers . append ( cipher ) <EOL> ciphers . sort ( ) <EOL> ret [ '<STR_LIT>' ] = ciphers <EOL> return ret <EOL> class ELB ( Watcher ) : <EOL> index = '<STR_LIT>' <EOL> i_am_singular = '<STR_LIT>' <EOL> i_am_plural = '<STR_LIT>' <EOL> def __init__ ( self , accounts = None , debug = False ) : <EOL> super ( ELB , self ) . __init__ ( accounts = accounts , debug = debug ) <EOL> def _setup_botocore ( self , account ) : <EOL> from security_monkey . common . sts_connect import connect <EOL> self . botocore_session = connect ( account , '<STR_LIT>' ) <EOL> def _get_listener_policies ( self , operation , elb ) : <EOL> response_data = self . wrap_aws_rate_limited_call ( operation , LoadBalancerName = elb . name ) <EOL> policies = { } <EOL> for policy in response_data . get ( '<STR_LIT>' , [ ] ) : <EOL> p = { "<STR_LIT:name>" : policy [ '<STR_LIT>' ] , "<STR_LIT:type>" : policy [ '<STR_LIT>' ] , "<STR_LIT>" : { } } <EOL> for attribute in policy [ '<STR_LIT>' ] : <EOL> if attribute [ '<STR_LIT>' ] == "<STR_LIT:true>" : <EOL> p [ '<STR_LIT>' ] [ attribute [ '<STR_LIT>' ] ] = True <EOL> elif attribute [ '<STR_LIT>' ] == "<STR_LIT:false>" : <EOL> p [ '<STR_LIT>' ] [ attribute [ '<STR_LIT>' ] ] = False <EOL> else : <EOL> p [ '<STR_LIT>' ] [ attribute [ '<STR_LIT>' ] ] = attribute [ '<STR_LIT>' ] <EOL> if "<STR_LIT>" in p [ '<STR_LIT>' ] : <EOL> p [ '<STR_LIT>' ] = p [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> del p [ '<STR_LIT>' ] <EOL> else : <EOL> p = parse_policy ( p ) <EOL> policies [ policy [ '<STR_LIT>' ] ] = p <EOL> return policies <EOL> def slurp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . prep_for_slurp ( ) <EOL> from security_monkey . common . sts_connect import connect <EOL> item_list = [ ] <EOL> exception_map = { } <EOL> for account in self . accounts : <EOL> self . _setup_botocore ( account ) <EOL> for region in regions ( ) : <EOL> app . logger . debug ( "<STR_LIT>" . format ( self . index , account , region . name ) ) <EOL> elb_conn = connect ( account , '<STR_LIT>' , region = region . name ) <EOL> botocore_client = self . botocore_session . create_client ( '<STR_LIT>' , region_name = region . name ) <EOL> botocore_operation = botocore_client . describe_load_balancer_policies <EOL> try : <EOL> all_elbs = [ ] <EOL> marker = None <EOL> while True : <EOL> response = self . wrap_aws_rate_limited_call ( <EOL> elb_conn . get_all_load_balancers , <EOL> marker = marker <EOL> ) <EOL> all_elbs . extend ( response ) <EOL> if response . next_marker : <EOL> marker = response . next_marker <EOL> else : <EOL> break <EOL> except Exception as e : <EOL> if region . name not in TROUBLE_REGIONS : <EOL> exc = BotoConnectionIssue ( str ( e ) , self . index , account , region . name ) <EOL> self . slurp_exception ( ( self . index , account , region . name ) , exc , exception_map ) <EOL> continue <EOL> app . logger . debug ( "<STR_LIT>" . format ( len ( all_elbs ) , self . i_am_plural ) ) <EOL> for elb in all_elbs : <EOL> if self . check_ignore_list ( elb . name ) : <EOL> continue <EOL> try : <EOL> elb_map = { } <EOL> elb_map [ '<STR_LIT>' ] = list ( elb . availability_zones ) <EOL> elb_map [ '<STR_LIT>' ] = elb . canonical_hosted_zone_name <EOL> elb_map [ '<STR_LIT>' ] = elb . canonical_hosted_zone_name_id <EOL> elb_map [ '<STR_LIT>' ] = elb . dns_name <EOL> elb_map [ '<STR_LIT>' ] = { '<STR_LIT:target>' : elb . health_check . target , '<STR_LIT>' : elb . health_check . interval } <EOL> elb_map [ '<STR_LIT>' ] = self . wrap_aws_rate_limited_call ( <EOL> elb . is_cross_zone_load_balancing <EOL> ) <EOL> elb_map [ '<STR_LIT>' ] = elb . scheme <EOL> elb_map [ '<STR_LIT>' ] = list ( elb . security_groups ) <EOL> elb_map [ '<STR_LIT>' ] = elb . source_security_group . name <EOL> elb_map [ '<STR_LIT>' ] = list ( elb . subnets ) <EOL> elb_map [ '<STR_LIT>' ] = elb . vpc_id <EOL> elb_map [ '<STR_LIT>' ] = self . wrap_aws_rate_limited_call ( <EOL> lambda : elb . get_attributes ( ) . access_log . enabled <EOL> ) <EOL> backends = [ ] <EOL> for be in elb . backends : <EOL> backend = { } <EOL> backend [ '<STR_LIT>' ] = be . instance_port <EOL> policies = [ ] <EOL> for bepol in be . policies : <EOL> policies . append ( bepol . policy_name ) <EOL> backend [ '<STR_LIT>' ] = policies <EOL> backends . append ( backend ) <EOL> elb_map [ '<STR_LIT>' ] = backends <EOL> elb_policies = self . _get_listener_policies ( botocore_operation , elb ) <EOL> listeners = [ ] <EOL> for li in elb . listeners : <EOL> listener = { <EOL> '<STR_LIT>' : li . load_balancer_port , <EOL> '<STR_LIT>' : li . instance_port , <EOL> '<STR_LIT>' : li . protocol , <EOL> '<STR_LIT>' : li . instance_protocol , <EOL> '<STR_LIT>' : li . ssl_certificate_id , <EOL> '<STR_LIT>' : [ elb_policies . get ( policy_name , { "<STR_LIT:name>" : policy_name } ) for policy_name in li . policy_names ] <EOL> } <EOL> listeners . append ( listener ) <EOL> elb_map [ '<STR_LIT>' ] = listeners <EOL> policies = { } <EOL> app_cookie_stickiness_policies = [ ] <EOL> for policy in elb . policies . app_cookie_stickiness_policies : <EOL> app_cookie_stickiness_policy = { } <EOL> app_cookie_stickiness_policy [ '<STR_LIT>' ] = policy . policy_name <EOL> app_cookie_stickiness_policy [ '<STR_LIT>' ] = policy . cookie_name <EOL> app_cookie_stickiness_policies . append ( app_cookie_stickiness_policy ) <EOL> policies [ '<STR_LIT>' ] = app_cookie_stickiness_policies <EOL> lb_cookie_stickiness_policies = [ ] <EOL> for policy in elb . policies . lb_cookie_stickiness_policies : <EOL> lb_cookie_stickiness_policy = { } <EOL> lb_cookie_stickiness_policy [ '<STR_LIT>' ] = policy . policy_name <EOL> lb_cookie_stickiness_policy [ '<STR_LIT>' ] = policy . cookie_expiration_period <EOL> lb_cookie_stickiness_policies . append ( lb_cookie_stickiness_policy ) <EOL> policies [ '<STR_LIT>' ] = lb_cookie_stickiness_policies <EOL> policies [ '<STR_LIT>' ] = [ ] <EOL> for opol in elb . policies . other_policies : <EOL> policies [ '<STR_LIT>' ] . append ( opol . policy_name ) <EOL> elb_map [ '<STR_LIT>' ] = policies <EOL> item = ELBItem ( region = region . name , account = account , name = elb . name , config = elb_map ) <EOL> item_list . append ( item ) <EOL> except Exception as e : <EOL> self . slurp_exception ( ( self . index , account , region . name , elb . name ) , e , exception_map ) <EOL> continue <EOL> return item_list , exception_map <EOL> class ELBItem ( ChangeItem ) : <EOL> def __init__ ( self , region = None , account = None , name = None , config = { } ) : <EOL> super ( ELBItem , self ) . __init__ ( <EOL> index = ELB . index , <EOL> region = region , <EOL> account = account , <EOL> name = name , <EOL> new_config = config ) </s>
