<commit_before>from django.core.urlresolvers import reverse
from tastypie import authorization
from tastypie.authentication import MultiAuthentication

from crits.backdoors.backdoor import Backdoor
from crits.backdoors.handlers import add_new_backdoor
from crits.core.api import CRITsApiKeyAuthentication, CRITsSessionAuthentication
from crits.core.api import CRITsSerializer, CRITsAPIResource


class BackdoorResource(CRITsAPIResource):
    """
    Class to handle everything related to the Backdoor API.

    Currently supports GET and POST.
    """

    class Meta:
        object_class = Backdoor
        allowed_methods = ('get', 'post', 'patch')
        resource_name = "backdoors"
        authentication = MultiAuthentication(CRITsApiKeyAuthentication(),
                                             CRITsSessionAuthentication())
        authorization = authorization.Authorization()
        serializer = CRITsSerializer()

    def get_object_list(self, request):
        """
        Use the CRITsAPIResource to get our objects but provide the class to get
        the objects from.

        :param request: The incoming request.
        :type request: :class:`django.http.HttpRequest`
        :returns: Resulting objects in the specified format (JSON by default).

        """

        return super(BackdoorResource, self).get_object_list(request, Backdoor)

    def obj_create(self, bundle, **kwargs):
        """
        Handles creating Backdoors through the API.

        :param bundle: Bundle containing the information to create the Backdoor.
        :type bundle: Tastypie Bundle object.
        :returns: HttpResponse object.
        """

        analyst = bundle.request.user.username
        data = bundle.data
        name = data.get('name', None)
        version = data.get('aliases', '')
        aliases = data.get('aliases', '')
        description = data.get('description', None)
        source = data.get('source', None)
        reference = data.get('reference', None)
        method = data.get('method', None)
        campaign = data.get('campaign', None)
        confidence = data.get('confidence', None)
        bucket_list = data.get('bucket_list', None)
        ticket = data.get('ticket', None)

        result = add_new_backdoor(name,
                                  version,
                                  aliases,
                                  description=description,
                                  source=source,
                                  source_method=method,
                                  source_reference=reference,
                                  campaign=campaign,
                                  confidence=confidence,
                                  analyst=analyst,
                                  bucket_list=bucket_list,
                                  ticket=ticket)

        content = {'return_code': 0,
                   'type': 'Backdoor',
                   'message': result.get('message', ''),
                   'id': result.get('id', '')}<commit_msg>Fix copy/paste mistake.<commit_after>from django.core.urlresolvers import reverse
from tastypie import authorization
from tastypie.authentication import MultiAuthentication

from crits.backdoors.backdoor import Backdoor
from crits.backdoors.handlers import add_new_backdoor
from crits.core.api import CRITsApiKeyAuthentication, CRITsSessionAuthentication
from crits.core.api import CRITsSerializer, CRITsAPIResource


class BackdoorResource(CRITsAPIResource):
    """
    Class to handle everything related to the Backdoor API.

    Currently supports GET and POST.
    """

    class Meta:
        object_class = Backdoor
        allowed_methods = ('get', 'post', 'patch')
        resource_name = "backdoors"
        authentication = MultiAuthentication(CRITsApiKeyAuthentication(),
                                             CRITsSessionAuthentication())
        authorization = authorization.Authorization()
        serializer = CRITsSerializer()

    def get_object_list(self, request):
        """
        Use the CRITsAPIResource to get our objects but provide the class to get
        the objects from.

        :param request: The incoming request.
        :type request: :class:`django.http.HttpRequest`
        :returns: Resulting objects in the specified format (JSON by default).

        """

        return super(BackdoorResource, self).get_object_list(request, Backdoor)

    def obj_create(self, bundle, **kwargs):
        """
        Handles creating Backdoors through the API.

        :param bundle: Bundle containing the information to create the Backdoor.
        :type bundle: Tastypie Bundle object.
        :returns: HttpResponse object.
        """

        analyst = bundle.request.user.username
        data = bundle.data
        name = data.get('name', None)
        version = data.get('version', '')
        aliases = data.get('aliases', '')
        description = data.get('description', None)
        source = data.get('source', None)
        reference = data.get('reference', None)
        method = data.get('method', None)
        campaign = data.get('campaign', None)
        confidence = data.get('confidence', None)
        bucket_list = data.get('bucket_list', None)
        ticket = data.get('ticket', None)

        result = add_new_backdoor(name,
                                  version,
                                  aliases,
                                  description=description,
                                  source=source,
                                  source_method=method,
                                  source_reference=reference,
                                  campaign=campaign,
                                  confidence=confidence,
                                  analyst=analyst,
                                  bucket_list=bucket_list,
                                  ticket=ticket)

        content = {'return_code': 0,
                   'type': 'Backdoor',
                   'message': result.get('message', ''),
                   'id': result.get('id', '')}
{'fraction_non_alphanumeric': 0.08607095926412615, 'fraction_numerical': 0.000328515111695138, 'mean_word_length': 1.8708156529938709, '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': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3587664', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1413, 'n_words': 380}