49 lines
2.2 KiB
Python
49 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""Remote Skill create API"""
|
|
import json, uuid, time
|
|
|
|
result = {'widgettype': 'Message', 'options': {'title': 'Error', 'message': 'Invalid request', 'type': 'error'}}
|
|
|
|
try:
|
|
dbname = get_module_dbname('harnessed_agent')
|
|
user_id = await get_user()
|
|
now = time.strftime('%Y-%m-%d %H:%M:%S')
|
|
new_id = str(uuid.uuid4()).replace('-', '')
|
|
|
|
name = params_kw.get('name', '').strip()
|
|
host = params_kw.get('host', '').strip()
|
|
port = params_kw.get('port', '').strip()
|
|
username = params_kw.get('username', '').strip()
|
|
remote_path = params_kw.get('remote_path', '').strip()
|
|
auth_method = params_kw.get('auth_method', '').strip()
|
|
ssh_key_path = params_kw.get('ssh_key_path', '').strip()
|
|
description = params_kw.get('description', '').strip()
|
|
category = params_kw.get('category', '').strip()
|
|
version = params_kw.get('version', '').strip()
|
|
enabled = params_kw.get('enabled', '').strip()
|
|
|
|
async with DBPools().sqlorContext(dbname) as sor:
|
|
await sor.sqlExe("""INSERT INTO harnessed_remote_skills (id, user_id, name, host, port, username, remote_path, auth_method, ssh_key_path, description, category, version, enabled, created_at, updated_at)
|
|
VALUES (${id}$, ${user_id}$, ${name}$, ${host}$, ${port}$, ${username}$, ${remote_path}$, ${auth_method}$, ${ssh_key_path}$, ${description}$, ${category}$, ${version}$, ${enabled}$, ${created_at}$, ${updated_at}$)""", {
|
|
'id': new_id, 'user_id': user_id,
|
|
'name': name,
|
|
'host': host,
|
|
'port': port,
|
|
'username': username,
|
|
'remote_path': remote_path,
|
|
'auth_method': auth_method,
|
|
'ssh_key_path': ssh_key_path,
|
|
'description': description,
|
|
'category': category,
|
|
'version': version,
|
|
'enabled': enabled,
|
|
'created_at': now, 'updated_at': now
|
|
})
|
|
result = {'widgettype': 'Message', 'options': {'title': 'Success', 'message': 'Remote Skill创建成功', 'type': 'success'}}
|
|
|
|
except Exception as e:
|
|
result['options'] = {'title': 'Error', 'message': '创建失败: ' + str(e), 'type': 'error'}
|
|
|
|
return json.dumps(result, ensure_ascii=False)
|