Skip to content

Commit

Permalink
Nickname support
Browse files Browse the repository at this point in the history
  • Loading branch information
bravechamp committed Mar 13, 2022
1 parent 61440c4 commit 663e838
Show file tree
Hide file tree
Showing 10 changed files with 669 additions and 197 deletions.
53 changes: 53 additions & 0 deletions cmd/headscale/cli/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ func init() {
}
nodeCmd.AddCommand(expireNodeCmd)

renameNodeCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
err = renameNodeCmd.MarkFlagRequired("identifier")
if err != nil {
log.Fatalf(err.Error())
}
nodeCmd.AddCommand(renameNodeCmd)

deleteNodeCmd.Flags().Uint64P("identifier", "i", 0, "Node identifier (ID)")
err = deleteNodeCmd.MarkFlagRequired("identifier")
if err != nil {
Expand Down Expand Up @@ -207,6 +214,50 @@ var expireNodeCmd = &cobra.Command{
},
}

var renameNodeCmd = &cobra.Command{
Use: "rename NEW_NAME",
Short: "Renames a machine in your network",
Run: func(cmd *cobra.Command, args []string) {
output, _ := cmd.Flags().GetString("output")

identifier, err := cmd.Flags().GetUint64("identifier")
if err != nil {
ErrorOutput(
err,
fmt.Sprintf("Error converting ID to integer: %s", err),
output,
)

return
}

ctx, client, conn, cancel := getHeadscaleCLIClient()
defer cancel()
defer conn.Close()

request := &v1.RenameMachineRequest{
MachineId: identifier,
NewName: args[0],
}

response, err := client.RenameMachine(ctx, request)
if err != nil {
ErrorOutput(
err,
fmt.Sprintf(
"Cannot expire machine: %s\n",
status.Convert(err).Message(),
),
output,
)

return
}

SuccessOutput(response.Machine, "Machine renamed", output)
},
}

var deleteNodeCmd = &cobra.Command{
Use: "delete",
Short: "Delete a node",
Expand Down Expand Up @@ -304,6 +355,7 @@ func nodesToPtables(
{
"ID",
"Name",
"Nickname",
"NodeKey",
"Namespace",
"IP addresses",
Expand Down Expand Up @@ -368,6 +420,7 @@ func nodesToPtables(
[]string{
strconv.FormatUint(machine.Id, headscale.Base10),
machine.Name,
machine.Nickname,
nodeKey.ShortString(),
namespace,
strings.Join(machine.IpAddresses, ", "),
Expand Down
215 changes: 114 additions & 101 deletions gen/go/headscale/v1/headscale.pb.go

Large diffs are not rendered by default.

119 changes: 119 additions & 0 deletions gen/go/headscale/v1/headscale.pb.gw.go

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

36 changes: 36 additions & 0 deletions gen/go/headscale/v1/headscale_grpc.pb.go

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

Loading

0 comments on commit 663e838

Please sign in to comment.