Skip to content

Commit

Permalink
Drop Airflow v1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Bonomi committed Sep 19, 2024
1 parent 14bf9b8 commit d531e97
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 288 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ With Git support enabled, DAGs are stored in a Git repository, enabling users to
### System Requirements

* Airflow Versions
* 1.10.3 or newer
* 2.0.0 or newer
* git Versions (git is not required if git support is disabled)
* 2.0 or newer

Expand Down
3 changes: 1 addition & 2 deletions airflow_code_editor/airflow_code_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from airflow_code_editor.app_builder_view import api_reference_menu, appbuilder_view
from airflow_code_editor.commons import STATIC, VERSION
from airflow_code_editor.flask_admin_view import admin_view
from airflow_code_editor.utils import is_enabled

__author__ = 'Andrea Bonomi <andrea.bonomi@gmail.com>'
Expand Down Expand Up @@ -54,7 +53,7 @@ class CodeEditorPlugin(AirflowPlugin):
flask_blueprints = flask_blueprints
hooks = []
executors = []
admin_views = [admin_view] if (is_enabled() and admin_view is not None) else []
admin_views = []
menu_links = []
appbuilder_menu_items = [api_reference_menu] if (is_enabled() and api_blueprint is not None) else []
appbuilder_views = [appbuilder_view] if is_enabled() else []
243 changes: 83 additions & 160 deletions airflow_code_editor/app_builder_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# limitations under the Licens
#

from airflow.security import permissions
from airflow.www import auth
from flask import redirect, request
from flask_appbuilder import BaseView, expose

Expand All @@ -31,166 +33,87 @@

__all__ = ["appbuilder_view", "api_reference_menu"]

try:
from airflow.security import permissions
from airflow.www import auth

PERMISSIONS = [
(permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE),
]

# ############################################################################
# AppBuilder (Airflow >= 2.0)

class AppBuilderCodeEditorView(BaseView, AbstractCodeEditorView):
route_base = ROUTE
base_permissions = ["can_list", "can_create", "menu_acccess"]

@expose("/")
@auth.has_access(PERMISSIONS)
def list(self):
return self._index()

@expose("/api/")
@auth.has_access(PERMISSIONS)
def api(self):
return redirect(request.path + "/ui")

@expose("/repo", methods=["POST"])
@auth.has_access(PERMISSIONS)
def repo_base(self):
return self._execute_git_command()

@expose("/files/<path:path>", methods=["POST"])
@auth.has_access(PERMISSIONS)
def save(self, path=None):
return self._save(path)

@expose("/files/<path:path>", methods=["GET"])
@auth.has_access(PERMISSIONS)
def load(self, path=None):
return self._load(path)

@expose("/files/<path:path>", methods=["DELETE"])
@auth.has_access(PERMISSIONS)
def delete(self, path=None):
return self._delete(path)

@expose("/format", methods=["POST"])
@auth.has_access(PERMISSIONS)
def format(self):
return self._format()

@expose("/tree", methods=["GET", "HEAD"])
@auth.has_access(PERMISSIONS)
def tree_base(self, path=None):
return self._tree(path, args=request.args, method=request.method)

@expose("/tree/<path:path>", methods=["GET", "HEAD"])
@auth.has_access(PERMISSIONS)
def tree(self, path=None):
return self._tree(path, args=request.args, method=request.method)

@expose("/search", methods=["GET"])
@auth.has_access(PERMISSIONS)
def search(self):
return self._search(args=request.args)

@expose("/version", methods=["GET"])
@auth.has_access(PERMISSIONS)
def get_version(self):
return self._get_version()

@expose("/ping", methods=["GET"])
@auth.has_access(PERMISSIONS)
def ping(self):
return self._ping()

def _render(self, template, *args, **kargs):
return self.render_template(
template + "_appbuilder.html",
airflow_major_version=self.airflow_major_version,
js_files=JS_FILES,
version=VERSION,
*args,
**kargs
)

except (ImportError, ModuleNotFoundError):
from airflow.www_rbac.decorators import has_dag_access

from airflow_code_editor.auth import has_access

# ############################################################################
# AppBuilder (Airflow >= 1.10 < 2.0 and rbac = True)

class AppBuilderCodeEditorView(BaseView, AbstractCodeEditorView):
route_base = ROUTE
base_permissions = ["can_list"]

@expose("/")
@has_dag_access(can_dag_edit=True)
@has_access
def list(self):
return self._index()

@expose("/repo", methods=["POST"])
@has_dag_access(can_dag_edit=True)
def repo_base(self):
return self._execute_git_command()

@expose("/files/<path:path>", methods=["POST"])
@has_dag_access(can_dag_edit=True)
def save(self, path=None):
return self._save(path)

@expose("/files/<path:path>", methods=["GET"])
@has_dag_access(can_dag_edit=True)
def load(self, path=None):
return self._load(path)

@expose("/files/<path:path>", methods=["DELETE"])
@has_dag_access(can_dag_edit=True)
def delete(self, path=None):
return self._delete(path)

@expose("/format", methods=["POST"])
@has_dag_access(can_dag_edit=True)
def format(self):
return self._format()

@expose("/tree", methods=["GET"])
@has_dag_access(can_dag_edit=True)
def tree_base(self, path=None):
return self._tree(path, args=request.args, method=request.method)

@expose("/tree/<path:path>", methods=["GET"])
@has_dag_access(can_dag_edit=True)
def tree(self, path=None):
return self._tree(path, args=request.args, method=request.method)

@expose("/search", methods=["GET"])
@has_dag_access(can_dag_edit=True)
def search(self):
return self._search(args=request.args)

@expose("/version", methods=["GET"])
def get_version(self):
return self._get_version()

@expose("/ping", methods=["GET"])
def ping(self):
return self._ping()

def _render(self, template, *args, **kargs):
return self.render_template(
template + "_appbuilder.html",
airflow_major_version=self.airflow_major_version,
js_files=JS_FILES,
version=VERSION,
*args,
**kargs
)
PERMISSIONS = [
(permissions.ACTION_CAN_READ, permissions.RESOURCE_WEBSITE),
]

# ############################################################################
# AppBuilder (Airflow >= 2.0)


class AppBuilderCodeEditorView(BaseView, AbstractCodeEditorView):
route_base = ROUTE
base_permissions = ["can_list", "can_create", "menu_acccess"]

@expose("/")
@auth.has_access(PERMISSIONS)
def list(self):
return self._index()

@expose("/api/")
@auth.has_access(PERMISSIONS)
def api(self):
return redirect(request.path + "/ui")

@expose("/repo", methods=["POST"])
@auth.has_access(PERMISSIONS)
def repo_base(self):
return self._execute_git_command()

@expose("/files/<path:path>", methods=["POST"])
@auth.has_access(PERMISSIONS)
def save(self, path=None):
return self._save(path)

@expose("/files/<path:path>", methods=["GET"])
@auth.has_access(PERMISSIONS)
def load(self, path=None):
return self._load(path)

@expose("/files/<path:path>", methods=["DELETE"])
@auth.has_access(PERMISSIONS)
def delete(self, path=None):
return self._delete(path)

@expose("/format", methods=["POST"])
@auth.has_access(PERMISSIONS)
def format(self):
return self._format()

@expose("/tree", methods=["GET", "HEAD"])
@auth.has_access(PERMISSIONS)
def tree_base(self, path=None):
return self._tree(path, args=request.args, method=request.method)

@expose("/tree/<path:path>", methods=["GET", "HEAD"])
@auth.has_access(PERMISSIONS)
def tree(self, path=None):
return self._tree(path, args=request.args, method=request.method)

@expose("/search", methods=["GET"])
@auth.has_access(PERMISSIONS)
def search(self):
return self._search(args=request.args)

@expose("/version", methods=["GET"])
@auth.has_access(PERMISSIONS)
def get_version(self):
return self._get_version()

@expose("/ping", methods=["GET"])
@auth.has_access(PERMISSIONS)
def ping(self):
return self._ping()

def _render(self, template, *args, **kargs):
return self.render_template(
template + "_appbuilder.html",
airflow_major_version=self.airflow_major_version,
js_files=JS_FILES,
version=VERSION,
*args,
**kargs
)


appbuilder_code_editor_view = AppBuilderCodeEditorView()
Expand Down
Loading

0 comments on commit d531e97

Please sign in to comment.