Example #1
0
def test_sigv4_only_region(tmpdir, monkeypatch):
    monkeypatch.setenv('AWS_REGION', 'eu-central-1')
    sigv4_check_apply()

    bucket_name = bucket_name_mangle('sigv4')
    creds = Credentials(os.getenv('AWS_ACCESS_KEY_ID'),
                        os.getenv('AWS_SECRET_ACCESS_KEY'))
    cinfo = calling_format.from_store_name(bucket_name)
    conn = cinfo.connect(creds)

    try:
        conn.create_bucket(bucket_name, location='eu-central-1')
    except boto.exception.S3CreateError:
        pass

    source = unicode(tmpdir.join('source'))
    contents = 'abcdefghijklmnopqrstuvwxyz\n' * 100
    with open(source, 'wb') as f:
        f.write(contents)

    data_url = 's3://{0}/data'.format(bucket_name)

    with open(source) as f:
        uri_put_file(creds, data_url, f)

    results = uri_get_file(creds, data_url)
    assert contents == results
Example #2
0
def test_sigv4_only_region(tmpdir, monkeypatch):
    monkeypatch.setenv('AWS_REGION', 'eu-central-1')
    sigv4_check_apply()

    bucket_name = bucket_name_mangle('sigv4')
    creds = Credentials(os.getenv('AWS_ACCESS_KEY_ID'),
                        os.getenv('AWS_SECRET_ACCESS_KEY'))
    cinfo = calling_format.from_store_name(bucket_name)
    conn = cinfo.connect(creds)

    try:
        conn.create_bucket(bucket_name, location='eu-central-1')
    except boto.exception.S3CreateError:
        pass

    source = unicode(tmpdir.join('source'))
    contents = 'abcdefghijklmnopqrstuvwxyz\n' * 100
    with open(source, 'wb') as f:
        f.write(contents)

    data_url = 's3://{0}/data'.format(bucket_name)

    with open(source) as f:
        uri_put_file(creds, data_url, f)

    results = uri_get_file(creds, data_url)
    assert contents == results
Example #3
0
    def upload_download():
        """ Test uri_put_file and uri_get_file in eu-central-1"""
        source = str(tmpdir.join('source'))
        contents = b'abcdefghijklmnopqrstuvwxyz\n' * 100
        with open(source, 'wb') as f:
            f.write(contents)

        data_url = 's3://{0}/data'.format(bucket_name)

        with open(source) as f:
            uri_put_file(creds, data_url, f)

        results = uri_get_file(creds, data_url)
        assert contents == results
Example #4
0
    def upload_download():
        """ Test uri_put_file and uri_get_file in eu-central-1"""
        source = str(tmpdir.join("source"))
        contents = b"abcdefghijklmnopqrstuvwxyz\n" * 100
        with open(source, "wb") as f:
            f.write(contents)

        data_url = "s3://{0}/data".format(bucket_name)

        with open(source) as f:
            uri_put_file(creds, data_url, f)

        results = uri_get_file(creds, data_url)
        assert contents == results
Example #5
0
def test_uri_put_file(sts_conn):
    bn = 'wal-e.sts.uri.put.file'
    cf = connection.OrdinaryCallingFormat()
    policy_text = make_policy(bn, 'test-prefix', allow_get_location=True)
    fed = sts_conn.get_federation_token('wal-e-test-uri-put-file',
                                        policy=policy_text)

    key_path = 'test-prefix/test-key'

    creds = Credentials(fed.credentials.access_key,
                        fed.credentials.secret_key,
                        fed.credentials.session_token)

    with FreshBucket(bn, keys=[key_path], calling_format=cf,
                     host='s3-us-west-1.amazonaws.com') as fb:
        fb.create(location='us-west-1')
        uri_put_file(creds, 's3://' + bn + '/' + key_path,
                     StringIO('test-content'))
        k = connection.Key(fb.conn.get_bucket(bn, validate=False))
        k.name = key_path
        assert k.get_contents_as_string() == 'test-content'
Example #6
0
def test_uri_put_file(sts_conn):
    bn = 'wal-e.sts.uri.put.file'
    cf = connection.OrdinaryCallingFormat()
    policy_text = make_policy(bn, 'test-prefix', allow_get_location=True)
    fed = sts_conn.get_federation_token('wal-e-test-uri-put-file',
                                        policy=policy_text)

    key_path = 'test-prefix/test-key'

    creds = Credentials(fed.credentials.access_key, fed.credentials.secret_key,
                        fed.credentials.session_token)

    with FreshBucket(bn,
                     keys=[key_path],
                     calling_format=cf,
                     host='s3-us-west-1.amazonaws.com') as fb:
        fb.create(location='us-west-1')
        uri_put_file(creds, 's3://' + bn + '/' + key_path,
                     StringIO('test-content'))
        k = connection.Key(fb.conn.get_bucket(bn, validate=False))
        k.name = key_path
        assert k.get_contents_as_string() == 'test-content'