Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Support for comma-separation and ranges in port-forward #4166

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

Merged
merged 3 commits into from
Oct 3, 2022

Conversation

mafredri
Copy link
Member

This PR adds support for a more condensed port-forwarding syntax (e.g. --tcp 8080,9000-9010,9990-9999:10990-10999).

Tests implemented as an internal test since testing the effect (multiple port ranges) isn't feasible externally.

Fixes #3766

@mafredri mafredri self-assigned this Sep 23, 2022
@mafredri mafredri requested review from deansheather and a team September 23, 2022 13:01
@matifali
Copy link
Member

Please, also update the docs with all example cases.

@mafredri
Copy link
Member Author

@matifali any thoughts on an example that would be most helpful? Currently we show one and defer to coder port-forward --help for more examples.

@bpmct
Copy link
Member

bpmct commented Sep 23, 2022

@matifali any thoughts on an example that would be most helpful? Currently we show one and defer to coder port-forward --help for more examples.

How about this?

Forward the remote TCP port 8080 to local port 8000 like so:
coder port-forward myworkspace --tcp 8000:8080

# Forward a range remote UDP ports `3000` to `3006` like so:
coder port-forward myworkspace --udp 3000-3006

@matifali
Copy link
Member

coder port-forward --help is a good reference. examples can be added there

@mafredri
Copy link
Member Author

@bpmct @matifali pushed some docs updates, thoughts? fc538e4

Copy link
Member

@bpmct bpmct left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs LGTM!

Comment on lines +311 to +313
type parsedSrcDestPort struct {
local, remote uint16
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just have the function return a portForwardSpec directly? You could pass it a listen and dial network and it would return []portForwardSpec instead of having an intermediary type

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was probably influenced by the previous implementation, and keeping the type "plain until use". Why plain? For instance, if you see the test where we mangle the portForwardSpec to make testing more convenient, that's not ideal IMO. In fact I could see parsePortForwards returning []parsedSrcDestPort if it was updated with protocol string field. Then all items could be post-processed into portForwardSpec as a last step ¯\_(ツ)_/¯. That code would seem more re-usable if we ever want to parse the port format in other places.

I'm not married to this by any means, I can change it, but I don't see a clear benefit to either way of doing it.

@mafredri mafredri merged commit 092a22f into main Oct 3, 2022
@mafredri mafredri deleted the mafredri/allow-port-forward-condensed-syntax branch October 3, 2022 08:58
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.

Forward a range of ports with the port-forward subcommand
5 participants