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 <uuid>
fm event-suppress --alarm_id <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-<req_id>)"
to:
"Error: Forbidden."

Story: 2010149
Task: 46620

Signed-off-by: Joao Victor Portal <Joao.VictorPortal@windriver.com>
Change-Id: I45007a7f5319ef0a0238a07d671a859b5081660a
This commit is contained in:
Joao Victor Portal 2022-10-18 16:32:30 -03:00
parent 8a07de3ea1
commit 277c64bed7
2 changed files with 14 additions and 0 deletions

View File

@ -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:

View File

@ -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.