1
# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
2
# Licenced under the txaws licence available at /LICENSE in the txaws source.
4
"""Credentials for accessing AWS services."""
6
__all__ = ['AWSCredentials']
10
from txaws.util import *
12
class AWSCredentials(object):
14
def __init__(self, access_key=None, secret_key=None):
15
"""Create an AWSCredentials object.
17
:param access_key: The access key to use. If None the environment
18
variable AWS_ACCESS_KEY_ID is consulted.
19
:param secret_key: The secret key to use. If None the environment
20
variable AWS_SECRET_ACCESS_KEY is consulted.
22
self.secret_key = secret_key
23
if self.secret_key is None:
24
self.secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
25
if self.secret_key is None:
26
raise ValueError('Could not find AWS_SECRET_ACCESS_KEY')
27
self.access_key = access_key
28
if self.access_key is None:
29
self.access_key = os.environ.get('AWS_ACCESS_KEY_ID')
30
if self.access_key is None:
31
raise ValueError('Could not find AWS_ACCESS_KEY_ID')
33
def sign(self, bytes):
34
"""Sign some bytes."""
35
return hmac_sha1(self.secret_key, bytes)