You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2015/03/28 15:51:23 UTC

[06/16] libcloud git commit: Small fixes

Small fixes

Signed-off-by: Tomaz Muraus <to...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/5db12e2e
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/5db12e2e
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/5db12e2e

Branch: refs/heads/trunk
Commit: 5db12e2e314eb14219ee5c08a9119f2265b506d4
Parents: 7bb5689
Author: Gertjan Oude Lohuis <ge...@byte.nl>
Authored: Thu Mar 5 15:51:14 2015 +0100
Committer: Tomaz Muraus <to...@apache.org>
Committed: Fri Mar 6 15:58:12 2015 +0100

----------------------------------------------------------------------
 libcloud/common/aws.py | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/5db12e2e/libcloud/common/aws.py
----------------------------------------------------------------------
diff --git a/libcloud/common/aws.py b/libcloud/common/aws.py
index 9cc269d..697a47e 100644
--- a/libcloud/common/aws.py
+++ b/libcloud/common/aws.py
@@ -219,13 +219,10 @@ class V4SignedAWSConnection(AWSTokenConnection):
             'aws4_request')
 
     def _get_string_to_sign(self, params, headers, dt):
-        credential_scope = self._get_credential_scope(dt)
-        canonical_request = self._get_canonical_request(params, headers)
-
         return '\n'.join(['AWS4-HMAC-SHA256',
                           dt.strftime('%Y%m%dT%H%M%SZ'),
-                          credential_scope,
-                          hashlib.sha256(canonical_request).hexdigest()])
+                          self._get_credential_scope(dt),
+                          _hash(self._get_canonical_request(params, headers))])
 
     def _get_credential_scope(self, dt):
         return '/'.join([dt.strftime('%Y%m%d'),
@@ -237,13 +234,11 @@ class V4SignedAWSConnection(AWSTokenConnection):
         return ';'.join([k.lower() for k in sorted(headers.keys())])
 
     def _get_canonical_headers(self, headers):
-        canonical_headers = '\n'.join([':'.join([k.lower(), v.strip()])
-                                       for k, v in sorted(headers.items())])
-        canonical_headers += '\n'
-        return canonical_headers
+        return '\n'.join([':'.join([k.lower(), v.strip()])
+                          for k, v in sorted(headers.items())]) + '\n'
 
     def _get_payload_hash(self):
-        return hashlib.sha256('').hexdigest()
+        return _hash('')
 
     def _get_request_params(self, params):
         # For self.method == GET
@@ -263,9 +258,13 @@ class V4SignedAWSConnection(AWSTokenConnection):
 
 def _sign(key, msg, hex=False):
     if hex:
-        return hmac.new(key, b(msg), hashlib.sha256).hexdigest()
+        return hmac.new(b(key), b(msg), hashlib.sha256).hexdigest()
     else:
-        return hmac.new(key, b(msg), hashlib.sha256).digest()
+        return hmac.new(b(key), b(msg), hashlib.sha256).digest()
+
+
+def _hash(msg):
+    return hashlib.sha256(b(msg)).hexdigest()
 
 
 class AWSDriver(BaseDriver):