From 4de17cb63cca7b43335b6bc211debfa1de67ef9c Mon Sep 17 00:00:00 2001 From: Pasha Sviderski Date: Tue, 3 Mar 2026 18:03:06 +1000 Subject: [PATCH] chore: delete the obsolete 'machine token' command --- cmd/uncloud/machine/root.go | 1 - cmd/uncloud/machine/token.go | 39 --------------------------------- internal/daemon/token.go | 42 ------------------------------------ 3 files changed, 82 deletions(-) delete mode 100644 cmd/uncloud/machine/token.go delete mode 100644 internal/daemon/token.go diff --git a/cmd/uncloud/machine/root.go b/cmd/uncloud/machine/root.go index 6d984075..cf42c026 100644 --- a/cmd/uncloud/machine/root.go +++ b/cmd/uncloud/machine/root.go @@ -17,7 +17,6 @@ func NewRootCommand() *cobra.Command { NewRenameCommand(), NewRmCommand(), NewUpdateCommand(), - NewTokenCommand(), ) return cmd } diff --git a/cmd/uncloud/machine/token.go b/cmd/uncloud/machine/token.go deleted file mode 100644 index fed1fb87..00000000 --- a/cmd/uncloud/machine/token.go +++ /dev/null @@ -1,39 +0,0 @@ -package machine - -import ( - "fmt" - - "github.com/psviderski/uncloud/internal/daemon" - "github.com/psviderski/uncloud/internal/machine" - "github.com/spf13/cobra" -) - -type tokenOptions struct { - dataDir string -} - -func NewTokenCommand() *cobra.Command { - opts := tokenOptions{} - cmd := &cobra.Command{ - Use: "token", - Short: "Print the local machine's token for adding it to a cluster.", - RunE: func(cmd *cobra.Command, args []string) error { - token, err := daemon.MachineToken(opts.dataDir) - if err != nil { - return fmt.Errorf("get machine token: %w", err) - } - tokenStr, err := token.String() - if err != nil { - return fmt.Errorf("encode machine token: %w", err) - } - fmt.Println(tokenStr) - return nil - }, - } - - cmd.Flags().StringVarP(&opts.dataDir, "data-dir", "d", machine.DefaultDataDir, - "Directory for storing persistent machine state.") - _ = cmd.MarkFlagDirname("data-dir") - - return cmd -} diff --git a/internal/daemon/token.go b/internal/daemon/token.go deleted file mode 100644 index f4d6b408..00000000 --- a/internal/daemon/token.go +++ /dev/null @@ -1,42 +0,0 @@ -package daemon - -import ( - "errors" - "fmt" - "net/netip" - "os" - - "github.com/psviderski/uncloud/internal/machine" - "github.com/psviderski/uncloud/internal/machine/network" -) - -// MachineToken returns the local machine's token that can be used for adding the machine to a cluster. -// TODO: ideally, this should be an RPC call to the daemon API to ensure the config is created and up-to-date. -func MachineToken(dataDir string) (machine.Token, error) { - state, err := machine.ParseState(machine.StatePath(dataDir)) - if err != nil { - if errors.Is(err, os.ErrNotExist) { - return machine.Token{}, fmt.Errorf("load machine config (is uncloudd daemon running?): %w", err) - } - return machine.Token{}, fmt.Errorf("load machine config: %w", err) - } - if len(state.Network.PublicKey) == 0 { - return machine.Token{}, errors.New("public key is not set in machine config") - } - - ips, err := network.ListRoutableIPs() - if err != nil { - return machine.Token{}, fmt.Errorf("list routable addresses: %w", err) - } - publicIP, err := network.GetPublicIP() - // Ignore the error if failed to get the public IP using API services. - if err == nil { - ips = append(ips, publicIP) - } - - endpoints := make([]netip.AddrPort, len(ips)) - for i, ip := range ips { - endpoints[i] = netip.AddrPortFrom(ip, network.WireGuardPort) - } - return machine.NewToken(state.Network.PublicKey, publicIP, endpoints), nil -}