pipeline-sdlc/wwwroot/sd_deploy_envs/get_sd_deploy_envs.dspy

183 lines
4.2 KiB
Plaintext

ns = params_kw.copy()
debug(f'get_sd_deploy_envs.dspy:{ns=}')
if not ns.get('page'):
ns['page'] = 1
if not ns.get('sort'):
ns['sort'] = ["env_type"]
sql = '''select a.*, b.project_id_text, c.env_type_text, d.status_text
from (select * from sd_deploy_envs where 1=1 [[filterstr]]) a left join (select id as project_id,
name as project_id_text from sd_projects where 1 = 1) b on a.project_id = b.project_id left join (select k as env_type,
v as env_type_text from appcodes_kv where parentid='sd_env_type') c on a.env_type = c.env_type left join (select k as status,
v as status_text from appcodes_kv where parentid='sd_env_status') d on a.status = d.status'''
filterjson = params_kw.get('data_filter')
if filterjson and isinstance(filterjson, str):
try:
filterjson = json.loads(filterjson)
except (json.JSONDecodeError, TypeError):
filterjson = None
fields_str=r'''[
{
"name": "id",
"title": "主键ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "project_id",
"title": "项目ID",
"type": "str",
"length": 32,
"nullable": "no"
},
{
"name": "env_type",
"title": "环境类型",
"type": "str",
"length": 20,
"nullable": "no"
},
{
"name": "host",
"title": "SSH主机地址",
"type": "str",
"length": 200,
"nullable": "no"
},
{
"name": "port",
"title": "SSH端口",
"type": "int",
"nullable": "no",
"default": "22"
},
{
"name": "user",
"title": "SSH用户",
"type": "str",
"length": 100,
"nullable": "no"
},
{
"name": "ssh_key_path",
"title": "SSH密钥路径",
"type": "str",
"length": 500
},
{
"name": "sudo_enabled",
"title": "免密Sudo",
"type": "str",
"length": 1,
"nullable": "no",
"default": "'N'"
},
{
"name": "deploy_path",
"title": "部署目录",
"type": "str",
"length": 500,
"nullable": "no"
},
{
"name": "python_path",
"title": "Python路径",
"type": "str",
"length": 500
},
{
"name": "db_host",
"title": "数据库地址",
"type": "str",
"length": 200
},
{
"name": "db_port",
"title": "数据库端口",
"type": "int",
"default": "3306"
},
{
"name": "db_name",
"title": "数据库名",
"type": "str",
"length": 100
},
{
"name": "db_user",
"title": "数据库用户",
"type": "str",
"length": 100
},
{
"name": "db_password",
"title": "数据库密码(加密)",
"type": "str",
"length": 500
},
{
"name": "status",
"title": "环境状态",
"type": "str",
"length": 20,
"nullable": "no",
"default": "'configured'"
},
{
"name": "verified_at",
"title": "最近验证时间",
"type": "timestamp"
},
{
"name": "created_at",
"title": "创建时间",
"type": "timestamp",
"nullable": "no"
},
{
"name": "updated_at",
"title": "更新时间",
"type": "timestamp"
}
]'''
ori_fields = json.loads(fields_str)
if not filterjson:
fields = [ f['name'] for f in ori_fields ]
filterjson = default_filterjson(fields, ns)
filterdic = ns.copy()
filterdic['filterstr'] = ''
filterdic['userorgid'] = '${userorgid}$'
filterdic['userid'] = '${userid}$'
if filterjson:
dbf = DBFilter(filterjson)
conds = dbf.gen(ns)
if conds:
ns.update(dbf.consts)
conds = f' and {conds}'
filterdic['filterstr'] = conds
ac = ArgsConvert('[[', ']]')
vars = ac.findAllVariables(sql)
NameSpace = {v:'${' + v + '}$' for v in vars if v != 'filterstr' }
filterdic.update(NameSpace)
sql = ac.convert(sql, filterdic)
debug(f'{sql=}')
db = DBPools()
dbname = get_module_dbname('pipeline_sdlc')
async with db.sqlorContext(dbname) as sor:
r = await sor.sqlPaging(sql, ns)
return r
return {
"total":0,
"rows":[]
}