]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: ensure password is a string before encoding it 40522/head
authorKefu Chai <kchai@redhat.com>
Wed, 31 Mar 2021 11:09:56 +0000 (19:09 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 31 Mar 2021 11:35:07 +0000 (19:35 +0800)
otherwise we have following failure:

AttributeError: 'bytes' object has no attribute 'encode'

this change is not cherry-picked from master, as master has dropped
python2 support.

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

index 9ea7a01cd44f888b7376a76181196b044fbebbf3..5cc35dff44ceabe4d1a9ecbdcf8e44842ddd5dd9 100644 (file)
@@ -7,7 +7,6 @@ import errno
 import json
 import threading
 import time
-import six
 
 import bcrypt
 
@@ -15,6 +14,7 @@ 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, \
@@ -25,8 +25,7 @@ from ..exceptions import RoleAlreadyExists, RoleDoesNotExist, ScopeNotValid, \
 def password_hash(password, salt_password=None):
     if not password:
         return None
-    if six.PY2:
-        password = unicode(password, 'utf-8') if isinstance(password, str) else password
+    password = ensure_str(password)
     if not salt_password:
         salt_password = bcrypt.gensalt()
     else: