mirror of
https://github.com/apache/superset.git
synced 2026-04-11 04:15:33 +00:00
* add BUSINESS_TYPE_ADDONS to config with example callback * Removing uneeded whitespace * [Work in progress] Modifying cidr function to allow for single ip and adding port outline * Added test REST endpoint, added some more ports I've thrown in a test.py script as well that will try to connect to the business_type endpoint. * Moving code from config.py into the business api Very simple api is exposed that will allow someone to call a checkport endpoint and get back a response. * Removing commented out bits. * Adding fucntion dict back to the config * Moving business_type endpoint to charts * Adding schema for get endpoint * Removing imports, updating docstring, fixing typo Just some small changes as described in the title. I've updated the test.py as well so it functions with the endpoint changes. * Adding translation dict * Fixing ops * Adding check for list * Modifying changes to add quotes where needed Also changed BusinessTypeResponse to resp. * Adding in some code to call the filter config If a column starts with "cidr_" it will call the code in config.py to try to translate the filter. Nothing is changed in the JSON being executed, just some information is dumped to console. * Porting Ryan's changes * Adding migration script (as per Ryan's PR) * Fixing typo * Prettier fixes * [CLDN-1043] Adding rough version of filter changes for business types * fix down migration * Fixing bugs after merge * adding functionality to appy filters in back end * Fixing linting issues * fix down revision * Changing conversion callback to handle multiple values at once * Adding string representation of values * Code cleanup plus fixing debouce to only be called once for each entry * Removing non needed logginh * Changing operator list to use sting values * Using text value operators * Removing clear operator call * Moving business type endpoints * fix down revision * Adding port functions * update migration * fix bad rebase and add ff * implement validator * dont add invalid values to response * [CLDN-1205] Added a new exception type for a business type translation error. Added the error message in the display_value field within the business type response. Modified the IP and Port business types to populate the error message field in the response if an error occurs * [CLDN-1205] Added meaningful error message for port translation errors * Removing status field from businesstype Response and adding in error message * [CLDN-1205] Added check to make sure the port business type is within the valid range of ports, if it is not, it will populate the error message * [CLDN-1205] Fixed the if statement that checks to see if the string_value is in the valid range of port numbers. It did not corrently verify this before now. * [CLDN-1205] Fixed an error where it was trying to use string_value in <= statements. I just casted string_value to an integer if it is numeric, which allows <= operators to be used on it * [CLDN-1207] Added unit tests for the cidr_func and port_translation_func functions which are located in /superset/config.py * [CLDN-1207] removed the assertRaises line as it does not work with the cidr_func and port_translation_func functions * [CLDN-1207] Added the skeleton of the test_cidr_translate_filter_func unit test, still need to update what the expected response from the function will be. * [CLDN-1207] Added the remainder of the back-end unit tests for the business types * [CLDN-1207] Fixed the syntax error which caused the test_cidr_translate_filter_func_NOT_IN_double unit test to fail * [CLDN-1207] Removed the logging that was added for debugging purposes * [CLDN-1207] Formatted the commands_tests.py file to make it nicer to look at/read through * [CLDN-1207] Fixed the code so that it conformed to the pylint requirements (i.e., pylint no longer complains about the code in commands_tests.py) * [CLDN-1207] Modified some of the docstrings so they made better use of the 100 character per line, line limit * [CLDN-1207] Added the beginnings of the unit tests for the business types API * [CLDN-1207] Added a comment to the top of the commands_tests.py file explaining how to run the unit tests. This prevents the next person who tries to run them from having to waste time trying the different forms of testing that Superset supports (e.g., pytest, tox, etc.) * [CLDN-1207] Added a grammar fix to the comments describing how to run the unit tests * [CLDN-1207] Modified the description of the business_type API endpoints as they did not represent what the API was actually doing * [CLDN-1207] Added further instructions on how to run the unit tests that are within the business_type/api_tests.py file * add request validation * disable request if business type missing * [CLDN-1207] Unit tests for the business type API are now working, however, they need to be modified to make use of @mock as we don't want to have to run the server to be able to run the unit tests * Removing businesss types deffinitons from config * Adding select to only show valid business types * Fixed Enzyme tests * Added scalfolding for selecting filter dropdown * Adding intigration tests * fix revision * fix typos and unnecessary requests * break out useBusinessTypes * Added front-end RTL unit tests for the business type API endpoint * Fixed error from unit tests * Added a unit test to ensure the operator list is updated after a business type API response is received * Removing elect compoenet for business types * Adding feature flag and allowing saving when no business type present * fixing useEffect hooks * Adding feature flag to model * Changing behavior such that an empty string returns a default response * add form validation * Modified comments in unit test as command to run test has changed * Modified comments in unit test as filename to run test has changed * Modified the api_tests.py file to conform to the linting requirements * Changed the name of one of the tests to reflect what the test is actually testing * Added cypress back to the package.json * Added informative comments * Updated comments in files as well as removed imports which were not being used * Changes made by npm run prettier * Fixed spelling mistakes * Updated models.py to remove placeholder comments used in development * Added feature flag mocking in unit test * Fixing open api failure * Fixing business types to pass unit tests * Reverting unsafe connections back to false * Removing print statement * Adding business tpye to export test * setting default feature flag to false for business type * Reverting pre commit * Reverting pre commit and running pre commit * Reverting pre commit and running pre commit * Fixing formatting * Adding license * Fixing Linting * Protecting api enpoints * updating model * Fixing code path when business type exists * Linting * Linting * Fixing linting * Fixing spelling * Fixing schemas * Fixing app import * fixing item render * Added RTL test to make sure business type operator list is updated after API response * Fixing linting * fix migration * Changing unit tests * Fixing import and DB migration after rebase * Renaming to advanced types * Fixing Linting * More renaming * Removing uneeded change * Fixing linting and test errors * Removing unused imports * linting * Adding more detailed name for migration * Moving files to plugins * more renaming * Fixing schema name * Disabling feature flag that should not be enabled by default * Adding extra cehck * NameChange * formatting * Fixing equals check * Moveing all advanced type classes and types to one file, and converting tests to functional * Adding advanced type to test and fix linitng Co-authored-by: Ville Brofeldt <ville.v.brofeldt@gmail.com> Co-authored-by: Dan Parent <daniel.parent@cse-cst.gc.ca> Co-authored-by: GITHUB_USERNAME <EMAIL> Co-authored-by: cccs-Dustin <96579982+cccs-Dustin@users.noreply.github.com>
611 lines
22 KiB
Python
611 lines
22 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with 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.
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
import os
|
|
from typing import Any, Callable, Dict, TYPE_CHECKING
|
|
|
|
import wtforms_json
|
|
from deprecation import deprecated
|
|
from flask import Flask, redirect
|
|
from flask_appbuilder import expose, IndexView
|
|
from flask_babel import gettext as __, lazy_gettext as _
|
|
from flask_compress import Compress
|
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
|
|
|
from superset.connectors.connector_registry import ConnectorRegistry
|
|
from superset.constants import CHANGE_ME_SECRET_KEY
|
|
from superset.extensions import (
|
|
_event_logger,
|
|
APP_DIR,
|
|
appbuilder,
|
|
async_query_manager,
|
|
cache_manager,
|
|
celery_app,
|
|
csrf,
|
|
db,
|
|
encrypted_field_factory,
|
|
feature_flag_manager,
|
|
machine_auth_provider_factory,
|
|
manifest_processor,
|
|
migrate,
|
|
profiling,
|
|
results_backend_manager,
|
|
talisman,
|
|
)
|
|
from superset.security import SupersetSecurityManager
|
|
from superset.superset_typing import FlaskResponse
|
|
from superset.utils.core import pessimistic_connection_handling
|
|
from superset.utils.log import DBEventLogger, get_event_logger_from_cfg_value
|
|
|
|
if TYPE_CHECKING:
|
|
from superset.app import SupersetApp
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SupersetAppInitializer: # pylint: disable=too-many-public-methods
|
|
def __init__(self, app: SupersetApp) -> None:
|
|
super().__init__()
|
|
|
|
self.superset_app = app
|
|
self.config = app.config
|
|
self.manifest: Dict[Any, Any] = {}
|
|
|
|
@deprecated(details="use self.superset_app instead of self.flask_app") # type: ignore
|
|
@property
|
|
def flask_app(self) -> SupersetApp:
|
|
return self.superset_app
|
|
|
|
def pre_init(self) -> None:
|
|
"""
|
|
Called before all other init tasks are complete
|
|
"""
|
|
wtforms_json.init()
|
|
|
|
if not os.path.exists(self.config["DATA_DIR"]):
|
|
os.makedirs(self.config["DATA_DIR"])
|
|
|
|
def post_init(self) -> None:
|
|
"""
|
|
Called after any other init tasks
|
|
"""
|
|
|
|
def configure_celery(self) -> None:
|
|
celery_app.config_from_object(self.config["CELERY_CONFIG"])
|
|
celery_app.set_default()
|
|
superset_app = self.superset_app
|
|
|
|
# Here, we want to ensure that every call into Celery task has an app context
|
|
# setup properly
|
|
task_base = celery_app.Task
|
|
|
|
class AppContextTask(task_base): # type: ignore
|
|
# pylint: disable=too-few-public-methods
|
|
abstract = True
|
|
|
|
# Grab each call into the task and set up an app context
|
|
def __call__(self, *args: Any, **kwargs: Any) -> Any:
|
|
with superset_app.app_context():
|
|
return task_base.__call__(self, *args, **kwargs)
|
|
|
|
celery_app.Task = AppContextTask
|
|
|
|
def init_views(self) -> None:
|
|
#
|
|
# We're doing local imports, as several of them import
|
|
# models which in turn try to import
|
|
# the global Flask app
|
|
#
|
|
# pylint: disable=import-outside-toplevel,too-many-locals,too-many-statements
|
|
from superset.advanced_data_type.api import AdvancedDataTypeRestApi
|
|
from superset.annotation_layers.annotations.api import AnnotationRestApi
|
|
from superset.annotation_layers.api import AnnotationLayerRestApi
|
|
from superset.async_events.api import AsyncEventsRestApi
|
|
from superset.cachekeys.api import CacheRestApi
|
|
from superset.charts.api import ChartRestApi
|
|
from superset.charts.data.api import ChartDataRestApi
|
|
from superset.connectors.sqla.views import (
|
|
RowLevelSecurityFiltersModelView,
|
|
SqlMetricInlineView,
|
|
TableColumnInlineView,
|
|
TableModelView,
|
|
)
|
|
from superset.css_templates.api import CssTemplateRestApi
|
|
from superset.dashboards.api import DashboardRestApi
|
|
from superset.dashboards.filter_sets.api import FilterSetRestApi
|
|
from superset.dashboards.filter_state.api import DashboardFilterStateRestApi
|
|
from superset.dashboards.permalink.api import DashboardPermalinkRestApi
|
|
from superset.databases.api import DatabaseRestApi
|
|
from superset.datasets.api import DatasetRestApi
|
|
from superset.datasets.columns.api import DatasetColumnsRestApi
|
|
from superset.datasets.metrics.api import DatasetMetricRestApi
|
|
from superset.embedded.api import EmbeddedDashboardRestApi
|
|
from superset.embedded.view import EmbeddedView
|
|
from superset.explore.form_data.api import ExploreFormDataRestApi
|
|
from superset.explore.permalink.api import ExplorePermalinkRestApi
|
|
from superset.importexport.api import ImportExportRestApi
|
|
from superset.queries.api import QueryRestApi
|
|
from superset.queries.saved_queries.api import SavedQueryRestApi
|
|
from superset.reports.api import ReportScheduleRestApi
|
|
from superset.reports.logs.api import ReportExecutionLogRestApi
|
|
from superset.security.api import SecurityRestApi
|
|
from superset.views.access_requests import AccessRequestsModelView
|
|
from superset.views.alerts import AlertView, ReportView
|
|
from superset.views.annotations import (
|
|
AnnotationLayerModelView,
|
|
AnnotationModelView,
|
|
)
|
|
from superset.views.api import Api
|
|
from superset.views.chart.views import SliceAsync, SliceModelView
|
|
from superset.views.core import Superset
|
|
from superset.views.css_templates import (
|
|
CssTemplateAsyncModelView,
|
|
CssTemplateModelView,
|
|
)
|
|
from superset.views.dashboard.views import (
|
|
Dashboard,
|
|
DashboardModelView,
|
|
DashboardModelViewAsync,
|
|
)
|
|
from superset.views.database.views import (
|
|
ColumnarToDatabaseView,
|
|
CsvToDatabaseView,
|
|
DatabaseView,
|
|
ExcelToDatabaseView,
|
|
)
|
|
from superset.views.datasource.views import Datasource
|
|
from superset.views.dynamic_plugins import DynamicPluginsView
|
|
from superset.views.key_value import KV
|
|
from superset.views.log.api import LogRestApi
|
|
from superset.views.log.views import LogModelView
|
|
from superset.views.redirects import R
|
|
from superset.views.sql_lab import (
|
|
SavedQueryView,
|
|
SavedQueryViewApi,
|
|
SqlLab,
|
|
TableSchemaView,
|
|
TabStateView,
|
|
)
|
|
from superset.views.tags import TagView
|
|
from superset.views.users.api import CurrentUserRestApi
|
|
|
|
#
|
|
# Setup API views
|
|
#
|
|
appbuilder.add_api(AnnotationRestApi)
|
|
appbuilder.add_api(AnnotationLayerRestApi)
|
|
appbuilder.add_api(AsyncEventsRestApi)
|
|
appbuilder.add_api(AdvancedDataTypeRestApi)
|
|
appbuilder.add_api(CacheRestApi)
|
|
appbuilder.add_api(ChartRestApi)
|
|
appbuilder.add_api(ChartDataRestApi)
|
|
appbuilder.add_api(CssTemplateRestApi)
|
|
appbuilder.add_api(CurrentUserRestApi)
|
|
appbuilder.add_api(DashboardFilterStateRestApi)
|
|
appbuilder.add_api(DashboardPermalinkRestApi)
|
|
appbuilder.add_api(DashboardRestApi)
|
|
appbuilder.add_api(DatabaseRestApi)
|
|
appbuilder.add_api(DatasetRestApi)
|
|
appbuilder.add_api(DatasetColumnsRestApi)
|
|
appbuilder.add_api(DatasetMetricRestApi)
|
|
appbuilder.add_api(EmbeddedDashboardRestApi)
|
|
appbuilder.add_api(ExploreFormDataRestApi)
|
|
appbuilder.add_api(ExplorePermalinkRestApi)
|
|
appbuilder.add_api(FilterSetRestApi)
|
|
appbuilder.add_api(ImportExportRestApi)
|
|
appbuilder.add_api(QueryRestApi)
|
|
appbuilder.add_api(ReportScheduleRestApi)
|
|
appbuilder.add_api(ReportExecutionLogRestApi)
|
|
appbuilder.add_api(SavedQueryRestApi)
|
|
#
|
|
# Setup regular views
|
|
#
|
|
appbuilder.add_link(
|
|
"Home",
|
|
label=__("Home"),
|
|
href="/superset/welcome/",
|
|
cond=lambda: bool(appbuilder.app.config["LOGO_TARGET_PATH"]),
|
|
)
|
|
appbuilder.add_view(
|
|
AnnotationLayerModelView,
|
|
"Annotation Layers",
|
|
label=__("Annotation Layers"),
|
|
icon="fa-comment",
|
|
category="Manage",
|
|
category_label=__("Manage"),
|
|
category_icon="",
|
|
)
|
|
appbuilder.add_view(
|
|
DashboardModelView,
|
|
"Dashboards",
|
|
label=__("Dashboards"),
|
|
icon="fa-dashboard",
|
|
category="",
|
|
category_icon="",
|
|
)
|
|
appbuilder.add_view(
|
|
SliceModelView,
|
|
"Charts",
|
|
label=__("Charts"),
|
|
icon="fa-bar-chart",
|
|
category="",
|
|
category_icon="",
|
|
)
|
|
appbuilder.add_view(
|
|
DynamicPluginsView,
|
|
"Plugins",
|
|
label=__("Plugins"),
|
|
category="Manage",
|
|
category_label=__("Manage"),
|
|
icon="fa-puzzle-piece",
|
|
menu_cond=lambda: feature_flag_manager.is_feature_enabled(
|
|
"DYNAMIC_PLUGINS"
|
|
),
|
|
)
|
|
appbuilder.add_view(
|
|
CssTemplateModelView,
|
|
"CSS Templates",
|
|
label=__("CSS Templates"),
|
|
icon="fa-css3",
|
|
category="Manage",
|
|
category_label=__("Manage"),
|
|
category_icon="",
|
|
)
|
|
appbuilder.add_view(
|
|
RowLevelSecurityFiltersModelView,
|
|
"Row Level Security",
|
|
label=__("Row Level Security"),
|
|
category="Security",
|
|
category_label=__("Security"),
|
|
icon="fa-lock",
|
|
)
|
|
|
|
#
|
|
# Setup views with no menu
|
|
#
|
|
appbuilder.add_view_no_menu(Api)
|
|
appbuilder.add_view_no_menu(CssTemplateAsyncModelView)
|
|
appbuilder.add_view_no_menu(CsvToDatabaseView)
|
|
appbuilder.add_view_no_menu(ExcelToDatabaseView)
|
|
appbuilder.add_view_no_menu(ColumnarToDatabaseView)
|
|
appbuilder.add_view_no_menu(Dashboard)
|
|
appbuilder.add_view_no_menu(DashboardModelViewAsync)
|
|
appbuilder.add_view_no_menu(Datasource)
|
|
appbuilder.add_view_no_menu(EmbeddedView)
|
|
appbuilder.add_view_no_menu(KV)
|
|
appbuilder.add_view_no_menu(R)
|
|
appbuilder.add_view_no_menu(SavedQueryView)
|
|
appbuilder.add_view_no_menu(SavedQueryViewApi)
|
|
appbuilder.add_view_no_menu(SliceAsync)
|
|
appbuilder.add_view_no_menu(SqlLab)
|
|
appbuilder.add_view_no_menu(SqlMetricInlineView)
|
|
appbuilder.add_view_no_menu(AnnotationModelView)
|
|
appbuilder.add_view_no_menu(Superset)
|
|
appbuilder.add_view_no_menu(TableColumnInlineView)
|
|
appbuilder.add_view_no_menu(TableModelView)
|
|
appbuilder.add_view_no_menu(TableSchemaView)
|
|
appbuilder.add_view_no_menu(TabStateView)
|
|
appbuilder.add_view_no_menu(TagView)
|
|
appbuilder.add_view_no_menu(ReportView)
|
|
|
|
#
|
|
# Add links
|
|
#
|
|
appbuilder.add_link(
|
|
"Import Dashboards",
|
|
label=__("Import Dashboards"),
|
|
href="/superset/import_dashboards/",
|
|
icon="fa-cloud-upload",
|
|
category="Manage",
|
|
category_label=__("Manage"),
|
|
category_icon="fa-wrench",
|
|
cond=lambda: not feature_flag_manager.is_feature_enabled(
|
|
"VERSIONED_EXPORT"
|
|
),
|
|
)
|
|
appbuilder.add_link(
|
|
"SQL Editor",
|
|
label=_("SQL Editor"),
|
|
href="/superset/sqllab/",
|
|
category_icon="fa-flask",
|
|
icon="fa-flask",
|
|
category="SQL Lab",
|
|
category_label=__("SQL Lab"),
|
|
)
|
|
appbuilder.add_link(
|
|
__("Saved Queries"),
|
|
href="/savedqueryview/list/",
|
|
icon="fa-save",
|
|
category="SQL Lab",
|
|
)
|
|
appbuilder.add_link(
|
|
"Query Search",
|
|
label=_("Query History"),
|
|
href="/superset/sqllab/history/",
|
|
icon="fa-search",
|
|
category_icon="fa-flask",
|
|
category="SQL Lab",
|
|
category_label=__("SQL Lab"),
|
|
)
|
|
appbuilder.add_view(
|
|
DatabaseView,
|
|
"Databases",
|
|
label=__("Databases"),
|
|
icon="fa-database",
|
|
category="Data",
|
|
category_label=__("Data"),
|
|
category_icon="fa-database",
|
|
)
|
|
appbuilder.add_link(
|
|
"Datasets",
|
|
label=__("Datasets"),
|
|
href="/tablemodelview/list/",
|
|
icon="fa-table",
|
|
category="Data",
|
|
category_label=__("Data"),
|
|
category_icon="fa-table",
|
|
)
|
|
appbuilder.add_separator("Data")
|
|
|
|
appbuilder.add_api(LogRestApi)
|
|
appbuilder.add_view(
|
|
LogModelView,
|
|
"Action Log",
|
|
label=__("Action Log"),
|
|
category="Security",
|
|
category_label=__("Security"),
|
|
icon="fa-list-ol",
|
|
menu_cond=lambda: (
|
|
self.config["FAB_ADD_SECURITY_VIEWS"]
|
|
and self.config["SUPERSET_LOG_VIEW"]
|
|
),
|
|
)
|
|
appbuilder.add_api(SecurityRestApi)
|
|
#
|
|
# Conditionally setup email views
|
|
#
|
|
|
|
appbuilder.add_view(
|
|
AlertView,
|
|
"Alerts & Report",
|
|
label=__("Alerts & Reports"),
|
|
category="Manage",
|
|
category_label=__("Manage"),
|
|
icon="fa-exclamation-triangle",
|
|
menu_cond=lambda: feature_flag_manager.is_feature_enabled("ALERT_REPORTS"),
|
|
)
|
|
|
|
appbuilder.add_view(
|
|
AccessRequestsModelView,
|
|
"Access requests",
|
|
label=__("Access requests"),
|
|
category="Security",
|
|
category_label=__("Security"),
|
|
icon="fa-table",
|
|
menu_cond=lambda: bool(self.config["ENABLE_ACCESS_REQUEST"]),
|
|
)
|
|
|
|
def init_app_in_ctx(self) -> None:
|
|
"""
|
|
Runs init logic in the context of the app
|
|
"""
|
|
self.configure_fab()
|
|
self.configure_url_map_converters()
|
|
self.configure_data_sources()
|
|
self.configure_auth_provider()
|
|
self.configure_async_queries()
|
|
|
|
# Hook that provides administrators a handle on the Flask APP
|
|
# after initialization
|
|
flask_app_mutator = self.config["FLASK_APP_MUTATOR"]
|
|
if flask_app_mutator:
|
|
flask_app_mutator(self.superset_app)
|
|
|
|
self.init_views()
|
|
|
|
def check_secret_key(self) -> None:
|
|
if self.config["SECRET_KEY"] == CHANGE_ME_SECRET_KEY:
|
|
top_banner = 80 * "-" + "\n" + 36 * " " + "WARNING\n" + 80 * "-"
|
|
bottom_banner = 80 * "-" + "\n" + 80 * "-"
|
|
logger.warning(top_banner)
|
|
logger.warning(
|
|
"A Default SECRET_KEY was detected, please use superset_config.py "
|
|
"to override it.\n"
|
|
"Use a strong complex alphanumeric string and use a tool to help"
|
|
" you generate \n"
|
|
"a sufficiently random sequence, ex: openssl rand -base64 42"
|
|
)
|
|
logger.warning(bottom_banner)
|
|
|
|
def init_app(self) -> None:
|
|
"""
|
|
Main entry point which will delegate to other methods in
|
|
order to fully init the app
|
|
"""
|
|
self.pre_init()
|
|
self.check_secret_key()
|
|
# Configuration of logging must be done first to apply the formatter properly
|
|
self.configure_logging()
|
|
# Configuration of feature_flags must be done first to allow init features
|
|
# conditionally
|
|
self.configure_feature_flags()
|
|
self.configure_db_encrypt()
|
|
self.setup_db()
|
|
self.configure_celery()
|
|
self.enable_profiling()
|
|
self.setup_event_logger()
|
|
self.setup_bundle_manifest()
|
|
self.register_blueprints()
|
|
self.configure_wtf()
|
|
self.configure_middlewares()
|
|
self.configure_cache()
|
|
|
|
with self.superset_app.app_context():
|
|
self.init_app_in_ctx()
|
|
|
|
self.post_init()
|
|
|
|
def configure_auth_provider(self) -> None:
|
|
machine_auth_provider_factory.init_app(self.superset_app)
|
|
|
|
def setup_event_logger(self) -> None:
|
|
_event_logger["event_logger"] = get_event_logger_from_cfg_value(
|
|
self.superset_app.config.get("EVENT_LOGGER", DBEventLogger())
|
|
)
|
|
|
|
def configure_data_sources(self) -> None:
|
|
# Registering sources
|
|
module_datasource_map = self.config["DEFAULT_MODULE_DS_MAP"]
|
|
module_datasource_map.update(self.config["ADDITIONAL_MODULE_DS_MAP"])
|
|
ConnectorRegistry.register_sources(module_datasource_map)
|
|
|
|
def configure_cache(self) -> None:
|
|
cache_manager.init_app(self.superset_app)
|
|
results_backend_manager.init_app(self.superset_app)
|
|
|
|
def configure_feature_flags(self) -> None:
|
|
feature_flag_manager.init_app(self.superset_app)
|
|
|
|
def configure_fab(self) -> None:
|
|
if self.config["SILENCE_FAB"]:
|
|
logging.getLogger("flask_appbuilder").setLevel(logging.ERROR)
|
|
|
|
custom_sm = self.config["CUSTOM_SECURITY_MANAGER"] or SupersetSecurityManager
|
|
if not issubclass(custom_sm, SupersetSecurityManager):
|
|
raise Exception(
|
|
"""Your CUSTOM_SECURITY_MANAGER must now extend SupersetSecurityManager,
|
|
not FAB's security manager.
|
|
See [4565] in UPDATING.md"""
|
|
)
|
|
|
|
appbuilder.indexview = SupersetIndexView
|
|
appbuilder.base_template = "superset/base.html"
|
|
appbuilder.security_manager_class = custom_sm
|
|
appbuilder.init_app(self.superset_app, db.session)
|
|
|
|
def configure_url_map_converters(self) -> None:
|
|
#
|
|
# Doing local imports here as model importing causes a reference to
|
|
# app.config to be invoked and we need the current_app to have been setup
|
|
#
|
|
# pylint: disable=import-outside-toplevel
|
|
from superset.utils.url_map_converters import (
|
|
ObjectTypeConverter,
|
|
RegexConverter,
|
|
)
|
|
|
|
self.superset_app.url_map.converters["regex"] = RegexConverter
|
|
self.superset_app.url_map.converters["object_type"] = ObjectTypeConverter
|
|
|
|
def configure_middlewares(self) -> None:
|
|
if self.config["ENABLE_CORS"]:
|
|
# pylint: disable=import-outside-toplevel
|
|
from flask_cors import CORS
|
|
|
|
CORS(self.superset_app, **self.config["CORS_OPTIONS"])
|
|
|
|
if self.config["ENABLE_PROXY_FIX"]:
|
|
self.superset_app.wsgi_app = ProxyFix( # type: ignore
|
|
self.superset_app.wsgi_app, **self.config["PROXY_FIX_CONFIG"]
|
|
)
|
|
|
|
if self.config["ENABLE_CHUNK_ENCODING"]:
|
|
|
|
class ChunkedEncodingFix: # pylint: disable=too-few-public-methods
|
|
def __init__(self, app: Flask) -> None:
|
|
self.app = app
|
|
|
|
def __call__(
|
|
self, environ: Dict[str, Any], start_response: Callable[..., Any]
|
|
) -> Any:
|
|
# Setting wsgi.input_terminated tells werkzeug.wsgi to ignore
|
|
# content-length and read the stream till the end.
|
|
if environ.get("HTTP_TRANSFER_ENCODING", "").lower() == "chunked":
|
|
environ["wsgi.input_terminated"] = True
|
|
return self.app(environ, start_response)
|
|
|
|
self.superset_app.wsgi_app = ChunkedEncodingFix( # type: ignore
|
|
self.superset_app.wsgi_app # type: ignore
|
|
)
|
|
|
|
if self.config["UPLOAD_FOLDER"]:
|
|
try:
|
|
os.makedirs(self.config["UPLOAD_FOLDER"])
|
|
except OSError:
|
|
pass
|
|
|
|
for middleware in self.config["ADDITIONAL_MIDDLEWARE"]:
|
|
self.superset_app.wsgi_app = middleware( # type: ignore
|
|
self.superset_app.wsgi_app
|
|
)
|
|
|
|
# Flask-Compress
|
|
Compress(self.superset_app)
|
|
|
|
if self.config["TALISMAN_ENABLED"]:
|
|
talisman.init_app(self.superset_app, **self.config["TALISMAN_CONFIG"])
|
|
|
|
def configure_logging(self) -> None:
|
|
self.config["LOGGING_CONFIGURATOR"].configure_logging(
|
|
self.config, self.superset_app.debug
|
|
)
|
|
|
|
def configure_db_encrypt(self) -> None:
|
|
encrypted_field_factory.init_app(self.superset_app)
|
|
|
|
def setup_db(self) -> None:
|
|
db.init_app(self.superset_app)
|
|
|
|
with self.superset_app.app_context():
|
|
pessimistic_connection_handling(db.engine)
|
|
|
|
migrate.init_app(self.superset_app, db=db, directory=APP_DIR + "/migrations")
|
|
|
|
def configure_wtf(self) -> None:
|
|
if self.config["WTF_CSRF_ENABLED"]:
|
|
csrf.init_app(self.superset_app)
|
|
csrf_exempt_list = self.config["WTF_CSRF_EXEMPT_LIST"]
|
|
for ex in csrf_exempt_list:
|
|
csrf.exempt(ex)
|
|
|
|
def configure_async_queries(self) -> None:
|
|
if feature_flag_manager.is_feature_enabled("GLOBAL_ASYNC_QUERIES"):
|
|
async_query_manager.init_app(self.superset_app)
|
|
|
|
def register_blueprints(self) -> None:
|
|
for bp in self.config["BLUEPRINTS"]:
|
|
try:
|
|
logger.info("Registering blueprint: %s", bp.name)
|
|
self.superset_app.register_blueprint(bp)
|
|
except Exception: # pylint: disable=broad-except
|
|
logger.exception("blueprint registration failed")
|
|
|
|
def setup_bundle_manifest(self) -> None:
|
|
manifest_processor.init_app(self.superset_app)
|
|
|
|
def enable_profiling(self) -> None:
|
|
if self.config["PROFILING"]:
|
|
profiling.init_app(self.superset_app)
|
|
|
|
|
|
class SupersetIndexView(IndexView):
|
|
@expose("/")
|
|
def index(self) -> FlaskResponse:
|
|
return redirect("/superset/welcome/")
|