Skip to content

Commit

Permalink
Merge pull request #9 from CiscoSecurity/release-1.0.2
Browse files Browse the repository at this point in the history
Release 1.0.2
  • Loading branch information
mstoro authored Apr 7, 2022
2 parents 01a1efd + 14cafdd commit 712784e
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 14 deletions.
6 changes: 0 additions & 6 deletions code/api/enrich.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
get_observables = partial(get_json, schema=ObservableSchema(many=True))


@enrich_api.route('/deliberate/observables', methods=['POST'])
def deliberate_observables():
# Not implemented
return jsonify_data({})


@enrich_api.route('/observe/observables', methods=['POST'])
def observe_observables():
def query_qradar(obs):
Expand Down
5 changes: 4 additions & 1 deletion code/api/rest_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
QRadarUnexpectedError,
AuthorizationError,
)
from .utils import handle_connection_error
from .utils import handle_connection_error, handle_auth_errors


class RestApiClient:
Expand Down Expand Up @@ -35,6 +35,7 @@ def _get_response_data(response):
raise QRadarUnexpectedError(response)

@handle_connection_error
@handle_auth_errors
def _get(self, endpoint, headers=None, params=None):
response = requests.get(
f'https://{self.server_ip}{self.base_uri}{endpoint}',
Expand All @@ -43,13 +44,15 @@ def _get(self, endpoint, headers=None, params=None):
return self._get_response_data(response)

@handle_connection_error
@handle_auth_errors
def _post(self, endpoint, data=None):
response = requests.post(
f'https://{self.server_ip}{self.base_uri}{endpoint}',
data, headers=self.headers, verify=False, auth=self.credentials)
return self._get_response_data(response)

@handle_connection_error
@handle_auth_errors
def _delete(self, endpoint, headers):
response = requests.delete(
f'https://{self.server_ip}{self.base_uri}{endpoint}',
Expand Down
10 changes: 10 additions & 0 deletions code/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,13 @@ def filter_observables(relay_input):
observables.append(value)

return observables


def handle_auth_errors(func):
def wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except UnicodeEncodeError:
raise AuthorizationError()

return wrapper
8 changes: 6 additions & 2 deletions code/app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import traceback

from flask import Flask, jsonify, g

from api.enrich import enrich_api
Expand All @@ -23,21 +25,23 @@

@app.errorhandler(Exception)
def handle_error(exception):
app.logger.error(exception)
code = getattr(exception, 'code', 500)
message = getattr(exception, 'description', 'Something went wrong.')
reason = '.'.join([
exception.__class__.__module__,
exception.__class__.__name__,
])

if code != 404:
app.logger.error(traceback.format_exc())

response = jsonify(code=code, message=message, reason=reason)
return response, code


@app.errorhandler(CTRBaseError)
def handle_tr_formatted_error(error):
app.logger.error(error.json)
app.logger.error(traceback.format_exc())
g.errors = [error.json]
return jsonify_result()

Expand Down
2 changes: 1 addition & 1 deletion code/container_settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"VERSION": "1.0.1",
"VERSION": "1.0.2",
"NAME": "QRadar"
}
1 change: 0 additions & 1 deletion code/tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def calls():
yield Call('DELETE', '/delete', HTTPStatus.NOT_FOUND)

yield Call('GET', '/health', HTTPStatus.METHOD_NOT_ALLOWED)
yield Call('GET', '/deliberate/observables', HTTPStatus.METHOD_NOT_ALLOWED)
yield Call('GET', '/observe/observables', HTTPStatus.METHOD_NOT_ALLOWED)
yield Call('GET', '/refer/observables', HTTPStatus.METHOD_NOT_ALLOWED)
yield Call('GET', '/respond/observables', HTTPStatus.METHOD_NOT_ALLOWED)
Expand Down
7 changes: 4 additions & 3 deletions module_type.json.sample

Large diffs are not rendered by default.

0 comments on commit 712784e

Please sign in to comment.