-
Notifications
You must be signed in to change notification settings - Fork 0
/
amazon-proxy.py
69 lines (50 loc) · 1.91 KB
/
amazon-proxy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# vim: set fileencoding=utf-8
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.api import urlfetch
import re
import time
import urllib
import ConfigParser
import paapi as am
# hashlib.sha256(message).hexdigest()
def config():
c = ConfigParser.ConfigParser()
c.read('amazon-proxy.ini')
c.access_key = lambda: c.get('amazon-proxy', 'access_key')
c.secret_key = lambda: c.get('amazon-proxy', 'secret_key')
c.entry_point = lambda: c.get('amazon-proxy', 'entry_point')
c.default_aid = lambda: c.get('amazon-proxy', 'default_aid')
return c
class MainPage(webapp.RequestHandler):
def get(self):
params = self.request.GET
newparams = []
conf = config()
for (key, value) in params.iteritems():
if key in ("AWSAccessKeyId","SubscriptionId"):
newparams.append((key, conf.access_key()))
elif key in ('Timestamp', 'Signature'):
# ignore this key
pass
else:
newparams.append((key, value))
if not params.has_key('AssociateTag'):
newparams.append(('AssociateTag', conf.default_aid()))
newparams.append(('Timestamp',
time.strftime('%Y-%m-%dT%XZ', time.gmtime())))
url = am.encode(newparams, conf.secret_key())
self.response.headers['Content-Type'] = 'text/xml; charset=utf-8'
result = urlfetch.fetch(url)
if result.status_code == 200:
self.response.out.write(result.content)
else:
self.response.set_status(result.status_code)
self.response.out.write(result.content)
application = webapp.WSGIApplication(
[('/.*', MainPage)],
debug=False)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()