def add_group(self, req, resp, user_id): user = tradius_user() user.sql_id(user_id) validate_access(req, user) attr = obj(req, tradius_user_group) attr['user_id'] = user_id attr.commit()
def rm_prefix(self, req, resp, pool_id): pool = calabiyau_pool() pool.sql_id(pool_id) validate_access(req, pool) if not req.json.get('prefix'): raise ValueError('Prefix Required') prefix = ip_network(req.json['prefix']).with_prefixlen pool_delete(pool_id, prefix)
def attrs(self, req, resp, user_id): user = tradius_user() user.sql_id(user_id) validate_access(req, user) where = {'user_id': user_id} return sql_list(req, 'tradius_user_attr', ( 'id', 'attribute', 'op', 'value', ), where=where)
def obj(req, ModelClass, sql_id=None, hide=None): if not issubclass(ModelClass, SQLModel): raise ValueError('Expecting SQL Model') model = ModelClass(hide=hide) if sql_id: model.sql_id(sql_id) validate_access(req, model) if req.method in ['POST', 'PATCH', 'PUT']: model.update(req.json) validate_set_scope(req, model) elif (req.method == 'DELETE' and issubclass(ModelClass, SQLModel) and sql_id): model.delete() return model
def rm_prefix(self, req, resp, id): pool = tradius_pool() pool.sql_id(id) validate_access(req, pool) if req.json.get('prefix'): prefix = IPNetwork(req.json['prefix']).prefix() else: prefix = None with rmq() as mb: message = { 'type': 'delete_pool', 'pool': { 'name': pool['pool_name'], 'prefix': prefix, 'domain': req.context_domain } } mb.distribute('tradius', **message)
def add_prefix(self, req, resp, id): pool = tradius_pool() pool.sql_id(id) validate_access(req, pool) prefix = IPNetwork(req.json['prefix']).prefix() if not req.json.get('prefix'): raise ValueError('Prefix Required') with rmq() as mb: message = { 'type': 'append_pool', 'pool': { 'name': pool['pool_name'], 'prefix': prefix, 'domain': req.context_domain } } mb.distribute('tradius', **message)
def rm_attr(self, req, resp, user_id, group_id): user = tradius_user() user.sql_id(user_id) validate_access(req, user) attr = obj(req, tradius_user_attr, sql_id=group_id) attr.commit()
def groups(self, req, resp, user_id): user = tradius_user() user.sql_id(user_id) validate_access(req, user) user_groups = get_user_groups(user_id) return raw_list(req, user_groups, sql=False)