mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 05:49:07 +02:00
build client config in sync response
This commit is contained in:
@@ -12,8 +12,6 @@ import (
|
|||||||
goproto "google.golang.org/protobuf/proto"
|
goproto "google.golang.org/protobuf/proto"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
"google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
|
||||||
integrationsConfig "github.com/netbirdio/management-integrations/integrations/config"
|
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/client/ssh/auth"
|
"github.com/netbirdio/netbird/client/ssh/auth"
|
||||||
|
|
||||||
nbdns "github.com/netbirdio/netbird/dns"
|
nbdns "github.com/netbirdio/netbird/dns"
|
||||||
@@ -147,9 +145,7 @@ func ToSyncResponse(ctx context.Context, config *nbconfig.Config, httpConfig *nb
|
|||||||
Checks: toProtocolChecks(ctx, checks),
|
Checks: toProtocolChecks(ctx, checks),
|
||||||
}
|
}
|
||||||
|
|
||||||
nbConfig := toNetbirdConfig(config, turnCredentials, relayCredentials, extraSettings)
|
response.NetbirdConfig = toNetbirdConfig(config, turnCredentials, relayCredentials, extraSettings)
|
||||||
extendedConfig := integrationsConfig.ExtendNetBirdConfig(peer.ID, peerGroups, nbConfig, extraSettings)
|
|
||||||
response.NetbirdConfig = extendedConfig
|
|
||||||
|
|
||||||
response.NetworkMap.PeerConfig = response.PeerConfig
|
response.NetworkMap.PeerConfig = response.PeerConfig
|
||||||
|
|
||||||
@@ -363,7 +359,6 @@ func toProtocolFirewallRules(rules []*types.FirewallRule, includeIPv6, useSource
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// populateSourcePrefixes sets SourcePrefixes on fwRule and returns any
|
// populateSourcePrefixes sets SourcePrefixes on fwRule and returns any
|
||||||
// additional rules needed (e.g. a v6 wildcard clone when the peer IP is unspecified).
|
// additional rules needed (e.g. a v6 wildcard clone when the peer IP is unspecified).
|
||||||
func populateSourcePrefixes(fwRule *proto.FirewallRule, rule *types.FirewallRule, includeIPv6 bool) []*proto.FirewallRule {
|
func populateSourcePrefixes(fwRule *proto.FirewallRule, rule *types.FirewallRule, includeIPv6 bool) []*proto.FirewallRule {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
|
|
||||||
integrationsConfig "github.com/netbirdio/management-integrations/integrations/config"
|
|
||||||
"github.com/netbirdio/netbird/management/internals/controllers/network_map"
|
"github.com/netbirdio/netbird/management/internals/controllers/network_map"
|
||||||
nbconfig "github.com/netbirdio/netbird/management/internals/server/config"
|
nbconfig "github.com/netbirdio/netbird/management/internals/server/config"
|
||||||
"github.com/netbirdio/netbird/management/server/groups"
|
"github.com/netbirdio/netbird/management/server/groups"
|
||||||
@@ -41,8 +40,6 @@ type TimeBasedAuthSecretsManager struct {
|
|||||||
turnHmacToken *auth.TimedHMAC
|
turnHmacToken *auth.TimedHMAC
|
||||||
relayHmacToken *authv2.Generator
|
relayHmacToken *authv2.Generator
|
||||||
updateManager network_map.PeersUpdateManager
|
updateManager network_map.PeersUpdateManager
|
||||||
settingsManager settings.Manager
|
|
||||||
groupsManager groups.Manager
|
|
||||||
turnCancelMap map[string]chan struct{}
|
turnCancelMap map[string]chan struct{}
|
||||||
relayCancelMap map[string]chan struct{}
|
relayCancelMap map[string]chan struct{}
|
||||||
wgKey wgtypes.Key
|
wgKey wgtypes.Key
|
||||||
@@ -62,8 +59,6 @@ func NewTimeBasedAuthSecretsManager(updateManager network_map.PeersUpdateManager
|
|||||||
relayCfg: relayCfg,
|
relayCfg: relayCfg,
|
||||||
turnCancelMap: make(map[string]chan struct{}),
|
turnCancelMap: make(map[string]chan struct{}),
|
||||||
relayCancelMap: make(map[string]chan struct{}),
|
relayCancelMap: make(map[string]chan struct{}),
|
||||||
settingsManager: settingsManager,
|
|
||||||
groupsManager: groupsManager,
|
|
||||||
wgKey: key,
|
wgKey: key,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,8 +234,6 @@ func (m *TimeBasedAuthSecretsManager) pushNewTURNAndRelayTokens(ctx context.Cont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.extendNetbirdConfig(ctx, peerID, accountID, update)
|
|
||||||
|
|
||||||
log.WithContext(ctx).Debugf("sending new TURN credentials to peer %s", peerID)
|
log.WithContext(ctx).Debugf("sending new TURN credentials to peer %s", peerID)
|
||||||
m.updateManager.SendUpdate(ctx, peerID, &network_map.UpdateMessage{
|
m.updateManager.SendUpdate(ctx, peerID, &network_map.UpdateMessage{
|
||||||
Update: update,
|
Update: update,
|
||||||
@@ -266,26 +259,9 @@ func (m *TimeBasedAuthSecretsManager) pushNewRelayTokens(ctx context.Context, ac
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
m.extendNetbirdConfig(ctx, peerID, accountID, update)
|
|
||||||
|
|
||||||
log.WithContext(ctx).Debugf("sending new relay credentials to peer %s", peerID)
|
log.WithContext(ctx).Debugf("sending new relay credentials to peer %s", peerID)
|
||||||
m.updateManager.SendUpdate(ctx, peerID, &network_map.UpdateMessage{
|
m.updateManager.SendUpdate(ctx, peerID, &network_map.UpdateMessage{
|
||||||
Update: update,
|
Update: update,
|
||||||
MessageType: network_map.MessageTypeControlConfig,
|
MessageType: network_map.MessageTypeControlConfig,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *TimeBasedAuthSecretsManager) extendNetbirdConfig(ctx context.Context, peerID, accountID string, update *proto.SyncResponse) {
|
|
||||||
extraSettings, err := m.settingsManager.GetExtraSettings(ctx, accountID)
|
|
||||||
if err != nil {
|
|
||||||
log.WithContext(ctx).Errorf("failed to get extra settings: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
peerGroups, err := m.groupsManager.GetPeerGroupIDs(ctx, accountID, peerID)
|
|
||||||
if err != nil {
|
|
||||||
log.WithContext(ctx).Errorf("failed to get peer groups: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
extendedConfig := integrationsConfig.ExtendNetBirdConfig(peerID, peerGroups, update.NetbirdConfig, extraSettings)
|
|
||||||
update.NetbirdConfig = extendedConfig
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user