From 2cd94293268116838c3ddcebdedde4fbd9cb93aa Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 31 Mar 2021 19:09:56 +0800 Subject: [PATCH] mgr/dashboard: ensure password is a string before encoding it 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 --- src/pybind/mgr/dashboard/services/access_control.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/dashboard/services/access_control.py b/src/pybind/mgr/dashboard/services/access_control.py index 9ea7a01cd44f8..5cc35dff44cea 100644 --- a/src/pybind/mgr/dashboard/services/access_control.py +++ b/src/pybind/mgr/dashboard/services/access_control.py @@ -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: -- 2.39.5