summaryrefslogtreecommitdiff
path: root/s3/gen_policy.py
blob: 4d0180c54ec35f01d82b61a077ed5f718ec153af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import base64
import hmac, hashlib

POLICY = """{"expiration": "2012-01-01T00:00:00Z",
  "conditions": [
    {"bucket": "AWS_BUCKET_NAME"}, 
    ["starts-with", "$key", "uploads/"],
    {"acl": "private"},
    {"success_action_redirect": "/"},
    ["starts-with", "$Content-Type", ""],
    ["content-length-range", 0, 1048576]
  ]
}"""

KEY = "AWS_SECRET_KEY"

policy = base64.b64encode(POLICY)

sig = base64.b64encode(hmac.new(KEY, policy, hashlib.sha1).digest())

print sig