Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivial: Add port option to forward script #1996

Merged
merged 2 commits into from
Mar 4, 2025

Conversation

elsand
Copy link
Member

@elsand elsand commented Mar 4, 2025

Adds an option to define local port for SSH forwarded database access, which lets one connect to a remote db without having to take down postgres running locally (eg. dialogporten-db in docker)

@elsand elsand requested a review from a team as a code owner March 4, 2025 07:05
Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

📝 Walkthrough

Walkthrough

This pull request updates the database-forwarder script (forward.sh) by introducing a new local_port variable used in constructing connection strings for PostgreSQL and Redis. The SSH tunnel setup function has been refactored by renaming the existing port parameter to remote_port and adding a new local_port parameter. In addition, a command-line option (-p) has been added to allow specifying the local port, and the usage message and connection output now display both the local and remote ports.

Changes

File Change Summary
scripts/.../forward.sh - Modified connection strings in get_postgres_info and get_redis_info to use local_port.
- Updated setup_ssh_tunnel signature: renamed port to remote_port and added local_port parameter.
- Added -p command-line option and updated usage/output messages to include both local and remote ports.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f60249a and 17adccb.

📒 Files selected for processing (1)
  • scripts/database-forwarder/forward.sh (4 hunks)
🔇 Additional comments (7)
scripts/database-forwarder/forward.sh (7)

130-130: PostgreSQL Connection String Update

The connection string now uses ${local_port:-$port} to allow a custom local port while defaulting to the original remote port if none is specified. This change improves flexibility for port-forwarding.


152-152: Redis Connection String Update

The updated Redis connection string now references ${local_port:-$port}, which aligns with the PostgreSQL update. This ensures consistency across different database types.


158-159: SSH Tunnel Parameter Refactoring

The setup_ssh_tunnel function has been refactored to rename the third parameter to remote_port and introduce a new local_port parameter (with a default fallback to remote_port). This enhances clarity in distinguishing between the remote and local ports.


250-251: Enhanced Connection Details Display

The connection details printed in the box now show both the local port (using ${local_port:-$port}) and the remote port. This added clarity aids users in verifying the tunnel configuration at a glance.


256-256: SSH Tunnel Invocation Update

The call to setup_ssh_tunnel now correctly passes the remote port (${port}) and the local port (${local_port:-$port}). This ensures that the SSH tunnel is established with the intended port mapping.


262-274: New Command-Line Option for Local Port

A new command-line option (-p) has been added to specify the local port. The script correctly initializes the local_port variable and updates the usage message to document this option.


283-284: Global Variable Usage in Main Invocation

The main function is invoked with only the environment and db_type parameters while local_port is handled as a global variable. Ensure that this design—relying on a global variable for local_port—is intentional and well documented for maintainability.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@elsand elsand changed the title Add port option to forward script trivial: Add port option to forward script Mar 4, 2025
@elsand elsand merged commit 0f2d557 into main Mar 4, 2025
17 of 18 checks passed
@elsand elsand deleted the add-port-option-to-forward-script branch March 4, 2025 08:59
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.

2 participants