Skip to content

Commit

Permalink
Fix some of the remarks from the linter
Browse files Browse the repository at this point in the history
  • Loading branch information
pascal-fischer committed Dec 6, 2023
1 parent 0f7343d commit 5f3f5dc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 54 deletions.
8 changes: 8 additions & 0 deletions client/ios/NetBirdSDK/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func (c *Client) Run(fd int32, interfaceName string) error {
var ctx context.Context
//nolint
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
//nolint
ctxWithValues = context.WithValue(ctxWithValues, system.OsNameCtxKey, c.osName)
//nolint
ctxWithValues = context.WithValue(ctxWithValues, system.OsVersionCtxKey, c.osVersion)
c.ctxCancelLock.Lock()
ctx, c.ctxCancel = context.WithCancel(ctxWithValues)
Expand Down Expand Up @@ -151,8 +153,11 @@ func (c *Client) RemoveConnectionListener() {

func (c *Client) IsLoginRequired() bool {
var ctx context.Context
//nolint
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
//nolint
ctxWithValues = context.WithValue(ctxWithValues, system.OsNameCtxKey, c.osName)
//nolint
ctxWithValues = context.WithValue(ctxWithValues, system.OsVersionCtxKey, c.osVersion)
c.ctxCancelLock.Lock()
defer c.ctxCancelLock.Unlock()
Expand All @@ -168,8 +173,11 @@ func (c *Client) IsLoginRequired() bool {

func (c *Client) LoginForMobile() string {
var ctx context.Context
//nolint
ctxWithValues := context.WithValue(context.Background(), system.DeviceNameCtxKey, c.deviceName)
//nolint
ctxWithValues = context.WithValue(ctxWithValues, system.OsNameCtxKey, c.osName)
//nolint
ctxWithValues = context.WithValue(ctxWithValues, system.OsVersionCtxKey, c.osVersion)
c.ctxCancelLock.Lock()
defer c.ctxCancelLock.Unlock()
Expand Down
8 changes: 1 addition & 7 deletions client/ios/NetBirdSDK/logger.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package NetBirdSDK

import (
"os"

"github.com/netbirdio/netbird/util"
)

var logFile *os.File

// InitializeLog initializes the log file.
func InitializeLog(logLevel string, filePath string) error {
var err error
err = util.InitLog(logLevel, filePath)
return err
return util.InitLog(logLevel, filePath)
}
25 changes: 0 additions & 25 deletions client/ios/NetBirdSDK/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/netbirdio/netbird/client/cmd"
"github.com/netbirdio/netbird/client/internal"
"github.com/netbirdio/netbird/client/internal/auth"
"github.com/netbirdio/netbird/client/system"
)

Expand Down Expand Up @@ -150,30 +149,6 @@ func (a *Auth) Login() error {
return nil
}

func (a *Auth) foregroundGetTokenInfo(urlOpener URLOpener) (*auth.TokenInfo, error) {
oAuthFlow, err := auth.NewOAuthFlow(a.ctx, a.config, false)
if err != nil {
return nil, err
}

flowInfo, err := oAuthFlow.RequestAuthInfo(context.TODO())
if err != nil {
return nil, fmt.Errorf("getting a request OAuth flow info failed: %v", err)
}

go urlOpener.Open(flowInfo.VerificationURIComplete)

waitTimeout := time.Duration(flowInfo.ExpiresIn)
waitCTX, cancel := context.WithTimeout(a.ctx, waitTimeout*time.Second)
defer cancel()
tokenInfo, err := oAuthFlow.WaitToken(waitCTX, flowInfo)
if err != nil {
return nil, fmt.Errorf("waiting for browser login failed: %v", err)
}

return &tokenInfo, nil
}

func (a *Auth) withBackOff(ctx context.Context, bf func() error) error {
return backoff.RetryNotify(
bf,
Expand Down
8 changes: 4 additions & 4 deletions client/ios/NetBirdSDK/preferences_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ func TestPreferences_ReadUncommitedValues(t *testing.T) {
p.SetManagementURL(exampleString)
resp, err = p.GetManagementURL()
if err != nil {
t.Fatalf("failed to read managmenet url: %s", err)
t.Fatalf("failed to read management url: %s", err)
}

if resp != exampleString {
t.Errorf("unexpected managemenet url: %s", resp)
t.Errorf("unexpected management url: %s", resp)
}

p.SetPreSharedKey(exampleString)
Expand Down Expand Up @@ -102,11 +102,11 @@ func TestPreferences_Commit(t *testing.T) {

resp, err = p.GetManagementURL()
if err != nil {
t.Fatalf("failed to read managmenet url: %s", err)
t.Fatalf("failed to read management url: %s", err)
}

if resp != exampleURL {
t.Errorf("unexpected managemenet url: %s", resp)
t.Errorf("unexpected management url: %s", resp)
}

resp, err = p.GetPreSharedKey()
Expand Down
18 changes: 0 additions & 18 deletions client/system/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,6 @@ func extractDeviceName(ctx context.Context, defaultName string) string {
return v
}

// extractOsVersion extracts operating system version from context or returns the default
func extractOsVersion(ctx context.Context, defaultName string) string {
v, ok := ctx.Value(OsVersionCtxKey).(string)
if !ok {
return defaultName
}
return v
}

// extractOsName extracts operating system name from context or returns the default
func extractOsName(ctx context.Context, defaultName string) string {
v, ok := ctx.Value(OsNameCtxKey).(string)
if !ok {
return defaultName
}
return v
}

// GetDesktopUIUserAgent returns the Desktop ui user agent
func GetDesktopUIUserAgent() string {
return "netbird-desktop-ui/" + version.NetbirdVersion()
Expand Down
18 changes: 18 additions & 0 deletions client/system/info_ios.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ func GetInfo(ctx context.Context) *Info {

return gio
}

// extractOsVersion extracts operating system version from context or returns the default
func extractOsVersion(ctx context.Context, defaultName string) string {
v, ok := ctx.Value(OsVersionCtxKey).(string)
if !ok {
return defaultName
}
return v
}

// extractOsName extracts operating system name from context or returns the default
func extractOsName(ctx context.Context, defaultName string) string {
v, ok := ctx.Value(OsNameCtxKey).(string)
if !ok {
return defaultName
}
return v
}

0 comments on commit 5f3f5dc

Please sign in to comment.