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>
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
// Package secret keeps NetBox API tokens in the operating system's keyring
|
|
// (Secret Service on Linux, Keychain on macOS) instead of the config file.
|
|
package secret
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/zalando/go-keyring"
|
|
)
|
|
|
|
// Service is the keyring service name of all netssh entries.
|
|
const Service = "netssh"
|
|
|
|
// ErrNotFound means the keyring has no token for the account.
|
|
var ErrNotFound = errors.New("no token in the system keyring")
|
|
|
|
// Get returns the token stored for account.
|
|
func Get(account string) (string, error) {
|
|
token, err := keyring.Get(Service, account)
|
|
if errors.Is(err, keyring.ErrNotFound) {
|
|
return "", fmt.Errorf("%w for %q (store one with: netssh token set %s)", ErrNotFound, account, account)
|
|
}
|
|
if err != nil {
|
|
return "", fmt.Errorf("system keyring: %w", err)
|
|
}
|
|
return token, nil
|
|
}
|
|
|
|
// Set stores token for account, replacing an existing one.
|
|
func Set(account, token string) error {
|
|
if err := keyring.Set(Service, account, token); err != nil {
|
|
return fmt.Errorf("system keyring: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Delete removes the token of account; a missing entry is not an error.
|
|
func Delete(account string) error {
|
|
err := keyring.Delete(Service, account)
|
|
if err != nil && !errors.Is(err, keyring.ErrNotFound) {
|
|
return fmt.Errorf("system keyring: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// MockInit replaces the system keyring with an in-memory one, for tests.
|
|
func MockInit() { keyring.MockInit() }
|