profilemanager

package
v0.52.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2025 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultManagementURL points to the NetBird's cloud management endpoint
	DefaultManagementURL = "https://api.netbird.io:443"

	// DefaultAdminURL points to NetBird's cloud management console
	DefaultAdminURL = "https://app.netbird.io:443"
)

Variables

View Source
var (
	ErrProfileNotFound      = errors.New("profile not found")
	ErrProfileAlreadyExists = errors.New("profile already exists")
	ErrNoActiveProfile      = errors.New("no active profile set")
)
View Source
var (
	DefaultConfigPathDir   = ""
	DefaultConfigPath      = ""
	ActiveProfileStatePath = ""
)
View Source
var ConfigDirOverride string
View Source
var DefaultInterfaceBlacklist = []string{
	iface.WgInterfaceDefault, "wt", "utun", "tun0", "zt", "ZeroTier", "wg", "ts",
	"Tailscale", "tailscale", "docker", "veth", "br-", "lo",
}
View Source
var (
	ErrorOldDefaultConfigNotFound = errors.New("old default config not found")
)

Functions

func WriteOutConfig

func WriteOutConfig(path string, config *Config) error

WriteOutConfig write put the prepared config to the given path

Types

type ActiveProfileState

type ActiveProfileState struct {
	Name     string `json:"name"`
	Username string `json:"username"`
}

func (*ActiveProfileState) FilePath

func (a *ActiveProfileState) FilePath() (string, error)

type Config

type Config struct {
	// Wireguard private key of local peer
	PrivateKey           string
	PreSharedKey         string
	ManagementURL        *url.URL
	AdminURL             *url.URL
	WgIface              string
	WgPort               int
	NetworkMonitor       *bool
	IFaceBlackList       []string
	DisableIPv6Discovery bool
	RosenpassEnabled     bool
	RosenpassPermissive  bool
	ServerSSHAllowed     *bool

	DisableClientRoutes bool
	DisableServerRoutes bool
	DisableDNS          bool
	DisableFirewall     bool
	BlockLANAccess      bool
	BlockInbound        bool

	DisableNotifications *bool

	DNSLabels domain.List

	// SSHKey is a private SSH key in a PEM format
	SSHKey string

	NATExternalIPs []string
	// CustomDNSAddress sets the DNS resolver listening address in format ip:port
	CustomDNSAddress string

	// DisableAutoConnect determines whether the client should not start with the service
	// it's set to false by default due to backwards compatibility
	DisableAutoConnect bool

	// DNSRouteInterval is the interval in which the DNS routes are updated
	DNSRouteInterval time.Duration
	// Path to a certificate used for mTLS authentication
	ClientCertPath string

	// Path to corresponding private key of ClientCertPath
	ClientCertKeyPath string

	ClientCertKeyPair *tls.Certificate `json:"-"`

	LazyConnectionEnabled bool
}

Config Configuration type

func CreateInMemoryConfig

func CreateInMemoryConfig(input ConfigInput) (*Config, error)

CreateInMemoryConfig generate a new config but do not write out it to the store

func GetConfig

func GetConfig(configPath string) (*Config, error)

func ReadConfig

func ReadConfig(configPath string) (*Config, error)

ReadConfig read config file and return with Config. If it is not exists create a new with default values

func UpdateConfig

func UpdateConfig(input ConfigInput) (*Config, error)

UpdateConfig update existing configuration according to input configuration and return with the configuration

func UpdateOldManagementURL

func UpdateOldManagementURL(ctx context.Context, config *Config, configPath string) (*Config, error)

UpdateOldManagementURL checks whether client can switch to the new Management URL with port 443 and the management domain. If it can switch, then it updates the config and returns a new one. Otherwise, it returns the provided config. The check is performed only for the NetBird's managed version.

func UpdateOrCreateConfig

func UpdateOrCreateConfig(input ConfigInput) (*Config, error)

UpdateOrCreateConfig reads existing config or generates a new one

type ConfigInput

type ConfigInput struct {
	ManagementURL       string
	AdminURL            string
	ConfigPath          string
	StateFilePath       string
	PreSharedKey        *string
	ServerSSHAllowed    *bool
	NATExternalIPs      []string
	CustomDNSAddress    []byte
	RosenpassEnabled    *bool
	RosenpassPermissive *bool
	InterfaceName       *string
	WireguardPort       *int
	NetworkMonitor      *bool
	DisableAutoConnect  *bool
	ExtraIFaceBlackList []string
	DNSRouteInterval    *time.Duration
	ClientCertPath      string
	ClientCertKeyPath   string

	DisableClientRoutes *bool
	DisableServerRoutes *bool
	DisableDNS          *bool
	DisableFirewall     *bool
	BlockLANAccess      *bool
	BlockInbound        *bool

	DisableNotifications *bool

	DNSLabels domain.List

	LazyConnectionEnabled *bool
}

ConfigInput carries configuration changes to the client

type Profile

type Profile struct {
	Name     string
	IsActive bool
}

func (*Profile) FilePath

func (p *Profile) FilePath() (string, error)

func (*Profile) IsDefault

func (p *Profile) IsDefault() bool

type ProfileManager

type ProfileManager struct {
	// contains filtered or unexported fields
}

func NewProfileManager

func NewProfileManager() *ProfileManager

func (*ProfileManager) GetActiveProfile

func (pm *ProfileManager) GetActiveProfile() (*Profile, error)

func (*ProfileManager) GetProfileState

func (pm *ProfileManager) GetProfileState(profileName string) (*ProfileState, error)

func (*ProfileManager) SetActiveProfileState

func (pm *ProfileManager) SetActiveProfileState(state *ProfileState) error

func (*ProfileManager) SwitchProfile

func (pm *ProfileManager) SwitchProfile(profileName string) error

type ProfileState

type ProfileState struct {
	Email string `json:"email"`
}

type ServiceManager

type ServiceManager struct{}

func (*ServiceManager) AddProfile

func (s *ServiceManager) AddProfile(profileName, username string) error

func (*ServiceManager) CopyDefaultProfileIfNotExists

func (s *ServiceManager) CopyDefaultProfileIfNotExists() (bool, error)

func (*ServiceManager) CreateDefaultProfile

func (s *ServiceManager) CreateDefaultProfile() error

func (*ServiceManager) DefaultProfilePath

func (s *ServiceManager) DefaultProfilePath() string

func (*ServiceManager) GetActiveProfileState

func (s *ServiceManager) GetActiveProfileState() (*ActiveProfileState, error)

func (*ServiceManager) GetStatePath

func (s *ServiceManager) GetStatePath() string

GetStatePath returns the path to the state file based on the operating system It returns an empty string if the path cannot be determined.

func (*ServiceManager) ListProfiles

func (s *ServiceManager) ListProfiles(username string) ([]Profile, error)

func (*ServiceManager) RemoveProfile

func (s *ServiceManager) RemoveProfile(profileName, username string) error

func (*ServiceManager) SetActiveProfileState

func (s *ServiceManager) SetActiveProfileState(a *ActiveProfileState) error

func (*ServiceManager) SetActiveProfileStateToDefault

func (s *ServiceManager) SetActiveProfileStateToDefault() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL