Skip to content

[management, client] Add logout feature #4268

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

Merged
merged 3 commits into from
Aug 4, 2025
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
57 changes: 57 additions & 0 deletions client/cmd/logout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
"context"
"fmt"
"os/user"
"time"

"github.com/spf13/cobra"

"github.com/netbirdio/netbird/client/proto"
)

var logoutCmd = &cobra.Command{
Use: "logout",
Short: "logout from the Netbird Management Service and delete peer",
RunE: func(cmd *cobra.Command, args []string) error {
SetFlagsFromEnvVars(rootCmd)

cmd.SetOut(cmd.OutOrStdout())

ctx, cancel := context.WithTimeout(context.Background(), time.Second*7)
defer cancel()

conn, err := DialClientGRPCServer(ctx, daemonAddr)
if err != nil {
return fmt.Errorf("connect to daemon: %v", err)
}
defer conn.Close()

daemonClient := proto.NewDaemonServiceClient(conn)

req := &proto.LogoutRequest{}

if profileName != "" {
req.ProfileName = &profileName

currUser, err := user.Current()
if err != nil {
return fmt.Errorf("get current user: %v", err)
}
username := currUser.Username
req.Username = &username
}

if _, err := daemonClient.Logout(ctx, req); err != nil {
return fmt.Errorf("logout: %v", err)
}

cmd.Println("Logged out successfully")
return nil
},
}

func init() {
logoutCmd.PersistentFlags().StringVar(&profileName, profileNameFlag, "", profileNameDesc)
}
12 changes: 6 additions & 6 deletions client/cmd/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ package cmd
import (
"context"
"fmt"
"time"

"os/user"
"time"

"github.com/spf13/cobra"

Expand All @@ -22,10 +21,11 @@ var profileCmd = &cobra.Command{
}

var profileListCmd = &cobra.Command{
Use: "list",
Short: "list all profiles",
Long: `List all available profiles in the Netbird client.`,
RunE: listProfilesFunc,
Use: "list",
Short: "list all profiles",
Long: `List all available profiles in the Netbird client.`,
Aliases: []string{"ls"},
RunE: listProfilesFunc,
}

var profileAddCmd = &cobra.Command{
Expand Down
1 change: 1 addition & 0 deletions client/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func init() {
rootCmd.AddCommand(downCmd)
rootCmd.AddCommand(statusCmd)
rootCmd.AddCommand(loginCmd)
rootCmd.AddCommand(logoutCmd)
rootCmd.AddCommand(versionCmd)
rootCmd.AddCommand(sshCmd)
rootCmd.AddCommand(networksCMD)
Expand Down
3 changes: 2 additions & 1 deletion client/internal/profilemanager/profilemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
)

const (
defaultProfileName = "default"
DefaultProfileName = "default"
defaultProfileName = DefaultProfileName // Keep for backward compatibility
activeProfileStateFilename = "active_profile.txt"
)

Expand Down
198 changes: 149 additions & 49 deletions client/proto/daemon.pb.go

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion client/proto/daemon.proto
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ service DaemonService {
rpc ListProfiles(ListProfilesRequest) returns (ListProfilesResponse) {}

rpc GetActiveProfile(GetActiveProfileRequest) returns (GetActiveProfileResponse) {}

// Logout disconnects from the network and deletes the peer from the management server
rpc Logout(LogoutRequest) returns (LogoutResponse) {}
}


Expand Down Expand Up @@ -614,4 +617,11 @@ message GetActiveProfileRequest {}
message GetActiveProfileResponse {
string profileName = 1;
string username = 2;
}
}

message LogoutRequest {
optional string profileName = 1;
optional string username = 2;
}

message LogoutResponse {}
38 changes: 38 additions & 0 deletions client/proto/daemon_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading