<s> """<STR_LIT>""" <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 . rds import regions <EOL> class RDSSecurityGroup ( 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 ( RDSSecurityGroup , self ) . __init__ ( accounts = accounts , debug = debug ) <EOL> def slurp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . prep_for_slurp ( ) <EOL> item_list = [ ] <EOL> exception_map = { } <EOL> from security_monkey . common . sts_connect import connect <EOL> for account in self . accounts : <EOL> for region in regions ( ) : <EOL> app . logger . debug ( "<STR_LIT>" . format ( self . index , account , region . name ) ) <EOL> sgs = [ ] <EOL> try : <EOL> rds = connect ( account , '<STR_LIT>' , region = region ) <EOL> marker = None <EOL> while True : <EOL> response = self . wrap_aws_rate_limited_call ( <EOL> rds . get_all_dbsecurity_groups , <EOL> marker = marker <EOL> ) <EOL> sgs . extend ( response ) <EOL> if response . marker : <EOL> marker = response . 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 ( sgs ) , self . i_am_plural ) ) <EOL> for sg in sgs : <EOL> if self . check_ignore_list ( sg . name ) : <EOL> continue <EOL> name = sg . name <EOL> vpc_id = None <EOL> if hasattr ( sg , '<STR_LIT>' ) : <EOL> vpc_id = sg . VpcId <EOL> name = "<STR_LIT>" . format ( sg . name , vpc_id ) <EOL> item_config = { <EOL> "<STR_LIT:name>" : sg . name , <EOL> "<STR_LIT:description>" : sg . description , <EOL> "<STR_LIT>" : sg . owner_id , <EOL> "<STR_LIT>" : region . name , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : vpc_id <EOL> } <EOL> for ipr in sg . ip_ranges : <EOL> ipr_config = { <EOL> "<STR_LIT>" : ipr . cidr_ip , <EOL> "<STR_LIT:status>" : ipr . status , <EOL> } <EOL> item_config [ "<STR_LIT>" ] . append ( ipr_config ) <EOL> item_config [ "<STR_LIT>" ] = sorted ( item_config [ "<STR_LIT>" ] ) <EOL> for ec2_sg in sg . ec2_groups : <EOL> ec2sg_config = { <EOL> "<STR_LIT:name>" : ec2_sg . name , <EOL> "<STR_LIT>" : ec2_sg . owner_id , <EOL> "<STR_LIT>" : ec2_sg . Status , <EOL> } <EOL> item_config [ "<STR_LIT>" ] . append ( ec2sg_config ) <EOL> item_config [ "<STR_LIT>" ] = sorted ( item_config [ "<STR_LIT>" ] ) <EOL> item = RDSSecurityGroupItem ( region = region . name , account = account , name = name , config = item_config ) <EOL> item_list . append ( item ) <EOL> return item_list , exception_map <EOL> class RDSSecurityGroupItem ( ChangeItem ) : <EOL> def __init__ ( self , region = None , account = None , name = None , config = { } ) : <EOL> super ( RDSSecurityGroupItem , self ) . __init__ ( <EOL> index = RDSSecurityGroup . index , <EOL> region = region , <EOL> account = account , <EOL> name = name , <EOL> new_config = config ) </s>
