~tribaal/txaws/xss-hardening

« back to all changes in this revision

Viewing changes to txaws/credentials.py

  • Committer: Tristan Seligmann
  • Date: 2009-04-27 23:53:32 UTC
  • mfrom: (3.1.5 client)
  • Revision ID: mithrandi@mithrandi.net-20090427235332-l8azkl1kvn5pjtay
mergeĀ lp:~lifeless/txaws/client

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2009 Robert Collins <robertc@robertcollins.net>
 
2
# Licenced under the txaws licence available at /LICENSE in the txaws source.
 
3
 
 
4
"""Credentials for accessing AWS services."""
 
5
 
 
6
__all__ = ['AWSCredentials']
 
7
 
 
8
import os
 
9
 
 
10
from txaws.util import *
 
11
 
 
12
class AWSCredentials(object):
 
13
 
 
14
    def __init__(self, access_key=None, secret_key=None):
 
15
        """Create an AWSCredentials object.
 
16
 
 
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.
 
21
        """
 
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')
 
32
 
 
33
    def sign(self, bytes):
 
34
        """Sign some bytes."""
 
35
        return hmac_sha1(self.secret_key, bytes)