浏览代码

获取ailab表判断项目特殊修改

liweiquan 2 年之前
父节点
当前提交
7a6b8e7855
共有 6 个文件被更改,包括 27 次插入13 次删除
  1. 3 6
      app/crud/data_table.py
  2. 10 4
      app/routers/auth.py
  3. 1 0
      app/schemas/auth.py
  4. 11 1
      app/utils/send_util.py
  5. 1 1
      development.ini
  6. 1 1
      sxkj.ini

+ 3 - 6
app/crud/data_table.py

@@ -8,6 +8,7 @@ from app.common.hive import hiveDs
 from configs.globals import g
 from configs.settings import DefaultOption, config
 database_name = config.get('HIVE', 'DATABASE_NAME')
+special_project_id = config.get('PERMISSIONS', 'special_project_id')
 
 def import_datalake(db: Session, item: schemas.ImportDataLake):
     # 校验数据湖中是否存在此库表
@@ -122,13 +123,9 @@ def create_table(db: Session, item: schemas.CreateAilab):
 def filter_by_name(table_name):
     return not bool(re.search(r'(?:job.*_tmp|task.*_tmp)',table_name))
 
-def get_ailab_table(db: Session, project_id: int):
-    project: models.Project = db.query(models.Project)\
-        .filter(models.Project.id==project_id).first()
-    if not project:
-        raise Exception('项目不存在')
+def get_ailab_table(db: Session, project_id: str):
     res = []
-    if project.type == 0:
+    if project_id == special_project_id:
         table_list = hiveDs.list_tables()
         for table_name in table_list:
             if filter_by_name(table_name): res.append(table_name)

+ 10 - 4
app/routers/auth.py

@@ -22,17 +22,23 @@ router = APIRouter(
 @web_try()
 @sxtimeit
 def switch_project(switch: schemas.SwitchProject):
+    role_id = 0
     if switch.project_id == special_project_id and super_admin_role in switch.role_ids:
-        return {"role_id": 1}
+        role_id = 1
     elif switch.project_id == special_project_id:
-        return {"role_id": 3}
+        role_id = 3
     else:
-        return {"role_id": 5}
+        role_id = 5
+    token_data = {"user_id": switch.user_id,"user_name":switch.user_name,"project_id": switch.project_id, "role_id": role_id}
+    token_data_str =json.dumps(token_data)
+    access_token = encode_base64(token_data_str).replace('\n','')
+    return {"access_token": access_token, "token_type": "Bearer", "role_id": role_id}
+
 
 @router.post("/login",response_model=schemas.Token)
 async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
     user_id, project_id = form_data.username, form_data.password
-    token_data = {"user_id": user_id,"user_name":"admin","project_id": project_id, "role_id": 1}
+    token_data = {"user_id": user_id,"user_name":"刘涛","project_id": project_id, "role_id": 1}
     token_data_str =json.dumps(token_data)
     access_token = encode_base64(token_data_str).replace('\n','')
     return {"access_token": access_token, "token_type": "bearer"}

+ 1 - 0
app/schemas/auth.py

@@ -7,6 +7,7 @@ class Token(BaseModel):
 
 class TokenData(BaseModel):
     user_id: str
+    user_name: str
     project_id: str
     role_id: int
 

+ 11 - 1
app/utils/send_util.py

@@ -170,4 +170,14 @@ def update_jupyter(data):
         return res.json()
     else:
         msg = result['msg'] if 'msg' in result.keys() else result
-        raise Exception(f'更新jupyter,请求jupyter端失败-->{msg}')
+        raise Exception(f'更新jupyter,请求jupyter端失败-->{msg}')
+
+# 获取jupyter服务状态
+def get_jupyter_status(data):
+    res = requests.post(url=f'http://{PROGRAMME_URL}/helm/ops/status', json=data)
+    result = res.json()
+    if 'code' in result.keys() and result['code'] == 200:
+        return res.json()
+    else:
+        msg = result['msg'] if 'msg' in result.keys() else result
+        raise Exception(f'获取jupyter服务状态,请求jupyter端失败-->{msg}')

+ 1 - 1
development.ini

@@ -80,7 +80,7 @@ special_project_id = test
 url = aihub-dag.sxkj.com
 namespace = airflow
 super_image = SXKJ:32775/jupyterlab
-ordinary_image = SXKJ:32775/jupyterlab0
+ordinary_image = SXKJ:32775/jupyterlab
 tag = sxkj
 host = aihub-dag.sxkj.com
 chart = aihub-dag-jupyter.tgz

+ 1 - 1
sxkj.ini

@@ -88,7 +88,7 @@ special_project_id = test
 url = aihub-dag.sxkj.com
 namespace = airflow
 super_image = SXKJ:32775/jupyterlab
-ordinary_image = SXKJ:32775/jupyterlab0
+ordinary_image = SXKJ:32775/jupyterlab
 tag = sxkj
 host = aihub-dag.sxkj.com
 chart = aihub-dag-jupyter.tgz