Project

General

Profile

testauthenticatedread.py

Rahul Aggarwal, 09/23/2015 10:41 AM

Download (804 Bytes)

 
1
import boto
2
import requests
3
import boto.s3.connection
4
from boto import exception
5
access_key = '8d52e5231eed4a899220e7e85affd840'
6
secret_key = '03ad4895c4f9465aa57ff8d116d9eebb'
7
boto.config.add_section("Boto")
8
boto.config.set("Boto", "num_retries", "1")
9
conn = boto.connect_s3(
10
aws_access_key_id = access_key,
11
aws_secret_access_key = secret_key,
12
port=80,
13
host = 'localhost',
14
is_secure=True,
15
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
16
debug=1
17
)
18

    
19
bucket = conn.create_bucket("new_cont1")
20
bucket.set_canned_acl('authenticated-read')
21
key = bucket.new_key("one")
22
key.set_contents_from_string("testing bucket level acl")
23
url = bucket.generate_url(3600)
24
l = url.split("/")
25
url = l[0] + "/" + "/" + l[2] + "/" + l[3]
26
r = requests.get(url)
27
data = r.text
28
print data
29
assert (r.status_code == 403)
30