-
Notifications
You must be signed in to change notification settings - Fork 1
/
central.py
executable file
·57 lines (45 loc) · 2.17 KB
/
central.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
#!/usr/bin/env python
# @author: Kevin S. Hahn
# Gunnar Schaefer
"""Scitran Central peer registry."""
import logging
logging.basicConfig(
format='%(asctime)s %(name)16.16s:%(levelname)4.4s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.DEBUG,
)
log = logging.getLogger('central')
logging.getLogger('requests').setLevel(logging.WARNING) # silence Requests library logging
logging.getLogger('MARKDOWN').setLevel(logging.WARNING) # silence Mardkwon library logging
import webapp2
import webapp2_extras.routes
import core
import remotes
import instances
routes = [
webapp2.Route(r'/api', core.Core),
webapp2.Route(r'/api/instances', instances.Instances),
webapp2_extras.routes.PathPrefixRoute(r'/api/instances', [
webapp2.Route(r'/schema', instances.Instance, handler_method='schema', methods=['GET']),
webapp2.Route(r'/<_id>', instances.Instance, methods=['GET', 'PUT']),
]),
webapp2.Route(r'/api/remotes', remotes.Remotes),
]
app = webapp2.WSGIApplication(routes)
if __name__ == '__main__':
import pymongo
import argparse
import paste.httpserver
arg_parser = argparse.ArgumentParser()
arg_parser.add_argument('ssl_cert', help-'scitran central ssl cert, containing key and certificate, in pem format')
arg_parser.add_argument('--db_uri', help='internims DB URI [mongodb://127.0.0.1/central]', default='mongodb://127.0.0.1/central')
arg_parser.add_argument('--log_level', help='logging level [info]', default='info')
args = arg_parser.parse_args()
logging.getLogger('paste.httpserver').setLevel(logging.INFO) # silence paste loggin
log.setLevel(getattr(logging, args.log_level.upper()))
kwargs = dict(tz_aware=True)
db_client = pymongo.MongoReplicaSetClient(args.db_uri, **kwargs) if 'replicaSet' in args.db_uri else pymongo.MongoClient(args.db_uri, **kwargs)
app.db = db_client.get_default_database()
app.ssl_cert = args.ssl_cert
app.debug = True
paste.httpserver.serve(app, port='8080')