Skip to content

Update main.go#1

Closed
sullrich wants to merge 6 commits into
alebeck:mainfrom
sullrich:main
Closed

Update main.go#1
sullrich wants to merge 6 commits into
alebeck:mainfrom
sullrich:main

Conversation

@sullrich
Copy link
Copy Markdown

@sullrich sullrich commented Oct 5, 2024

  1. Add new "connect" command to directly SSH into configured tunnels

    • Implement connectTunnel function to handle SSH connections
    • Update main() to include "connect" in the command switch
    • Modify printUsage() to include information about the new command
  2. Fix Tunnel struct field access in connectTunnel function

    • Replace t.RemotePort with port extraction from t.RemoteAddress
    • Add fallback to default "root" user if t.User is not specified
  3. Update import statements

    • Add "strings" package for string manipulation
    • Remove "strconv" package as it's no longer needed
  4. Improve error handling and user feedback

    • Provide more descriptive error messages for configuration issues
    • Use log.Fatalf for critical errors to exit the program
  5. Enhance code comments for better maintainability

These changes allow users to easily connect to their configured tunnels using the "boring connect <tunnel_name>" command, improving the overall functionality and user experience of the boring CLI tool.

1. Add new "connect" command to directly SSH into configured tunnels
   - Implement `connectTunnel` function to handle SSH connections
   - Update main() to include "connect" in the command switch
   - Modify printUsage() to include information about the new command

2. Fix Tunnel struct field access in connectTunnel function
   - Replace t.RemotePort with port extraction from t.RemoteAddress
   - Add fallback to default "root" user if t.User is not specified

3. Update import statements
   - Add "strings" package for string manipulation
   - Remove "strconv" package as it's no longer needed

4. Improve error handling and user feedback
   - Provide more descriptive error messages for configuration issues
   - Use log.Fatalf for critical errors to exit the program

5. Enhance code comments for better maintainability

These changes allow users to easily connect to their configured tunnels
using the "boring connect <tunnel_name>" command, improving the overall
functionality and user experience of the boring CLI tool.
When using the 'connect' command to SSH into a host, pasting large amounts of text would cause the session to lock up. This issue was due to the SSH process not being attached to a proper terminal (PTY), leading to improper handling of interactive input/output.

This commit fixes the issue by modifying the 'connectTunnel' function to allocate a PTY using the 'github.com/creack/pty' package. By starting the SSH command with a pseudo-terminal and setting the terminal to raw mode, we enable proper input/output handling for interactive sessions, including handling large pasted inputs without freezing.

Additional changes:
- Handle terminal resizing by listening for SIGWINCH signals and adjusting the PTY size accordingly using 'pty.InheritSize'.
- Use 'io.Copy' to forward data between the user's terminal and the SSH process, ensuring seamless interaction.
- Default the SSH port to '22' if not specified in the tunnel configuration.
- Update error handling to provide clearer messages using the existing 'log' package.

Dependencies added:
- github.com/creack/pty
- golang.org/x/term

This ensures that SSH sessions initiated via the 'connect' command behave correctly in an interactive terminal environment.
- Added a check to ensure the tunnel is not reopened if it's already running. 
  This prevents the error "Tunnel could not be opened: tunnel already running" by querying tunnel status before attempting to open it.

- Introduced the `-t` flag to allow reconnecting to the SSH session using tmux. 
  When the `-t` flag is passed, the SSH command attaches to or creates a new tmux session (`tmux new-session -A -s boring-session`).
  
- Maintained existing functionality for SSH multiplexing, keep-alive, terminal resizing, and PTY handling.

- Preserved signal handling (SIGWINCH) for terminal resizing, raw terminal mode for interactive sessions, and SSH control master multiplexing logic.
  
This ensures smooth reconnections to running tunnels, while allowing users to reconnect via tmux when needed.
Alter the connect command to ssh.
… the application by checking the command line arguments. It also adds dependencies on the `github.com/creack/pty` and `golang.org/x/term` packages in the `go.mod` file.
@sullrich sullrich closed this Oct 12, 2024
@sullrich
Copy link
Copy Markdown
Author

This PR was a bit premature. Will circle back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant