mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
* [client] Add Expose support to embed library Add ability to expose local services via the NetBird reverse proxy from embedded client code. Introduce ExposeSession with a blocking Wait method that keeps the session alive until the context is cancelled. Extract ProtocolType with ParseProtocolType into the expose package and use it across CLI and embed layers. * Fix TestNewRequest assertion to use ProtocolType instead of int * Add documentation for Request and KeepAlive in expose manager * Refactor ExposeSession to pass context explicitly in Wait method * Refactor ExposeSession Wait method to explicitly pass context * Update client/embed/expose.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Fix build * Update client/embed/expose.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Viktor Liu <viktor@netbird.io> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Viktor Liu <17948409+lixmal@users.noreply.github.com>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package embed
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
|
|
"github.com/netbirdio/netbird/client/internal/expose"
|
|
)
|
|
|
|
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)
|
|
}
|