From: Kefu Chai Date: Thu, 14 Jan 2021 14:19:48 +0000 (+0800) Subject: mgr/dashboard/awsauth: drop py2 support X-Git-Tag: v17.0.0~52^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=42b41f897d2a0a7673ad7fb4b6d2a3426f9609c1;p=ceph-ci.git mgr/dashboard/awsauth: drop py2 support silences the warning from mypy: dashboard/awsauth.py:42: error: Module 'base64' has no attribute 'encodestring' Signed-off-by: Kefu Chai --- diff --git a/src/pybind/mgr/dashboard/awsauth.py b/src/pybind/mgr/dashboard/awsauth.py index 911052e4c91..ad8dc20faaa 100644 --- a/src/pybind/mgr/dashboard/awsauth.py +++ b/src/pybind/mgr/dashboard/awsauth.py @@ -32,21 +32,13 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. import hmac +from base64 import encodebytes as encodestring from email.utils import formatdate from hashlib import sha1 as sha +from urllib.parse import unquote, urlparse from requests.auth import AuthBase -py3k = False -try: - from base64 import encodestring - - from urlparse import unquote, urlparse -except ImportError: - py3k = True - from base64 import encodebytes as encodestring - from urllib.parse import unquote, urlparse - class S3Auth(AuthBase): @@ -77,20 +69,15 @@ class S3Auth(AuthBase): localtime=False, usegmt=True) signature = self.get_signature(r) - if py3k: - signature = signature.decode('utf-8') + signature = signature.decode('utf-8') r.headers['Authorization'] = 'AWS %s:%s' % (self.access_key, signature) return r def get_signature(self, r): canonical_string = self.get_canonical_string( r.url, r.headers, r.method) - if py3k: - key = self.secret_key.encode('utf-8') - msg = canonical_string.encode('utf-8') - else: - key = self.secret_key # type: ignore - msg = canonical_string + key = self.secret_key.encode('utf-8') + msg = canonical_string.encode('utf-8') h = hmac.new(key, msg, digestmod=sha) return encodestring(h.digest()).strip() @@ -120,12 +107,8 @@ class S3Auth(AuthBase): interesting_headers[lk] = headers[key].strip() # If x-amz-date is used it supersedes the date header. - if not py3k: - if 'x-amz-date' in interesting_headers: - interesting_headers['date'] = '' - else: - if 'x-amz-date' in interesting_headers: - interesting_headers['date'] = '' + if 'x-amz-date' in interesting_headers: + interesting_headers['date'] = '' buf = '%s\n' % method for key in sorted(interesting_headers.keys()):