feat: enhance host resolution, filtering, and cache management
Release / release (push) Successful in 49s
Release / release (push) Successful in 49s
- **Strategies**: Add resolver strategy input validation and parsing in setup wizard. Support comma-separated input with known strategy mapping. - **Client**: Extend Search and SearchAll to include kind and tag filters. Add pagination for full cache refresh handling large datasets. - **Cache**: Introduce `RecentlyUsed` and `MarkUsed`. Persist `LastUsed` timestamps for entries. - **TUI**: Add recent hosts view, tag/kind filters, and inline editor for user/port override. - **Tests**: Comprehensive unit tests for new features, including strategy validation, cache behavior, and client filtering. - **Docs**: Update README with new TUI features and cache subcommands.
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
# netssh
|
||||
|
||||
> **Vibe-coded project** — this codebase was written entirely by an AI assistant (Claude) without human code review. Use in production at your own risk.
|
||||
|
||||
A transparent SSH wrapper that resolves hostnames via [NetBox](https://netbox.dev/) before connecting.
|
||||
|
||||
Instead of looking up an IP manually, you just type the hostname as it appears in NetBox:
|
||||
@@ -16,7 +18,12 @@ netssh -p 2222 admin@app-server-03 uptime
|
||||
- **Transparent proxy** — replaces itself with `ssh` via `syscall.Exec`, preserving all SSH flags and options
|
||||
- **Flexible IP resolution** — configurable chain of strategies: management subnet, primary IP, or named interface
|
||||
- **Interactive TUI** — fuzzy search with live NetBox queries and 300 ms debouncing (start with `netssh`, no arguments)
|
||||
- **Recently-used list** — TUI opens with your 10 most-recently-connected hosts, no typing needed
|
||||
- **Tag/kind filter** — press `Ctrl+F` in the TUI to filter by `tag:prod` or `kind:vm`
|
||||
- **User/port override** — press `e` in the TUI to override the SSH user or port before connecting
|
||||
- **Persistent cache** — successful lookups are cached to `~/.cache/netssh/hosts.json` for instant shell completion
|
||||
- **Full pagination** — `cache refresh` fetches all hosts from NetBox (not just the first 50)
|
||||
- **Selective refresh** — `cache refresh --tag prod --kind vm` limits what gets synced
|
||||
- **Setup wizard** — interactive first-run onboarding; re-run anytime with `netssh configure`
|
||||
- **Shell completion** — install without sudo via `netssh completion install`
|
||||
- **Default SSH user** — set a fallback username once in config instead of typing it every time
|
||||
@@ -140,20 +147,43 @@ Run without arguments to open the interactive search:
|
||||
netssh
|
||||
```
|
||||
|
||||
The TUI opens with your 10 most-recently-connected hosts. Start typing to search all cached hosts or query NetBox live.
|
||||
|
||||
| Key | Action |
|
||||
|-----|--------|
|
||||
| type | filter hosts (300 ms debounce → NetBox query) |
|
||||
| `Tab` | autocomplete top result into the search field |
|
||||
| `↑` / `↓` | navigate results |
|
||||
| `Enter` | connect to selected host |
|
||||
| `Esc` / `Ctrl+C` | quit |
|
||||
| `e` | open inline editor to override user/port before connecting |
|
||||
| `Ctrl+F` | open/close tag and kind filter (`tag:prod kind:vm`) |
|
||||
| `Esc` / `Ctrl+C` | quit (or close filter/edit if open) |
|
||||
|
||||
**Tag and kind filter** — press `Ctrl+F` to open a second input line:
|
||||
|
||||
```
|
||||
Filter: tag:prod kind:vm
|
||||
```
|
||||
|
||||
Multiple `tag:` values are AND-combined. The filter is applied locally against the cache; when doing a live NetBox search the first tag is also forwarded as a query parameter.
|
||||
|
||||
**User/port override** — press `e` on any highlighted host:
|
||||
|
||||
```
|
||||
Connect as: admin@my-router:22
|
||||
```
|
||||
|
||||
Edit the pre-filled value and press `Enter` to connect. `Esc` cancels. Port 22 is treated as default and omitted from the ssh command.
|
||||
|
||||
### Cache management
|
||||
|
||||
```sh
|
||||
netssh cache list # show all cached entries
|
||||
netssh cache refresh # re-fetch all hosts from NetBox
|
||||
netssh cache clear # wipe the cache
|
||||
netssh cache list # show all cached entries
|
||||
netssh cache refresh # re-fetch ALL hosts from NetBox (paginated)
|
||||
netssh cache refresh --tag prod # only hosts with the "prod" tag
|
||||
netssh cache refresh --kind vm # only virtual machines
|
||||
netssh cache refresh --tag prod --kind vm # combine filters
|
||||
netssh cache clear # wipe the cache
|
||||
```
|
||||
|
||||
### Search (for scripting)
|
||||
@@ -207,6 +237,10 @@ go build ./... # build all packages
|
||||
|
||||
The test suite covers the cache, NetBox client (via `httptest`), IP resolver chain, SSH argument parser, config loading, and the setup wizard.
|
||||
|
||||
## Disclaimer
|
||||
|
||||
This is a **vibe-coded** project: the entire codebase — architecture, implementation, tests, and docs — was generated by an AI assistant (Claude by Anthropic). No human has reviewed or audited the code. It works for the author's personal use case, but correctness and security are not guaranteed. Read the source before running it in sensitive environments.
|
||||
|
||||
## How it works
|
||||
|
||||
1. `netssh` checks whether the first argument is a known subcommand (`configure`, `search`, `cache`, `completion`). If not, it enters SSH wrapper mode.
|
||||
|
||||
Reference in New Issue
Block a user