From ad997b54c2728b9a72745b69fbe80c94db6eefc8 Mon Sep 17 00:00:00 2001 From: Volker Theile Date: Wed, 2 May 2018 17:33:24 +0200 Subject: [PATCH] mgr/dashboard: Refactor RGW backend - Do some polishing in the docs. - Refactor RgwClient::is_service_online() method. The system is considered as online if the response structure is valid. The response content itself is not validated in this case. - Relocate NoCredentialsException and derive it from RequestException. Signed-off-by: Volker Theile --- doc/mgr/dashboard.rst | 8 ++-- src/pybind/mgr/dashboard/exceptions.py | 7 +--- .../mgr/dashboard/services/rgw_client.py | 37 ++++++++++++------- 3 files changed, 29 insertions(+), 23 deletions(-) diff --git a/doc/mgr/dashboard.rst b/doc/mgr/dashboard.rst index 74ee63f9182f6..6c4856b538e93 100644 --- a/doc/mgr/dashboard.rst +++ b/doc/mgr/dashboard.rst @@ -147,7 +147,7 @@ enabled. If you do not have a user which shall be used for providing those credentials, you will also need to create one:: - $ radosgw-admin user create --uid= --display-name= \ + $ radosgw-admin user create --uid= --display-name= \ --system Take note of the keys ``access_key`` and ``secret_key`` in the output of this @@ -156,7 +156,7 @@ command. The credentials of an existing user can also be obtained by using `radosgw-admin`:: - $ radosgw-admin user info --uid= + $ radosgw-admin user info --uid= Finally, provide the credentials to the dashboard module:: @@ -177,8 +177,8 @@ In addition to the settings mentioned so far, the following settings do also exist and you may find yourself in the situation that you have to use them:: $ ceph dashboard set-rgw-api-scheme # http or https - $ ceph dashboard set-rgw-api-admin-resource - $ ceph dashboard set-rgw-api-user-id + $ ceph dashboard set-rgw-api-admin-resource + $ ceph dashboard set-rgw-api-user-id Accessing the dashboard ^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/pybind/mgr/dashboard/exceptions.py b/src/pybind/mgr/dashboard/exceptions.py index 8e240951fd53d..ff356d303c773 100644 --- a/src/pybind/mgr/dashboard/exceptions.py +++ b/src/pybind/mgr/dashboard/exceptions.py @@ -2,9 +2,4 @@ from __future__ import absolute_import -class NoCredentialsException(Exception): - def __init__(self): - super(Exception, self).__init__( - 'No RGW credentials found, ' - 'please consult the documentation on how to enable RGW for ' - 'the dashboard.') +# Add generic exceptions here. diff --git a/src/pybind/mgr/dashboard/services/rgw_client.py b/src/pybind/mgr/dashboard/services/rgw_client.py index e34fb75edce80..d07c9db4907a2 100644 --- a/src/pybind/mgr/dashboard/services/rgw_client.py +++ b/src/pybind/mgr/dashboard/services/rgw_client.py @@ -6,10 +6,17 @@ from ..awsauth import S3Auth from ..settings import Settings, Options from ..rest_client import RestClient, RequestException from ..tools import build_url, dict_contains_path -from ..exceptions import NoCredentialsException from .. import mgr, logger +class NoCredentialsException(RequestException): + def __init__(self): + super(NoCredentialsException, self).__init__( + 'No RGW credentials found, ' + 'please consult the documentation on how to enable RGW for ' + 'the dashboard.') + + def _determine_rgw_addr(): """ Get a RGW daemon to determine the configured host (IP address) and port. @@ -83,19 +90,19 @@ class RgwClient(RestClient): @staticmethod def _load_settings(): - if Settings.RGW_API_SCHEME and Settings.RGW_API_ACCESS_KEY and \ - Settings.RGW_API_SECRET_KEY: - if Options.has_default_value('RGW_API_HOST') and \ - Options.has_default_value('RGW_API_PORT'): - host, port = _determine_rgw_addr() - else: - host, port = Settings.RGW_API_HOST, Settings.RGW_API_PORT - else: + # The API access key and secret key are mandatory for a minimal configuration. + if not (Settings.RGW_API_ACCESS_KEY and Settings.RGW_API_SECRET_KEY): logger.warning('No credentials found, please consult the ' 'documentation about how to enable RGW for the ' 'dashboard.') raise NoCredentialsException() + if Options.has_default_value('RGW_API_HOST') and \ + Options.has_default_value('RGW_API_PORT'): + host, port = _determine_rgw_addr() + else: + host, port = Settings.RGW_API_HOST, Settings.RGW_API_PORT + RgwClient._host = host RgwClient._port = port RgwClient._ssl = Settings.RGW_API_SCHEME == 'https' @@ -103,7 +110,7 @@ class RgwClient(RestClient): RgwClient._SYSTEM_USERID = Settings.RGW_API_USER_ID logger.info("Creating new connection for user: %s", - Settings.RGW_API_USER_ID) + RgwClient._SYSTEM_USERID) RgwClient._user_instances[RgwClient._SYSTEM_USERID] = \ RgwClient(Settings.RGW_API_USER_ID, Settings.RGW_API_ACCESS_KEY, Settings.RGW_API_SECRET_KEY) @@ -165,10 +172,14 @@ class RgwClient(RestClient): logger.info("Creating new connection") - @RestClient.api_get('/', resp_structure='[0] > ID') + @RestClient.api_get('/', resp_structure='[0] > (ID & DisplayName)') def is_service_online(self, request=None): - response = request({'format': 'json'}) - return response[0]['ID'] == 'online' + """ + Consider the service as online if the response contains the + specified keys. Nothing more is checked here. + """ + request({'format': 'json'}) + return True @RestClient.api_get('/{admin_path}/metadata/user', resp_structure='[+]') def _is_system_user(self, admin_path, request=None): -- 2.39.5