don't expose exception info on http response

Change-Id: Ibd38f68895489b4da49477f7306e3019b406f288
Closes-Bug: #1776635
Depends-On: Ide6906ee477aa7df9ab0918d3b45a7001afdcf74
This commit is contained in:
Eyal 2018-06-14 11:20:46 +03:00 committed by Ifat Afek
parent 43c29716ee
commit 6484eb0f9f
8 changed files with 60 additions and 76 deletions

View File

@ -18,7 +18,6 @@ import pecan
from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string
from osprofiler import profiler
from pecan.core import abort
@ -33,6 +32,7 @@ from vitrage.common.constants import VertexProperties as Vprops
LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("alarm controller",
info={}, hide_args=False, trace_private=False)
class AlarmsController(RootRestController):
@ -54,10 +54,9 @@ class AlarmsController(RootRestController):
try:
return self._get_alarms(vitrage_id, all_tenants)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to get alarms.')
abort(404, to_unicode)
abort(404, 'Failed to get alarms.')
@staticmethod
def _get_alarms(vitrage_id=None, all_tenants=False):
@ -71,10 +70,9 @@ class AlarmsController(RootRestController):
alarms_list = json.loads(alarms_json)['alarms']
return alarms_list
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to open file.')
abort(404, to_unicode)
abort(404, 'Failed to get alarms')
@pecan.expose('json')
def get(self, vitrage_id):
@ -87,10 +85,9 @@ class AlarmsController(RootRestController):
try:
return self._show_alarm(vitrage_id)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to load JSON.')
abort(404, to_unicode)
abort(404, "Failed to show alarm.")
@staticmethod
def _show_alarm(vitrage_id):
@ -103,7 +100,6 @@ class AlarmsController(RootRestController):
alarms_list = json.loads(alarm_json)
return alarms_list
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to load JSON.')
abort(404, to_unicode)
abort(404, 'Failed to show alarm.')

View File

@ -14,7 +14,6 @@ import json
import pecan
from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string
from pecan.core import abort
@ -25,6 +24,7 @@ from vitrage.api.policy import enforce
LOG = log.getLogger(__name__)
# noinspection PyBroadException
class CountsController(RootRestController):
@pecan.expose('json')
@ -50,7 +50,6 @@ class CountsController(RootRestController):
return json.loads(alarm_counts_json)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('failed to get alarm count.')
abort(404, to_unicode)
abort(404, 'Failed to get alarm count.')

View File

@ -15,7 +15,6 @@
import pecan
from oslo_log import log
from oslo_utils import encodeutils
from osprofiler import profiler
from pecan.core import abort
@ -26,6 +25,7 @@ from vitrage.api.policy import enforce
LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("event controller",
info={}, hide_args=False, trace_private=False)
class EventController(RootRestController):
@ -51,7 +51,6 @@ class EventController(RootRestController):
event_time=event_time,
event_type=event_type,
details=details)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
LOG.exception('Failed to post an event %s', to_unicode)
abort(404, to_unicode)
except Exception:
LOG.exception('Failed to post an event')
abort(404, 'Failed to post event')

View File

@ -17,7 +17,6 @@ import json
import pecan
from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string
from osprofiler import profiler
from pecan.core import abort
@ -28,6 +27,7 @@ from vitrage.api.policy import enforce
LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("rca controller",
info={}, hide_args=False, trace_private=False)
class RCAController(RootRestController):
@ -59,7 +59,6 @@ class RCAController(RootRestController):
graph = json.loads(graph_data)
return graph
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to get RCA.')
abort(404, to_unicode)
abort(404, 'Failed to get RCA')

View File

@ -13,7 +13,6 @@ import json
import pecan
from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string
from osprofiler import profiler
from pecan.core import abort
@ -25,6 +24,7 @@ from vitrage.api.policy import enforce
LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("resource controller",
info={}, hide_args=False, trace_private=False)
class ResourcesController(RootRestController):
@ -46,10 +46,9 @@ class ResourcesController(RootRestController):
try:
return self._get_resources(resource_type, all_tenants)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to list resources.')
abort(404, to_unicode)
abort(404, 'Failed to list resources.')
@staticmethod
def _get_resources(resource_type=None, all_tenants=False):
@ -64,10 +63,9 @@ class ResourcesController(RootRestController):
LOG.info(resources_json)
resources = json.loads(resources_json)['resources']
return resources
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to get resources.')
abort(404, to_unicode)
abort(404, 'Failed to list resources.')
@pecan.expose('json')
def get(self, vitrage_id):
@ -94,8 +92,7 @@ class ResourcesController(RootRestController):
LOG.debug('resource found = %s', resource)
return json.loads(resource)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('failed to show resource with vitrage_id(%s).',
vitrage_id)
abort(404, to_unicode)
abort(404, 'Failed to show resource.')

View File

@ -15,7 +15,6 @@ import json
import pecan
from oslo_log import log
from oslo_utils import encodeutils
from osprofiler import profiler
from pecan.core import abort
@ -27,6 +26,7 @@ from vitrage.common.exception import VitrageError
LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("template controller",
info={}, hide_args=False, trace_private=False)
class TemplateController(RootRestController):
@ -42,10 +42,9 @@ class TemplateController(RootRestController):
{})
try:
return self._get_templates()
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('failed to get template list.')
abort(404, to_unicode)
abort(404, 'Failed to get template list')
@pecan.expose('json')
def get(self, template_uuid):
@ -59,11 +58,10 @@ class TemplateController(RootRestController):
try:
return self._show_template(template_uuid)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to show template %s.',
template_uuid)
abort(404, to_unicode)
abort(404, 'Failed to show template.')
@pecan.expose('json')
def delete(self, **kwargs):
@ -76,9 +74,9 @@ class TemplateController(RootRestController):
{})
try:
return self._delete(uuid)
except Exception as e:
except Exception:
LOG.exception('Failed to delete template.')
abort(404, str(e))
abort(404, 'Failed to delete template.')
@pecan.expose('json')
def put(self, **kwargs):
@ -93,9 +91,9 @@ class TemplateController(RootRestController):
try:
return self._add(templates, template_type)
except Exception as e:
except Exception:
LOG.exception('Failed to add template.')
abort(404, str(e))
abort(404, 'Failed to add template.')
@pecan.expose('json')
def post(self, **kwargs):
@ -112,10 +110,9 @@ class TemplateController(RootRestController):
try:
return self._validate(templates, template_type)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to validate template(s).')
abort(404, to_unicode)
abort(404, 'Failed to validate template.')
@classmethod
def _get_templates(cls):
@ -124,10 +121,9 @@ class TemplateController(RootRestController):
templates = [t for t in templates if t.status != TStatus.DELETED]
templates.sort(key=lambda template: template.created_at)
return [cls._db_template_to_dict(t) for t in templates]
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to get template list.')
abort(404, to_unicode)
abort(404, 'Failed to get template list.')
@staticmethod
def _show_template(uuid):
@ -136,10 +132,9 @@ class TemplateController(RootRestController):
if not templates:
raise VitrageError("Template %s not found", uuid)
return templates[0].file_content
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to show template with uuid: %s ', uuid)
abort(404, to_unicode)
abort(404, 'Failed to show template.')
@staticmethod
def _validate(templates, template_type):
@ -150,10 +145,9 @@ class TemplateController(RootRestController):
template_type=template_type)
try:
return json.loads(result_json)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('Failed to open template file(s).')
abort(404, to_unicode)
abort(404, 'Failed to validate template file.')
@classmethod
def _add(cls, templates, template_type):
@ -164,9 +158,9 @@ class TemplateController(RootRestController):
templates=templates,
template_type=template_type)
return results
except Exception as e:
except Exception:
LOG.exception('Failed to add template file.')
abort(404, str(e))
abort(404, 'Failed to add template file.')
@staticmethod
def _db_template_to_dict(template):
@ -187,6 +181,6 @@ class TemplateController(RootRestController):
'delete_template',
uuids=uuid)
return results
except Exception as e:
except Exception:
LOG.exception('Failed to delete template.')
abort(404, str(e))
abort(404, 'Failed to delete template.')

View File

@ -16,7 +16,6 @@
import json
from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string
from osprofiler import profiler
import pecan
@ -33,6 +32,7 @@ from vitrage.datasources.transformer_base import CLUSTER_ID
LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("topology controller",
info={}, hide_args=False, trace_private=False)
class TopologyController(RootRestController):
@ -89,10 +89,9 @@ class TopologyController(RootRestController):
break
return RootRestController.as_tree(graph, node_id)
except Exception as e:
to_unicode = encodeutils.exception_to_unicode(e)
except Exception:
LOG.exception('failed to get topology.')
abort(404, to_unicode)
abort(404, 'Failed to get topology.')
@staticmethod
def _check_input_para(graph_type, depth, query, root, all_tenants):

View File

@ -25,6 +25,7 @@ from vitrage.common.constants import TenantProps
LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("webhook controller",
info={}, hide_args=False, trace_private=False)
class WebhookController(RootRestController):
@ -45,9 +46,9 @@ class WebhookController(RootRestController):
try:
return self._get_all(all_tenants)
except Exception as e:
except Exception:
LOG.exception('Failed to list webhooks.')
abort(404, str(e))
abort(404, 'Failed to list webhooks.')
@staticmethod
def _get_all(all_tenants):
@ -67,9 +68,9 @@ class WebhookController(RootRestController):
try:
return self._get(id)
except Exception as e:
LOG.exception('Failed to get webhooks.')
abort(404, str(e))
except Exception:
LOG.exception('Failed to get webhook.')
abort(404, 'Failed to get webhook.')
@staticmethod
def _get(id):
@ -90,9 +91,9 @@ class WebhookController(RootRestController):
pecan.request.enforcer, {})
try:
return self._post(**kwargs)
except Exception as e:
except Exception:
LOG.exception('Failed to add webhooks.')
abort(400, str(e))
abort(400, 'Failed to add webhooks.')
@staticmethod
def _post(**kwargs):
@ -124,9 +125,9 @@ class WebhookController(RootRestController):
try:
return self._delete_registration(id)
except Exception as e:
except Exception:
LOG.exception('Failed to delete webhook "%s"', id)
abort(404, str(e))
abort(404, 'Failed to delete webhook.')
@staticmethod
def _delete_registration(id):