Beispiel #1
0
def dotransform(request, response, config):

    try:
        url = request.fields['url']
    except KeyError:
        url = request.value

    try:
        indicators = search_indicator(url)
    except ThreatCentralError as err:
        response += UIMessage(err.value, type='PartialError')
    else:
        try:
            for indicator in indicators:
                if indicator.get('tcScore'):
                    weight = int(indicator.get('tcScore'))
                else:
                    weight = 1
                indicator = indicator.get('resource')
                e = Indicator(encode_to_utf8(indicator.get('title')),
                              weight=weight)
                e.title = encode_to_utf8(indicator.get('title'))
                # e.resourceId = indicator.get('resourceId')
                e.resourceId = indicator.get('resourceId')

                if indicator.get('severity'):
                    e += Label(
                        'Severity',
                        indicator.get('severity', dict()).get('displayName'))
                    e.severity = indicator.get('severity',
                                               dict()).get('displayName')
                if indicator.get('confidence'):
                    e += Label(
                        'Confidence',
                        indicator.get('confidence', dict()).get('displayName'))
                    e.confidence = indicator.get('confidence',
                                                 dict()).get('displayName')
                if indicator.get('indicatorType'):
                    e += Label(
                        'Indicator Type',
                        indicator.get('indicatorType',
                                      dict()).get('displayName'))
                    e.indicatorType = indicator.get('indicatorType',
                                                    dict()).get('displayName')
                if indicator.get('description'):
                    e += Label(
                        'Description', '<br/>'.join(
                            encode_to_utf8(
                                indicator.get('description')).split('\n')))

                response += e

        except AttributeError as err:
            response += UIMessage('Error: {}'.format(err), type='PartialError')
        except ThreatCentralError as err:
            response += UIMessage(err.value, type='PartialError')
        except TypeError:
            return response

    return response
def dotransform(request, response, config):

    try:
        url = request.fields['url']
    except KeyError:
        url = request.value

    try:
        indicators = search_indicator(url)
    except ThreatCentralError as err:
        response += UIMessage(err.value, type='PartialError')
    else:
        try:
            for indicator in indicators:
                if indicator.get('tcScore'):
                    weight = int(indicator.get('tcScore'))
                else:
                    weight = 1
                indicator = indicator.get('resource')
                e = Indicator(encode_to_utf8(indicator.get('title')), weight=weight)
                e.title = encode_to_utf8(indicator.get('title'))
                # e.resourceId = indicator.get('resourceId')
                e.resourceId = indicator.get('resourceId')

                if indicator.get('severity'):
                    e += Label('Severity', indicator.get('severity', dict()).get('displayName'))
                    e.severity = indicator.get('severity', dict()).get('displayName')
                if indicator.get('confidence'):
                    e += Label('Confidence', indicator.get('confidence', dict()).get('displayName'))
                    e.confidence = indicator.get('confidence', dict()).get('displayName')
                if indicator.get('indicatorType'):
                    e += Label('Indicator Type', indicator.get('indicatorType', dict()).get('displayName'))
                    e.indicatorType = indicator.get('indicatorType', dict()).get('displayName')
                if indicator.get('description'):
                    e += Label('Description', '<br/>'.join(encode_to_utf8(indicator.get('description')
                                                                          ).split('\n')))

                response += e

        except AttributeError as err:
            response += UIMessage('Error: {}'.format(err), type='PartialError')
        except ThreatCentralError as err:
            response += UIMessage(err.value, type='PartialError')
        except TypeError:
            return response

    return response