From 28d90bc160a4d4b43e91c1a3b40ec4d040a71093 Mon Sep 17 00:00:00 2001 From: mstoro <78480384+mstoro@users.noreply.github.com> Date: Tue, 7 Dec 2021 16:35:50 +0200 Subject: [PATCH 1/2] [CCTRI-3430] handle error caused by cyrillic symbol or space in 'key' (#52) * [CCTRI-3430] handle error caused by cyrillic symbol or space in 'key' * [CCTRI-3413] add traceback to log file --- code/api/client.py | 11 +++++++---- code/app.py | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/code/api/client.py b/code/api/client.py index 042f7b8..b0ca2b3 100644 --- a/code/api/client.py +++ b/code/api/client.py @@ -2,7 +2,7 @@ from ssl import SSLCertVerificationError import requests -from requests.exceptions import SSLError +from requests.exceptions import SSLError, InvalidHeader from api.errors import ( SSLCertificateVerificationFailedError, @@ -11,6 +11,9 @@ ) +AUTHORIZATION_FAILED = "Authorization failed on AlienVault OTX side" + + class Client: def __init__(self, key, url, headers=None, params=None): @@ -38,14 +41,14 @@ def query(self, endpoint, headers=None, params=None): getattr(error, 'verify_message', error.args[0]).capitalize() ) raise SSLCertificateVerificationFailedError(reason=reason) + except (InvalidHeader, UnicodeEncodeError): + raise AuthenticationRequiredError(reason=AUTHORIZATION_FAILED) if response.status_code == HTTPStatus.BAD_REQUEST: return None if response.status_code == HTTPStatus.FORBIDDEN: - raise AuthenticationRequiredError( - reason="Authorization failed on AlienVault OTX side" - ) + raise AuthenticationRequiredError(reason=AUTHORIZATION_FAILED) if response.status_code == HTTPStatus.NOT_FOUND: return None diff --git a/code/app.py b/code/app.py index c159dea..1ffa8ef 100644 --- a/code/app.py +++ b/code/app.py @@ -1,10 +1,11 @@ +import traceback + from flask import Flask, jsonify from api.enrich import enrich_api from api.health import health_api from api.version import version_api from api.watchdog import watchdog_api - from api.errors import RelayError from api.utils import jsonify_errors @@ -21,13 +22,13 @@ @app.errorhandler(RelayError) def handle_relay_error(error): - app.logger.error(error.json()) + app.logger.error(traceback.format_exc()) return jsonify_errors(error) @app.errorhandler(Exception) def handle_error(exception): - app.logger.error(exception) + app.logger.error(traceback.format_exc()) code = getattr(exception, 'code', 500) message = getattr(exception, 'description', 'Something went wrong.') reason = '.'.join([ From e2a9e58066b9dedcf096e33c63e1685ae1c400fe Mon Sep 17 00:00:00 2001 From: mstoro Date: Thu, 16 Dec 2021 11:42:11 +0200 Subject: [PATCH 2/2] Release 2.0.4 --- code/container_settings.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/container_settings.json b/code/container_settings.json index c889bdc..fe111cc 100644 --- a/code/container_settings.json +++ b/code/container_settings.json @@ -1,4 +1,4 @@ { - "VERSION": "2.0.3", + "VERSION": "2.0.4", "NAME": "AlienVault OTX" }