feat: first-run setup screen + VPC-aware connection management (#11)#12
Merged
Conversation
Make tusk easy to start against real databases.
Onboarding: when a connection can't be established — no config, an unknown
profile, or an unreachable DB — tusk now opens an interactive setup screen
instead of printing a cobra error and exiting. The user enters a connection
(or a tunnel), tusk validates it with a real Ping, optionally saves it as a
profile (comment-preserving), and drops straight into the TUI. Subsequent
launches connect through.
Connectivity: new TUI-free internal/connect package turns a profile into a
reachable DSN, establishing a tunnel first when needed and tearing it down on
exit. Methods:
- direct (default): use the URL/fields as-is.
- kube-port-forward: spawn `kubectl port-forward` into a cluster (GKE), wait
for the local port, connect, kill the process group on exit.
- exec: run an arbitrary tunnel command (SSH bastion, cloud-sql-proxy, …)
with {local_port} substitution.
Both tusk and the tuskd daemon use it, so headless enforcement works against
VPC databases too.
Config gains a `connect:` block (ConnectConfig) and omitempty on Profile
fields; SaveProfile persists a profile via the same comment-preserving YAML
node edit as SaveProfileRules, carrying existing rules over.
Tests: connect method dispatch, kube argv, {local_port} substitution,
freePort/waitForPort (incl. process-death), and spawn/teardown; SaveProfile
round-trips. Verified end-to-end against local Postgres: direct onboarding
saves a working profile and re-runs connect through, and an exec tunnel
(via a stand-in forwarder) drives tuskd against a real DB and cleans up.
Closes #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Makes tusk easy to start against real (VPC) databases.
Onboarding. When no connection can be established — no config, an unknown profile (
tusk -P nope), or an unreachable DB — tusk opens an interactive setup screen instead of a cobra error + exit. It validates the connection with a realPing, optionally saves it as a profile (comment-preserving), and drops straight into the TUI. Next launch connects through.Connectivity. New TUI-free
internal/connectpackage turns a profile into a reachable DSN, establishing a tunnel first and tearing it down on exit:direct(default) — URL/fields as-is.kube-port-forward— spawnskubectl port-forwardinto a cluster (GKE), waits for the local port, connects, kills the process group on exit.exec— arbitrary tunnel command (SSH bastion,cloud-sql-proxy, …) with{local_port}substitution.Both
tuskand thetuskddaemon use it, so headless enforcement works against VPC DBs too.Config gains a
connect:block +omitemptyonProfile;SaveProfilepersists via the same comment-preserving YAML-node edit asSaveProfileRules(and carries existing rules over).Why
Issue #11 — direct Postgres-over-the-internet is the exception; the databases worth watching live inside a VPC. This gets people into the TUI in one screen instead of a second terminal juggling port-forwards.
Validation
go build ./...,go vet ./...,golangci-lint run ./...(0 issues),go test -race ./...;go mod tidyclean.{local_port}/freePort/waitForPort(incl. process-death) + spawn/teardown;SaveProfileround-trips (comments, omitempty, rules preserved).exectunnel (stand-in forwarder) drovetuskdagainst the real DB and cleaned the process up on exit.Review guide
internal/connect/{connect,methods}.go— tunnel establishment + teardown.internal/tui/setup.go— the setup screen.cmd/tusk/main.go—establish→ setup fallback.internal/config/config.go—ConnectConfig,SaveProfile.Closes #11