def update_for_group(group, since): """ Returns all items updated past a specific date in utc. :Parameters: - `since`: a specific date in utc - `group`: group to limit items to """ try: items = Hash.objects( date__gt=datetime.datetime.strptime(since, "%Y-%m-%dT%H:%M:%S"), group=group ) fields = None if request.args.get('fields', None): fields = [] for field in request.args.get( 'fields').replace(' ', '').split(','): inmodel = Hash.fieldname(field) if inmodel: fields.append(inmodel) items = items.only(*fields) return stream_items(items, fields) except Exception as e: current_app.logger.debug(e) return error()
def update(group, since): """ Returns all items updated past a specific date in utc. :Parameters: - `since`: a specific date in utc - `group`: group to limit items to """ try: items = Hash.objects( date__gt=datetime.datetime.strptime(since, "%Y-%m-%dT%H:%M:%S"), group=group ) fields = API_UPDATES_DEFAULT_FIELDS fields_arg = request.args.get('fields', None) if fields_arg is not None: fields = [ Hash.modelname(field) for field in fields_arg.replace(' ', '').split(',') ] items = items.only(*fields) return stream_items(items, fields) except Exception as e: current_app.logger.debug(e) return error()
def hashes(format=None): hashes = Hash.objects(status='RELEASED') group = request.args.get('group', 'all') if group != 'all': if format not in Hash.objects.distinct('group'): flash('Group of hashes not found', 'error') else: hashes = hashes.filter(group=group) return render_template('hashes.html', hashes=hashes)
def update(revision): try: revision = int(revision) result = [] for item in Hash.objects(_v1__db_version__gte=int(revision)): newitem = {} newitem['name'] = item['name'] newitem['vendor'] = item['vendor'] newitem['status'] = 'In Database' newitem['format'] = item['format'].upper() newitem['version'] = item['version'] newitem['submitter'] = item['submitter'] newitem['hash'] = item['hashes']['sha512']['combined'] newitem['db_version'] = int(item['_v1']['db_version']) newitem['cves'] = ','.join(item.cve_list()) newitem['submitter'] = str(item['submitter']) result.append({'fields': newitem}) return make_response(json.dumps(result)) except: return error()
def update_front_page_stats(): stats = {} stats['hashes'] = Hash.objects(status='RELEASED').only('group') stats['submitted'] = Submission.objects( approval='REQUESTED').only('group') stats['pending'] = Submission.objects( approval='PENDING_APPROVAL').only('group') # Generate counts for objects and for each format # data will contain hashes, hashes_jars, hashes_eggs etc. groups = SUBMISSION_GROUPS.keys() groups.sort() data = {'groups': groups, 'stats': {}} for group in groups: stat = {} for key in stats: if group == 'all': stat[key] = len(stats[key]) else: stat[key] = len(stats[key].filter(group=group)) data['stats'][group] = stat _CONFIG.front_page_stats = data
def hashes(groups): hashes = Hash.objects( status='RELEASED', group__in=groups ).only('name', 'version', 'hashes.sha512.combined') return render_template('hashes.html', hashes=hashes)
def getInfoFromDb(rowId): return Hash.objects(id=rowId).first()