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

Function setup_app

st2api/st2api/app.py:37–97  ·  view source on GitHub ↗
(config=None)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 12

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