def _add_view(config: pyramid.config.Configurator, name: str, path: str, view: Callable[[pyramid.request.Request], Any]) -> None: config.add_route("c2c_debug_" + name, config_utils.get_base_path(config) + r"/debug/" + path, request_method="GET") config.add_view(view, route_name="c2c_debug_" + name, renderer="fast_json", http_cache=0)
def init(config: pyramid.config.Configurator) -> None: """Initialize the statistic view.""" config.add_route("c2c_read_stats_json", config_utils.get_base_path(config) + r"/stats.json", request_method="GET") memory_backend = cast(stats.MemoryBackend, stats.BACKENDS["memory"]) config.add_view(memory_backend.get_stats, route_name="c2c_read_stats_json", renderer="fast_json", http_cache=0)
def includeme(config: pyramid.config.Configurator) -> None: """Install the view to configure the loggers, if configured to do so.""" if auth.is_enabled(config, ENV_KEY, CONFIG_KEY): config.add_route( "c2c_db_maintenance", config_utils.get_base_path(config) + r"/db/maintenance", request_method="GET", ) config.add_view(_db_maintenance, route_name="c2c_db_maintenance", renderer="fast_json", http_cache=0) _restore(config) LOG.info("Enabled the /db/maintenance API")
def init(config: pyramid.config.Configurator) -> None: """Install a pyramid event handler that adds the request information.""" broadcast.subscribe("c2c_sql_profiler", _setup_profiler) config.add_route("c2c_sql_profiler", config_utils.get_base_path(config) + r"/sql_profiler", request_method="GET") config.add_view(_sql_profiler_view, route_name="c2c_sql_profiler", renderer="fast_json", http_cache=0) LOG.info("Enabled the /sql_profiler API")
def includeme(config: pyramid.config.Configurator) -> None: """Install the view to configure the loggers, if configured to do so.""" if auth.is_enabled(config, ENV_KEY, CONFIG_KEY): config.add_route("c2c_logging_level", config_utils.get_base_path(config) + r"/logging/level", request_method="GET") config.add_view(_logging_change_level, route_name="c2c_logging_level", renderer="fast_json", http_cache=0) _restore_overrides(config) LOG.info("Enabled the /logging/level API")
def __init__(self, config: pyramid.config.Configurator) -> None: config.add_route( "c2c_health_check", config_utils.get_base_path(config) + r"/health_check", request_method="GET" ) config.add_view(self._view, route_name="c2c_health_check", renderer="fast_json", http_cache=0) self._checks: List[Tuple[str, Callable[[pyramid.request.Request], Any], int]] = [] self.name = config_utils.env_or_config( config, redis_utils.REDIS_SENTINELS_KEY, redis_utils.REDIS_SENTINELS_KEY_PROP, config_utils.env_or_config(config, redis_utils.REDIS_URL_KEY, redis_utils.REDIS_URL_KEY_PROP), ) if self.name: self.add_redis_check(level=2) if version.get_version() is not None: self.add_version_check(level=2)
def includeme(config: pyramid.config.Configurator) -> None: """Initialize the index page.""" base_path = config_utils.get_base_path(config) if base_path != "": config.add_route("c2c_index", base_path, request_method=("GET", "POST")) config.add_view(_index, route_name="c2c_index", http_cache=0) config.add_route("c2c_index_slash", base_path + "/", request_method=("GET", "POST")) config.add_view(_index, route_name="c2c_index_slash", http_cache=0) settings = config.get_settings() auth_type_ = auth_type(settings) if auth_type_ == AuthenticationType.SECRET: LOG.warning( "It is recommended to use OAuth2 with GitHub login instead of the `C2C_SECRET` because it " "protects from brute force attacks and the access grant is personal and can be revoked." ) if auth_type_ == AuthenticationType.GITHUB: config.add_route("c2c_github_login", base_path + "/github-login", request_method=("GET", )) config.add_view(_github_login, route_name="c2c_github_login", http_cache=0) config.add_route("c2c_github_callback", base_path + "/github-callback", request_method=("GET", )) config.add_view(_github_login_callback, route_name="c2c_github_callback", http_cache=0, renderer="fast_json") config.add_route("c2c_github_logout", base_path + "/github-logout", request_method=("GET", )) config.add_view(_github_logout, route_name="c2c_github_logout", http_cache=0)