-
Notifications
You must be signed in to change notification settings - Fork 8
/
quicklook_server.py
78 lines (52 loc) · 1.97 KB
/
quicklook_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
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
69
70
71
72
73
74
75
76
77
78
import json
import os
import sys
from jinja2 import Environment, FileSystemLoader
import tornado.autoreload
import tornado.ioloop
import tornado.web
class BaseHandler(tornado.web.RequestHandler):
def enrich(self, context):
pass
def get(self):
template = templates.get_template(self.template)
context = json.loads(self.get_argument('context', '{}'))
self.enrich(context)
self.write(template.render(**context))
class Ec2QuicklookHandler(BaseHandler):
template = 'ec2.html.j2'
class S3QuicklookHandler(BaseHandler):
template = 's3.html.j2'
class RdsQuicklookHandler(BaseHandler):
template = 'rds.html.j2'
class CfnQuicklookHandler(BaseHandler):
template = 'cfn.html.j2'
class SqsQuicklookHandler(BaseHandler):
template = 'sqs.html.j2'
class RedshiftClusterQuicklookHandler(BaseHandler):
template = 'redshift.html.j2'
class LambdaQuicklookHandler(BaseHandler):
template = 'lambda.html.j2'
class EbQuicklookHandler(BaseHandler):
template = 'eb.html.j2'
class LogGroupQuicklookHandler(BaseHandler):
template = 'logs.html.j2'
def make_app():
return tornado.web.Application([
(r'/static/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(os.getcwd(), 'static')}),
(r'/quicklook/ec2', Ec2QuicklookHandler),
(r'/quicklook/s3', S3QuicklookHandler),
(r'/quicklook/rds', RdsQuicklookHandler),
(r'/quicklook/cfn', CfnQuicklookHandler),
(r'/quicklook/sqs', SqsQuicklookHandler),
(r'/quicklook/redshift', RedshiftClusterQuicklookHandler),
(r'/quicklook/lambda', LambdaQuicklookHandler),
(r'/quicklook/eb', EbQuicklookHandler),
(r'/quicklook/logs', LogGroupQuicklookHandler),
])
if __name__ == '__main__':
templates = Environment(loader=FileSystemLoader(os.path.join(os.getcwd(), 'templates')))
app = make_app()
app.listen(int(sys.argv[1]))
tornado.autoreload.start()
tornado.ioloop.IOLoop.current().start()