From: Kefu Chai Date: Thu, 1 Apr 2021 04:14:31 +0000 (+0800) Subject: mgr/dashboard: do not import tools in access_control X-Git-Tag: v14.2.22~27^2~14^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e2614de5d3ebb8b240facbc5e7ef3fc6293fbe12;p=ceph.git mgr/dashboard: do not import tools in access_control 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 --- diff --git a/src/pybind/mgr/dashboard/services/access_control.py b/src/pybind/mgr/dashboard/services/access_control.py index 5cc35dff44ce..fafc3789ab0a 100644 --- a/src/pybind/mgr/dashboard/services/access_control.py +++ b/src/pybind/mgr/dashboard/services/access_control.py @@ -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: