feat: add --type support to --add command
- Support for all server types: ssh, telnet, mariadb, mssql, postgresql, redis, grafana, prometheus, winrm, rdp - Add --type, --database, --token options to --add command - Add server type validation - Add type-specific fields (database, token, auth_method) - Update skill-ssh.md with new usage Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -50,7 +50,7 @@ python ~/.server-connections/ssh.py --remove ALIAS
|
||||
|
||||
### Добавить сервер
|
||||
```bash
|
||||
python ~/.server-connections/ssh.py --add ALIAS IP PORT USER PASSWORD [--note "описание"]
|
||||
python ~/.server-connections/ssh.py --add ALIAS IP PORT USER PASSWORD [--type ssh|telnet|mariadb|mssql|postgresql|redis|grafana|prometheus|winrm|rdp] [--note "описание"] [--database DB] [--token TOKEN]
|
||||
```
|
||||
- Автоматически устанавливает SSH-ключ после добавления
|
||||
- Обновляет `~/.ssh/config`
|
||||
|
||||
68
tools/ssh.py
68
tools/ssh.py
@@ -14,7 +14,7 @@ Usage (SSH):
|
||||
python ssh.py --status
|
||||
python ssh.py --info ALIAS # full info (no passwords)
|
||||
python ssh.py --set-note ALIAS "desc" # update server notes
|
||||
python ssh.py --add ALIAS IP PORT USER PASSWORD [--note "desc"]
|
||||
python ssh.py --add ALIAS IP PORT USER PASSWORD [--type ssh|telnet|mariadb|mssql|postgresql|redis|grafana|prometheus|winrm|rdp] [--note "desc"] [--database DB] [--token TOKEN]
|
||||
python ssh.py --remove ALIAS
|
||||
|
||||
SQL (type: mariadb / mssql / postgresql):
|
||||
@@ -762,15 +762,40 @@ def check_status():
|
||||
|
||||
def add_server(args):
|
||||
if len(args) < 5:
|
||||
print("Usage: --add ALIAS IP PORT USER PASSWORD [--note \"desc\"]")
|
||||
print("Usage: --add ALIAS IP PORT USER PASSWORD [--type ssh|telnet|mariadb|mssql|postgresql|redis|grafana|prometheus|winrm|rdp] [--note \"desc\"] [--database DB] [--token TOKEN]")
|
||||
sys.exit(1)
|
||||
|
||||
alias, ip, port, user, password = args[0], args[1], int(args[2]), args[3], args[4]
|
||||
|
||||
# Parse optional arguments
|
||||
stype = "ssh" # default
|
||||
note = ""
|
||||
if "--note" in args:
|
||||
idx = args.index("--note")
|
||||
if idx + 1 < len(args):
|
||||
note = args[idx + 1]
|
||||
database = ""
|
||||
token = ""
|
||||
|
||||
i = 5
|
||||
while i < len(args):
|
||||
arg = args[i]
|
||||
if arg == "--type" and i + 1 < len(args):
|
||||
stype = args[i + 1]
|
||||
i += 2
|
||||
elif arg == "--note" and i + 1 < len(args):
|
||||
note = args[i + 1]
|
||||
i += 2
|
||||
elif arg == "--database" and i + 1 < len(args):
|
||||
database = args[i + 1]
|
||||
i += 2
|
||||
elif arg == "--token" and i + 1 < len(args):
|
||||
token = args[i + 1]
|
||||
i += 2
|
||||
else:
|
||||
i += 1
|
||||
|
||||
# Validate server type
|
||||
valid_types = ["ssh", "telnet", "mariadb", "mssql", "postgresql", "redis", "grafana", "prometheus", "winrm", "rdp"]
|
||||
if stype not in valid_types:
|
||||
print(f"ERROR: Invalid server type '{stype}'. Valid types: {', '.join(valid_types)}")
|
||||
sys.exit(1)
|
||||
|
||||
data, servers = load_servers()
|
||||
if alias in servers:
|
||||
@@ -778,20 +803,43 @@ def add_server(args):
|
||||
sys.exit(1)
|
||||
|
||||
new_server = {
|
||||
"alias": alias, "ip": ip, "port": port,
|
||||
"user": user, "auth": "ssh-key", "password": password,
|
||||
"alias": alias,
|
||||
"type": stype,
|
||||
"ip": ip,
|
||||
"port": port,
|
||||
"user": user,
|
||||
"password": password,
|
||||
"notes": note
|
||||
}
|
||||
|
||||
# Add type-specific fields
|
||||
if stype in ["mariadb", "mssql", "postgresql"]:
|
||||
if database:
|
||||
new_server["database"] = database
|
||||
elif stype in ["redis", "grafana", "prometheus"]:
|
||||
if token:
|
||||
new_server["token"] = token
|
||||
elif stype in ["winrm", "rdp"]:
|
||||
# WinRM/RDP may have additional auth fields
|
||||
new_server["auth_method"] = "password" # default
|
||||
|
||||
# SSH-specific fields
|
||||
if stype == "ssh":
|
||||
new_server["auth"] = "ssh-key" # default auth method
|
||||
|
||||
data["servers"].append(new_server)
|
||||
save_servers(data)
|
||||
update_ssh_config(alias, ip, port, user)
|
||||
print(f"Added: {alias}")
|
||||
|
||||
# Update SSH config only for SSH servers
|
||||
if stype == "ssh":
|
||||
update_ssh_config(alias, ip, port, user)
|
||||
try:
|
||||
install_key(new_server)
|
||||
except Exception as e:
|
||||
print(f"Warning: key not installed ({e}). Run: ssh.py {alias} --install-key")
|
||||
|
||||
print(f"Added: {alias} (type: {stype})")
|
||||
|
||||
|
||||
def set_note(alias: str, note: str):
|
||||
"""Update server notes — safe for AI (no credentials exposed)."""
|
||||
|
||||
Reference in New Issue
Block a user