Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bundle ping response and api call #207

Merged
merged 4 commits into from Nov 19, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -42,7 +42,16 @@ def match(self, pattern, observed_data_sdos, verbose=False):
return matching_sdos

def ping(self):
return {"success": True}
return_obj = dict()

response = self.call_api('head')
response_code = response.status_code

if response_code == 200 or response_code == 301:
return_obj['success'] = True
else:
ErrorResponder.fill_error(return_obj, ['message'])
mdazam1942 marked this conversation as resolved.
Show resolved Hide resolved
return return_obj

def create_query_connection(self, query):
return {"success": True, "search_id": query}
Expand All @@ -55,13 +64,7 @@ def create_results_connection(self, search_id, offset, length):
observations = []
return_obj = dict()

bundle_url = self.connection.get('host')
auth = self.configuration.get('auth')

if auth is not None:
response = requests.get(bundle_url, auth=(auth.get('username'), auth.get('password')))
else:
response = requests.get(bundle_url)
response = self.call_api('get')

response_code = response.status_code

Expand Down Expand Up @@ -103,3 +106,21 @@ def delete_query_connection(self, search_id):
return_obj = dict()
return_obj['success'] = True
return return_obj

def call_api(self, method):
call = getattr(requests, method.lower())

bundle_url = self.connection.get('host')
auth = self.configuration.get('auth')

if auth is not None:
username = auth.get('username')
password = auth.get('password')
if username is not None or password is not None:
response = call(bundle_url, auth=(auth.get('username'), auth.get('password')))
else:
response = call(bundle_url)
else:
response = call(bundle_url)

return response