(config=None)
| 34 | |
| 35 | |
| 36 | def 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 |
nothing calls this directly
no test coverage detected