def get(self): if not signed_request(request.args, request.form) or not registered(): abort(403) # determine how well the load is balanced. # are there any unassigned feeds? unassigned = [ x for x in feeds.find({'cat':'unassigned'}) ] app.logger.debug('%s' % unassigned) if not unassigned: return '' abort(401)
def post(self): if signed_request(request.args, request.form): name = request.form.get('name') pid = request.form.get('pid') addr = request.form.get('addr') if name and pid and addr: if register(name, pid, addr): return '' abort(403)
def add_feed_to_master_list(feed): candidates = [ x for x in feeds.find({'xml_url':feed['xml_url']})] if len(candidates) == 0: #add a new thing feed['subscribers'] = 1 feed['new'] = True gfid = feeds.insert(feed) elif len(candidates) == 1: gfid = candidates[0]['id'] #increment else: abort(406) #need a better code here return gfid
def register(name, pid, addr): # make sure we're not already registered. if fetchers.find_one({'name':name}): app.log.warning('fetcher %s already registered' % name) abort(403) #maybe different code? # we should also require that this is coming from the local subnet addr = addr.strip('http:/') if addr.find(':') != -1: addr = addr.split(':')[0] print request.remote_addr, addr if request.remote_addr != addr: abort(403) fetchers.insert({'name':name, 'pid':pid, 'addr':addr}) return True
def post(self, username, feed_id = None): user = self.user_validate(username) # got a new feed to add, validate title = request.form.get('title') alias = request.form.get('alias') xml_url = request.form.get('xml_url') http_url = request.form.get('http_url') feed_type = request.form.get('feed_type') if not xml_url: abort(400) # it's OK that some of these are None or blank, feedparser # will fix it up for us in the background. new_feed = {'title':title, 'alias':alias, 'xml_url':xml_url, 'http_url':http_url, 'feed_type':feed_type} global_feed_id = add_feed_to_master_list(new_feed) if not global_feed_id: abort(500) #need to explain this in the docs user_feed_id = add_feed_to_user(user, global_feed_id) # return the resource return '%s' % user_feed_id, 201
def delete(self, username, feed_id = None): user = self.user_validate(username) if not feed_id: abort(400) uf = user.get('feeds') if not uf: abort(404) removed = False for i, feed in enumerate(uf): if feed['feed_id'] == int(feed_id): del uf[i] removed = True if not removed: abort(404) users.save(user) return ''
def user_validate(self, username): user = users.find_one({'username':username}) if session.get('username') != username or not user: abort(401) return user
def get(self): if signed_request(request.args, request.form) and \ registered(): return '' else: abort(401)