-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[client] Add Expose support to embed library #5695
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
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1c80258
[client] Add Expose support to embed library
pappz 5582489
Fix TestNewRequest assertion to use ProtocolType instead of int
lixmal d9f54d5
Add documentation for Request and KeepAlive in expose manager
pappz 1d8a2f6
Refactor ExposeSession to pass context explicitly in Wait method
pappz 40cc469
Refactor ExposeSession Wait method to explicitly pass context
pappz 3989f80
Update client/embed/expose.go
pappz b1a8fa6
Fix build
lixmal 2cb2aeb
Update client/embed/expose.go
lixmal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package embed | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "github.com/netbirdio/netbird/client/internal/expose" | ||
| ) | ||
|
lixmal marked this conversation as resolved.
|
||
|
|
||
| const ( | ||
| // ExposeProtocolHTTP exposes the service as HTTP. | ||
| ExposeProtocolHTTP = expose.ProtocolHTTP | ||
| // ExposeProtocolHTTPS exposes the service as HTTPS. | ||
| ExposeProtocolHTTPS = expose.ProtocolHTTPS | ||
| // ExposeProtocolTCP exposes the service as TCP. | ||
| ExposeProtocolTCP = expose.ProtocolTCP | ||
| // ExposeProtocolUDP exposes the service as UDP. | ||
| ExposeProtocolUDP = expose.ProtocolUDP | ||
| // ExposeProtocolTLS exposes the service as TLS. | ||
| ExposeProtocolTLS = expose.ProtocolTLS | ||
| ) | ||
|
|
||
| // ExposeRequest is a request to expose a local service via the NetBird reverse proxy. | ||
| type ExposeRequest = expose.Request | ||
|
|
||
| // ExposeProtocolType represents the protocol used for exposing a service. | ||
| type ExposeProtocolType = expose.ProtocolType | ||
|
|
||
| // ExposeSession represents an active expose session. Use Wait to block until the session ends. | ||
| type ExposeSession struct { | ||
| Domain string | ||
| ServiceName string | ||
| ServiceURL string | ||
|
|
||
| mgr *expose.Manager | ||
| } | ||
|
|
||
| // Wait blocks while keeping the expose session alive. | ||
| // It returns when ctx is cancelled or a keep-alive error occurs, then terminates the session. | ||
| func (s *ExposeSession) Wait(ctx context.Context) error { | ||
| if s == nil || s.mgr == nil { | ||
| return errors.New("expose session is not initialized") | ||
| } | ||
| return s.mgr.KeepAlive(ctx, s.Domain) | ||
|
pappz marked this conversation as resolved.
|
||
| } | ||
|
lixmal marked this conversation as resolved.
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package expose | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "strings" | ||
| ) | ||
|
|
||
| // ProtocolType represents the protocol used for exposing a service. | ||
| type ProtocolType int | ||
|
|
||
| const ( | ||
| // ProtocolHTTP exposes the service as HTTP. | ||
| ProtocolHTTP ProtocolType = 0 | ||
| // ProtocolHTTPS exposes the service as HTTPS. | ||
| ProtocolHTTPS ProtocolType = 1 | ||
| // ProtocolTCP exposes the service as TCP. | ||
| ProtocolTCP ProtocolType = 2 | ||
| // ProtocolUDP exposes the service as UDP. | ||
| ProtocolUDP ProtocolType = 3 | ||
| // ProtocolTLS exposes the service as TLS. | ||
| ProtocolTLS ProtocolType = 4 | ||
| ) | ||
|
|
||
| // ParseProtocolType parses a protocol string into a ProtocolType. | ||
| func ParseProtocolType(s string) (ProtocolType, error) { | ||
| switch strings.ToLower(s) { | ||
| case "http": | ||
| return ProtocolHTTP, nil | ||
| case "https": | ||
| return ProtocolHTTPS, nil | ||
| case "tcp": | ||
| return ProtocolTCP, nil | ||
| case "udp": | ||
| return ProtocolUDP, nil | ||
| case "tls": | ||
| return ProtocolTLS, nil | ||
| default: | ||
| return 0, fmt.Errorf("unsupported protocol %q: must be http, https, tcp, udp, or tls", s) | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.