mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-24 06:19:08 +02:00
move relay config and management config path to types
this helps avoid circular import cycle through all the code
This commit is contained in:
@@ -1403,7 +1403,7 @@ func startManagement(t *testing.T, dataDir, testFile string) (*grpc.Server, stri
|
|||||||
config := &server.Config{
|
config := &server.Config{
|
||||||
Stuns: []*server.Host{},
|
Stuns: []*server.Host{},
|
||||||
TURNConfig: &server.TURNConfig{},
|
TURNConfig: &server.TURNConfig{},
|
||||||
Relay: &server.Relay{
|
Relay: &types.Relay{
|
||||||
Addresses: []string{"127.0.0.1:1234"},
|
Addresses: []string{"127.0.0.1:1234"},
|
||||||
CredentialsTTL: util.Duration{Duration: time.Hour},
|
CredentialsTTL: util.Duration{Duration: time.Hour},
|
||||||
Secret: "222222222222222222",
|
Secret: "222222222222222222",
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ import (
|
|||||||
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/realip"
|
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/realip"
|
||||||
|
|
||||||
"github.com/netbirdio/management-integrations/integrations"
|
"github.com/netbirdio/management-integrations/integrations"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/peers"
|
"github.com/netbirdio/netbird/management/server/peers"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
|
|
||||||
"github.com/netbirdio/netbird/encryption"
|
"github.com/netbirdio/netbird/encryption"
|
||||||
"github.com/netbirdio/netbird/formatter/hook"
|
"github.com/netbirdio/netbird/formatter/hook"
|
||||||
@@ -101,9 +103,9 @@ var (
|
|||||||
// detect whether user specified a port
|
// detect whether user specified a port
|
||||||
userPort := cmd.Flag("port").Changed
|
userPort := cmd.Flag("port").Changed
|
||||||
|
|
||||||
config, err = loadMgmtConfig(ctx, MgmtConfig)
|
config, err = loadMgmtConfig(ctx, types.MgmtConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed reading provided config file: %s: %v", MgmtConfig, err)
|
return fmt.Errorf("failed reading provided config file: %s: %v", types.MgmtConfigPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmd.Flag(idpSignKeyRefreshEnabledFlagName).Changed {
|
if cmd.Flag(idpSignKeyRefreshEnabledFlagName).Changed {
|
||||||
@@ -183,7 +185,7 @@ var (
|
|||||||
if config.DataStoreEncryptionKey != key {
|
if config.DataStoreEncryptionKey != key {
|
||||||
log.WithContext(ctx).Infof("update config with activity store key")
|
log.WithContext(ctx).Infof("update config with activity store key")
|
||||||
config.DataStoreEncryptionKey = key
|
config.DataStoreEncryptionKey = key
|
||||||
err := updateMgmtConfig(ctx, MgmtConfig, config)
|
err := updateMgmtConfig(ctx, types.MgmtConfigPath, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to write out store encryption key: %s", err)
|
return fmt.Errorf("failed to write out store encryption key: %s", err)
|
||||||
}
|
}
|
||||||
@@ -636,7 +638,7 @@ func handleRebrand(cmd *cobra.Command) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if MgmtConfig == defaultMgmtConfig {
|
if types.MgmtConfigPath == defaultMgmtConfig {
|
||||||
if migrateToNetbird(oldDefaultMgmtConfig, defaultMgmtConfig) {
|
if migrateToNetbird(oldDefaultMgmtConfig, defaultMgmtConfig) {
|
||||||
cmd.Printf("will copy Config dir %s and its content to %s\n", oldDefaultMgmtConfigDir, defaultMgmtConfigDir)
|
cmd.Printf("will copy Config dir %s and its content to %s\n", oldDefaultMgmtConfigDir, defaultMgmtConfigDir)
|
||||||
err = cpDir(oldDefaultMgmtConfigDir, defaultMgmtConfigDir)
|
err = cpDir(oldDefaultMgmtConfigDir, defaultMgmtConfigDir)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
"github.com/netbirdio/netbird/version"
|
"github.com/netbirdio/netbird/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,7 +20,6 @@ const (
|
|||||||
var (
|
var (
|
||||||
dnsDomain string
|
dnsDomain string
|
||||||
mgmtDataDir string
|
mgmtDataDir string
|
||||||
MgmtConfig string
|
|
||||||
logLevel string
|
logLevel string
|
||||||
logFile string
|
logFile string
|
||||||
disableMetrics bool
|
disableMetrics bool
|
||||||
@@ -56,7 +56,7 @@ func init() {
|
|||||||
mgmtCmd.Flags().IntVar(&mgmtPort, "port", 80, "server port to listen on (defaults to 443 if TLS is enabled, 80 otherwise")
|
mgmtCmd.Flags().IntVar(&mgmtPort, "port", 80, "server port to listen on (defaults to 443 if TLS is enabled, 80 otherwise")
|
||||||
mgmtCmd.Flags().IntVar(&mgmtMetricsPort, "metrics-port", 9090, "metrics endpoint http port. Metrics are accessible under host:metrics-port/metrics")
|
mgmtCmd.Flags().IntVar(&mgmtMetricsPort, "metrics-port", 9090, "metrics endpoint http port. Metrics are accessible under host:metrics-port/metrics")
|
||||||
mgmtCmd.Flags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location")
|
mgmtCmd.Flags().StringVar(&mgmtDataDir, "datadir", defaultMgmtDataDir, "server data directory location")
|
||||||
mgmtCmd.Flags().StringVar(&MgmtConfig, "config", defaultMgmtConfig, "Netbird config file location. Config params specified via command line (e.g. datadir) have a precedence over configuration from this file")
|
mgmtCmd.Flags().StringVar(&types.MgmtConfigPath, "config", defaultMgmtConfig, "Netbird config file location. Config params specified via command line (e.g. datadir) have a precedence over configuration from this file")
|
||||||
mgmtCmd.Flags().StringVar(&mgmtLetsencryptDomain, "letsencrypt-domain", "", "a domain to issue Let's Encrypt certificate for. Enables TLS using Let's Encrypt. Will fetch and renew certificate, and run the server with TLS")
|
mgmtCmd.Flags().StringVar(&mgmtLetsencryptDomain, "letsencrypt-domain", "", "a domain to issue Let's Encrypt certificate for. Enables TLS using Let's Encrypt. Will fetch and renew certificate, and run the server with TLS")
|
||||||
mgmtCmd.Flags().StringVar(&mgmtSingleAccModeDomain, "single-account-mode-domain", defaultSingleAccModeDomain, "Enables single account mode. This means that all the users will be under the same account grouped by the specified domain. If the installation has more than one account, the property is ineffective. Enabled by default with the default domain "+defaultSingleAccModeDomain)
|
mgmtCmd.Flags().StringVar(&mgmtSingleAccModeDomain, "single-account-mode-domain", defaultSingleAccModeDomain, "Enables single account mode. This means that all the users will be under the same account grouped by the specified domain. If the installation has more than one account, the property is ineffective. Enabled by default with the default domain "+defaultSingleAccModeDomain)
|
||||||
mgmtCmd.Flags().BoolVar(&disableSingleAccMode, "disable-single-account-mode", false, "If set to true, disables single account mode. The --single-account-mode-domain property will be ignored and every new user will have a separate NetBird account.")
|
mgmtCmd.Flags().BoolVar(&disableSingleAccMode, "disable-single-account-mode", false, "If set to true, disables single account mode. The --single-account-mode-domain property will be ignored and every new user will have a separate NetBird account.")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/netbirdio/netbird/management/server/idp"
|
"github.com/netbirdio/netbird/management/server/idp"
|
||||||
"github.com/netbirdio/netbird/management/server/store"
|
"github.com/netbirdio/netbird/management/server/store"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
"github.com/netbirdio/netbird/util"
|
"github.com/netbirdio/netbird/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ const (
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
Stuns []*Host
|
Stuns []*Host
|
||||||
TURNConfig *TURNConfig
|
TURNConfig *TURNConfig
|
||||||
Relay *Relay
|
Relay *types.Relay
|
||||||
Signal *Host
|
Signal *Host
|
||||||
|
|
||||||
Datadir string
|
Datadir string
|
||||||
@@ -76,12 +77,6 @@ type TURNConfig struct {
|
|||||||
Turns []*Host
|
Turns []*Host
|
||||||
}
|
}
|
||||||
|
|
||||||
type Relay struct {
|
|
||||||
Addresses []string
|
|
||||||
CredentialsTTL util.Duration
|
|
||||||
Secret string
|
|
||||||
}
|
|
||||||
|
|
||||||
// HttpServerConfig is a config of the HTTP Management service server
|
// HttpServerConfig is a config of the HTTP Management service server
|
||||||
type HttpServerConfig struct {
|
type HttpServerConfig struct {
|
||||||
LetsEncryptDomain string
|
LetsEncryptDomain string
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/netbirdio/netbird/management/proto"
|
"github.com/netbirdio/netbird/management/proto"
|
||||||
"github.com/netbirdio/netbird/management/server/settings"
|
"github.com/netbirdio/netbird/management/server/settings"
|
||||||
|
"github.com/netbirdio/netbird/management/server/types"
|
||||||
auth "github.com/netbirdio/netbird/relay/auth/hmac"
|
auth "github.com/netbirdio/netbird/relay/auth/hmac"
|
||||||
authv2 "github.com/netbirdio/netbird/relay/auth/hmac/v2"
|
authv2 "github.com/netbirdio/netbird/relay/auth/hmac/v2"
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ type SecretsManager interface {
|
|||||||
type TimeBasedAuthSecretsManager struct {
|
type TimeBasedAuthSecretsManager struct {
|
||||||
mux sync.Mutex
|
mux sync.Mutex
|
||||||
turnCfg *TURNConfig
|
turnCfg *TURNConfig
|
||||||
relayCfg *Relay
|
relayCfg *types.Relay
|
||||||
turnHmacToken *auth.TimedHMAC
|
turnHmacToken *auth.TimedHMAC
|
||||||
relayHmacToken *authv2.Generator
|
relayHmacToken *authv2.Generator
|
||||||
updateManager *PeersUpdateManager
|
updateManager *PeersUpdateManager
|
||||||
@@ -44,7 +45,7 @@ type TimeBasedAuthSecretsManager struct {
|
|||||||
|
|
||||||
type Token auth.Token
|
type Token auth.Token
|
||||||
|
|
||||||
func NewTimeBasedAuthSecretsManager(updateManager *PeersUpdateManager, turnCfg *TURNConfig, relayCfg *Relay, settingsManager settings.Manager) *TimeBasedAuthSecretsManager {
|
func NewTimeBasedAuthSecretsManager(updateManager *PeersUpdateManager, turnCfg *TURNConfig, relayCfg *types.Relay, settingsManager settings.Manager) *TimeBasedAuthSecretsManager {
|
||||||
mgr := &TimeBasedAuthSecretsManager{
|
mgr := &TimeBasedAuthSecretsManager{
|
||||||
updateManager: updateManager,
|
updateManager: updateManager,
|
||||||
turnCfg: turnCfg,
|
turnCfg: turnCfg,
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ func TestTimeBasedAuthSecretsManager_GenerateCredentials(t *testing.T) {
|
|||||||
secret := "some_secret"
|
secret := "some_secret"
|
||||||
peersManager := NewPeersUpdateManager(nil)
|
peersManager := NewPeersUpdateManager(nil)
|
||||||
|
|
||||||
rc := &Relay{
|
rc := &types.Relay{
|
||||||
Addresses: []string{"localhost:0"},
|
Addresses: []string{"localhost:0"},
|
||||||
CredentialsTTL: ttl,
|
CredentialsTTL: ttl,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
@@ -81,7 +81,7 @@ func TestTimeBasedAuthSecretsManager_SetupRefresh(t *testing.T) {
|
|||||||
peer := "some_peer"
|
peer := "some_peer"
|
||||||
updateChannel := peersManager.CreateChannel(context.Background(), peer)
|
updateChannel := peersManager.CreateChannel(context.Background(), peer)
|
||||||
|
|
||||||
rc := &Relay{
|
rc := &types.Relay{
|
||||||
Addresses: []string{"localhost:0"},
|
Addresses: []string{"localhost:0"},
|
||||||
CredentialsTTL: ttl,
|
CredentialsTTL: ttl,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
@@ -184,7 +184,7 @@ func TestTimeBasedAuthSecretsManager_CancelRefresh(t *testing.T) {
|
|||||||
peersManager := NewPeersUpdateManager(nil)
|
peersManager := NewPeersUpdateManager(nil)
|
||||||
peer := "some_peer"
|
peer := "some_peer"
|
||||||
|
|
||||||
rc := &Relay{
|
rc := &types.Relay{
|
||||||
Addresses: []string{"localhost:0"},
|
Addresses: []string{"localhost:0"},
|
||||||
CredentialsTTL: ttl,
|
CredentialsTTL: ttl,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
import "github.com/netbirdio/netbird/util"
|
||||||
|
|
||||||
|
// MgmtConfigPath Config path of the Management service
|
||||||
|
var MgmtConfigPath string
|
||||||
|
|
||||||
|
// Relay configuration type
|
||||||
|
type Relay struct {
|
||||||
|
Addresses []string
|
||||||
|
CredentialsTTL util.Duration
|
||||||
|
Secret string
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user