コード例 #1
0
ファイル: app.py プロジェクト: st2sandbox/st2
def setup_app(config=None):
    config = config or {}

    LOG.info("Creating st2api: %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
        st2api_config.register_opts(ignore_errors=True)
        capabilities = {
            "name": "api",
            "listen_host": cfg.CONF.api.host,
            "listen_port": cfg.CONF.api.port,
            "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="api",
            config=st2api_config,
            setup_db=True,
            register_mq_exchanges=True,
            register_signal_handlers=True,
            register_internal_trigger_types=True,
            run_migrations=True,
            service_registry=True,
            capabilities=capabilities,
            config_args=config.get("config_args", None),
        )

    # Additional pre-run time checks
    validate_rbac_is_correctly_configured()

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

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

    app = router.as_wsgi

    # Order is important. Check middleware for detailed explanation.
    app = StreamingMiddleware(app, path_whitelist=["/v1/executions/*/output*"])
    app = ErrorHandlingMiddleware(app)
    app = CorsMiddleware(app)
    app = LoggingMiddleware(app, router)
    app = ResponseInstrumentationMiddleware(app, router, service_name="api")
    app = RequestIDMiddleware(app)
    app = RequestInstrumentationMiddleware(app, router, service_name="api")

    return app
コード例 #2
0
def setup_app(config={}):
    LOG.info('Creating st2api: %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()

        st2api_config.register_opts()
        capabilities = {
            'name': 'api',
            'listen_host': cfg.CONF.api.host,
            'listen_port': cfg.CONF.api.port,
            '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='api',
                     config=st2api_config,
                     setup_db=True,
                     register_mq_exchanges=True,
                     register_signal_handlers=True,
                     register_internal_trigger_types=True,
                     run_migrations=True,
                     service_registry=True,
                     capabilities=capabilities,
                     config_args=config.get('config_args', None))

    # Additional pre-run time checks
    validate_rbac_is_correctly_configured()

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

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

    app = router.as_wsgi

    # Order is important. Check middleware for detailed explanation.
    app = StreamingMiddleware(app, path_whitelist=['/v1/executions/*/output*'])
    app = ErrorHandlingMiddleware(app)
    app = CorsMiddleware(app)
    app = LoggingMiddleware(app, router)
    app = ResponseInstrumentationMiddleware(app, router, service_name='api')
    app = RequestIDMiddleware(app)
    app = RequestInstrumentationMiddleware(app, router, service_name='api')

    return app
コード例 #3
0
ファイル: app.py プロジェクト: nzlosh/st2
def setup_app(config={}):
    LOG.info('Creating st2api: %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()

        st2api_config.register_opts()
        capabilities = {
            'name': 'api',
            'listen_host': cfg.CONF.api.host,
            'listen_port': cfg.CONF.api.port,
            '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='api', config=st2api_config, setup_db=True,
                     register_mq_exchanges=True,
                     register_signal_handlers=True,
                     register_internal_trigger_types=True,
                     run_migrations=True,
                     service_registry=True,
                     capabilities=capabilities,
                     config_args=config.get('config_args', None))

    # Additional pre-run time checks
    validate_rbac_is_correctly_configured()

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

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

    app = router.as_wsgi

    # Order is important. Check middleware for detailed explanation.
    app = StreamingMiddleware(app, path_whitelist=['/v1/executions/*/output*'])
    app = ErrorHandlingMiddleware(app)
    app = CorsMiddleware(app)
    app = LoggingMiddleware(app, router)
    app = ResponseInstrumentationMiddleware(app, router, service_name='api')
    app = RequestIDMiddleware(app)
    app = RequestInstrumentationMiddleware(app, router, service_name='api')

    return app
コード例 #4
0
ファイル: app.py プロジェクト: yuemanxilou/st2
def setup_app(config=None):
    LOG.info('Creating st2api: %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()

        st2api_config.register_opts()
        # 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='api',
                     config=st2api_config,
                     setup_db=True,
                     register_mq_exchanges=True,
                     register_signal_handlers=True,
                     register_internal_trigger_types=True,
                     run_migrations=True,
                     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)

    active_hooks = [
        hooks.RequestIDHook(),
        hooks.JSONErrorResponseHook(),
        hooks.LoggingHook()
    ]

    active_hooks.append(hooks.AuthHook())
    active_hooks.append(hooks.CorsHook())

    app = pecan.make_app(app_conf.pop('root'),
                         logging=getattr(config, 'logging', {}),
                         hooks=active_hooks,
                         **app_conf)

    # Static middleware which servers common static assets such as logos
    static_root = os.path.join(BASE_DIR, 'public')
    app = StaticFileMiddleware(app=app, directory=static_root)

    LOG.info('%s app created.' % __name__)

    return app
コード例 #5
0
ファイル: app.py プロジェクト: Bala96/st2
def setup_app(config=None):
    LOG.info('Creating st2api: %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()

        st2api_config.register_opts()
        # 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='api', config=st2api_config, setup_db=True,
                     register_mq_exchanges=True,
                     register_signal_handlers=True,
                     register_internal_trigger_types=True,
                     run_migrations=True,
                     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)

    active_hooks = [hooks.RequestIDHook(), hooks.JSONErrorResponseHook(),
                    hooks.LoggingHook()]

    if cfg.CONF.auth.enable:
        active_hooks.append(hooks.AuthHook())

    active_hooks.append(hooks.CorsHook())

    app = pecan.make_app(app_conf.pop('root'),
                         logging=getattr(config, 'logging', {}),
                         hooks=active_hooks,
                         **app_conf
                         )

    # Static middleware which servers common static assets such as logos
    static_root = os.path.join(BASE_DIR, 'public')
    app = StaticFileMiddleware(app=app, directory=static_root)

    LOG.info('%s app created.' % __name__)

    return app
コード例 #6
0
ファイル: app.py プロジェクト: amitnavindgi/st2
def setup_app(config=None):
    LOG.info("Creating st2api: %s as Pecan app.", VERSION_STRING)

    is_gunicorn = getattr(config, "is_gunicorn", False)
    if is_gunicorn:
        st2api_config.register_opts()
        # 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="api",
            config=st2api_config,
            setup_db=True,
            register_mq_exchanges=True,
            register_signal_handlers=True,
            register_internal_trigger_types=True,
            run_migrations=True,
            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)

    active_hooks = [hooks.RequestIDHook(), hooks.JSONErrorResponseHook(), hooks.LoggingHook()]

    if cfg.CONF.auth.enable:
        active_hooks.append(hooks.AuthHook())

    active_hooks.append(hooks.CorsHook())

    app = pecan.make_app(app_conf.pop("root"), logging=getattr(config, "logging", {}), hooks=active_hooks, **app_conf)

    # Static middleware which servers common static assets such as logos
    static_root = os.path.join(BASE_DIR, "public")
    app = StaticFileMiddleware(app=app, directory=static_root)

    LOG.info("%s app created." % __name__)

    return app
コード例 #7
0
def setup_app(config={}):
    LOG.info('Creating st2api: %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()

        st2api_config.register_opts()
        # 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='api',
                     config=st2api_config,
                     setup_db=True,
                     register_mq_exchanges=True,
                     register_signal_handlers=True,
                     register_internal_trigger_types=True,
                     run_migrations=True,
                     config_args=config.get('config_args', None))

    # Additional pre-run time checks
    validate_rbac_is_correctly_configured()

    router = Router(debug=cfg.CONF.api.debug, auth=cfg.CONF.auth.enable)

    spec = spec_loader.load_spec('st2common', 'openapi.yaml')
    transforms = {
        '^/api/v1/': ['/', '/v1/'],
        '^/api/v1/executions': ['/actionexecutions', '/v1/actionexecutions'],
        '^/api/exp/': ['/exp/']
    }
    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
コード例 #8
0
ファイル: api.py プロジェクト: StackStorm/st2
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import sys

import eventlet
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 st2api import config
config.register_opts()
from st2api import app

from st2api.validation import validate_rbac_is_correctly_configured

__all__ = [
    'main'
]

monkey_patch()

LOG = logging.getLogger(__name__)

# How much time to give to the request in progress to finish in seconds before killing them
WSGI_SERVER_REQUEST_SHUTDOWN_TIME = 2
コード例 #9
0
ファイル: api.py プロジェクト: shivankittech/st2
# See https://github.com/StackStorm/st2/issues/4832 and https://github.com/gevent/gevent/issues/1016
# for details.
from st2common.util.monkey_patch import monkey_patch

monkey_patch()

import eventlet
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 st2api import config

config.register_opts()
from st2api import app

from st2api.validation import validate_rbac_is_correctly_configured

__all__ = ["main"]

LOG = logging.getLogger(__name__)

# How much time to give to the request in progress to finish in seconds before killing them
WSGI_SERVER_REQUEST_SHUTDOWN_TIME = 2


def _setup():
    capabilities = {
        "name": "api",
コード例 #10
0
ファイル: api.py プロジェクト: wingiti/st2
# for details.
from st2common.util.monkey_patch import monkey_patch

monkey_patch()

import eventlet
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 st2api import config

config.register_opts(ignore_errors=True)

from st2api import app
from st2api.validation import validate_rbac_is_correctly_configured

__all__ = ["main"]

LOG = logging.getLogger(__name__)
API = "api"

# How much time to give to the request in progress to finish in seconds before killing them
WSGI_SERVER_REQUEST_SHUTDOWN_TIME = 2


def _setup():
    capabilities = {