]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/dashboard/awsauth: drop py2 support
authorKefu Chai <kchai@redhat.com>
Thu, 14 Jan 2021 14:19:48 +0000 (22:19 +0800)
committerKefu Chai <kchai@redhat.com>
Fri, 15 Jan 2021 09:25:27 +0000 (17:25 +0800)
silences the warning from mypy:

dashboard/awsauth.py:42: error: Module 'base64' has no attribute
'encodestring'

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

index 911052e4c91bc51262c2e536938767231dd25889..ad8dc20faaa6037ae215973b97536455c9047fdd 100644 (file)
 # 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()):