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

Function setup_app

st2auth/st2auth/app.py:36–92  ·  view source on GitHub ↗
(config=None)

Source from the content-addressed store, hash-verified

34
35
36def setup_app(config=None):
37 config = config or {}
38
39 LOG.info("Creating st2auth: %s as OpenAPI app.", VERSION_STRING)
40
41 is_gunicorn = config.get("is_gunicorn", False)
42 if is_gunicorn:
43 # NOTE: We only want to perform this logic in the WSGI worker
44 st2auth_config.register_opts(ignore_errors=True)
45 capabilities = {
46 "name": "auth",
47 "listen_host": cfg.CONF.auth.host,
48 "listen_port": cfg.CONF.auth.port,
49 "listen_ssl": cfg.CONF.auth.use_ssl,
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="auth",
58 config=st2auth_config,
59 setup_db=True,
60 register_mq_exchanges=False,
61 register_signal_handlers=True,
62 register_internal_trigger_types=False,
63 run_migrations=False,
64 service_registry=True,
65 capabilities=capabilities,
66 config_args=config.get("config_args", None),
67 )
68
69 # pysaml2 uses subprocess communicate which calls communicate_with_poll
70 if cfg.CONF.auth.sso and cfg.CONF.auth.sso_backend == "saml2":
71 use_select_poll_workaround(nose_only=False)
72
73 # Additional pre-run time checks
74 validate_auth_backend_is_correctly_configured()
75
76 router = Router(debug=cfg.CONF.auth.debug, is_gunicorn=is_gunicorn)
77
78 spec = spec_loader.load_spec("st2common", "openapi.yaml.j2")
79 transforms = {"^/auth/v1/": ["/", "/v1/"]}
80 router.add_spec(spec, transforms=transforms)
81
82 app = router.as_wsgi
83
84 # Order is important. Check middleware for detailed explanation.
85 app = ErrorHandlingMiddleware(app)
86 app = CorsMiddleware(app)
87 app = LoggingMiddleware(app, router)
88 app = ResponseInstrumentationMiddleware(app, router, service_name="auth")
89 app = RequestIDMiddleware(app)
90 app = RequestInstrumentationMiddleware(app, router, service_name="auth")
91
92 return app

Callers

nothing calls this directly

Calls 11

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

Tested by

no test coverage detected