fix: [expansion] Better config field handling for various modules

- Testing if config is present before trying to
  look whithin the config field
- The config field should be there when the module
  is called form MISP, but it is not always the
  case when the module is queried from somewhere else
new_module
chrisr3d 2019-10-30 09:09:55 +01:00
parent dc7463a67e
commit d0ddfb3355
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
4 changed files with 6 additions and 8 deletions

View File

@ -16,10 +16,9 @@ def handler(q=False):
if q is False:
return False
request = json.loads(q)
if (request.get('config')):
if (request['config'].get('apikey') is None):
misperrors['error'] = 'Farsight DNSDB apikey is missing'
return misperrors
if not request.get('config') or not request['config'].get('apikey'):
misperrors['error'] = 'Farsight DNSDB apikey is missing'
return misperrors
client = DnsdbClient(server, request['config']['apikey'])
if request.get('hostname'):
res = lookup_name(client, request['hostname'])

View File

@ -31,9 +31,8 @@ def handler(q=False):
else:
return False
if request['config'].get('api_key'):
if request.get('config') and request['config'].get('api_key'):
api_key = request['config'].get('api_key')
else:
misperrors['error'] = 'Authorization required'
return misperrors

View File

@ -24,7 +24,7 @@ def handler(q=False):
request = json.loads(q)
if not request.get('config') and not (request['config'].get('apikey')):
if not request.get('config') or not request['config'].get('apikey'):
misperrors['error'] = 'Onyphe authentication is missing'
return misperrors

View File

@ -25,7 +25,7 @@ def handler(q=False):
request = json.loads(q)
if not request.get('config') and not (request['config'].get('apikey')):
if not request.get('config') or not request['config'].get('apikey'):
misperrors['error'] = 'Onyphe authentication is missing'
return misperrors