Documentation
¶
Index ¶
- Constants
- Variables
- func ConfigToJSON(config *Config) (string, error)
- func DirectWriteOutConfig(path string, config *Config) error
- func GetLoginHint() string
- func IsValidProfileFilenameStem(id ID) bool
- func StripCtrlChars(name string) string
- func WriteOutConfig(path string, config *Config) error
- type ActiveProfileState
- type AmbiguityKind
- type Config
- func ConfigFromJSON(jsonStr string) (*Config, error)
- func CreateInMemoryConfig(input ConfigInput) (*Config, error)
- func DirectUpdateOrCreateConfig(input ConfigInput) (*Config, error)
- func GetConfig(configPath string) (*Config, error)
- func ReadConfig(configPath string) (*Config, error)
- func UpdateConfig(input ConfigInput) (*Config, error)
- func UpdateOldManagementURL(ctx context.Context, config *Config, configPath string) (*Config, error)
- func UpdateOrCreateConfig(input ConfigInput) (*Config, error)
- type ConfigInput
- type ErrAmbiguousHandle
- type ID
- type Profile
- type ProfileManager
- type ProfileState
- type ServiceManager
- func (s *ServiceManager) AddProfile(displayName, username string) (*Profile, error)
- func (s *ServiceManager) CopyDefaultProfileIfNotExists() (bool, error)
- func (s *ServiceManager) CreateDefaultProfile() error
- func (s *ServiceManager) DefaultProfilePath() string
- func (s *ServiceManager) GetActiveProfileState() (*ActiveProfileState, error)
- func (s *ServiceManager) GetStatePath() string
- func (s *ServiceManager) ListProfiles(username string) ([]Profile, error)
- func (s *ServiceManager) RemoveProfile(id ID, username string) error
- func (s *ServiceManager) RenameProfile(id ID, username string, newName string) error
- func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, error)
- func (s *ServiceManager) SetActiveProfileState(a *ActiveProfileState) error
- func (s *ServiceManager) SetActiveProfileStateToDefault() error
Constants ¶
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" )
const (
DefaultProfileName = "default"
)
Variables ¶
var ( ErrProfileNotFound = errors.New("profile not found") ErrProfileAlreadyExists = errors.New("profile already exists") ErrNoActiveProfile = errors.New("no active profile set") )
var ( DefaultConfigPathDir = "" DefaultConfigPath = "" ActiveProfileStatePath = "" ErrorOldDefaultConfigNotFound = errors.New("old default config not found") )
var ConfigDirOverride string
var DefaultInterfaceBlacklist = []string{ iface.WgInterfaceDefault, "wt", "utun", "tun0", "zt", "ZeroTier", "wg", "ts", "Tailscale", "tailscale", "docker", "veth", "br-", "lo", }
Functions ¶
func ConfigToJSON ¶ added in v0.61.1
ConfigToJSON serializes a Config struct to a JSON string. This is useful for exporting config to alternative storage mechanisms (e.g., UserDefaults on tvOS where file writes are blocked).
func DirectWriteOutConfig ¶ added in v0.61.1
DirectWriteOutConfig writes config directly without atomic temp file operations. Use this on platforms where atomic writes are blocked (e.g., tvOS sandbox).
func GetLoginHint ¶ added in v0.60.0
func GetLoginHint() string
GetLoginHint retrieves the email from the active profile to use as login_hint.
func IsValidProfileFilenameStem ¶ added in v0.73.0
IsValidProfileFilenameStem reports whether id is safe to use as the stem of a profile JSON filename.
func StripCtrlChars ¶ added in v0.73.0
StripCtrlChars control characters from a name before printing it.
func WriteOutConfig ¶
WriteOutConfig write put the prepared config to the given path
Types ¶
type ActiveProfileState ¶
type ActiveProfileState struct {
// ID is the on-disk filename stem of the active profile. The JSON tag stays
// as "name" for backwards compatibility with active state files written
// before the ID-based config files. Legacy values were profile names, which
// were also the legacy filename stems, so they still resolve to the correct
// file on disk.
ID ID `json:"name"`
Username string `json:"username"`
}
func (*ActiveProfileState) FilePath ¶
func (a *ActiveProfileState) FilePath() (string, error)
type AmbiguityKind ¶ added in v0.73.0
type AmbiguityKind int
AmbiguityKind describes which matcher produced the ambiguity, so callers can tailor the error message.
const ( AmbiguityKindIDPrefix AmbiguityKind = iota AmbiguityKindName )
type Config ¶
type Config struct {
// Name is the human-readable profile name shown in CLI/UI listings.
// It is independent of the profile's on-disk filename (which is the ID).
Name string
// Wireguard private key of local peer
PrivateKey string
ManagementURL *url.URL
AdminURL *url.URL
WgIface string
WgPort int
NetworkMonitor *bool
IFaceBlackList []string
DisableIPv6Discovery bool
RosenpassEnabled bool
RosenpassPermissive bool
ServerSSHAllowed *bool
EnableSSHRoot *bool
EnableSSHSFTP *bool
EnableSSHLocalPortForwarding *bool
EnableSSHRemotePortForwarding *bool
DisableSSHAuth *bool
SSHJWTCacheTTL *int
DisableClientRoutes bool
DisableServerRoutes bool
DisableDNS bool
DisableFirewall bool
BlockLANAccess bool
BlockInbound bool
DisableIPv6 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:"-"`
// LazyConnection is the MDM-managed lazy-connection override ("on"/"off"/"").
// Runtime-only: re-derived from MDM policy on each load, never persisted.
LazyConnection string `json:"-"`
MTU uint16
// contains filtered or unexported fields
}
Config Configuration type
func ConfigFromJSON ¶ added in v0.61.1
ConfigFromJSON deserializes a JSON string to a Config struct. This is useful for restoring config from alternative storage mechanisms. After unmarshaling, defaults are applied to ensure the config is fully initialized.
func CreateInMemoryConfig ¶
func CreateInMemoryConfig(input ConfigInput) (*Config, error)
CreateInMemoryConfig generate a new config but do not write out it to the store
func DirectUpdateOrCreateConfig ¶ added in v0.61.1
func DirectUpdateOrCreateConfig(input ConfigInput) (*Config, error)
DirectUpdateOrCreateConfig is like UpdateOrCreateConfig but uses direct (non-atomic) writes. Use this on platforms where atomic writes are blocked (e.g., tvOS sandbox).
func GetConfig ¶
GetConfig read config file and return with Config and if it was created. Errors out if it does not exist
func ReadConfig ¶
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
ServerSSHAllowed *bool
EnableSSHRoot *bool
EnableSSHSFTP *bool
EnableSSHLocalPortForwarding *bool
EnableSSHRemotePortForwarding *bool
DisableSSHAuth *bool
SSHJWTCacheTTL *int
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
DisableIPv6 *bool
DisableNotifications *bool
DNSLabels domain.List
MTU *uint16
}
ConfigInput carries configuration changes to the client
type ErrAmbiguousHandle ¶ added in v0.73.0
type ErrAmbiguousHandle struct {
Handle string
Candidates []Profile
Kind AmbiguityKind
}
ErrAmbiguousHandle is returned when a profile handle (ID prefix or name) matches more than one profile. Callers can render Candidates to help the user disambiguate.
func (*ErrAmbiguousHandle) Error ¶ added in v0.73.0
func (e *ErrAmbiguousHandle) Error() string
type ID ¶ added in v0.73.0
type ID string
type Profile ¶
type Profile struct {
// ID is the on-disk filename stem (without .json). For new profiles
// it is a 32-char hex string; legacy profiles created before the
// ID-keyed layout keep their original name as their ID. The reserved
// value "default" identifies the special default profile.
ID ID
// Name is the human-readable display name. Falls back to ID when the
// underlying JSON has no "name" field set.
Name string
// Path is the absolute path to the profile JSON. Populated by the
// loader so callers do not have to reconstruct it from ID + dir.
Path string
IsActive 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)
GetActiveProfile returns the active profile as recorded in the local user state file. Only ID is populated.
func (*ProfileManager) GetProfileState ¶
func (pm *ProfileManager) GetProfileState(id ID) (*ProfileState, error)
GetProfileState reads the per-profile state file keyed by profile ID. The state file lives in the user's config directory. Legacy state files keyed by the old profile name remain readable.
func (*ProfileManager) SetActiveProfileState ¶
func (pm *ProfileManager) SetActiveProfileState(state *ProfileState) error
func (*ProfileManager) SwitchProfile ¶
func (pm *ProfileManager) SwitchProfile(id ID) error
SwitchProfile records the given profile ID as active in the local user state file.
type ProfileState ¶
type ProfileState struct {
Email string `json:"email"`
}
type ServiceManager ¶
type ServiceManager struct {
// contains filtered or unexported fields
}
func NewServiceManager ¶ added in v0.53.0
func NewServiceManager(defaultConfigPath string) *ServiceManager
func NewServiceManagerWithProfilesDir ¶ added in v0.61.0
func NewServiceManagerWithProfilesDir(defaultConfigPath string, profilesDir string) *ServiceManager
NewServiceManagerWithProfilesDir creates a ServiceManager with a specific profiles directory This allows setting the profiles directory without modifying the global ConfigDirOverride
func (*ServiceManager) AddProfile ¶
func (s *ServiceManager) AddProfile(displayName, username string) (*Profile, error)
AddProfile creates a new profile with a generated ID. The user-supplied displayName is stored inside the JSON's name field, the on-disk filename uses the generated ID.
The returned Profile carries the freshly-generated ID so callers can show it to the user (and so the gRPC AddProfileResponse can include it).
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)
ListProfiles returns every profile for the given user, including the default profile, with IsActive flags set.
func (*ServiceManager) RemoveProfile ¶
func (s *ServiceManager) RemoveProfile(id ID, username string) error
RemoveProfile deletes the profile identified by id. Callers must have already resolved any user-supplied handle to a concrete ID via ResolveProfile.
func (*ServiceManager) RenameProfile ¶ added in v0.73.0
func (s *ServiceManager) RenameProfile(id ID, username string, newName string) error
func (*ServiceManager) ResolveProfile ¶ added in v0.73.0
func (s *ServiceManager) ResolveProfile(handle, username string) (*Profile, error)
ResolveProfile turns a user-supplied handle into a Profile. Resolution precedence is: exact ID match, then unique exact name, then unique ID prefix. Ambiguous matches return *ErrAmbiguousHandle so callers can surface the candidates.
func (*ServiceManager) SetActiveProfileState ¶
func (s *ServiceManager) SetActiveProfileState(a *ActiveProfileState) error
func (*ServiceManager) SetActiveProfileStateToDefault ¶
func (s *ServiceManager) SetActiveProfileStateToDefault() error