Пример #1
0
    def _create_base_url_client(client: minio.Minio, bucket_name: str,
                                base_url: str):
        """
        Clone a Minio client, using a different endpoint from `base_url`.
        """
        base_url_parts = urlsplit(base_url)

        # Clone from the normal client, but with base_url as the endpoint
        base_url_client = minio.Minio(
            base_url_parts.netloc,
            access_key=client._access_key,
            secret_key=client._secret_key,
            session_token=client._session_token,
            secure=base_url_parts.scheme == "https",
            # The bucket region may be auto-detected by client (via an HTTP
            # request), so don't just use client._region
            region=client._get_bucket_region(bucket_name),
            http_client=client._http,
        )
        if hasattr(client, "_credentials"):
            # Client credentials do not exist prior to minio-py 5.0.7, but
            # they should be reused if possible
            base_url_client._credentials = client._credentials

        return base_url_client
 def test_can_include_response_headers(self):
     client = Minio('localhost:9000', 'my_access_key', 'my_secret_key',
                    secure=True)
     client._get_bucket_region = mock.Mock(return_value='us-east-1')
     r = client.presigned_get_object(
         'mybucket', 'myfile.pdf',
         response_headers={
             'Response-Content-Type': 'application/pdf',
             'Response-Content-Disposition': 'inline;  filename="test.pdf"'
         })
     self.assertIn('inline', r)
     self.assertIn('test.pdf', r)
     self.assertIn('application%2Fpdf', r)
 def test_can_include_response_headers(self):
     client = Minio('localhost:9000', 'my_access_key', 'my_secret_key',
                    secure=True)
     client._get_bucket_region = mock.Mock(return_value='us-east-1')
     r = client.presigned_get_object(
         'mybucket', 'myfile.pdf',
         response_headers={
             'Response-Content-Type': 'application/pdf',
             'Response-Content-Disposition': 'inline;  filename="test.pdf"'
         })
     self.assertIn('inline', r)
     self.assertIn('test.pdf', r)
     self.assertIn('application%2Fpdf', r)