当前位置:网站首页>关于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
边栏推荐
- .NET-6.WinForm2.NanUI learning and summary
- ABC D - Distinct Trio(k元组的个数
- 【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
- 精解四大集合框架:List 核心知识总结
- a different object with the same identifier value was already associated with the session
- [Cloud Native] DevOps (5): Integrating Harbor
- Minio上传文件ssl证书不受信任
- Information System Project Manager Core Test Site (55) Configuration Manager (CMO) Work
- TOGAF之架构标准规范(一)
- 12个MySQL慢查询的原因分析
猜你喜欢
MySQL database backup
Shell重油常压塔模拟仿真与控制
Unity手机游戏性能优化系列:针对CPU端的性能调优
110 MySQL interview questions and answers (continuously updated)
sql语句之多表查询
[Introduction to MySQL 8 to Mastery] Basics - silent installation of MySQL on Linux system, cross-version upgrade
MySQL_关于JSON数据的查询
再见了繁琐的Excel,掌握数据分析处理技术就靠它了
MySQL-如何分库分表?一看就懂
【mysql 提高查询效率】Mysql 数据库查询好慢问题解决
随机推荐
pycharm专业版使用
城市内涝及桥洞隧道积水在线监测系统
MySQL8--Windows下使用压缩包安装的方法
关于小白安装nodejs遇到的问题(npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
MySQL事务隔离级别详解
Interviewer: If the order is not paid within 30 minutes, it will be automatically canceled. How to do this?
Error EPERM operation not permitted, mkdir 'Dsoftwarenodejsnode_cache_cacach Two solutions
Simple read operation of EasyExcel
12 reasons for MySQL slow query
About the problems encountered by Xiaobai installing nodejs (npm WARN config global `--global`, `--local` are deprecated. Use `--location=glob)
MySQL_关于JSON数据的查询
The 15th day of the special assault version of the sword offer
Mysql——字符串函数
精解四大集合框架:List 核心知识总结
MySQL-如何分库分表?一看就懂
MySQL8.0安装教程,在Linux环境安装MySQL8.0教程,最新教程 超详细
The Vue project connects to the MySQL database through node and implements addition, deletion, modification and query operations
面试官,不要再问我三次握手和四次挥手
PCL calculates the point cloud coordinate maximum and its index
MYSQL一站式学习,看完即学完