fix: interface_name strategy, instance hosts in sftp/scp, alias rewrites

Found by the new Docker test environment against a real NetBox 4.7:

- The interface_name strategy filtered IP addresses with interface_name
  and vminterface_name, which NetBox ignores, so it returned the first
  address of the host instead of the named interface's. Use the real
  filters interface and vminterface; a missing interface (HTTP 400)
  falls through to the next strategy.
- sftp and scp took instance-qualified hosts (prod/web01:/path) for
  local paths, because a "/" comes before the ":". Such arguments are
  remote when the prefix is a configured NetBox instance.
- Shell aliases of instance-qualified hosts ran the shortcut rules on
  "instance/host", so anchored rewrite rules never matched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-14 12:30:24 +01:00
1 parent 3c9e54b254
commit 55e7a5106b
10 files changed
+144 -11

No files matched your search

+24
View File
@@ -154,3 +154,27 @@ func TestApplyInsertsOptionsBeforeDoubleDash(t *testing.T) {
t.Fatalf("got %v, want %v", got, want)
}
}
// Instance-qualified hosts contain "/" before the ":" of host:path; only
// configured instances make such an argument remote.
func TestInstanceQualifiedHostPath(t *testing.T) {
scp := SCP.WithInstances([]string{"prod"})
ops, err := scp.Operands([]string{"a.txt", "ops@prod/web01:/tmp/", "dir/file:x"})
if err != nil {
t.Fatal(err)
}
if want := []Operand{{Idx: 1, User: "ops", Host: "prod/web01", Path: "/tmp/"}}; !reflect.DeepEqual(ops, want) {
t.Fatalf("got %+v", ops)
}
got := scp.Apply([]string{"a.txt", "ops@prod/web01:/tmp/"}, []int{1}, Host{Name: "web01", IP: "192.0.2.1"}, config.SSHOptions{}, WrapperFlags{}).Args
if want := []string{"a.txt", "ops@192.0.2.1:/tmp/"}; !reflect.DeepEqual(got, want) {
t.Fatalf("apply: %v", got)
}
sftp := SFTP.WithInstances([]string{"prod"})
if p := sftp.Parse([]string{"prod/web01:/var/log"}); p == nil || p.Host != "prod/web01" || p.Path != "/var/log" {
t.Fatalf("sftp: %+v", p)
}
if ops, _ := SCP.Operands([]string{"prod/web01:/tmp/", "."}); len(ops) != 0 {
t.Fatalf("unknown instance must stay local: %+v", ops)
}
}