forked from cidrblock/td4a
-
Notifications
You must be signed in to change notification settings - Fork 0
/
td4a-server
executable file
·58 lines (55 loc) · 2.21 KB
/
td4a-server
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
#! /usr/bin/env python
from td4a import app
from td4a.models.filters import filters_load
from td4a.models.inventory import inventory_load
from argparse import ArgumentParser, RawTextHelpFormatter
import os
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.wsgi import WSGIResource
def parse_args():
""" parse the cli args and add environ
"""
parser = ArgumentParser(description='',
formatter_class=RawTextHelpFormatter)
parser.add_argument('-f', action="store", dest="custom_filters",
required=False,
help="A folder containing custom filters.")
parser.add_argument('-i', action="append", dest="inventory_source",
required=False,
help="A folder containing the inventory.")
parser.add_argument('-v', action="store", dest="vault_secret",
required=False,
help="A vault secret.")
parser.add_argument('-m', action="store", dest="ui_mode",
choices=['jinja', 'schema'],
required=False,
default='jinja',
help="The mode for the UI. (default: jinja)")
args = parser.parse_args()
args.username = os.environ.get('COUCH_USERNAME', False)
args.password = os.environ.get('COUCH_PASSWORD', False)
args.url = os.environ.get('COUCH_URL', False)
return args
def main():
print "Loading..."
app.args = parse_args()
app.filters = filters_load(app.args.custom_filters)
if app.args.inventory_source:
app.inventory = inventory_load(inventory_sources=app.args.inventory_source,
vault_secret=app.args.vault_secret)
reactor_args = {}
app.debug = False
def wsgi():
resource = WSGIResource(reactor, reactor.getThreadPool(), app)
site = Site(resource)
reactor.listenTCP(5000, site)
reactor.run(**reactor_args)
if app.debug:
reactor_args['installSignalHandlers'] = 0
import werkzeug.serving
wsgi = werkzeug.serving.run_with_reloader(wsgi)
print "Ready."
wsgi()
if __name__ == '__main__':
main()