Apache Superset 的自定义安全管理器有什么问题?

问题描述 投票:0回答:2

我正在 Python 虚拟环境中的 Debian 服务器上运行 Apache Superset 1.4.0

我正在尝试实现一个自定义安全管理器,但我陷入困境,因为 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
放在错误的目录中,我应该把它放在哪里?

还是关于

import
里面的
custom_security_manager.py
线?

python apache-superset
2个回答
0
投票

显然我的

imports
中缺少了一些
custom_security_manager.py

当我将其修改为以下内容时,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)

0
投票

一切看起来都很棒,但方法

 login_user('some_user_name', remember=False)
不对,而是:

from superset import security_manager  user = security_manager.find_user(username='some-user_name') login_user(user, remember=False) 
现在,它需要一个对象用户。

© www.soinside.com 2019 - 2024. All rights reserved.