当前位置:网站首页>关于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语句之多表查询
- Temporal介绍
- MySQL开窗函数
- ERROR 1064 (42000) You have an error in your SQL syntax; check the manual that corresponds to your
- 2022-07-30:以下go语言代码输出什么?A:[]byte{} []byte;B:[]byte{} []uint8;C:[]uint8{} []byte;D:[]uin8{} []uint8。
- Minesweeper game (written in c language)
- About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
- 关于LocalDateTime的全局返回时间带“T“的时间格式处理
- MySQL window function
- centos7安装mysql5.7
猜你喜欢

【MQ我可以讲一个小时】
【一起学Rust】Rust学习前准备——注释和格式化输出

Mysql application cannot find my.ini file after installation

Moment Pool Cloud quickly installs packages such as torch-sparse and torch-geometric

Typec手机有线网卡网线转网口转接口快充方案

Apache DButils使用注意事项--with modifiers “public“

1. 获取数据-requests.get()

面试Redis 高可靠性|主从模式、哨兵模式、Cluster集群模式

太厉害了,终于有人能把文件上传漏洞讲的明明白白了

Unity mobile game performance optimization series: performance tuning for the CPU side
随机推荐
Lua,ILRuntime, HybridCLR(wolong)/huatuo hot update comparative analysis
关于LocalDateTime的全局返回时间带“T“的时间格式处理
MySQL(更新中)
MySQL8.0.26安装配置教程(windows 64位)
[C language] Detailed explanation of operators
一文了解大厂的DDD领域驱动设计
DVWA installation tutorial (understand what you don't understand · in detail)
1. Get data - requests.get()
The monitoring of Doris study notes
Doris学习笔记之监控
面试官:生成订单30分钟未支付,则自动取消,该怎么实现?
Linux的mysql报ERROR 1045 (28000) Access denied for user ‘root‘@‘localhost‘ (using password NOYSE)
Goodbye to the cumbersome Excel, mastering data analysis and processing technology depends on it
centos7安装mysql5.7
Unity手机游戏性能优化系列:针对CPU端的性能调优
CentOS7 - yum install mysql
Paginate the list collection and display the data on the page
ES source code API call link source code analysis
太厉害了,终于有人能把文件上传漏洞讲的明明白白了
Temporal线上部署