-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmdq.py
More file actions
99 lines (77 loc) · 2.61 KB
/
mdq.py
File metadata and controls
99 lines (77 loc) · 2.61 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
"""
pyFFd is the SAML metadata aggregator daemon
"""
from __future__ import unicode_literals
import os
import gunicorn.app.base
from six import iteritems
from pyff.api import mkapp
from pyff.constants import config, parse_options
from pyff.logs import get_log
from pyff.repo import MDRepository
log = get_log(__name__)
class MDQApplication(gunicorn.app.base.BaseApplication):
def init(self, parser, opts, args):
super().init(self, parser, opts, args)
def __init__(self, options=None):
self.options = options or {}
super(MDQApplication, self).__init__()
def load_config(self):
cfg = dict(
[(key, value) for key, value in iteritems(self.options) if key in self.cfg.settings and value is not None]
)
for key, value in iteritems(cfg):
self.cfg.set(key.lower(), value)
def load(self):
return mkapp(config.pipeline, md=MDRepository())
def main():
"""
The (new) main entrypoint for the pyffd command.
"""
args = parse_options("pyffd", __doc__)
if config.base_dir:
os.chdir(config.base_dir)
options = {
'bind': '{}:{}'.format(config.host, config.port),
'workers': config.worker_pool_size,
'loglevel': config.loglevel,
'preload_app': True,
'env': config.environ,
'daemon': config.daemonize,
'capture_output': False,
'timeout': config.worker_timeout,
'worker_class': 'gthread',
'worker_tmp_dir': '/dev/shm',
'threads': config.threads,
}
if config.pid_file:
options['pidfile'] = config.pid_file
if args:
config.pipeline = args[0]
if config.logger:
options['logconfig'] = config.logger
else:
options['logconfig_dict'] = {
'version': 1,
'formatters': {
'default': {'format': '%(asctime)s %(levelname)s %(name)s %(message)s', 'datefmt': '%Y-%m-%d %H:%M:%S'}
},
'filters': {},
'loggers': {
'root': {'handlers': ['console'], 'level': config.loglevel},
'pyff': {'handlers': ['console'], 'propagate': False, 'level': config.loglevel},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'default',
'level': config.loglevel,
'stream': 'ext://sys.stderr',
}
},
}
if config.aliases is not None:
config.aliases['metadata'] = 'entities'
MDQApplication(options).run()
if __name__ == "__main__":
main()