mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 07:16:38 +00:00
* updates to client file writing * numerous * minor * - Align OnLoginSuccess behavior with Android (only call on nil error) - Remove verbose debug logging from WaitToken in device_flow.go - Improve TUN FD=0 fallback comments and warning messages - Document why config save after login differs from Android * Add nolint directive for staticcheck SA1029 in login.go * Fix CodeRabbit review issues for iOS/tvOS SDK - Remove goroutine from OnLoginSuccess callback, invoke synchronously - Stop treating PermissionDenied as success, propagate as permanent error - Replace context.TODO() with bounded timeout context (30s) in RequestAuthInfo - Handle DirectUpdateOrCreateConfig errors in IsLoginRequired and LoginForMobile - Add permission enforcement to DirectUpdateOrCreateConfig for existing configs - Fix variable shadowing in device_ios.go where err was masked by := in else block * Address additional CodeRabbit review issues for iOS/tvOS SDK - Make tunFd == 0 a hard error with exported ErrInvalidTunnelFD (remove dead fallback code) - Apply defaults in ConfigFromJSON to prevent partially-initialized configs - Add nil guards for listener/urlOpener interfaces in public SDK entry points - Reorder config save before OnLoginSuccess to prevent teardown race - Add explanatory comment for urlOpener.Open goroutine * Make urlOpener.Open() synchronous in device auth flow
120 lines
3.2 KiB
Go
120 lines
3.2 KiB
Go
//go:build ios
|
|
|
|
package NetBirdSDK
|
|
|
|
import (
|
|
"github.com/netbirdio/netbird/client/internal/profilemanager"
|
|
)
|
|
|
|
// Preferences export a subset of the internal config for gomobile
|
|
type Preferences struct {
|
|
configInput profilemanager.ConfigInput
|
|
}
|
|
|
|
// NewPreferences create new Preferences instance
|
|
func NewPreferences(configPath string, stateFilePath string) *Preferences {
|
|
ci := profilemanager.ConfigInput{
|
|
ConfigPath: configPath,
|
|
StateFilePath: stateFilePath,
|
|
}
|
|
return &Preferences{ci}
|
|
}
|
|
|
|
// GetManagementURL read url from config file
|
|
func (p *Preferences) GetManagementURL() (string, error) {
|
|
if p.configInput.ManagementURL != "" {
|
|
return p.configInput.ManagementURL, nil
|
|
}
|
|
|
|
cfg, err := profilemanager.ReadConfig(p.configInput.ConfigPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return cfg.ManagementURL.String(), err
|
|
}
|
|
|
|
// SetManagementURL store the given url and wait for commit
|
|
func (p *Preferences) SetManagementURL(url string) {
|
|
p.configInput.ManagementURL = url
|
|
}
|
|
|
|
// GetAdminURL read url from config file
|
|
func (p *Preferences) GetAdminURL() (string, error) {
|
|
if p.configInput.AdminURL != "" {
|
|
return p.configInput.AdminURL, nil
|
|
}
|
|
|
|
cfg, err := profilemanager.ReadConfig(p.configInput.ConfigPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return cfg.AdminURL.String(), err
|
|
}
|
|
|
|
// SetAdminURL store the given url and wait for commit
|
|
func (p *Preferences) SetAdminURL(url string) {
|
|
p.configInput.AdminURL = url
|
|
}
|
|
|
|
// GetPreSharedKey read preshared key from config file
|
|
func (p *Preferences) GetPreSharedKey() (string, error) {
|
|
if p.configInput.PreSharedKey != nil {
|
|
return *p.configInput.PreSharedKey, nil
|
|
}
|
|
|
|
cfg, err := profilemanager.ReadConfig(p.configInput.ConfigPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return cfg.PreSharedKey, err
|
|
}
|
|
|
|
// SetPreSharedKey store the given key and wait for commit
|
|
func (p *Preferences) SetPreSharedKey(key string) {
|
|
p.configInput.PreSharedKey = &key
|
|
}
|
|
|
|
// SetRosenpassEnabled store if rosenpass is enabled
|
|
func (p *Preferences) SetRosenpassEnabled(enabled bool) {
|
|
p.configInput.RosenpassEnabled = &enabled
|
|
}
|
|
|
|
// GetRosenpassEnabled read rosenpass enabled from config file
|
|
func (p *Preferences) GetRosenpassEnabled() (bool, error) {
|
|
if p.configInput.RosenpassEnabled != nil {
|
|
return *p.configInput.RosenpassEnabled, nil
|
|
}
|
|
|
|
cfg, err := profilemanager.ReadConfig(p.configInput.ConfigPath)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return cfg.RosenpassEnabled, err
|
|
}
|
|
|
|
// SetRosenpassPermissive store the given permissive and wait for commit
|
|
func (p *Preferences) SetRosenpassPermissive(permissive bool) {
|
|
p.configInput.RosenpassPermissive = &permissive
|
|
}
|
|
|
|
// GetRosenpassPermissive read rosenpass permissive from config file
|
|
func (p *Preferences) GetRosenpassPermissive() (bool, error) {
|
|
if p.configInput.RosenpassPermissive != nil {
|
|
return *p.configInput.RosenpassPermissive, nil
|
|
}
|
|
|
|
cfg, err := profilemanager.ReadConfig(p.configInput.ConfigPath)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
return cfg.RosenpassPermissive, err
|
|
}
|
|
|
|
// Commit write out the changes into config file
|
|
func (p *Preferences) Commit() error {
|
|
// Use DirectUpdateOrCreateConfig to avoid atomic file operations (temp file + rename)
|
|
// which are blocked by the tvOS sandbox in App Group containers
|
|
_, err := profilemanager.DirectUpdateOrCreateConfig(p.configInput)
|
|
return err
|
|
}
|