From b6ae60cc44bd8218443c21da0473d9b193c8ca7d Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Fri, 26 Nov 2021 14:49:51 -0500 Subject: [PATCH 1/2] The `create-node` subcommand under `debug` needs a 64 character key. --- cmd/headscale/cli/debug.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/headscale/cli/debug.go b/cmd/headscale/cli/debug.go index 46bdb9e8..226ae5e7 100644 --- a/cmd/headscale/cli/debug.go +++ b/cmd/headscale/cli/debug.go @@ -77,6 +77,16 @@ var createNodeCmd = &cobra.Command{ return } + if len(machineKey) != 64 { + err = fmt.Errorf("key '%s' too short, must be 64 hexadecimal characters", machineKey) + ErrorOutput( + err, + fmt.Sprintf("Error: %s", err), + output, + ) + + return + } routes, err := cmd.Flags().GetStringSlice("route") if err != nil { From cb2ea300ad19e3ef76d3d7b4802ce28708e48225 Mon Sep 17 00:00:00 2001 From: Ward Vandewege Date: Sat, 27 Nov 2021 13:59:39 -0500 Subject: [PATCH 2/2] Fix linter errors. --- cmd/headscale/cli/debug.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmd/headscale/cli/debug.go b/cmd/headscale/cli/debug.go index 226ae5e7..8010a9be 100644 --- a/cmd/headscale/cli/debug.go +++ b/cmd/headscale/cli/debug.go @@ -9,6 +9,16 @@ import ( "google.golang.org/grpc/status" ) +const ( + keyLength = 64 + errPreAuthKeyTooShort = Error("key too short, must be 64 hexadecimal characters") +) + +// Error is used to compare errors as per https://dave.cheney.net/2016/04/07/constant-errors +type Error string + +func (e Error) Error() string { return string(e) } + func init() { rootCmd.AddCommand(debugCmd) @@ -77,8 +87,8 @@ var createNodeCmd = &cobra.Command{ return } - if len(machineKey) != 64 { - err = fmt.Errorf("key '%s' too short, must be 64 hexadecimal characters", machineKey) + if len(machineKey) != keyLength { + err = errPreAuthKeyTooShort ErrorOutput( err, fmt.Sprintf("Error: %s", err),