首页 > 技术文章 > superset 杂记

yifugui 2022-03-07 17:26 原文

先从官方文档开始:https://superset.apache.org/docs/intro/

再参考“数据行者”大佬的文档:https://www.cnblogs.com/datawalkman/p/15191066.html

在superset根目录下创建run.py文件启动:

import superset
app = superset.create_app()
if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=8000)

配置config文件:\superset\config.py   (superset的登录二次开发)

SUPERSET_WEBSERVER_PROTOCOL = "http"
SUPERSET_WEBSERVER_ADDRESS = "0.0.0.0"
SUPERSET_WEBSERVER_PORT = 8088

# This is an important setting, and should be lower than your
# [load balancer / proxy / envoy / kong / ...] timeout settings.
# You should also make sure to configure your WSGI server
# (gunicorn, nginx, apache, ...) timeout setting to be <= to this setting
SUPERSET_WEBSERVER_TIMEOUT = 60

SUPERSET_DASHBOARD_POSITION_DATA_LIMIT = 65535
# CUSTOM_SECURITY_MANAGER = None
SQLALCHEMY_TRACK_MODIFICATIONS = False

from superset.obtest import CustomSecurityManager
CUSTOM_SECURITY_MANAGER = CustomSecurityManager

编辑superset/obtest.py文件(后台业务代码)

# _*_ coding: utf-8 _*_
"""
Time:     2022/3/3 16:31
Author:   Ivan Yi
Version:  V 0.1
File:     obtest.py
"""
from flask import redirect, g, flash, request
from flask_appbuilder.security.views import AuthDBView
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.views import expose
from flask_login import login_user, logout_user


class CustomAuthDBView(AuthDBView):
    login_template = 'appbuilder/general/security/login_db.html'

    @expose('/login/', methods=['GET', 'POST'])
    def login(self):
        redirect_url = self.appbuilder.get_url_for_index
        if request.args.get('redirect') is not None:
            redirect_url = request.args.get('redirect')

        if request.args.get('username') is not None:
            user = self.appbuilder.sm.find_user(username=request.args.get('username'))
            login_user(user, remember=False)
            return redirect(redirect_url)
        elif g.user is not None and g.user.is_authenticated: 
            return redirect(redirect_url)
        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)

 

推荐阅读