Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[client] Parse data from setup key #2411

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions client/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ var loginCmd = &cobra.Command{
ctx = context.WithValue(ctx, system.DeviceNameCtxKey, hostName)
}

if setupKeyPath != "" && setupKey == "" {
setupKey, err = getSetupKeyFromFile(setupKeyPath)
if err != nil {
return err
}
providedSetupKey, err := getSetupKey()
if err != nil {
return err
}

// workaround to run without service
Expand All @@ -69,7 +67,7 @@ var loginCmd = &cobra.Command{

config, _ = internal.UpdateOldManagementURL(ctx, config, configPath)

err = foregroundLogin(ctx, cmd, config, setupKey)
err = foregroundLogin(ctx, cmd, config, providedSetupKey)
if err != nil {
return fmt.Errorf("foreground login failed: %v", err)
}
Expand All @@ -88,7 +86,7 @@ var loginCmd = &cobra.Command{
client := proto.NewDaemonServiceClient(conn)

loginRequest := proto.LoginRequest{
SetupKey: setupKey,
SetupKey: providedSetupKey,
ManagementUrl: managementURL,
IsLinuxDesktopClient: isLinuxRunningDesktop(),
Hostname: hostName,
Expand Down
12 changes: 11 additions & 1 deletion client/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,19 @@ var CLIBackOffSettings = &backoff.ExponentialBackOff{
Clock: backoff.SystemClock,
}

func getSetupKey() (string, error) {
if setupKeyPath != "" && setupKey == "" {
return getSetupKeyFromFile(setupKeyPath)
}
return setupKey, nil
}

func getSetupKeyFromFile(setupKeyPath string) (string, error) {
data, err := os.ReadFile(setupKeyPath)
return string(data), err
if err != nil {
return "", fmt.Errorf("failed to read setup key file: %v", err)
}
return strings.TrimSpace(string(data)), nil
}

func handleRebrand(cmd *cobra.Command) error {
Expand Down
21 changes: 12 additions & 9 deletions client/cmd/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ func upFunc(cmd *cobra.Command, args []string) error {
ctx = context.WithValue(ctx, system.DeviceNameCtxKey, hostName)
}

if setupKeyPath != "" && setupKey == "" {
setupKey, err = getSetupKeyFromFile(setupKeyPath)
if err != nil {
return err
}
}

if foregroundMode {
return runInForegroundMode(ctx, cmd)
}
Expand Down Expand Up @@ -154,14 +147,19 @@ func runInForegroundMode(ctx context.Context, cmd *cobra.Command) error {
ic.DNSRouteInterval = &dnsRouteInterval
}

providedSetupKey, err := getSetupKey()
if err != nil {
return err
}

config, err := internal.UpdateOrCreateConfig(ic)
if err != nil {
return fmt.Errorf("get config file: %v", err)
}

config, _ = internal.UpdateOldManagementURL(ctx, config, configPath)

err = foregroundLogin(ctx, cmd, config, setupKey)
err = foregroundLogin(ctx, cmd, config, providedSetupKey)
if err != nil {
return fmt.Errorf("foreground login failed: %v", err)
}
Expand Down Expand Up @@ -206,8 +204,13 @@ func runInDaemonMode(ctx context.Context, cmd *cobra.Command) error {
return nil
}

providedSetupKey, err := getSetupKey()
if err != nil {
return err
}

loginRequest := proto.LoginRequest{
SetupKey: setupKey,
SetupKey: providedSetupKey,
ManagementUrl: managementURL,
AdminURL: adminURL,
NatExternalIPs: natExternalIPs,
Expand Down
Loading