Beispiel #1
0
def fill_new_user(org):
    user_types = utils.roundrobin(
        [CERT_CLIENT_POOL] * settings.app.user_pool_size, [CERT_SERVER_POOL] * settings.app.server_user_pool_size
    )

    for user_type in user_types:
        org.new_user(type=user_type, block=False)
Beispiel #2
0
def fill_dh_params():
    collection = mongo.get_collection('dh_params')
    queue_collection = mongo.get_collection('queue')

    new_dh_params = []
    dh_param_bits_pool = settings.app.dh_param_bits_pool
    dh_param_counts = utils.LeastCommonCounter()

    for dh_param_bits in dh_param_bits_pool:
        pool_count = collection.find({
            'dh_param_bits': dh_param_bits,
        }, {
            '_id': True
        }).count()

        dh_param_counts[dh_param_bits] = pool_count

        pool_count = queue_collection.find({
            'type': 'dh_params',
            'dh_param_bits': dh_param_bits,
        }, {
            '_id': True
        }).count()

        dh_param_counts[dh_param_bits] += pool_count

    for dh_param_bits, count in dh_param_counts.least_common():
        new_dh_params.append([dh_param_bits] * (
            settings.app.server_pool_size - count))

    for dh_param_bits in utils.roundrobin(*new_dh_params):
        que = queue.start('dh_params', dh_param_bits=dh_param_bits,
            priority=LOW)
Beispiel #3
0
def fill_dh_params():
    collection = mongo.get_collection('dh_params')
    queue_collection = mongo.get_collection('queue')

    new_dh_params = []
    dh_param_bits_pool = settings.app.dh_param_bits_pool
    dh_param_counts = utils.LeastCommonCounter()

    for dh_param_bits in dh_param_bits_pool:
        pool_count = collection.find({
            'dh_param_bits': dh_param_bits,
        }, {
            '_id': True
        }).count()

        dh_param_counts[dh_param_bits] = pool_count

        pool_count = queue_collection.find(
            {
                'type': 'dh_params',
                'dh_param_bits': dh_param_bits,
            }, {
                '_id': True
            }).count()

        dh_param_counts[dh_param_bits] += pool_count

    for dh_param_bits, count in dh_param_counts.least_common():
        new_dh_params.append([dh_param_bits] *
                             (settings.app.server_pool_size - count))

    for dh_param_bits in utils.roundrobin(*new_dh_params):
        que = queue.start('dh_params',
                          dh_param_bits=dh_param_bits,
                          priority=LOW)
Beispiel #4
0
def fill_new_user(org):
    user_types = utils.roundrobin(
        [CERT_CLIENT_POOL] * settings.app.user_pool_size,
        [CERT_SERVER_POOL] * settings.app.server_user_pool_size,
    )

    for user_type in user_types:
        org.new_user(type=user_type, block=False)
Beispiel #5
0
def fill_user():
    collection = mongo.get_collection("users")
    org_collection = mongo.get_collection("organizations")
    queue_collection = mongo.get_collection("queue")

    orgs = {}
    orgs_count = utils.LeastCommonCounter()
    type_to_size = {CERT_CLIENT_POOL: settings.app.user_pool_size, CERT_SERVER_POOL: settings.app.server_user_pool_size}

    for org in organization.iter_orgs(type=None):
        orgs[org.id] = org
        orgs_count[org.id, CERT_CLIENT_POOL] = 0
        orgs_count[org.id, CERT_SERVER_POOL] = 0

    pools = collection.aggregate(
        [
            {"$match": {"type": {"$in": (CERT_CLIENT_POOL, CERT_SERVER_POOL)}}},
            {"$project": {"org_id": True, "type": True}},
            {"$group": {"_id": {"org_id": "$org_id", "type": "$type"}, "count": {"$sum": 1}}},
        ]
    )

    for pool in pools:
        orgs_count[pool["_id"]["org_id"], pool["_id"]["type"]] += pool["count"]

    pools = queue_collection.aggregate(
        [
            {"$match": {"type": "init_user_pooled", "user_doc.type": {"$in": (CERT_CLIENT_POOL, CERT_SERVER_POOL)}}},
            {"$project": {"user_doc.org_id": True, "user_doc.type": True}},
            {"$group": {"_id": {"org_id": "$user_doc.org_id", "type": "$user_doc.type"}, "count": {"$sum": 1}}},
        ]
    )

    for pool in pools:
        orgs_count[pool["_id"]["org_id"], pool["_id"]["type"]] += pool["count"]

    new_users = []

    for org_id_user_type, count in orgs_count.least_common():
        org_id, user_type = org_id_user_type
        pool_size = type_to_size[user_type]

        if count >= pool_size:
            break

        org = orgs.get(org_id)
        if not org:
            logger.warning("Pooler cannot find org from user_count", "pooler", org_id=org_id, user_type=user_type)
            continue
        new_users.append([(org, user_type)] * (pool_size - count))

    for org, user_type in utils.roundrobin(*new_users):
        org.new_user(type=user_type, block=False)
Beispiel #6
0
def fill_user():
    collection = mongo.get_collection('users')
    queue_collection = mongo.get_collection('queue')

    orgs = {}
    orgs_count = utils.LeastCommonCounter()
    type_to_size = {
        CERT_CLIENT_POOL: settings.app.user_pool_size,
        CERT_SERVER_POOL: settings.app.server_user_pool_size,
    }

    for org in organization.iter_orgs(type=None):
        orgs[org.id] = org
        orgs_count[org.id, CERT_CLIENT_POOL] = 0
        orgs_count[org.id, CERT_SERVER_POOL] = 0

    pools = collection.aggregate([
        {
            '$match': {
                'type': {
                    '$in': (CERT_CLIENT_POOL, CERT_SERVER_POOL)
                },
            }
        },
        {
            '$project': {
                'org_id': True,
                'type': True,
            }
        },
        {
            '$group': {
                '_id': {
                    'org_id': '$org_id',
                    'type': '$type',
                },
                'count': {
                    '$sum': 1
                },
            }
        },
    ])

    for pool in pools:
        orgs_count[pool['_id']['org_id'], pool['_id']['type']] += pool['count']

    pools = queue_collection.aggregate([
        {
            '$match': {
                'type': 'init_user_pooled',
                'user_doc.type': {
                    '$in': (CERT_CLIENT_POOL, CERT_SERVER_POOL)
                },
            }
        },
        {
            '$project': {
                'user_doc.org_id': True,
                'user_doc.type': True,
            }
        },
        {
            '$group': {
                '_id': {
                    'org_id': '$user_doc.org_id',
                    'type': '$user_doc.type',
                },
                'count': {
                    '$sum': 1
                },
            }
        },
    ])

    for pool in pools:
        orgs_count[pool['_id']['org_id'], pool['_id']['type']] += pool['count']

    new_users = []

    for org_id_user_type, count in orgs_count.least_common():
        org_id, user_type = org_id_user_type
        pool_size = type_to_size[user_type]

        if count >= pool_size:
            break

        org = orgs.get(org_id)
        if not org:
            continue
        new_users.append([(org, user_type)] * (pool_size - count))

    for org, user_type in utils.roundrobin(*new_users):
        org.new_user(type=user_type, block=False)
Beispiel #7
0
def fill_dh_params():
    collection = mongo.get_collection('dh_params')
    queue_collection = mongo.get_collection('queue')

    dh_param_bits_pool = settings.app.dh_param_bits_pool
    if len(dh_param_bits_pool) > 1:
        dh_param_counts = utils.LeastCommonCounter(
            {x: 0 for x in dh_param_bits_pool})

        pools = collection.aggregate([
            {'$match': {
                'dh_param_bits': {'$in': dh_param_bits_pool},
            }},
            {'$project': {
                'dh_param_bits': True,
            }},
            {'$group': {
                '_id': '$dh_param_bits',
                'count': {'$sum': 1},
            }},
        ])['result']

        for pool in pools:
            dh_param_counts[pool['_id']] = pool['count']

        pools = queue_collection.aggregate([
            {'$match': {
                'type': 'dh_params',
                'dh_param_bits': {'$in': dh_param_bits_pool},
            }},
            {'$project': {
                'dh_param_bits': True,
            }},
            {'$group': {
                '_id': '$dh_param_bits',
                'count': {'$sum': 1},
            }},
        ])['result']

        for pool in pools:
            dh_param_counts[pool['_id']] += pool['count']
    else:
        dh_param_counts = utils.LeastCommonCounter()

        pool_count = collection.find({
            'dh_param_bits': dh_param_bits_pool[0],
        }, {
            '_id': True
        }).count()

        dh_param_counts[dh_param_bits_pool[0]] = pool_count

        pool_count = queue_collection.find({
            'type': 'dh_params',
            'dh_param_bits': dh_param_bits_pool[0],
        }, {
            '_id': True
        }).count()

        dh_param_counts[dh_param_bits_pool[0]] += pool_count

    new_dh_params = []

    for dh_param_bits, count in dh_param_counts.least_common():
        new_dh_params.append([dh_param_bits] * (
            settings.app.server_pool_size - count))

    for dh_param_bits in utils.roundrobin(*new_dh_params):
        que = queue.start('dh_params', dh_param_bits=dh_param_bits,
            priority=LOW)
        logger.debug('Queue dh params', 'server',
            queue_id=que.id,
            dh_param_bits=dh_param_bits,
        )
Beispiel #8
0
def fill_user():
    collection = mongo.get_collection('users')
    org_collection = mongo.get_collection('organizations')
    queue_collection = mongo.get_collection('queue')

    orgs = {}
    orgs_count = utils.LeastCommonCounter()
    type_to_size = {
        CERT_CLIENT_POOL: settings.app.user_pool_size,
        CERT_SERVER_POOL: settings.app.server_user_pool_size,
    }

    for org in organization.iter_orgs(type=None):
        orgs[org.id] = org
        orgs_count[org.id, CERT_CLIENT_POOL] = 0
        orgs_count[org.id, CERT_SERVER_POOL] = 0

    pools = collection.aggregate([
        {'$match': {
            'type': {'$in': (CERT_CLIENT_POOL, CERT_SERVER_POOL)},
        }},
        {'$project': {
            'org_id': True,
            'type': True,
        }},
        {'$group': {
            '_id': {
                'org_id': '$org_id',
                'type': '$type',
            },
            'count': {'$sum': 1},
        }},
    ])['result']

    for pool in pools:
        orgs_count[pool['_id']['org_id'], pool['_id']['type']] += pool[
            'count']

    pools = queue_collection.aggregate([
        {'$match': {
            'type': 'init_user_pooled',
            'user_doc.type': {'$in': (CERT_CLIENT_POOL, CERT_SERVER_POOL)},
        }},
        {'$project': {
            'user_doc.org_id': True,
            'user_doc.type': True,
        }},
        {'$group': {
            '_id': {
                'org_id': '$user_doc.org_id',
                'type': '$user_doc.type',
            },
            'count': {'$sum': 1},
        }},
    ])['result']

    for pool in pools:
        orgs_count[pool['_id']['org_id'], pool['_id']['type']] += pool[
            'count']

    new_users = []

    for org_id_user_type, count in orgs_count.least_common():
        org_id, user_type = org_id_user_type
        pool_size = type_to_size[user_type]

        if count >= pool_size:
            break

        org = orgs.get(org_id)
        if not org:
            logger.warning('Pooler cannot find org from user_count', 'pooler',
                org_id=org_id,
                user_type=user_type,
            )
            continue
        new_users.append([(org, user_type)] * (pool_size - count))

    for org, user_type in utils.roundrobin(*new_users):
        org.new_user(type=user_type, block=False)