From 277c64bed7ec9184a4e614e164c2addbf1c6b4a0 Mon Sep 17 00:00:00 2001 From: Joao Victor Portal Date: Tue, 18 Oct 2022 16:32:30 -0300 Subject: [PATCH] Fix FM error messages for forbidden requests The CLI error messages for users with reader role were not clear to the operator and this change fixes this. Test Plan: PASS: In an AIO-SX with this change present, create a new openstack user with reader role and through this user execute the commands: fm alarm-list fm alarm-delete fm event-suppress --alarm_id and check that the "alarm-list" command is executed without errors and that the error message of the other commands changes from: "HTTP Client Error (HTTP 403) (Request-ID: req-)" to: "Error: Forbidden." Story: 2010149 Task: 46620 Signed-off-by: Joao Victor Portal Change-Id: I45007a7f5319ef0a0238a07d671a859b5081660a --- .../fmclient/fmclient/common/exceptions.py | 11 +++++++++++ python-fmclient/fmclient/fmclient/shell.py | 3 +++ 2 files changed, 14 insertions(+) diff --git a/python-fmclient/fmclient/fmclient/common/exceptions.py b/python-fmclient/fmclient/fmclient/common/exceptions.py index 46012b31..bcba578c 100644 --- a/python-fmclient/fmclient/fmclient/common/exceptions.py +++ b/python-fmclient/fmclient/fmclient/common/exceptions.py @@ -85,6 +85,15 @@ class HTTPClientError(HttpError): message = _("HTTP Client Error") +class HTTPForbidden(HTTPClientError): + """HTTP 403 - Forbidden + + Exception for cases in which the server understands the request + but refuses to authorize it. + """ + message = _("HTTP Client Error: Forbidden") + + class HTTPNotFound(HTTPClientError): """HTTP 404 - Not Found @@ -172,6 +181,8 @@ def from_response(response, method, url=None): except KeyError: if 500 <= response.status_code < 600: cls = HttpServerError + elif 403 == response.status_code: + cls = HTTPForbidden elif 404 == response.status_code: cls = HTTPNotFound elif 400 <= response.status_code < 500: diff --git a/python-fmclient/fmclient/fmclient/shell.py b/python-fmclient/fmclient/fmclient/shell.py index b20df4a3..a35ab525 100644 --- a/python-fmclient/fmclient/fmclient/shell.py +++ b/python-fmclient/fmclient/fmclient/shell.py @@ -17,6 +17,7 @@ import sys from oslo_utils import importutils import fmclient +from fmclient.common import exceptions from fmclient.common import utils from fmclient import exc from fmclient import client @@ -292,6 +293,8 @@ class FmShell(object): args.func(client, args) except exc.Unauthorized: raise exc.CommandError("Invalid Identity credentials.") + except exceptions.HTTPForbidden: + raise exc.CommandError("Error: Forbidden.") def do_bash_completion(self, args): """Prints all of the commands and options to stdout.