Apache Superset 的这个自定义安全管理器有什么问题?
What is the problem with this custom security manager for Apache Superset?
我是 运行 Apache Superset 1.4.0,在 Debian 服务器上,在 Python 虚拟环境中。
我正在尝试实施自定义安全管理器,但我被卡住了,因为 Apache Superset 抱怨导入。
我的 superset
和 superset_config.py
在 /home/administrator/venv-superset/bin/
目录中。
我在同一目录下新建了一个custom_security_manager.py
文件,即/home/administrator/venv-superset/bin
,内容如下:
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.views import UserDBModelView,AuthDBView
class CustomAuthDBView(AuthDBView):
@expose('/login/', methods=['GET', 'POST'])
def login(self):
token = request.args.get('token')
if token == 'SOME_TOKEN_VALUE':
login_user('some_user_name', remember=False)
else:
flash('Unable to auto login', 'warning')
return super(CustomAuthDBView,self).login()
class CustomSecurityManager(SupersetSecurityManager):
authdbview = CustomAuthDBView
def __init__(self, appbuilder):
super(CustomSecurityManager, self).__init__(appbuilder)
我的superset_config.py
内容如下:
FEATURE_FLAGS = {
"ENABLE_TEMPLATE_PROCESSING": True,
}
from custom_security_manager import CustomSecurityManager
CUSTOM_SECURITY_MANAGER = CustomSecurityManager
当我启动 Superset 服务然后检查日志时,我看到以下内容:
Jan 28 13:46:46 dashboard-server python[17190]: Found but failed to import local superset_config
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/superset/config.py", line 1298, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: import superset_config # pylint: disable=import-error
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/superset_config.py", line 5, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 4, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 7, in CustomAuthDBView
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/superset", line 11, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: load_entry_point('apache-superset==1.4.0', 'console_scripts', 'superset')()
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2443, in load
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2449, in resolve
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/superset/cli.py", line 39, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: from superset import app, appbuilder, config, security_manager
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/superset/config.py", line 1298, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: import superset_config # pylint: disable=import-error
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/superset_config.py", line 5, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 4, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 7, in CustomAuthDBView
如果我把custom_security_manager.py
放在错误的目录下,我应该把它放在哪里?
还是关于 custom_security_manager.py
中的 import
行?
显然我在 custom_security_manager.py
中遗漏了一些 imports
。
当我修改如下时,Apache Superset 不再报错了:
from flask import redirect, g, flash, request
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.views import UserDBModelView,AuthDBView
from flask_appbuilder.security.views import expose
from flask_login import login_user, logout_user
class CustomAuthDBView(AuthDBView):
@expose('/login/', methods=['GET', 'POST'])
def login(self):
token = request.args.get('token')
if token == 'SOME_TOKEN_VALUE':
login_user('some_user_name', remember=False)
else:
flash('Unable to auto login', 'warning')
return super(CustomAuthDBView,self).login()
class CustomSecurityManager(SupersetSecurityManager):
authdbview = CustomAuthDBView
def __init__(self, appbuilder):
super(CustomSecurityManager, self).__init__(appbuilder)
我是 运行 Apache Superset 1.4.0,在 Debian 服务器上,在 Python 虚拟环境中。
我正在尝试实施自定义安全管理器,但我被卡住了,因为 Apache Superset 抱怨导入。
我的 superset
和 superset_config.py
在 /home/administrator/venv-superset/bin/
目录中。
我在同一目录下新建了一个custom_security_manager.py
文件,即/home/administrator/venv-superset/bin
,内容如下:
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.views import UserDBModelView,AuthDBView
class CustomAuthDBView(AuthDBView):
@expose('/login/', methods=['GET', 'POST'])
def login(self):
token = request.args.get('token')
if token == 'SOME_TOKEN_VALUE':
login_user('some_user_name', remember=False)
else:
flash('Unable to auto login', 'warning')
return super(CustomAuthDBView,self).login()
class CustomSecurityManager(SupersetSecurityManager):
authdbview = CustomAuthDBView
def __init__(self, appbuilder):
super(CustomSecurityManager, self).__init__(appbuilder)
我的superset_config.py
内容如下:
FEATURE_FLAGS = {
"ENABLE_TEMPLATE_PROCESSING": True,
}
from custom_security_manager import CustomSecurityManager
CUSTOM_SECURITY_MANAGER = CustomSecurityManager
当我启动 Superset 服务然后检查日志时,我看到以下内容:
Jan 28 13:46:46 dashboard-server python[17190]: Found but failed to import local superset_config
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/superset/config.py", line 1298, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: import superset_config # pylint: disable=import-error
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/superset_config.py", line 5, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 4, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 7, in CustomAuthDBView
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/superset", line 11, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: load_entry_point('apache-superset==1.4.0', 'console_scripts', 'superset')()
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 489, in load_entry_point
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2852, in load_entry_point
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2443, in load
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/pkg_resources/__init__.py", line 2449, in resolve
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/superset/cli.py", line 39, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: from superset import app, appbuilder, config, security_manager
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/lib/python3.9/site-packages/superset/config.py", line 1298, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: import superset_config # pylint: disable=import-error
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/superset_config.py", line 5, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 4, in <module>
Jan 28 13:46:46 dashboard-server python[17190]: File "/home/administrator/venv-superset/bin/custom_security_manager.py", line 7, in CustomAuthDBView
如果我把custom_security_manager.py
放在错误的目录下,我应该把它放在哪里?
还是关于 custom_security_manager.py
中的 import
行?
显然我在 custom_security_manager.py
中遗漏了一些 imports
。
当我修改如下时,Apache Superset 不再报错了:
from flask import redirect, g, flash, request
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.views import UserDBModelView,AuthDBView
from flask_appbuilder.security.views import expose
from flask_login import login_user, logout_user
class CustomAuthDBView(AuthDBView):
@expose('/login/', methods=['GET', 'POST'])
def login(self):
token = request.args.get('token')
if token == 'SOME_TOKEN_VALUE':
login_user('some_user_name', remember=False)
else:
flash('Unable to auto login', 'warning')
return super(CustomAuthDBView,self).login()
class CustomSecurityManager(SupersetSecurityManager):
authdbview = CustomAuthDBView
def __init__(self, appbuilder):
super(CustomSecurityManager, self).__init__(appbuilder)