Beispiel #1
0
    def process(event):
        dynamo_db_allocator = DynamoAllocator()
        dynamo_resource = dynamo_db_allocator.resource()
        dynamo_client = dynamo_db_allocator.client()
        unbannable_ips = DynamoGetUnbannable().get_unbannables(dynamo_client, dynamo_resource)

        for country in get_countries():
            region = get_region_from_country(country)
            ec2_client = EC2Allocator().client(region_name=region)
            ip_unbanner = IpUnbanner(ec2_client=ec2_client)
            vpc_id = VpcFinder().get_vpc(ec2_client, country)
            nacl, proposed_rulenumber = VpcNaclElector(
            ).get_available_nacl_and_proposed_rulenumber(ec2_client, vpc_id, 100)
            ip_unbanner.unban_ips(unbannable_ips, nacl, vpc_id)
    def test_get_unbannables(self):
        vpc_id, acl_id = self.create_resources()
        ip_hash_map = {'244.244.244.244': 1}
        ec2_client = EC2Allocator().client('eu-west-1')
        dynamo_allocator = DynamoAllocator()
        dynamo_resource = dynamo_allocator.resource()
        dynamo_client = dynamo_allocator.client()
        table = dynamo_resource.Table(get_dynamo_table())
        struct_time = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
        epoch = UTC_time_to_epoch(struct_time)
        table.put_item(
            Item={
                'ip': '244.244.244.244',
                'last_seen': epoch,
                'times_seen': 1,
                'banned': True
            })

        unbannables = DynamoGetUnbannable().get_unbannables(
            dynamo_client, dynamo_resource)

        assert '244.244.244.244' in unbannables