def __init__(self, *args, **kwargs): """ AWS4Auth instances can be created by supplying scoping parameters directly or by using a pre-generated signing key: >>> auth = AWS4Auth(access_id, access_key, region, service) or >>> auth = AWS4Auth(access_id, signing_key) access_id -- This is your AWS access ID access_key -- This is your AWS access key region -- The region you're connecting to, as per this list at http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region e.g. us-east-1. For services which don't require a region (e.g. IAM), use us-east-1. service -- The name of the service you're connecting to, as per endpoints at: http://docs.aws.amazon.com/general/latest/gr/rande.html e.g. elasticbeanstalk. signing_key - An AWS4SigningKey instance. All arguments except signing_key should be supplied as strings. """ l = len(args) if l not in [2, 4]: msg = 'AWS4Auth() takes 2 or 4 arguments, {} given'.format(l) raise TypeError(msg) self.access_id = args[0] if isinstance(args[1], AWS4SigningKey) and len(args) == 2: # instantiate from signing key key = args[1] self.region = key.region self.service = key.service self.signing_key = key elif len(args) == 4: # instantiate from args access_key = args[1] self.region = args[2] self.service = args[3] self.signing_key = AWS4SigningKey(access_key, self.region, self.service) else: raise TypeError() if 'include_hdrs' in kwargs: self.include_hdrs = kwargs[str('include_hdrs')] else: self.include_hdrs = self.default_include_headers AuthBase.__init__(self)
def __init__(self, *args, **kwargs): """ AWS4Auth instances can be created by supplying key scope parameters directly or by using an AWS4SigningKey instance: access_id -- This is your AWS access ID secret_key -- This is your AWS secret access key region -- The region you're connecting to, as per the list at http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region e.g. us-east-1. For services which don't require a region (e.g. IAM), use us-east-1. service -- The name of the service you're connecting to, as per endpoints at: http://docs.aws.amazon.com/general/latest/gr/rande.html e.g. elasticbeanstalk. date -- Date this instance is valid for. 8-digit date as str of the form YYYYMMDD. Key is only valid for requests with a Date or X-Amz-Date header matching this date. If date is not supplied the current date is used. signing_key -- An AWS4SigningKey instance. raise_invalid_date -- Must be supplied as keyword argument. AWS4Auth tries to parse a date from the X-Amz-Date and Date headers of the request, first trying X-Amz-Date, and then Date if X-Amz-Date is not present or is in an unrecognised format. If one or both of the two headers are present yet neither are in a format which AWS4Auth recognises then it will remove both headers and replace with a new X-Amz-Date header using the current date. If this behaviour is not wanted, set the raise_invalid_date keyword argument to True, and instead an InvalidDateError will be raised when neither date is recognised. If neither header is present at all then an X-Amz-Date header will still be added containing the current date. See the AWS4Auth class docstring for supported date formats. session_token -- Must be supplied as keyword argument. If session_token is set, then it is used for the x-amz-security-token header, for use with STS temporary credentials. """ l = len(args) if l not in [2, 4, 5]: msg = 'AWS4Auth() takes 2, 4 or 5 arguments, {} given'.format(l) raise TypeError(msg) self.access_id = args[0] if isinstance(args[1], AWS4SigningKey) and l == 2: # instantiate from signing key self.signing_key = args[1] self.region = self.signing_key.region self.service = self.signing_key.service self.date = self.signing_key.date elif l in [4, 5]: # instantiate from args secret_key = args[1] self.region = args[2] self.service = args[3] self.date = args[4] if l == 5 else None self.signing_key = None self.regenerate_signing_key(secret_key=secret_key) else: raise TypeError() raise_invalid_date = kwargs.get('raise_invalid_date', False) if raise_invalid_date in [True, False]: self.raise_invalid_date = raise_invalid_date else: raise ValueError('raise_invalid_date must be True or False in AWS4Auth.__init__()') self.session_token = kwargs.get('session_token') if self.session_token: self.default_include_headers.append('x-hyper-security-token') self.include_hdrs = kwargs.get('include_hdrs', self.default_include_headers) AuthBase.__init__(self)
def test_custom_http_auth_is_allowed(self): auth = AuthBase() c = RequestsHttpConnection(http_auth=auth) self.assertEquals(auth, c.session.auth)
def __init__(self, *args, **kwargs): """ AWS4Auth instances can be created by supplying key scope parameters directly or by using an AWS4SigningKey instance: access_id -- This is your AWS access ID secret_key -- This is your AWS secret access key region -- The region you're connecting to, as per the list at http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region e.g. us-east-1. For services which don't require a region (e.g. IAM), use us-east-1. service -- The name of the service you're connecting to, as per endpoints at: http://docs.aws.amazon.com/general/latest/gr/rande.html e.g. elasticbeanstalk. date -- Date this instance is valid for. 8-digit date as str of the form YYYYMMDD. Key is only valid for requests with a Date or X-Amz-Date header matching this date. If date is not supplied the current date is used. signing_key -- An AWS4SigningKey instance. raise_invalid_date -- Must be supplied as keyword argument. AWS4Auth tries to parse a date from the X-Amz-Date and Date headers of the request, first trying X-Amz-Date, and then Date if X-Amz-Date is not present or is in an unrecognised format. If one or both of the two headers are present yet neither are in a format which AWS4Auth recognises then it will remove both headers and replace with a new X-Amz-Date header using the current date. If this behaviour is not wanted, set the raise_invalid_date keyword argument to True, and instead an InvalidDateError will be raised when neither date is recognised. If neither header is present at all then an X-Amz-Date header will still be added containing the current date. See the AWS4Auth class docstring for supported date formats. session_token -- Must be supplied as keyword argument. If session_token is set, then it is used for the x-amz-security-token header, for use with STS temporary credentials. """ l = len(args) if l not in [2, 4, 5]: msg = 'AWS4Auth() takes 2, 4 or 5 arguments, {} given'.format(l) raise TypeError(msg) self.access_id = args[0] if isinstance(args[1], AWS4SigningKey) and l == 2: # instantiate from signing key self.signing_key = args[1] self.region = self.signing_key.region self.service = self.signing_key.service self.date = self.signing_key.date elif l in [4, 5]: # instantiate from args secret_key = args[1] self.region = args[2] self.service = args[3] self.date = args[4] if l == 5 else None self.signing_key = None self.regenerate_signing_key(secret_key=secret_key) else: raise TypeError() raise_invalid_date = kwargs.get('raise_invalid_date', False) if raise_invalid_date in [True, False]: self.raise_invalid_date = raise_invalid_date else: raise ValueError( 'raise_invalid_date must be True or False in AWS4Auth.__init__()' ) self.session_token = kwargs.get('session_token') if self.session_token: self.default_include_headers.append('x-hyper-security-token') self.include_hdrs = kwargs.get('include_hdrs', self.default_include_headers) AuthBase.__init__(self)
def mock_auth(self): return mock.create_autospec(AuthBase())