def _get_headers( self, instant, method, url_context, app_headers, body, metadata, amz_headers, content_sha256, ): """ Build the list of headers needed in order to perform AWS operations. """ headers = { "x-amz-date": _auth_v4.makeAMZDate(instant), } for key, value in metadata.iteritems(): headers["x-amz-meta-" + key] = value for key, value in amz_headers.iteritems(): headers["x-amz-" + key] = value if content_sha256 is None: content_sha256 = b"UNSIGNED-PAYLOAD" headers["x-amz-content-sha256"] = content_sha256 # Before we check if the content type is set, let's see if we can set # it by guessing the the mimetype. content_types = app_headers.getRawHeaders(u"content-type", None) if content_types is not None: headers["content-type"] = content_types[0] return headers
def get_headers(self, instant): """ Build the list of headers needed in order to perform S3 operations. """ headers = {'x-amz-date': _auth_v4.makeAMZDate(instant)} if self.body_producer is None: data = self.data if data is None: data = b"" headers["x-amz-content-sha256"] = hashlib.sha256(data).hexdigest() else: data = None headers["x-amz-content-sha256"] = b"UNSIGNED-PAYLOAD" for key, value in self.metadata.iteritems(): headers["x-amz-meta-" + key] = value for key, value in self.amz_headers.iteritems(): headers["x-amz-" + key] = value # Before we check if the content type is set, let's see if we can set # it by guessing the the mimetype. self.set_content_type() if self.content_type is not None: headers["Content-Type"] = self.content_type if self.creds is not None: headers["Authorization"] = self.sign( headers, data, s3_url_context(self.endpoint, self.bucket, self.object_name), instant, method=self.action) return headers
def get_headers(self, instant): """ Build the list of headers needed in order to perform S3 operations. """ headers = {'x-amz-date': _auth_v4.makeAMZDate(instant)} if self.body_producer is None: data = self.data if data is None: data = b"" headers["x-amz-content-sha256"] = hashlib.sha256(data).hexdigest() else: data = None headers["x-amz-content-sha256"] = b"UNSIGNED-PAYLOAD" for key, value in self.metadata.items(): headers["x-amz-meta-" + key] = value for key, value in self.amz_headers.items(): headers["x-amz-" + key] = value # Before we check if the content type is set, let's see if we can set # it by guessing the the mimetype. self.set_content_type() if self.content_type is not None: headers["Content-Type"] = self.content_type if self.creds is not None: headers["Authorization"] = self.sign( headers, data, s3_url_context(self.endpoint, self.bucket, self.object_name), instant, method=self.action) return headers
def test_makeAMZDate(self): """ A L{datetime.datetime} instance is formatted according to the convention for AMZ dates. """ instant = datetime.datetime(2016, 11, 11, 2, 45, 50) self.assertEqual(makeAMZDate(instant), "20161111T024550Z")
def _get_headers( self, instant, method, url_context, app_headers, body, metadata, amz_headers, content_sha256, ): """ Build the list of headers needed in order to perform AWS operations. """ headers = { "x-amz-date": _auth_v4.makeAMZDate(instant), } for key, value in metadata.items(): headers["x-amz-meta-" + key] = value for key, value in amz_headers.items(): headers["x-amz-" + key] = value if content_sha256 is None: content_sha256 = b"UNSIGNED-PAYLOAD" headers["x-amz-content-sha256"] = content_sha256 # Before we check if the content type is set, let's see if we can set # it by guessing the the mimetype. content_types = app_headers.getRawHeaders("content-type", None) if content_types is not None: headers["content-type"] = content_types[0] return headers
def _test_string_to_sign(self, path, canonical_request): """ Extract an AWS string-to-sign fixture from C{path} and compare it to a L{_SignableAWS4HMAC256Token} constructed from the provided canonical request. """ string_to_sign_path = self._globOne(path, "*.sts") with string_to_sign_path.open() as f: string_to_sign = f.read() token = _SignableAWS4HMAC256Token( makeAMZDate(self.instant), credential_scope=self.credential_scope, canonical_request=canonical_request) self.assertEqual(token.serialize(), string_to_sign)