Exemple #1
0
def setup_app(config=None):
    LOG.info('Creating st2auth: %s as Pecan app.', VERSION_STRING)

    is_gunicorn = getattr(config, 'is_gunicorn', False)
    if is_gunicorn:
        # This should be called in gunicorn case because we only want
        # workers to connect to db, rabbbitmq etc. In standalone HTTP
        # server case, this setup would have already occurred.
        st2auth_config.register_opts()
        common_setup(service='auth', config=st2auth_config, setup_db=True,
                     register_mq_exchanges=False,
                     register_signal_handlers=True,
                     register_internal_trigger_types=False,
                     run_migrations=False,
                     config_args=config.config_args)

    if not config:
        # standalone HTTP server case
        config = _get_pecan_config()
    else:
        # gunicorn case
        if is_gunicorn:
            config.app = _get_pecan_config().app

    app_conf = dict(config.app)

    app = pecan.make_app(
        app_conf.pop('root'),
        logging=getattr(config, 'logging', {}),
        hooks=[hooks.JSONErrorResponseHook(), hooks.CorsHook()],
        **app_conf
    )
    LOG.info('%s app created.' % __name__)

    return app
Exemple #2
0
def setup_app(config=None):
    config = config or {}

    LOG.info("Creating st2auth: %s as OpenAPI app.", VERSION_STRING)

    is_gunicorn = config.get("is_gunicorn", False)
    if is_gunicorn:
        # NOTE: We only want to perform this logic in the WSGI worker
        st2auth_config.register_opts(ignore_errors=True)
        capabilities = {
            "name": "auth",
            "listen_host": cfg.CONF.auth.host,
            "listen_port": cfg.CONF.auth.port,
            "listen_ssl": cfg.CONF.auth.use_ssl,
            "type": "active",
        }

        # This should be called in gunicorn case because we only want
        # workers to connect to db, rabbbitmq etc. In standalone HTTP
        # server case, this setup would have already occurred.
        common_setup(
            service="auth",
            config=st2auth_config,
            setup_db=True,
            register_mq_exchanges=False,
            register_signal_handlers=True,
            register_internal_trigger_types=False,
            run_migrations=False,
            service_registry=True,
            capabilities=capabilities,
            config_args=config.get("config_args", None),
        )

        # pysaml2 uses subprocess communicate which calls communicate_with_poll
        if cfg.CONF.auth.sso and cfg.CONF.auth.sso_backend == "saml2":
            use_select_poll_workaround(nose_only=False)

    # Additional pre-run time checks
    validate_auth_backend_is_correctly_configured()

    router = Router(debug=cfg.CONF.auth.debug, is_gunicorn=is_gunicorn)

    spec = spec_loader.load_spec("st2common", "openapi.yaml.j2")
    transforms = {"^/auth/v1/": ["/", "/v1/"]}
    router.add_spec(spec, transforms=transforms)

    app = router.as_wsgi

    # Order is important. Check middleware for detailed explanation.
    app = ErrorHandlingMiddleware(app)
    app = CorsMiddleware(app)
    app = LoggingMiddleware(app, router)
    app = ResponseInstrumentationMiddleware(app, router, service_name="auth")
    app = RequestIDMiddleware(app)
    app = RequestInstrumentationMiddleware(app, router, service_name="auth")

    return app
Exemple #3
0
def setup_app(config={}):
    LOG.info('Creating st2auth: %s as OpenAPI app.', VERSION_STRING)

    is_gunicorn = config.get('is_gunicorn', False)
    if is_gunicorn:
        # Note: We need to perform monkey patching in the worker. If we do it in
        # the master process (gunicorn_config.py), it breaks tons of things
        # including shutdown
        monkey_patch()

        st2auth_config.register_opts()
        capabilities = {
            'name': 'auth',
            'listen_host': cfg.CONF.auth.host,
            'listen_port': cfg.CONF.auth.port,
            'listen_ssl': cfg.CONF.auth.use_ssl,
            'type': 'active'
        }

        # This should be called in gunicorn case because we only want
        # workers to connect to db, rabbbitmq etc. In standalone HTTP
        # server case, this setup would have already occurred.
        common_setup(service='auth', config=st2auth_config, setup_db=True,
                     register_mq_exchanges=False,
                     register_signal_handlers=True,
                     register_internal_trigger_types=False,
                     run_migrations=False,
                     service_registry=True,
                     capabilities=capabilities,
                     config_args=config.get('config_args', None))

    # Additional pre-run time checks
    validate_auth_backend_is_correctly_configured()

    router = Router(debug=cfg.CONF.auth.debug, is_gunicorn=is_gunicorn)

    spec = spec_loader.load_spec('st2common', 'openapi.yaml.j2')
    transforms = {
        '^/auth/v1/': ['/', '/v1/']
    }
    router.add_spec(spec, transforms=transforms)

    app = router.as_wsgi

    # Order is important. Check middleware for detailed explanation.
    app = ErrorHandlingMiddleware(app)
    app = CorsMiddleware(app)
    app = LoggingMiddleware(app, router)
    app = ResponseInstrumentationMiddleware(app, router, service_name='auth')
    app = RequestIDMiddleware(app)
    app = RequestInstrumentationMiddleware(app, router, service_name='auth')

    return app
Exemple #4
0
def setup_app(config=None):
    LOG.info('Creating st2auth: %s as Pecan app.', VERSION_STRING)

    is_gunicorn = getattr(config, 'is_gunicorn', False)
    if is_gunicorn:
        # Note: We need to perform monkey patching in the worker. If we do it in
        # the master process (gunicorn_config.py), it breaks tons of things
        # including shutdown
        monkey_patch()

        # This should be called in gunicorn case because we only want
        # workers to connect to db, rabbbitmq etc. In standalone HTTP
        # server case, this setup would have already occurred.
        st2auth_config.register_opts()
        common_setup(service='auth',
                     config=st2auth_config,
                     setup_db=True,
                     register_mq_exchanges=False,
                     register_signal_handlers=True,
                     register_internal_trigger_types=False,
                     run_migrations=False,
                     config_args=config.config_args)

    if not config:
        # standalone HTTP server case
        config = _get_pecan_config()
    else:
        # gunicorn case
        if is_gunicorn:
            config.app = _get_pecan_config().app

    app_conf = dict(config.app)

    app = pecan.make_app(app_conf.pop('root'),
                         logging=getattr(config, 'logging', {}),
                         hooks=[
                             hooks.JSONErrorResponseHook(),
                             hooks.CorsHook(),
                             hooks.AuthHook()
                         ],
                         **app_conf)
    LOG.info('%s app created.' % __name__)

    return app
Exemple #5
0
def setup_app(config={}):
    LOG.info('Creating st2auth: %s as OpenAPI app.', VERSION_STRING)

    is_gunicorn = config.get('is_gunicorn', False)
    if is_gunicorn:
        # Note: We need to perform monkey patching in the worker. If we do it in
        # the master process (gunicorn_config.py), it breaks tons of things
        # including shutdown
        monkey_patch()

        # This should be called in gunicorn case because we only want
        # workers to connect to db, rabbbitmq etc. In standalone HTTP
        # server case, this setup would have already occurred.
        st2auth_config.register_opts()
        common_setup(service='auth',
                     config=st2auth_config,
                     setup_db=True,
                     register_mq_exchanges=False,
                     register_signal_handlers=True,
                     register_internal_trigger_types=False,
                     run_migrations=False,
                     config_args=config.get('config_args', None))

    router = Router(debug=cfg.CONF.auth.debug)

    spec = spec_loader.load_spec('st2common', 'openapi.yaml')
    transforms = {'^/auth/v1/': ['/', '/v1/']}
    router.add_spec(spec, transforms=transforms)

    app = router.as_wsgi

    app = CorsMiddleware(app)
    app = LoggingMiddleware(app, router)
    app = ErrorHandlingMiddleware(app)
    app = RequestIDMiddleware(app)

    return app
Exemple #6
0
# limitations under the License.

import eventlet
import os
import sys

from oslo_config import cfg
from eventlet import wsgi

from st2common import log as logging
from st2common.service_setup import setup as common_setup
from st2common.service_setup import teardown as common_teardown
from st2common.util.monkey_patch import monkey_patch
from st2common.constants.auth import VALID_MODES
from st2auth import config
config.register_opts()
from st2auth import app

__all__ = [
    'main'
]

monkey_patch()

LOG = logging.getLogger(__name__)


def _setup():
    common_setup(service='auth', config=config, setup_db=True, register_mq_exchanges=False,
                 register_signal_handlers=True, register_internal_trigger_types=False,
                 run_migrations=False)
Exemple #7
0
# limitations under the License.

import eventlet
import os
import sys

from oslo_config import cfg
from eventlet import wsgi

from st2common import log as logging
from st2common.service_setup import setup as common_setup
from st2common.service_setup import teardown as common_teardown
from st2common.util.monkey_patch import monkey_patch
from st2common.constants.auth import VALID_MODES
from st2auth import config
config.register_opts()
from st2auth import app

__all__ = ['main']

monkey_patch()

LOG = logging.getLogger(__name__)


def _setup():
    common_setup(service='auth',
                 config=config,
                 setup_db=True,
                 register_mq_exchanges=False,
                 register_signal_handlers=True,
Exemple #8
0
monkey_patch()

import eventlet
import os
import sys

from oslo_config import cfg
from eventlet import wsgi

from st2common import log as logging
from st2common.service_setup import setup as common_setup
from st2common.service_setup import teardown as common_teardown
from st2common.service_setup import deregister_service
from st2auth import config

config.register_opts(ignore_errors=True)

from st2auth import app
from st2auth.validation import validate_auth_backend_is_correctly_configured

__all__ = ["main"]

LOG = logging.getLogger(__name__)
AUTH = "auth"


def _setup():
    capabilities = {
        "name": "auth",
        "listen_host": cfg.CONF.auth.host,
        "listen_port": cfg.CONF.auth.port,