Merge "don't expose exception info on http response"

This commit is contained in:
Zuul 2018-06-18 10:54:06 +00:00 committed by Gerrit Code Review
commit 34000041fe
8 changed files with 60 additions and 76 deletions

View File

@ -18,7 +18,6 @@ import pecan
from oslo_log import log from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string from oslo_utils.strutils import bool_from_string
from osprofiler import profiler from osprofiler import profiler
from pecan.core import abort from pecan.core import abort
@ -33,6 +32,7 @@ from vitrage.common.constants import VertexProperties as Vprops
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("alarm controller", @profiler.trace_cls("alarm controller",
info={}, hide_args=False, trace_private=False) info={}, hide_args=False, trace_private=False)
class AlarmsController(RootRestController): class AlarmsController(RootRestController):
@ -54,10 +54,9 @@ class AlarmsController(RootRestController):
try: try:
return self._get_alarms(vitrage_id, all_tenants) return self._get_alarms(vitrage_id, all_tenants)
except Exception as e: except Exception:
to_unicode = encodeutils.exception_to_unicode(e)
LOG.exception('Failed to get alarms.') LOG.exception('Failed to get alarms.')
abort(404, to_unicode) abort(404, 'Failed to get alarms.')
@staticmethod @staticmethod
def _get_alarms(vitrage_id=None, all_tenants=False): def _get_alarms(vitrage_id=None, all_tenants=False):
@ -71,10 +70,9 @@ class AlarmsController(RootRestController):
alarms_list = json.loads(alarms_json)['alarms'] alarms_list = json.loads(alarms_json)['alarms']
return alarms_list return alarms_list
except Exception as e: except Exception:
to_unicode = encodeutils.exception_to_unicode(e)
LOG.exception('Failed to open file.') LOG.exception('Failed to open file.')
abort(404, to_unicode) abort(404, 'Failed to get alarms')
@pecan.expose('json') @pecan.expose('json')
def get(self, vitrage_id): def get(self, vitrage_id):
@ -87,10 +85,9 @@ class AlarmsController(RootRestController):
try: try:
return self._show_alarm(vitrage_id) return self._show_alarm(vitrage_id)
except Exception as e: except Exception:
to_unicode = encodeutils.exception_to_unicode(e)
LOG.exception('Failed to load JSON.') LOG.exception('Failed to load JSON.')
abort(404, to_unicode) abort(404, "Failed to show alarm.")
@staticmethod @staticmethod
def _show_alarm(vitrage_id): def _show_alarm(vitrage_id):
@ -103,7 +100,6 @@ class AlarmsController(RootRestController):
alarms_list = json.loads(alarm_json) alarms_list = json.loads(alarm_json)
return alarms_list return alarms_list
except Exception as e: except Exception:
to_unicode = encodeutils.exception_to_unicode(e)
LOG.exception('Failed to load JSON.') 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 import pecan
from oslo_log import log from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string from oslo_utils.strutils import bool_from_string
from pecan.core import abort from pecan.core import abort
@ -25,6 +24,7 @@ from vitrage.api.policy import enforce
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
# noinspection PyBroadException
class CountsController(RootRestController): class CountsController(RootRestController):
@pecan.expose('json') @pecan.expose('json')
@ -50,7 +50,6 @@ class CountsController(RootRestController):
return json.loads(alarm_counts_json) return json.loads(alarm_counts_json)
except Exception as e: except Exception:
to_unicode = encodeutils.exception_to_unicode(e)
LOG.exception('failed to get alarm count.') 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 import pecan
from oslo_log import log from oslo_log import log
from oslo_utils import encodeutils
from osprofiler import profiler from osprofiler import profiler
from pecan.core import abort from pecan.core import abort
@ -26,6 +25,7 @@ from vitrage.api.policy import enforce
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("event controller", @profiler.trace_cls("event controller",
info={}, hide_args=False, trace_private=False) info={}, hide_args=False, trace_private=False)
class EventController(RootRestController): class EventController(RootRestController):
@ -51,7 +51,6 @@ class EventController(RootRestController):
event_time=event_time, event_time=event_time,
event_type=event_type, event_type=event_type,
details=details) details=details)
except Exception as e: except Exception:
to_unicode = encodeutils.exception_to_unicode(e) LOG.exception('Failed to post an event')
LOG.exception('Failed to post an event %s', to_unicode) abort(404, 'Failed to post event')
abort(404, to_unicode)

View File

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

View File

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

View File

@ -16,7 +16,6 @@
import json import json
from oslo_log import log from oslo_log import log
from oslo_utils import encodeutils
from oslo_utils.strutils import bool_from_string from oslo_utils.strutils import bool_from_string
from osprofiler import profiler from osprofiler import profiler
import pecan import pecan
@ -33,6 +32,7 @@ from vitrage.datasources.transformer_base import CLUSTER_ID
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("topology controller", @profiler.trace_cls("topology controller",
info={}, hide_args=False, trace_private=False) info={}, hide_args=False, trace_private=False)
class TopologyController(RootRestController): class TopologyController(RootRestController):
@ -89,10 +89,9 @@ class TopologyController(RootRestController):
break break
return RootRestController.as_tree(graph, node_id) return RootRestController.as_tree(graph, node_id)
except Exception as e: except Exception:
to_unicode = encodeutils.exception_to_unicode(e)
LOG.exception('failed to get topology.') LOG.exception('failed to get topology.')
abort(404, to_unicode) abort(404, 'Failed to get topology.')
@staticmethod @staticmethod
def _check_input_para(graph_type, depth, query, root, all_tenants): 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__) LOG = log.getLogger(__name__)
# noinspection PyBroadException
@profiler.trace_cls("webhook controller", @profiler.trace_cls("webhook controller",
info={}, hide_args=False, trace_private=False) info={}, hide_args=False, trace_private=False)
class WebhookController(RootRestController): class WebhookController(RootRestController):
@ -45,9 +46,9 @@ class WebhookController(RootRestController):
try: try:
return self._get_all(all_tenants) return self._get_all(all_tenants)
except Exception as e: except Exception:
LOG.exception('Failed to list webhooks.') LOG.exception('Failed to list webhooks.')
abort(404, str(e)) abort(404, 'Failed to list webhooks.')
@staticmethod @staticmethod
def _get_all(all_tenants): def _get_all(all_tenants):
@ -67,9 +68,9 @@ class WebhookController(RootRestController):
try: try:
return self._get(id) return self._get(id)
except Exception as e: except Exception:
LOG.exception('Failed to get webhooks.') LOG.exception('Failed to get webhook.')
abort(404, str(e)) abort(404, 'Failed to get webhook.')
@staticmethod @staticmethod
def _get(id): def _get(id):
@ -90,9 +91,9 @@ class WebhookController(RootRestController):
pecan.request.enforcer, {}) pecan.request.enforcer, {})
try: try:
return self._post(**kwargs) return self._post(**kwargs)
except Exception as e: except Exception:
LOG.exception('Failed to add webhooks.') LOG.exception('Failed to add webhooks.')
abort(400, str(e)) abort(400, 'Failed to add webhooks.')
@staticmethod @staticmethod
def _post(**kwargs): def _post(**kwargs):
@ -124,9 +125,9 @@ class WebhookController(RootRestController):
try: try:
return self._delete_registration(id) return self._delete_registration(id)
except Exception as e: except Exception:
LOG.exception('Failed to delete webhook "%s"', id) LOG.exception('Failed to delete webhook "%s"', id)
abort(404, str(e)) abort(404, 'Failed to delete webhook.')
@staticmethod @staticmethod
def _delete_registration(id): def _delete_registration(id):