fix: Fixed pep8 + some copy paste issues introduced with the latest commits

pull/420/head
chrisr3d 2020-07-28 15:06:25 +02:00
parent 3ab67b23b6
commit d2661c7a20
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
5 changed files with 8 additions and 5 deletions

View File

@ -26,5 +26,6 @@ minimum_required_fields = ('type', 'uuid', 'value')
checking_error = 'containing at least a "type" field and a "value" field' checking_error = 'containing at least a "type" field and a "value" field'
standard_error_message = 'This module requires an "attribute" field as input' standard_error_message = 'This module requires an "attribute" field as input'
def check_input_attribute(attribute, requirements=minimum_required_fields): def check_input_attribute(attribute, requirements=minimum_required_fields):
return all(feature in attribute for feature in requirements) return all(feature in attribute for feature in requirements)

View File

@ -111,6 +111,7 @@ def handler(q=False):
request = json.loads(q) request = json.loads(q)
if not request.get('attribute') or not check_input_attribute(request['attribute']): if not request.get('attribute') or not check_input_attribute(request['attribute']):
return {'error': f'{standard_error_message}, which should contain at least a type, a value and an uuid.'} return {'error': f'{standard_error_message}, which should contain at least a type, a value and an uuid.'}
attribute = request['attribute']
if attribute.get('type') != 'vulnerability': if attribute.get('type') != 'vulnerability':
misperrors['error'] = 'Vulnerability id missing.' misperrors['error'] = 'Vulnerability id missing.'
return misperrors return misperrors

View File

@ -149,6 +149,7 @@ def handler(q=False):
if not request.get('attribute') or not check_input_attribute(request['attribute']): if not request.get('attribute') or not check_input_attribute(request['attribute']):
return {'error': f'{standard_error_message}, which should contain at least a type, a value and an uuid.'} return {'error': f'{standard_error_message}, which should contain at least a type, a value and an uuid.'}
attribute = request['attribute']
if not any(input_type == attribute['type'] for input_type in mispattributes['input']): if not any(input_type == attribute['type'] for input_type in mispattributes['input']):
return {'error': 'Unsupported attribute type.'} return {'error': 'Unsupported attribute type.'}

View File

@ -29,7 +29,7 @@ def handler(q=False):
q = json.loads(q) q = json.loads(q)
if "config" not in q or "api-key" not in q["config"]: if "config" not in q or "api-key" not in q["config"]:
return {"error": "Ransomcoindb API key is missing"} return {"error": "Ransomcoindb API key is missing"}
if not q.get('attribute') or not check_input_attribute(attribute, requirements=('type', 'value')): if not q.get('attribute') or not check_input_attribute(q['attribute'], requirements=('type', 'value')):
return {'error': f'{standard_error_message}, {checking_error}.'} return {'error': f'{standard_error_message}, {checking_error}.'}
if q['attribute']['type'] not in mispattributes['input']: if q['attribute']['type'] not in mispattributes['input']:
return {'error': 'Unsupported attribute type.'} return {'error': 'Unsupported attribute type.'}

View File

@ -1,8 +1,8 @@
from. import check_input_attribute, checking_error, standard_error_message
from pymisp import MISPEvent, MISPObject
import json import json
import requests import requests
import base64 import base64
from. import check_input_attribute, checking_error, standard_error_message
from pymisp import MISPEvent, MISPObject
from urllib.parse import quote from urllib.parse import quote
moduleinfo = {'version': '1.0', moduleinfo = {'version': '1.0',
@ -107,9 +107,9 @@ def handler(q=False):
It's free to sign up here https://aws.amazon.com/marketplace/pp/B07SLZPMCS." It's free to sign up here https://aws.amazon.com/marketplace/pp/B07SLZPMCS."
return misperrors return misperrors
to_check = (('type', 'value'), ('type', 'value1')) to_check = (('type', 'value'), ('type', 'value1'))
if not request.get('attribute') or not any(check_input_attribute(request['attribute'], requirements=check) for check in to_check): if not j.get('attribute') or not any(check_input_attribute(j['attribute'], requirements=check) for check in to_check):
return {'error': f'{standard_error_message}, {checking_error}.'} return {'error': f'{standard_error_message}, {checking_error}.'}
attribute = request['attribute'] attribute = j['attribute']
if attribute['type'] not in misp_types_in: if attribute['type'] not in misp_types_in:
return {'error': 'Unsupported attribute type.'} return {'error': 'Unsupported attribute type.'}
client = SophosLabsApi(j['config']['client_id'], j['config']['client_secret']) client = SophosLabsApi(j['config']['client_id'], j['config']['client_secret'])