feat: add pre_connect hook and optional shortcut alias display
- ssh.pre_connect: local shell command run before every connection, layered like proxy_jump (global, instance/static host, rules; "none" disables). Host details are passed as NETSSH_* env vars, a non-zero exit aborts the connection, --dry-run only prints it. - shortcuts.show: show shortcut aliases in the TUI host list, an ALIAS column in `cache list` / `hosts list` (also via --aliases) and in Tab completion. - Both editable in `netssh configure`; README and CHANGELOG updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAuVpPncumMViLLc8N4
This commit is contained in:
1 parent
3804c33669
commit
419c682a71
15 files changed
+507
-23
No files matched your search
@@ -210,3 +210,50 @@ func TestMultiConfig(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreConnectLayeringAndNone(t *testing.T) {
|
||||
cfg, err := loadYAML(t, `
|
||||
netboxes:
|
||||
- name: prod
|
||||
url: https://prod.example.com
|
||||
ssh:
|
||||
pre_connect: vpn-up prod
|
||||
- name: lab
|
||||
url: https://lab.example.com
|
||||
ssh:
|
||||
pre_connect: check-vpn
|
||||
rules:
|
||||
- match: {tag: dmz}
|
||||
pre_connect: none
|
||||
`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, tc := range []struct {
|
||||
host SSHHost
|
||||
want string
|
||||
}{
|
||||
{SSHHost{Instance: "lab", Name: "web01"}, "check-vpn"},
|
||||
{SSHHost{Instance: "prod", Name: "web01"}, "vpn-up prod"},
|
||||
{SSHHost{Instance: "prod", Name: "gw", Tags: []string{"dmz"}}, ""},
|
||||
} {
|
||||
if got := cfg.SSHOptionsFor(tc.host).PreConnectCommand(); got != tc.want {
|
||||
t.Errorf("%+v: got %q, want %q", tc.host, got, tc.want)
|
||||
}
|
||||
}
|
||||
if err := (SSHOptions{PreConnect: "a\x00b"}).Validate("ssh"); err == nil {
|
||||
t.Error("NUL byte in pre_connect accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPreConnectFromEnvironment(t *testing.T) {
|
||||
t.Setenv("NETSSH_SSH_PRE_CONNECT", "true")
|
||||
t.Setenv("NETSSH_SHORTCUTS_SHOW", "true")
|
||||
cfg, err := loadYAML(t, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if cfg.SSH.PreConnect != "true" || !cfg.Shortcuts.Show {
|
||||
t.Fatalf("env not applied: pre_connect=%q show=%v", cfg.SSH.PreConnect, cfg.Shortcuts.Show)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user