<commit_before>from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.utils import simplejson
from django.views.decorators.csrf import csrf_exempt
from functools import wraps
from zumanji.forms import UploadJsonForm
from zumanji.helpers import get_trace_data, get_changes
from zumanji.models import Project, Build, BuildTag, Test
from zumanji.importer import import_build


NOTSET = object()


def api_auth(func):
    @wraps(func)
    def wrapped(request, *args, **kwargs):
        if request.GET.get('api_key') == settings.ZUMANJI_CONFIG.get('API_KEY', NOTSET):
            return csrf_exempt(func)(request, *args, **kwargs)
        return func(request, *args, **kwargs)<commit_msg>Return a forbidden response when api_key is set but invalid, and support non-GET values of api_key<commit_after>from django.conf import settings
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect, HttpResponseForbidden
from django.shortcuts import render, get_object_or_404
from django.utils import simplejson
from django.views.decorators.csrf import csrf_exempt
from functools import wraps
from zumanji.forms import UploadJsonForm
from zumanji.helpers import get_trace_data, get_changes
from zumanji.models import Project, Build, BuildTag, Test
from zumanji.importer import import_build


NOTSET = object()


def api_auth(func):
    @wraps(func)
    def wrapped(request, *args, **kwargs):
        if request.REQUEST.get('api_key'):
            if request.REQUEST['api_key'] != settings.ZUMANJI_CONFIG.get('API_KEY', NOTSET):
                return HttpResponseForbidden('Invalid api_key')
            return csrf_exempt(func)(request, *args, **kwargs)
        return func(request, *args, **kwargs)
{'fraction_non_alphanumeric': 0.08247978436657682, 'fraction_numerical': 0.003234501347708895, 'mean_word_length': 5.025974025974026, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2841585', 'n_tokens_mistral': 550, 'n_tokens_neox': 544, 'n_words': 160}