]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: do not import tools in access_control
authorKefu Chai <kchai@redhat.com>
Thu, 1 Apr 2021 04:14:31 +0000 (12:14 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 1 Apr 2021 08:05:57 +0000 (16:05 +0800)
this addresses a regression introduced by
2cd94293268116838c3ddcebdedde4fbd9cb93aa. which

from ..tools import ensure_str

and it causes recursive import.

so, in this change, an copy of ensure_str() is added
to access_control.py

this change is not cherry-picked from master, as the offending commit
which is fixed by this change is not included in master.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/dashboard/services/access_control.py

index 5cc35dff44ceabe4d1a9ecbdcf8e44842ddd5dd9..fafc3789ab0af8fa672262c98d2c92144ee095c6 100644 (file)
@@ -7,6 +7,7 @@ import errno
 import json
 import threading
 import time
+import six
 
 import bcrypt
 
@@ -14,13 +15,25 @@ from mgr_module import CLICheckNonemptyFileInput, CLIReadCommand, CLIWriteComman
 
 from .. import mgr, logger
 from ..security import Scope, Permission
-from ..tools import ensure_str
 from ..exceptions import RoleAlreadyExists, RoleDoesNotExist, ScopeNotValid, \
                          PermissionNotValid, RoleIsAssociatedWithUser, \
                          UserAlreadyExists, UserDoesNotExist, ScopeNotInRole, \
                          RoleNotInUser
 
 
+# replicates tools.ensure_str() to avoid recursive import:
+# ..tools -> .services.auth -> .access_control -> ..tools
+def ensure_str(s, encoding='utf-8', errors='strict'):
+    """Ported from six."""
+    if not isinstance(s, (six.text_type, six.binary_type)):
+        raise TypeError("not expecting type '%s'" % type(s))
+    if six.PY2 and isinstance(s, six.text_type):
+        s = s.encode(encoding, errors)
+    elif six.PY3 and isinstance(s, six.binary_type):
+        s = s.decode(encoding, errors)
+    return s
+
+
 # password hashing algorithm
 def password_hash(password, salt_password=None):
     if not password: