]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard_v2: Refactoring of the access to mgr module instance
authorRicardo Dias <rdias@suse.com>
Mon, 29 Jan 2018 09:38:03 +0000 (09:38 +0000)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:07:02 +0000 (13:07 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard_v2/controllers/auth.py
src/pybind/mgr/dashboard_v2/tools.py

index 8829c9c3f55f1b411b70d837fe7a85bc2b6c3532..246314f6d3d77cb24f85463575116bcedbb19128 100644 (file)
@@ -30,31 +30,26 @@ class Auth(RESTController):
 
     DEFAULT_SESSION_EXPIRE = 1200.0
 
-    def __init__(self):
-        # pylint: disable=E1101
-        self._mod = Auth._mgr_module_
-        self._log = self._mod.log
-
     @RESTController.args_from_json
     def create(self, username, password):
         now = time.time()
-        config_username = self._mod.get_localized_config('username', None)
-        config_password = self._mod.get_localized_config('password', None)
+        config_username = self.mgr.get_localized_config('username', None)
+        config_password = self.mgr.get_localized_config('password', None)
         hash_password = Auth.password_hash(password,
                                            config_password)
         if username == config_username and hash_password == config_password:
             cherrypy.session.regenerate()
             cherrypy.session[Auth.SESSION_KEY] = username
             cherrypy.session[Auth.SESSION_KEY_TS] = now
-            self._log.debug('Login successful')
+            self.logger.debug('Login successful')
             return {'username': username}
 
         cherrypy.response.status = 403
-        self._log.debug('Login failed')
+        self.logger.debug('Login failed')
         return {'detail': 'Invalid credentials'}
 
     def bulk_delete(self):
-        self._log.debug('Logout successful')
+        self.logger.debug('Logout successful')
         cherrypy.session[Auth.SESSION_KEY] = None
         cherrypy.session[Auth.SESSION_KEY_TS] = None
 
@@ -68,22 +63,21 @@ class Auth(RESTController):
 
     @staticmethod
     def check_auth():
-        module = Auth._mgr_module_
         username = cherrypy.session.get(Auth.SESSION_KEY)
         if not username:
-            module.log.debug('Unauthorized access to {}'.format(cherrypy.url(
+            Auth.logger.debug('Unauthorized access to {}'.format(cherrypy.url(
                 relative='server')))
             raise cherrypy.HTTPError(401, 'You are not authorized to access '
                                           'that resource')
         now = time.time()
-        expires = float(module.get_localized_config(
+        expires = float(Auth.mgr.get_localized_config(
             'session-expire', Auth.DEFAULT_SESSION_EXPIRE))
         if expires > 0:
             username_ts = cherrypy.session.get(Auth.SESSION_KEY_TS, None)
             if username_ts and float(username_ts) < (now - expires):
                 cherrypy.session[Auth.SESSION_KEY] = None
                 cherrypy.session[Auth.SESSION_KEY_TS] = None
-                module.log.debug('Session expired')
+                Auth.logger.debug('Session expired')
                 raise cherrypy.HTTPError(401,
                                          'Session expired. You are not '
                                          'authorized to access that resource')
@@ -91,6 +85,6 @@ class Auth(RESTController):
 
     @staticmethod
     def set_login_credentials(username, password):
-        Auth._mgr_module_.set_localized_config('username', username)
+        Auth.mgr.set_localized_config('username', username)
         hashed_passwd = Auth.password_hash(password)
-        Auth._mgr_module_.set_localized_config('password', hashed_passwd)
+        Auth.mgr.set_localized_config('password', hashed_passwd)
index 7394e6587745b5656cd392f00c398ede71958f1e..6cc8688db6d2a3cc8cb50891b64348e1ab835e01 100644 (file)
@@ -57,7 +57,8 @@ def load_controllers(mgrmodule):
         for _, cls in mod.__dict__.items():
             if isinstance(cls, type) and hasattr(cls, '_cp_controller_'):
                 # found controller
-                cls._mgr_module_ = mgrmodule
+                cls.mgr = mgrmodule
+                cls.logger = mgrmodule.log
                 controllers.append(cls)
 
     return controllers