~bgh/nova/qmanager-ipam-fixes

« back to all changes in this revision

Viewing changes to nova/auth/signer.py

  • Committer: Gerrit Code Review
  • Author(s): Jenkins
  • Date: 2011-09-28 15:25:24 UTC
  • mfrom: (1640.1.1)
  • Revision ID: git-v1:4fb1ac26cb15ea7e21ab9873e1dd253da0c77157
Merge "Signer no longer fails if hashlib.sha256 is not available. test_signer unit test added."

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
        self.hmac = hmac.new(secret_key, digestmod=hashlib.sha1)
68
68
        if hashlib.sha256:
69
69
            self.hmac_256 = hmac.new(secret_key, digestmod=hashlib.sha256)
 
70
        else:
 
71
            self.hmac_256 = None
70
72
 
71
73
    def s3_authorization(self, headers, verb, path):
72
74
        """Generate S3 authorization string."""
77
79
        return b64_hmac
78
80
 
79
81
    def generate(self, params, verb, server_string, path):
80
 
        """Generate auth string according to what SignatureVersion is given."""
 
82
        """Generate auth string according to what SignatureVersion is given.
 
83
 
 
84
        The signature method defaults to SHA256 if available, or falls back to
 
85
        SHA1 if not.
 
86
 
 
87
        """
81
88
        if params['SignatureVersion'] == '0':
82
89
            return self._calc_signature_0(params)
83
90
        if params['SignatureVersion'] == '1':
150
157
 
151
158
 
152
159
if __name__ == '__main__':
153
 
    print Signer('foo').generate({'SignatureMethod': 'HmacSHA256',
154
 
                                  'SignatureVersion': '2'},
155
 
                                 'get', 'server', '/foo')
 
160
    print Signer('foo').generate({'SignatureVersion': '2'}, 'get', 'server',
 
161
                                  '/foo')