MCPcopy Create free account
hub / github.com/StackStorm/st2 / setup_app

Function setup_app

st2stream/st2stream/app.py:44–92  ·  view source on GitHub ↗
(config={})

Source from the content-addressed store, hash-verified

42
43
44def setup_app(config={}):
45 LOG.info("Creating st2stream: %s as OpenAPI app.", VERSION_STRING)
46
47 is_gunicorn = config.get("is_gunicorn", False)
48 if is_gunicorn:
49
50 st2stream_config.register_opts(ignore_errors=True)
51 capabilities = {
52 "name": "stream",
53 "listen_host": cfg.CONF.stream.host,
54 "listen_port": cfg.CONF.stream.port,
55 "type": "active",
56 }
57 # This should be called in gunicorn case because we only want
58 # workers to connect to db, rabbbitmq etc. In standalone HTTP
59 # server case, this setup would have already occurred.
60 common_setup(
61 service="stream",
62 config=st2stream_config,
63 setup_db=True,
64 register_mq_exchanges=True,
65 register_signal_handlers=True,
66 register_internal_trigger_types=False,
67 run_migrations=False,
68 service_registry=True,
69 capabilities=capabilities,
70 config_args=config.get("config_args", None),
71 )
72
73 router = Router(
74 debug=cfg.CONF.stream.debug, auth=cfg.CONF.auth.enable, is_gunicorn=is_gunicorn
75 )
76
77 spec = spec_loader.load_spec("st2common", "openapi.yaml.j2")
78 transforms = {"^/stream/v1/": ["/", "/v1/"]}
79 router.add_spec(spec, transforms=transforms)
80
81 app = router.as_wsgi
82
83 # Order is important. Check middleware for detailed explanation.
84 app = StreamingMiddleware(app)
85 app = ErrorHandlingMiddleware(app)
86 app = CorsMiddleware(app)
87 app = LoggingMiddleware(app, router)
88 app = ResponseInstrumentationMiddleware(app, router, service_name="stream")
89 app = RequestIDMiddleware(app)
90 app = RequestInstrumentationMiddleware(app, router, service_name="stream")
91
92 return app

Callers

nothing calls this directly

Calls 10

add_specMethod · 0.95
RouterClass · 0.90
StreamingMiddlewareClass · 0.90
CorsMiddlewareClass · 0.90
LoggingMiddlewareClass · 0.90
RequestIDMiddlewareClass · 0.90
getMethod · 0.45

Tested by

no test coverage detected