Пример #1
0
def clean_api_key(key_id):
    """Cleans an api key."""
    key_id = str(key_id)
    tmp = red.hgetall(_KEY_APIK.format(key_id))
    red.delete(_KEY_BUOYACTION.format(key_id))
    red.delete(_KEY_UUID_APIK.format(tmp['key']))
    pip = red.pipeline()
    pip.hset(_KEY_APIK.format(key_id), _ATTR_APIK_KEY, '')
    pip.hset(_KEY_APIK.format(key_id), _ATTR_APIK_GENERATED, '')
    pip.hset(_KEY_APIK.format(key_id), _ATTR_APIK_STATUS, const.BUOY_NOTDEP)
    pip.execute()
Пример #2
0
def _delete_api_key(user_id, apik_id):
    """Deletes an api key."""
    user_id = str(user_id)
    apik_id = str(apik_id)
    # Delete uuid to key
    tmp = red.hgetall(_KEY_APIK.format(apik_id))
    red.delete(_KEY_UUID_APIK.format(tmp['key']))
    pip = red.pipeline()
    if pip.scard(_KEY_APIKS_USER.format(user_id)) == 1:
        pip.delete(_KEY_APIKS_USER.format(user_id))
    else:
        pip.srem(_KEY_APIKS_USER.format(user_id), apik_id)
    pip.delete(_KEY_APIK.format(apik_id))
    pip.execute()
    # delete also the orders a buoy must perform
    red.delete(_KEY_BUOYACTION.format(apik_id))
Пример #3
0
def delete_host(user_id, host_id):
    """Deletes a host"""
    user_id = str(user_id)
    host_id = str(host_id)
    pip = red.pipeline()
    pip.srem(_KEY_USER_HOSTS.format(user_id), host_id)
    pip.delete(_KEY_HOST.format(host_id))
    servs = red.smembers(_KEY_HOST_SET_SERVS.format(host_id))
    for serv in servs:
        if red.scard(_KEY_SERVNAME_HOSTS.format(serv)) == 1:
            pip.delete(_KEY_SERVNAME_HOSTS.format(serv))
            pip.srem(_KEY_SERVS, serv)
        else:
            pip.srem(_KEY_SERVNAME_HOSTS.format(serv), host_id)
    red.delete(_KEY_HOST_SET_SERVS.format(host_id))
    pip.execute()
Пример #4
0
def delete_entry(user_id, entry_id):
    """Deletes an entry."""
    user_id = str(user_id)
    entry_id = str(entry_id)
    auth = entry_id in red.smembers(_KEY_ENTRY_BLACK_USER.format(user_id))
    if not auth:
        auth = entry_id in red.smembers(_KEY_ENTRY_WHITE_USER.format(user_id))
    if auth:
        temp_ent = get_entry(entry_id)
        if temp_ent['type'] == 'B':
            red.srem(_KEY_ENTRY_BLACK_USER.format(user_id), entry_id)
        else:
            red.srem(_KEY_ENTRY_WHITE_USER.format(user_id), entry_id)
        red.delete(_KEY_ENTRY.format(entry_id))
        for net in red.smembers(_KEY_ENTRY_SET_NETS.format(entry_id)):
            red.srem(_KEY_NET_SET_ENTRIES.format(net), entry_id)
        red.delete(_KEY_ENTRY_SET_NETS.format(entry_id))
Пример #5
0
    async def delete_group(cls, name: str):
        """
        Delete a group
        :param name:    Name of group
        :return:
        """
        try:
            # Delete from db
            if name:
                if group := await Group.get_or_none(name=name).only('id'):
                    await group.delete()

                    # Update cache
                    partialkey = s.CACHE_GROUPNAME.format(name)
                    red.delete(partialkey)
                    if groups := red.get('groups'):
                        groups = list(filter(lambda y: y != name, groups))
                    else:
                        groups = await Group.all().values_list('name',
                                                               flat=True)
                    red.set('groups', groups, clear=True)
                    return True
Пример #6
0
 def tearDown(self):
     red.delete(self.game_id)
Пример #7
0
def test_get_permissions(tempdb, loop, groups, perms, remove, src):
    async def ab():
        await tempdb()
        return await Group.get_permissions(*listify(groups), debug=True)

    groups = listify(groups)
    for idx, group in enumerate(groups):
        partialkey = s.CACHE_GROUPNAME.format(group)
        remove = listify(remove)
        if remove[idx]:
            red.delete(partialkey)
            assert not red.get(partialkey)
            assert not red.exists(partialkey)

    loop.run_until_complete(ab())
    # ic(x)
    # allperms, sources = loop.run_until_complete(ab())
    # assert Counter(allperms) == Counter(perms)
    # assert Counter(sources) == Counter(listify(src))


















# param = [
#     ('user.create', 'AdminGroup', True),
#     ('user.create', 'NoaddGroup', True),
#     ('page.create', 'ContentGroup', True),
#     ('page.create', 'NoaddGroup', False),
#     ('page.create', 'abc', False),
#     ('', 'abc', False),
#     ('page.create', '', False),
# ]
# @pytest.mark.parametrize('perm, group, out', param)
# @pytest.mark.focus
# def test_is_group(loop, perm, group, out):
#     async def ab():
#         assert await Permission.is_group(perm, group) == out
#     loop.run_until_complete(ab())


# # @pytest.mark.focus
# def test_abc(loop, tempdb):
#     from app.authentication import Option
#
#     async def ab():
#         await tempdb()
#         await Option.create(name='foo', value='bar')
#         opt = await Option.all()
#         ic(opt)
#
#     loop.run_until_complete(ab())
Пример #8
0
 def tearDown(self):
     red.delete(self.game_id)