Skip to content

Commit

Permalink
2024年12月13日 优化应用管理02
Browse files Browse the repository at this point in the history
  • Loading branch information
ss1917 committed Dec 13, 2024
1 parent 2213327 commit f1719fb
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 38 deletions.
56 changes: 37 additions & 19 deletions libs/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,53 @@
Version : 0.0.1
Contact : [email protected]
Author : shenshuo
Date : 2021/11/1 17:07
Desc : 注册各种信息到pass平台
Date : 2024/12/13 17:07
Desc : 注册各种信息到管理平台
"""

import json
import logging

from websdk2.client import AcsClient
from websdk2.configs import configs
from settings import settings

if configs.can_import: configs.import_dict(**settings)
client = AcsClient()

# uri = "/api/mg/v3/accounts/authority/register/"
uri = "/api/p/v4/authority/register/"

menu_list = [
{
"name": "MGauthority",
"details": "权限-权限管理"
"details": "管理后台-权限-权限管理"
}, {
"name": "MGuserlist",
"details": "权限-用户列表"
"details": "管理后台-权限-用户列表"
}, {
"name": "MGtokenlist",
"details": "权限-令牌列表"
"details": "管理后台-权限-令牌列表"
}, {
"name": "MGLinklist",
"details": "权限-免密链接"
"details": "管理后台-权限-免密链接"
}, {
"name": "MGapplist",
"details": "权限-应用列表"
"details": "管理后台-权限-应用列表"
}, {
"name": "MGbusiness",
"details": "权限-业务管理列表"
"details": "管理后台-权限-业务管理列表"
}, {
"name": "MGmenus",
"details": "权限-菜单列表"
"details": "管理后台-权限-菜单列表"
}, {
"name": "MGcomponents",
"details": "权限-前端组件"
"details": "管理后台-权限-前端组件"
}, {
"name": "MGfunctions",
"details": "权限-权限列表"
"details": "管理后台-权限-权限列表"
}, {
"name": "MGrole",
"details": "权限-角色管理"
"details": "管理后台-权限-角色管理"
},
{
"name": "systeMmanage",
Expand All @@ -61,19 +62,19 @@
},
{
"name": "systemEmail",
"details": "管理后台-邮件设置"
"details": "管理后台-配置-邮件设置"
},
{
"name": "systemLdap",
"details": "管理后台-LDAP设置"
"details": "管理后台-配置-LDAP设置"
},
{
"name": "systemBase",
"details": "管理后台-基础设置"
"details": "管理后台-配置-基础设置"
},
{
"name": "systemFeishu",
"details": "管理后台-飞书设置"
"details": "管理后台-配置-飞书设置"
},
{
"name": "systemAudit",
Expand All @@ -83,6 +84,22 @@
"name": "systemAuditLog",
"details": "管理后台-审计日志"
},
{
"name": "homepageManage",
"details": "管理后台-首页管理"
},
{
"name": "MGopsService",
"details": "管理后台-首页管理-导航页步骤"
},
{
"name": "MGopsGlobalCategory",
"details": "管理后台-首页管理-导航页项目分类"
},
{
"name": "MGopsGlobalService",
"details": "管理后台-首页管理-导航页项目服务"
},
]
component_list = [
{
Expand Down Expand Up @@ -242,14 +259,15 @@ def registration_to_paas():
body=json.dumps(body),
description='自动注册')
response = client.do_action(**registration_data)
print(json.loads(response))
logging.info(json.loads(response))
return response


class Registration:
def __init__(self, **kwargs):
pass

def start_server(self):
@staticmethod
def start_server():
registration_to_paas()
raise Exception('初始化完成')
3 changes: 1 addition & 2 deletions mg/handlers/apps_v4_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def get(self, *args, **kwargs):
(r"/v4/apps/", AppsV4Handler, {"handle_name": "PAAS管理-应用管理", "method": ["ALL"]}),
(r"/v4/role_app/", RoleAPPHandler, {"handle_name": "权限中心-应用角色管理", "method": ["ALL"]}),
(r"/v4/apps/list/", AppListHandler, {"handle_name": "PAAS-基础功能-查看应用列表", "method": ["GET"]}),
(r"/v4/na/apps/list/", AppListHandler, {"handle_name": "PAAS-基础功能-免认证查看应用列表", "method": ["GET"]}),

(r"/v4/na/apps/list/", AppListHandler, {"handle_name": "PAAS-基础功能-免认证查看应用列表", "method": ["GET"]})
]

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion mg/handlers/business_v4_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def get(self):

biz_v4_mg_urls = [
(r"/v4/biz/", BusinessHandler, {"handle_name": "权限中心-业务管理", "method": ["ALL"]}),
(r"/v4/biz/list/", BusinessListHandler, {"handle_name": "PAAS基础功能-查看业务列表和切换", "method": ["GET"]}),
(r"/v4/biz/list/", BusinessListHandler, {"handle_name": "PAAS-基础功能-查看业务列表和切换", "method": ["GET"]}),
(r"/v4/na/biz/list/", BizListNaHandler, {"handle_name": "PAAS-基础功能-免认证查看业务列表", "method": ["GET"]}),
(r"/v4/na/biz/change/", BizChangeNaHandler, {"handle_name": "PAAS-基础功能-免认证切换业务", "method": ["GET"]})
]
Expand Down
28 changes: 12 additions & 16 deletions mg/handlers/sys_mg_v4_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import base64
import json
import logging
from abc import ABC
from concurrent.futures import ThreadPoolExecutor

Expand Down Expand Up @@ -106,14 +107,15 @@ def post(self, *args, **kwargs):
try:
self.register_func(func_list)
except Exception as err:
print(err)
return self.write(dict(code=-2, msg='注册API权限失败'))
logging.error(f"注册API权限失败 {err}")
# return self.write(dict(code=-2, msg='注册API权限失败'))

if menu_list and isinstance(menu_list, list):
try:
self.register_menu(menu_list)
except Exception as err:
return self.write(dict(code=-3, msg='注册前端菜单失败'))
logging.error(f"注册前端菜单失败 {err}")
# return self.write(dict(code=-3, msg='注册前端菜单失败'))

if component_list and isinstance(component_list, list):
try:
Expand All @@ -130,23 +132,19 @@ def post(self, *args, **kwargs):
return self.write(dict(code=0, msg='注册结束'))

def register_menu(self, data):
for d in data:
menu_name = d.get('name')
details = d.get('details', '')[0:250]
if not menu_name: continue
valid_data = filter(lambda d: d.get('name'), data)
for d in valid_data:
with DBContext('w', None, True) as session:
menu_name = d['name']
details = (d.get('details') or '')[:250]
try:
session.add(insert_or_update(Menus, f"menu_name='{menu_name}' and app_code='{self.app_code}'",
app_code=self.app_code, details=details,
menu_name=menu_name))
except exc.IntegrityError as e:
print(e)
app_code=self.app_code, details=details, menu_name=menu_name))
except Exception as err:
print(err)

logging.error(err)
session.commit()
def register_component(self, data):
for d in data:
status = d.get('status', '0')
name = d.get('name')
details = d.get('details', '')[0:250]
if not name: continue
Expand All @@ -155,8 +153,6 @@ def register_component(self, data):
session.add(insert_or_update(Components,
f"name='{name}' and app_code='{self.app_code}'",
app_code=self.app_code, details=details, name=name))
except exc.IntegrityError as e:
print(e)
except Exception as err:
print(err)

Expand Down

0 comments on commit f1719fb

Please sign in to comment.