예제 #1
0
    def _init_wsgi_app(self,
                       service_name,
                       api_spec_dir=None,
                       api_spec_file=None):
        """
        Return an initialized service with common api resource and auth config
        :return:
        """

        try:
            self._application = connexion.FlaskApp(
                __name__, specification_dir=api_spec_dir)
            flask_app = self._application.app
            flask_app.url_map.strict_slashes = False

            # Setup some debug logging
            import logging as py_logging
            py_logging.basicConfig(level=py_logging.ERROR)

            # Intialize the authentication system
            self.init_auth()

            flask_app.before_request(self._inject_service)

            metrics.init_flask_metrics(flask_app, servicename=service_name)
            self._application.add_api(
                Path(api_spec_file),
                validate_responses=self.options.get('validate-responses'))

            return self._application
        except Exception as err:
            traceback.print_exc()
            raise err
예제 #2
0
    def _init_wsgi_app(self,
                       service_name,
                       api_spec_dir=None,
                       api_spec_file=None):
        """
        Return an initialized service with common api resource and auth config
        :return:
        """

        try:

            enable_swagger_ui = False
            if self.configuration.get("enable_swagger_ui", None) is not None:
                enable_swagger_ui = self.configuration.get("enable_swagger_ui")
            elif self.global_configuration.get("enable_swagger_ui",
                                               None) is not None:
                enable_swagger_ui = self.global_configuration.get(
                    "enable_swagger_ui")

            flask_app_options = {"swagger_ui": enable_swagger_ui}
            self._application = connexion.FlaskApp(
                __name__,
                specification_dir=api_spec_dir,
                options=flask_app_options)
            flask_app = self._application.app
            flask_app.url_map.strict_slashes = False

            # Ensure jsonify() calls add whitespace for nice error responses
            flask_app.config["JSONIFY_PRETTYPRINT_REGULAR"] = True

            # Suppress some verbose logs in dependencies
            import logging as py_logging

            py_logging.basicConfig(level=py_logging.ERROR)

            # Initialize the authentication system
            self.init_auth()

            flask_app.before_request(self._inject_service)
            flask_app.register_error_handler(AnchoreApiError,
                                             handle_api_exception)

            metrics.init_flask_metrics(flask_app, servicename=service_name)
            self._application.add_api(
                Path(api_spec_file),
                validate_responses=self.options.get("validate-responses"),
            )

            return self._application
        except Exception as err:
            logger.exception("Error initializing WSGI application")
            raise
예제 #3
0
    def _get_wsgi_app(self, service_name, api_spec_dir=None, api_spec_file=None):
        """
        Return an initialized service with common api resource and auth config
        :return:
        """

        try:
            application = connexion.FlaskApp(__name__, specification_dir=api_spec_dir)
            flask_app = application.app
            flask_app.url_map.strict_slashes = False

            metrics.init_flask_metrics(flask_app, servicename=service_name)
            application.add_api(Path(api_spec_file), validate_responses=self.options.get('validate-responses'))
            return application
        except Exception as err:
            traceback.print_exc()
            raise err
예제 #4
0
    def _init_wsgi_app(self,
                       service_name,
                       api_spec_dir=None,
                       api_spec_file=None):
        """
        Return an initialized service with common api resource and auth config
        :return:
        """

        try:
            self._application = connexion.FlaskApp(
                __name__, specification_dir=api_spec_dir)
            flask_app = self._application.app
            flask_app.url_map.strict_slashes = False

            # Ensure jsonify() calls add whitespace for nice error responses
            flask_app.config['JSONIFY_PRETTYPRINT_REGULAR'] = True

            # Suppress some verbose logs in dependencies
            import logging as py_logging
            py_logging.basicConfig(level=py_logging.ERROR)

            # Initialize the authentication system
            self.init_auth()

            flask_app.before_request(self._inject_service)
            flask_app.register_error_handler(AnchoreApiError,
                                             handle_api_exception)

            metrics.init_flask_metrics(flask_app, servicename=service_name)
            self._application.add_api(
                Path(api_spec_file),
                validate_responses=self.options.get('validate-responses'))

            return self._application
        except Exception as err:
            traceback.print_exc()
            raise err