Source code for airflow.providers.fab.auth_manager.cli_commands.utils
# 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__importannotationsimportosfromcontextlibimportcontextmanagerfromfunctoolsimportlru_cachefromos.pathimportisabsfromtypingimportTYPE_CHECKING,GeneratorfromflaskimportFlaskimportairflowfromairflow.configurationimportconffromairflow.exceptionsimportAirflowConfigExceptionfromairflow.www.appimportmake_urlfromairflow.www.extensions.init_appbuilderimportinit_appbuilderfromairflow.www.extensions.init_sessionimportinit_airflow_session_interfacefromairflow.www.extensions.init_viewsimportinit_pluginsifTYPE_CHECKING:fromairflow.www.extensions.init_appbuilderimportAirflowAppBuilder@lru_cache(maxsize=None)def_return_appbuilder(app:Flask)->AirflowAppBuilder:"""Return an appbuilder instance for the given app."""init_appbuilder(app)init_plugins(app)init_airflow_session_interface(app)returnapp.appbuilder# type: ignore[attr-defined]@contextmanager
[docs]defget_application_builder()->Generator[AirflowAppBuilder,None,None]:static_folder=os.path.join(os.path.dirname(airflow.__file__),"www","static")flask_app=Flask(__name__,static_folder=static_folder)webserver_config=conf.get_mandatory_value("webserver","config_file")withflask_app.app_context():# Enable customizations in webserver_config.py to be applied via Flask.current_app.flask_app.config.from_pyfile(webserver_config,silent=True)flask_app.config["SQLALCHEMY_DATABASE_URI"]=conf.get("database","SQL_ALCHEMY_CONN")url=make_url(flask_app.config["SQLALCHEMY_DATABASE_URI"])ifurl.drivername=="sqlite"andurl.databaseandnotisabs(url.database):raiseAirflowConfigException(f'Cannot use relative path: `{conf.get("database","SQL_ALCHEMY_CONN")}` to connect to sqlite. '"Please use absolute path such as `sqlite:////tmp/airflow.db`.")flask_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"]=Falseyield_return_appbuilder(flask_app)