mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-19 00:36:38 +00:00
use embedded netbird agent for tunneling
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
package reverseproxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/netbirdio/netbird/client/embed"
|
||||
)
|
||||
|
||||
const (
|
||||
clientStartupTimeout = 30 * time.Second
|
||||
)
|
||||
|
||||
// AddRoute adds a new route to the proxy
|
||||
@@ -20,8 +28,8 @@ func (p *Proxy) AddRoute(route *RouteConfig) error {
|
||||
if len(route.PathMappings) == 0 {
|
||||
return fmt.Errorf("route must have at least one path mapping")
|
||||
}
|
||||
if route.Conn == nil {
|
||||
return fmt.Errorf("route connection (Conn) is required")
|
||||
if route.SetupKey == "" {
|
||||
return fmt.Errorf("route setup key is required")
|
||||
}
|
||||
|
||||
p.mu.Lock()
|
||||
@@ -32,6 +40,19 @@ func (p *Proxy) AddRoute(route *RouteConfig) error {
|
||||
return fmt.Errorf("route for domain %s already exists", route.Domain)
|
||||
}
|
||||
|
||||
client, err := embed.New(embed.Options{DeviceName: fmt.Sprintf("ingress-%s", route.ID), ManagementURL: p.config.ManagementURL, SetupKey: route.SetupKey})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create embedded client for route %s: %v", route.ID, err)
|
||||
}
|
||||
|
||||
ctx, _ := context.WithTimeout(context.Background(), clientStartupTimeout)
|
||||
err = client.Start(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to start embedded client for route %s: %v", route.ID, err)
|
||||
}
|
||||
|
||||
route.nbClient = client
|
||||
|
||||
// Add route with domain as key
|
||||
p.routes[route.Domain] = route
|
||||
|
||||
|
||||
Reference in New Issue
Block a user