-
Notifications
You must be signed in to change notification settings - Fork 29
/
auth_server.py
37 lines (29 loc) · 943 Bytes
/
auth_server.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
import hashlib
import json
import os
import os.path
import sys
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import tornado.ioloop
import tornado.web
import upyun
USERNAME = os.getenv('UPYUN_USERNAME') or 'username'
PASSWORD = os.getenv('UPYUN_PASSWORD') or 'password'
class MainHandler(tornado.web.RequestHandler):
def post(self):
data = json.loads(self.request.body.decode())
if data.get('username') == USERNAME:
data['password'] = hashlib.md5(PASSWORD.encode()).hexdigest()
signature = upyun.make_signature(**data)
print(signature)
self.write(signature)
else:
print('Unknow username:', data.get('username'))
def make_app():
return tornado.web.Application([
(r'/', MainHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8080)
tornado.ioloop.IOLoop.current().start()