当前位置:网站首页>关于superset集成到自己的项目中
关于superset集成到自己的项目中
2022-07-31 05:09:00 【银色飞鱼】
下载&安装
方式一:pip install apache-superset
方式二:https://github.com/apache/superset.git
搭建虚拟环境(可选)
1.安装anaconda (https://www.anaconda.com/products/individual#Downloads)
2.anaconda下run一个python环境,(推荐python3.8)
运行
1.superset db upgrade #初始化数据库
2.superset fab create-admin #初始化用户
3.superset init # 初始化
4.superset run -h 0.0.0.0 -p 8088 --with-threads --reload --debugger # 启动
这个过程中可能会有诸多坑,下面列出我遇到的几个和解决方法:
1.Python-geohash、sasl包有问题:
下载文件安装:https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-geohash
2.markupsafe模块有问题:
安装201版本:pip install markupsafe==2.0.1
3.建议python-v >= 3.8
4.a "wsgi.py" or "app.py" module was not found in the current directory.
CD到app.py所在目录下再执行superset run命令
5.pip install Pillow
未安装Piollow可能会导致run不起来
6.error: Microsoft Visual C++ 14.0 is required. Get it with "Build Tools for Visual Studio":
下载安装:https://visualstudio.microsoft.com/downloads/
superset的集成
本文用的方式是Button点击跳URL到部署的superset上,下面进行接入账户系统和权限处理。
superset采用flask-appbuilder做身份验证,关于如何接入用户,官方文档已有详细说明:Security — Flask AppBuilder
本文的思路是:拦截/login请求到自己的项目,让其做登陆和验证的功能。同时传给其一个login的CallBack URL让其在登陆成功的情况下回调系统,在回调时把User写到当前系统的Session中去。Logout也是同样的道理。都是使用CallBack URL来做的。代码如下:
# config.py
from flask_appbuilder.security.manager import AUTH_REMOTE_USER
from my_security_manager import MySecurityManager
AUTH_TYPE = AUTH_REMOTE_USER # 设置模式
CUSTOM_SECURITY_MANAGER = MySecurityManager # 引入自己写的Security
AUTH_USER_REGISTRATION = True # 允许用户注册
AUTH_USER_REGISTRATION_ROLE = "Gamma" # 设置默认添加用户角色
# 与seperset文件夹同级目录下创建 my_security_manager.py
LOGIN_SERVER_URL = 'http://10.113.72.88:5000/login' # 接入系统的登录接口
CHECK_SERVER_URL = 'http://10.113.72.88:5000/check' # 接入系统的token检查接口
LOGINOUT_SERVER_URL = 'http://10.113.72.88:5000/logout' # 接入系统的登出接口
class MyAuthRemoteUserView(AuthRemoteUserView):
# 需继承config.py中AUTH_TYPE值相对应的父类
login_template = 'appbuilder/general/security/login_my.html'
title = "My Login"
@expose('/login/', methods=['GET', 'POST'])
def login(self):
token = request.args.get('token')
if not token:
token = request.cookies.get('access_token')
if not token:
return redirect(LOGIN_SERVER_URL)
manager = self.appbuilder.sm
# 根据你的系统修改参数
result = requests.get(CHECK_SERVER_URL + '?token=' + token)
# 根据你的系统修改验证条件
if result.status_code != 200:
return redirect(LOGIN_SERVER_URL)
# 这里的访问方式是,只验证token是否有效,所有用户进入superset看到的是相同页面
# 同一个superset账号(admin)
username = "admin"
user = manager.find_user(username=username)
login_user(user, remember=False)
return redirect(self.appbuilder.get_url_for_index)
# 也可以根据登录账号的不同在superset中生成不同的账号,不同用户的界面的是不同的。
# 相当于把接入系统的账号对应的在superset中进行创建,同时修改login方法,以自定义登录。
# if token is not None:
# jwt_payload = jwt.decode(token, 'secret', algorithms=['RS256'])
# user_name = jwt_payload.get("user_name")
# user = self.appbuilder.sm.find_user(username=user_name)
# if not user:
# role_admin = self.appbuilder.sm.find_role('Admin')
# user = self.appbuilder.sm.add_user(user_name, user_name, 'aimind', user_name + "@aimind.com", role_admin, password="aimind" + user_name)
# if user:
# login_user(user, remember=False)
# redirect_url = request.args.get('redirect')
# if not redirect_url:
# redirect_url = self.appbuilder.get_url_for_index
# return redirect(redirect_url)
# else:
# return super(AuthRemoteUserView, self).login()
class MySecurityManager(MyAuthRemoteUserView):
authremoteuserview = MyAuthRemoteUserView
边栏推荐
猜你喜欢

SQL injection of DVWA
【一起学Rust】Rust学习前准备——注释和格式化输出
![Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]](/img/7c/c9ab32bbf43b933e5f84f0d142f7bd.jpg)
Unity Tutorial: URP Rendering Pipeline Practical Tutorial Series [1]

The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands

面试官问我TCP三次握手和四次挥手,我真的是

MySQL window function

12 reasons for MySQL slow query

矩池云快速安装torch-sparse、torch-geometric等包

MySQL事务(transaction) (有这篇就足够了..)

sql statement - how to query data in another table based on the data in one table
随机推荐
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
Interview Redis High Reliability | Master-Slave Mode, Sentinel Mode, Cluster Cluster Mode
1. Get data - requests.get()
ERROR 1819 (HY000) Your password does not satisfy the current policy requirements
A complete introduction to JSqlParse of Sql parsing and conversion
The MySQL database installed configuration nanny level tutorial for 8.0.29 (for example) have hands
Why use Flink and how to get started with Flink?
Temporal介绍
ERP Production Operation Control Kingdee
关于LocalDateTime的全局返回时间带“T“的时间格式处理
Unity resources management series: Unity framework how to resource management
EasyExcel的简单读取操作
Paginate the list collection and display the data on the page
如何将项目部署到服务器上(全套教程)
城市内涝及桥洞隧道积水在线监测系统
ERROR 2003 (HY000) Can't connect to MySQL server on 'localhost3306' (10061)
SQL row-column conversion
MySQL transaction (transaction) (this is enough..)
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
Temporal客户端模型