

def slurp(self):
    '\n        :returns: item_list - list of Security Groups.\n        :returns: exception_map - A dict where the keys are a tuple containing the\n            location of the exception and the value is the actual exception\n\n        '
    self.prep_for_slurp()
    item_list = []
    exception_map = {
        
    }
    from security_monkey.common.sts_connect import connect
    for account in self.accounts:
        try:
            ec2 = connect(account, 'ec2')
            regions = ec2.get_all_regions()
        except Exception as e:
            exc = BotoConnectionIssue(str(e), self.index, account, None)
            self.slurp_exception((self.index, account), exc, exception_map)
            continue
        for region in regions:
            app.logger.debug('Checking {}/{}/{}'.format(self.index, account, region.name))
            try:
                rec2 = connect(account, 'ec2', region=region)
                sgs = self.wrap_aws_rate_limited_call(rec2.get_all_security_groups)
                if (self.get_detail_level() != 'NONE'):
                    tags = self.wrap_aws_rate_limited_call(rec2.get_all_tags)
                    instances = self.wrap_aws_rate_limited_call(rec2.get_only_instances)
                    app.logger.info('Number of instances found in region {}: {}'.format(region.name, len(instances)))
            except Exception as e:
                if (region.name not in TROUBLE_REGIONS):
                    exc = BotoConnectionIssue(str(e), self.index, account, region.name)
                    self.slurp_exception((self.index, account, region.name), exc, exception_map)
                continue
            app.logger.debug('Found {} {}'.format(len(sgs), self.i_am_plural))
            if (self.get_detail_level() != 'NONE'):
                app.logger.info("Creating mapping of sg_id's to instances")
                sg_instances = {
                    
                }
                for instance in instances:
                    for group in instance.groups:
                        if (group.id not in sg_instances):
                            sg_instances[group.id] = [instance]
                        else:
                            sg_instances[group.id].append(instance)
                app.logger.info("Creating mapping of instance_id's to tags")
                instance_tags = {
                    
                }
                for tag in tags:
                    if (tag.res_id not in instance_tags):
                        instance_tags[tag.res_id] = [tag]
                    else:
                        instance_tags[tag.res_id].append(tag)
                app.logger.info('Done creating mappings')
            for sg in sgs:
                if self.check_ignore_list(sg.name):
                    continue
                item_config = {
                    'id': sg.id,
                    'name': sg.name,
                    'description': sg.description,
                    'vpc_id': sg.vpc_id,
                    'owner_id': sg.owner_id,
                    'region': sg.region.name,
                    'rules': [],
                    'assigned_to': None,
                }
                for rule in sg.rules:
                    for grant in rule.grants:
                        rule_config = {
                            'ip_protocol': rule.ip_protocol,
                            'rule_type': 'ingress',
                            'from_port': rule.from_port,
                            'to_port': rule.to_port,
                            'cidr_ip': grant.cidr_ip,
                            'group_id': grant.group_id,
                            'name': grant.name,
                            'owner_id': grant.owner_id,
                        }
                        item_config['rules'].append(rule_config)
                for rule in sg.rules_egress:
                    for grant in rule.grants:
                        rule_config = {
                            'ip_protocol': rule.ip_protocol,
                            'rule_type': 'egress',
                            'from_port': rule.from_port,
                            'to_port': rule.to_port,
                            'cidr_ip': grant.cidr_ip,
                            'group_id': grant.group_id,
                            'name': grant.name,
                            'owner_id': grant.owner_id,
                        }
                        item_config['rules'].append(rule_config)
                item_config['rules'] = sorted(item_config['rules'])
                if (self.get_detail_level() == 'SUMMARY'):
                    if (sg.id in sg_instances):
                        item_config['assigned_to'] = '{} instances'.format(len(sg_instances[sg.id]))
                    else:
                        item_config['assigned_to'] = '0 instances'
                elif (instance.get_detail_level() == 'FULL'):
                    assigned_to = []
                    if (sg.id in sg_instances):
                        for instance in sg_instances[sg.id]:
                            if (instance.id in instance_tags):
                                tagdict = {tag.name: tag.value for tag in instance_tags[instance.id]}
                                tagdict['instance_id'] = instance.id
                            else:
                                tagdict = {
                                    'instance_id': instance.id,
                                }
                            assigned_to.append(tagdict)
                    item_config['assigned_to'] = assigned_to
                if sg.vpc_id:
                    sg_name = '{0} ({1} in {2})'.format(sg.name, sg.id, sg.vpc_id)
                else:
                    sg_name = '{0} ({1})'.format(sg.name, sg.id)
                item = SecurityGroupItem(region=region.name, account=account, name=sg_name, config=item_config)
                item_list.append(item)
    return (item_list, exception_map)

dataset/ETHPy150Open Netflix/security_monkey/security_monkey/watchers/security_group.py SecurityGroup.slurp/VarMisuse@814/1268 `self`->`instance`