Exemplo n.º 1
0
  def test_list_buckets(self):
    with patch('aws.s3.s3connection.S3RazClient.get_url') as get_url:
      with patch('aws.s3.s3connection.RazS3Connection._mexe') as _mexe:

        get_url.return_value = 'https://gethue-test.s3.amazonaws.com/?' + \
            'AWSAccessKeyId=AKIA23E77ZX2HVY76YGL' + \
            '&Signature=3lhK%2BwtQ9Q2u5VDIqb4MEpoY3X4%3D&Expires=1617207304'
        _mexe.return_value = ['<Bucket: demo-gethue>', '<Bucket: gethue-test>']

        client = RazS3Connection(host='s3-us-west-1.amazonaws.com')

        buckets = client.make_request(method='GET', bucket='', key='',)

        assert_equal(['<Bucket: demo-gethue>', '<Bucket: gethue-test>'], buckets)

        http_request = _mexe.call_args.args[0]

        if isinstance(http_request, six.string_types):
          raise SkipTest()  # Incorrect in Py3 CircleCi

        assert_equal('GET', http_request.method)
        assert_equal(
          's3-us-west-1.amazonaws.com:443' if sys.version_info[0] > 2 else 's3-us-west-1.amazonaws.com',
          http_request.host
        )
        assert_equal(
          '/?AWSAccessKeyId=AKIA23E77ZX2HVY76YGL&Signature=3lhK%2BwtQ9Q2u5VDIqb4MEpoY3X4%3D&Expires=1617207304',
          http_request.path
        )
        assert_equal('/', http_request.auth_path)
        assert_equal({}, http_request.headers )
        assert_equal({}, http_request.params)
        assert_equal('', http_request.body)
Exemplo n.º 2
0
def _make_client(identifier, user):
  if RAZ.IS_ENABLED.get() and not aws_conf.IS_SELF_SIGNING_ENABLED.get():
    s3_client = RazS3Connection()  # Note: AWS configuration is fully skipped
    s3_client_expiration = None
  else:
    client_conf = aws_conf.AWS_ACCOUNTS[identifier] if identifier in aws_conf.AWS_ACCOUNTS else None

    s3_client_builder = Client.from_config(client_conf, get_credential_provider(identifier, user))
    s3_client = s3_client_builder.get_s3_connection()
    s3_client_expiration = s3_client_builder.expiration

  return S3FileSystem(s3_client, s3_client_expiration)
Exemplo n.º 3
0
def _make_client(identifier, user):
    client_conf = aws_conf.AWS_ACCOUNTS[
        identifier] if identifier in aws_conf.AWS_ACCOUNTS else None

    if aws_conf.is_raz_s3():
        host = aws_conf.get_default_host() or client_conf.HOST.get()
        s3_client = RazS3Connection(
            username=user,
            host=host)  # Note: Remaining AWS configuration is fully skipped
        s3_client_expiration = None
    else:
        s3_client_builder = Client.from_config(
            client_conf, get_credential_provider(identifier, user))
        s3_client = s3_client_builder.get_s3_connection()
        s3_client_expiration = s3_client_builder.expiration

    return S3FileSystem(s3_client, s3_client_expiration)
Exemplo n.º 4
0
    def test_get_file(self):
        with patch('aws.s3.s3connection.RazS3Connection.get_url_request'
                   ) as get_url_request:
            with patch('aws.s3.s3connection.RazS3Connection._mexe') as _mexe:
                with patch('boto.connection.auth.get_auth_handler'
                           ) as get_auth_handler:

                    get_url_request.return_value = 'https://gethue-test.s3.amazonaws.com/gethue/data/customer.csv?' + \
                        'AWSAccessKeyId=AKIA23E77ZX2HVY76YGL' + \
                        '&Signature=3lhK%2BwtQ9Q2u5VDIqb4MEpoY3X4%3D&Expires=1617207304'
                    _mexe.return_value = '[<Bucket: demo-gethue>, <Bucket: gethue-test>]'

                    client = RazS3Connection()
                    http_request = Mock(path='/gethue/data/customer.csv',
                                        protocol='https',
                                        host='s3.amazonaws.com')
                    client.build_base_http_request = Mock(
                        return_value=http_request)

                    buckets = client.make_request(
                        method='GET',
                        bucket='gethue',
                        key='data/customer.csv',
                    )

                    assert_equal(
                        '[<Bucket: demo-gethue>, <Bucket: gethue-test>]',
                        buckets)
                    _mexe.assert_called_with(http_request,
                                             None,
                                             None,
                                             retry_handler=None)

                    assert_equal(
                        'https://gethue-test.s3.amazonaws.com/gethue/data/customer.csv',
                        http_request.path)
                    assert_equal(
                        {
                            'AWSAccessKeyId': 'AKIA23E77ZX2HVY76YGL',
                            'Signature': '3lhK%2BwtQ9Q2u5VDIqb4MEpoY3X4%3D',
                            'Expires': '1617207304'
                        }, http_request.headers)