feat(instances): allow disabling prefixes in aliases and TUI
Release / release (push) Canceled after 0s

This commit is contained in:
Sebastian Unterschütz committed 2026-11-16 22:13:05 +01:00
1 parent d9060a6eb7
commit 3804c33669
12 files changed
+298 -19

No files matched your search

+6 -5
View File
@@ -30,11 +30,12 @@ type ShellConfig struct {
}
type NetBoxConfig struct {
Name string `mapstructure:"name"`
URL string `mapstructure:"url"`
Token string `mapstructure:"token"`
TokenVersion int `mapstructure:"token_version"`
SSH SSHOptions `mapstructure:"ssh"`
DisablePrefix bool `mapstructure:"disable_prefix"`
Name string `mapstructure:"name"`
URL string `mapstructure:"url"`
Token string `mapstructure:"token"`
TokenVersion int `mapstructure:"token_version"`
SSH SSHOptions `mapstructure:"ssh"`
}
type ResolverConfig struct {
+14
View File
@@ -65,3 +65,17 @@ func (c *Config) CachePath() string {
sum := sha256.Sum256([]byte(strings.Join(identities, "\x00")))
return filepath.Join(filepath.Dir(c.Cache.Path), fmt.Sprintf("instances-%x", sum[:8]), filepath.Base(c.Cache.Path))
}
// HostLabel omits the configured instance prefix for display only. Callers
// must retain the canonical target for connections and handle label collisions.
func (c *Config) HostLabel(target string) string {
source, host, qualified := strings.Cut(target, "/")
if qualified {
for _, instance := range c.NetBoxes {
if instance.DisablePrefix && strings.EqualFold(instance.Name, source) {
return host
}
}
}
return target
}
+8
View File
@@ -15,6 +15,7 @@ func TestLoadNamedNetBoxes(t *testing.T) {
- name: Office
url: https://office.example/netbox
token: nbt_office
disable_prefix: true
- name: lab
url: https://lab.example
token: legacy-token
@@ -34,7 +35,14 @@ cache:
if cfg.NetBox.URL != "" {
t.Fatal("legacy environment variables added an unnamed instance")
}
if !cfg.NetBoxes[0].DisablePrefix || cfg.NetBoxes[1].DisablePrefix {
t.Fatal("per-instance alias prefix setting was not loaded")
}
first := cfg.CachePath()
cfg.NetBoxes[0].DisablePrefix = false
if cfg.CachePath() != first {
t.Fatal("alias prefix setting discarded cache")
}
if first == cfg.Cache.Path {
t.Fatal("named sources reuse legacy cache")
}