feat: NetBox insights, host tools and configurable TUI
Test / test (pull_request) Successful in 4m15s

- info/open/whois: NetBox details (site, nested locations, rack units,
  role, platform, tenant, IPs per interface), web page, reverse IP lookup
- cache status, site, role, platform, tenant, location chain and rack;
  ask before connecting to hosts in ssh.warn_status (--force skips)
- ssh rules and command restrictions match site/role/platform/tenant/status
- tui.columns selects what the TUI shows; optional TCP reachability column;
  detail view (Ctrl+L), NetBox page (Ctrl+G), status/location filters
- resolver.fallback tries other strategies' addresses when unreachable
- copy-id, known-hosts reset and address-change notices
- export ansible (YAML/INI) and export ssh-config
- token: keyring stores NetBox tokens in the system keyring
- fix stale menu number in testenv configure test

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-18 12:33:59 +01:00
1 parent e5bde9c61f
commit 1660bb3098
39 files changed
+4868 -96

No files matched your search

+67 -5
View File
@@ -6,6 +6,7 @@ import (
"path/filepath"
"regexp"
"strings"
"time"
"github.com/spf13/viper"
)
@@ -42,6 +43,11 @@ type NetBoxConfig struct {
}
type ResolverConfig struct {
// Fallback tries the addresses of the other strategies when the chosen
// address does not accept TCP connections on the SSH port.
Fallback bool `mapstructure:"fallback"`
// FallbackTimeout is the per-address connect timeout in milliseconds; 0 = 1000.
FallbackTimeout int `mapstructure:"fallback_timeout"`
Strategies []string `mapstructure:"strategies"`
ManagementSubnets []string `mapstructure:"management_subnets"`
InterfaceName string `mapstructure:"interface_name"`
@@ -57,8 +63,11 @@ type CacheConfig struct {
type SSHConfig struct {
DefaultUser string `mapstructure:"default_user"`
DefaultPort int `mapstructure:"default_port"`
SSHOptions `mapstructure:",squash"`
Rules []SSHRule `mapstructure:"rules"`
// WarnStatus lists NetBox status values that ask before connecting;
// nil means DefaultWarnStatus, an empty list disables the question.
WarnStatus []string `mapstructure:"warn_status"`
SSHOptions `mapstructure:",squash"`
Rules []SSHRule `mapstructure:"rules"`
}
type CompletionConfig struct {
@@ -100,6 +109,51 @@ func (s ShortcutsConfig) Validate() error {
return nil
}
// DefaultWarnStatus are the NetBox status values that ask before connecting.
var DefaultWarnStatus = []string{"offline", "planned", "staged", "failed", "inventory", "decommissioning"}
// KeyringToken as a token value reads the token from the system keyring.
const KeyringToken = "keyring"
// IsKeyringToken reports whether token refers to the system keyring.
func IsKeyringToken(token string) bool {
return strings.EqualFold(strings.TrimSpace(token), KeyringToken)
}
// KeyringAccount is the keyring entry of a NetBox instance; the unnamed
// single-instance configuration uses "default".
func (n NetBoxConfig) KeyringAccount() string {
if n.Name == "" {
return "default"
}
return strings.ToLower(n.Name)
}
// WarnsStatus reports whether status is configured to ask before connecting.
func (s SSHConfig) WarnsStatus(status string) bool {
if status == "" {
return false
}
list := s.WarnStatus
if list == nil {
list = DefaultWarnStatus
}
for _, warn := range list {
if strings.EqualFold(strings.TrimSpace(warn), status) {
return true
}
}
return false
}
// FallbackTimeoutDuration returns resolver.fallback_timeout, 1s by default.
func (r ResolverConfig) FallbackTimeoutDuration() time.Duration {
if r.FallbackTimeout <= 0 {
return time.Second
}
return time.Duration(r.FallbackTimeout) * time.Millisecond
}
// Path returns the canonical config file path.
func Path() string {
configDir, err := os.UserConfigDir()
@@ -131,7 +185,7 @@ func Load() (*Config, error) {
v.SetEnvPrefix("NETSSH")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
for _, key := range []string{"netbox.url", "netbox.token", "netbox.token_version", "resolver.strategies", "resolver.management_subnets", "resolver.interface_name", "resolver.hostname_domain", "cache.ttl", "cache.path", "ssh.default_user", "ssh.default_port", "shortcuts.domains", "shortcuts.strip_hyphens", "shortcuts.show", "shell.alias", "ssh.proxy_jump", "ssh.pre_connect", "ssh.post_disconnect", "tui.history_limit", "activity.enabled", "activity.retention_days", "activity.max_entries", "ssh.host_key_checking", "ssh.target", "ssh.address_family", "completion.max_results", "multi.multiplexer", "multi.panes_per_window"} {
for _, key := range []string{"netbox.url", "netbox.token", "netbox.token_version", "resolver.strategies", "resolver.management_subnets", "resolver.interface_name", "resolver.hostname_domain", "cache.ttl", "cache.path", "ssh.default_user", "ssh.default_port", "shortcuts.domains", "shortcuts.strip_hyphens", "shortcuts.show", "shell.alias", "ssh.proxy_jump", "ssh.pre_connect", "ssh.post_disconnect", "tui.history_limit", "activity.enabled", "activity.retention_days", "activity.max_entries", "ssh.host_key_checking", "ssh.target", "ssh.address_family", "completion.max_results", "multi.multiplexer", "multi.panes_per_window", "ssh.warn_status", "tui.columns", "tui.reachability_timeout", "resolver.fallback", "resolver.fallback_timeout"} {
if err := v.BindEnv(key); err != nil {
return nil, err
}
@@ -147,6 +201,14 @@ func Load() (*Config, error) {
if err := v.Unmarshal(&cfg); err != nil {
return nil, fmt.Errorf("parsing config: %w", err)
}
// "columns: []" shows only the hostname; only a missing key means the default.
if cfg.TUI.Columns == nil && v.IsSet("tui.columns") {
cfg.TUI.Columns = []string{}
}
// "warn_status: []" disables the question; only a missing key means the default.
if cfg.SSH.WarnStatus == nil && v.IsSet("ssh.warn_status") {
cfg.SSH.WarnStatus = []string{}
}
// Legacy environment variables must not invent an additional unnamed source
// when a file explicitly configures named instances (including wizard migration).
if len(cfg.NetBoxes) > 0 && !v.InConfig("netbox.url") {
@@ -157,7 +219,7 @@ func Load() (*Config, error) {
return nil, err
}
if cfg.NetBox.TokenVersion == 0 && cfg.NetBox.Token != "" {
if cfg.NetBox.TokenVersion == 0 && cfg.NetBox.Token != "" && !IsKeyringToken(cfg.NetBox.Token) {
if strings.HasPrefix(cfg.NetBox.Token, "nbt_") {
cfg.NetBox.TokenVersion = 2
} else {
@@ -189,7 +251,7 @@ func Load() (*Config, error) {
for i := range cfg.NetBoxes {
source := &cfg.NetBoxes[i]
source.Name = strings.ToLower(source.Name)
if source.TokenVersion == 0 && source.Token != "" {
if source.TokenVersion == 0 && source.Token != "" && !IsKeyringToken(source.Token) {
source.TokenVersion = 1
if strings.HasPrefix(source.Token, "nbt_") {
source.TokenVersion = 2