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
# the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os from oslo_config import cfg from st2common.util.monkey_patch import use_select_poll_workaround use_select_poll_workaround() from st2common.content.bootstrap import register_content from st2common.persistence.pack import Pack from st2common.persistence.pack import Config from st2common.persistence.pack import ConfigSchema from st2common.persistence.actionalias import ActionAlias from st2common.persistence.action import Action from st2common.persistence.rule import Rule from st2common.persistence.policy import Policy from st2common.persistence.sensor import SensorType as Sensor from st2common.persistence.trigger import TriggerType from st2tests.base import BaseActionTestCase from st2tests.base import CleanDbTestCase from st2tests import fixturesloader
from st2common.persistence.db_init import db_setup_with_retry from st2common.util import loader from st2common.util.config_loader import ContentPackConfigLoader from st2common.services.triggerwatcher import TriggerWatcher from st2common.services.trigger_dispatcher import TriggerDispatcherService from st2reactor.sensor.base import Sensor from st2reactor.sensor.base import PollingSensor from st2reactor.sensor import config from st2common.services.datastore import SensorDatastoreService from st2common.util.monkey_patch import monkey_patch from st2common.util.monkey_patch import use_select_poll_workaround __all__ = ['SensorWrapper', 'SensorService'] monkey_patch() use_select_poll_workaround(nose_only=False) class SensorService(object): """ Instance of this class is passed to the sensor instance and exposes "public" methods which can be called by the sensor. """ def __init__(self, sensor_wrapper): self._sensor_wrapper = sensor_wrapper self._logger = self._sensor_wrapper._logger self._trigger_dispatcher_service = TriggerDispatcherService( logger=sensor_wrapper._logger) self._datastore_service = SensorDatastoreService( logger=self._logger,
from st2common.services.triggerwatcher import TriggerWatcher from st2reactor.sensor.base import Sensor from st2reactor.sensor.base import PollingSensor from st2reactor.sensor import config from st2common.services.datastore import SensorDatastoreService from st2common.validators.api.reactor import validate_trigger_payload from st2common.util.monkey_patch import monkey_patch from st2common.util.monkey_patch import use_select_poll_workaround __all__ = [ 'SensorWrapper', 'SensorService' ] monkey_patch() use_select_poll_workaround(nose_only=False) class SensorService(object): """ Instance of this class is passed to the sensor instance and exposes "public" methods which can be called by the sensor. """ def __init__(self, sensor_wrapper): self._sensor_wrapper = sensor_wrapper self._logger = self._sensor_wrapper._logger self._dispatcher = TriggerDispatcher(self._logger) self._datastore_service = SensorDatastoreService( logger=self._logger, pack_name=self._sensor_wrapper._pack,
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import os from oslo_config import cfg from st2common.util.monkey_patch import use_select_poll_workaround use_select_poll_workaround() from st2common.content.bootstrap import register_content from st2common.persistence.pack import Pack from st2common.persistence.pack import Config from st2common.persistence.pack import ConfigSchema from st2common.persistence.actionalias import ActionAlias from st2common.persistence.action import Action from st2common.persistence.rule import Rule from st2common.persistence.policy import Policy from st2common.persistence.sensor import SensorType as Sensor from st2common.persistence.trigger import TriggerType from st2tests.base import BaseActionTestCase from st2tests.base import CleanDbTestCase from st2tests import fixturesloader