From 51dc0d57843c627f4e756aa03313d6501cb9b552 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Wed, 10 May 2023 10:19:37 +0200 Subject: [PATCH] update dependency path for cmd Signed-off-by: Kristoffer Dalby --- cmd/headscale/cli/api_key.go | 4 ++-- cmd/headscale/cli/debug.go | 4 ++-- cmd/headscale/cli/nodes.go | 8 ++++---- cmd/headscale/cli/root.go | 10 +++++----- cmd/headscale/cli/routes.go | 4 ++-- cmd/headscale/cli/users.go | 4 ++-- cmd/headscale/cli/utils.go | 18 +++++++++--------- cmd/headscale/headscale_test.go | 18 +++++++++--------- 8 files changed, 35 insertions(+), 35 deletions(-) diff --git a/cmd/headscale/cli/api_key.go b/cmd/headscale/cli/api_key.go index 5756db4..f7c7e3a 100644 --- a/cmd/headscale/cli/api_key.go +++ b/cmd/headscale/cli/api_key.go @@ -5,8 +5,8 @@ import ( "strconv" "time" - "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol" "github.com/prometheus/common/model" "github.com/pterm/pterm" "github.com/rs/zerolog/log" @@ -83,7 +83,7 @@ var listAPIKeys = &cobra.Command{ } tableData = append(tableData, []string{ - strconv.FormatUint(key.GetId(), headscale.Base10), + strconv.FormatUint(key.GetId(), hscontrol.Base10), key.GetPrefix(), expiration, key.GetCreatedAt().AsTime().Format(HeadscaleDateTimeFormat), diff --git a/cmd/headscale/cli/debug.go b/cmd/headscale/cli/debug.go index 383ed13..f2c8028 100644 --- a/cmd/headscale/cli/debug.go +++ b/cmd/headscale/cli/debug.go @@ -3,8 +3,8 @@ package cli import ( "fmt" - "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol" "github.com/rs/zerolog/log" "github.com/spf13/cobra" "google.golang.org/grpc/status" @@ -93,7 +93,7 @@ var createNodeCmd = &cobra.Command{ return } - if !headscale.NodePublicKeyRegex.Match([]byte(machineKey)) { + if !hscontrol.NodePublicKeyRegex.Match([]byte(machineKey)) { err = errPreAuthKeyMalformed ErrorOutput( err, diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index 5d8babd..772b428 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -9,8 +9,8 @@ import ( "time" survey "github.com/AlecAivazis/survey/v2" - "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol" "github.com/pterm/pterm" "github.com/spf13/cobra" "google.golang.org/grpc/status" @@ -529,7 +529,7 @@ func nodesToPtables( var machineKey key.MachinePublic err := machineKey.UnmarshalText( - []byte(headscale.MachinePublicKeyEnsurePrefix(machine.MachineKey)), + []byte(hscontrol.MachinePublicKeyEnsurePrefix(machine.MachineKey)), ) if err != nil { machineKey = key.MachinePublic{} @@ -537,7 +537,7 @@ func nodesToPtables( var nodeKey key.NodePublic err = nodeKey.UnmarshalText( - []byte(headscale.NodePublicKeyEnsurePrefix(machine.NodeKey)), + []byte(hscontrol.NodePublicKeyEnsurePrefix(machine.NodeKey)), ) if err != nil { return nil, err @@ -596,7 +596,7 @@ func nodesToPtables( } nodeData := []string{ - strconv.FormatUint(machine.Id, headscale.Base10), + strconv.FormatUint(machine.Id, hscontrol.Base10), machine.Name, machine.GetGivenName(), machineKey.ShortString(), diff --git a/cmd/headscale/cli/root.go b/cmd/headscale/cli/root.go index cf173f5..ab76fff 100644 --- a/cmd/headscale/cli/root.go +++ b/cmd/headscale/cli/root.go @@ -5,7 +5,7 @@ import ( "os" "runtime" - "github.com/juanfont/headscale" + "github.com/juanfont/headscale/hscontrol" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -38,18 +38,18 @@ func initConfig() { cfgFile = os.Getenv("HEADSCALE_CONFIG") } if cfgFile != "" { - err := headscale.LoadConfig(cfgFile, true) + err := hscontrol.LoadConfig(cfgFile, true) if err != nil { log.Fatal().Caller().Err(err).Msgf("Error loading config file %s", cfgFile) } } else { - err := headscale.LoadConfig("", false) + err := hscontrol.LoadConfig("", false) if err != nil { log.Fatal().Caller().Err(err).Msgf("Error loading config") } } - cfg, err := headscale.GetHeadscaleConfig() + cfg, err := hscontrol.GetHeadscaleConfig() if err != nil { log.Fatal().Caller().Err(err) } @@ -64,7 +64,7 @@ func initConfig() { zerolog.SetGlobalLevel(zerolog.Disabled) } - if cfg.Log.Format == headscale.JSONLogFormat { + if cfg.Log.Format == hscontrol.JSONLogFormat { log.Logger = log.Output(os.Stdout) } diff --git a/cmd/headscale/cli/routes.go b/cmd/headscale/cli/routes.go index 55f009e..206209d 100644 --- a/cmd/headscale/cli/routes.go +++ b/cmd/headscale/cli/routes.go @@ -6,8 +6,8 @@ import ( "net/netip" "strconv" - "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol" "github.com/pterm/pterm" "github.com/spf13/cobra" "google.golang.org/grpc/status" @@ -277,7 +277,7 @@ func routesToPtables(routes []*v1.Route) pterm.TableData { continue } - if prefix == headscale.ExitRouteV4 || prefix == headscale.ExitRouteV6 { + if prefix == hscontrol.ExitRouteV4 || prefix == hscontrol.ExitRouteV6 { isPrimaryStr = "-" } else { isPrimaryStr = strconv.FormatBool(route.IsPrimary) diff --git a/cmd/headscale/cli/users.go b/cmd/headscale/cli/users.go index 653ab53..3724fe9 100644 --- a/cmd/headscale/cli/users.go +++ b/cmd/headscale/cli/users.go @@ -4,8 +4,8 @@ import ( "fmt" survey "github.com/AlecAivazis/survey/v2" - "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol" "github.com/pterm/pterm" "github.com/rs/zerolog/log" "github.com/spf13/cobra" @@ -21,7 +21,7 @@ func init() { } const ( - errMissingParameter = headscale.Error("missing parameters") + errMissingParameter = hscontrol.Error("missing parameters") ) var userCmd = &cobra.Command{ diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index 3b3ac21..a2a5d59 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -8,8 +8,8 @@ import ( "os" "reflect" - "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" + "github.com/juanfont/headscale/hscontrol" "github.com/rs/zerolog/log" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -22,8 +22,8 @@ const ( SocketWritePermissions = 0o666 ) -func getHeadscaleApp() (*headscale.Headscale, error) { - cfg, err := headscale.GetHeadscaleConfig() +func getHeadscaleApp() (*hscontrol.Headscale, error) { + cfg, err := hscontrol.GetHeadscaleConfig() if err != nil { return nil, fmt.Errorf( "failed to load configuration while creating headscale instance: %w", @@ -31,7 +31,7 @@ func getHeadscaleApp() (*headscale.Headscale, error) { ) } - app, err := headscale.NewHeadscale(cfg) + app, err := hscontrol.NewHeadscale(cfg) if err != nil { return nil, err } @@ -39,8 +39,8 @@ func getHeadscaleApp() (*headscale.Headscale, error) { // We are doing this here, as in the future could be cool to have it also hot-reload if cfg.ACL.PolicyPath != "" { - aclPath := headscale.AbsolutePathFromConfigPath(cfg.ACL.PolicyPath) - err = app.LoadACLPolicy(aclPath) + aclPath := hscontrol.AbsolutePathFromConfigPath(cfg.ACL.PolicyPath) + err = app.LoadACLPolicyFromPath(aclPath) if err != nil { log.Fatal(). Str("path", aclPath). @@ -53,7 +53,7 @@ func getHeadscaleApp() (*headscale.Headscale, error) { } func getHeadscaleCLIClient() (context.Context, v1.HeadscaleServiceClient, *grpc.ClientConn, context.CancelFunc) { - cfg, err := headscale.GetHeadscaleConfig() + cfg, err := hscontrol.GetHeadscaleConfig() if err != nil { log.Fatal(). Err(err). @@ -74,7 +74,7 @@ func getHeadscaleCLIClient() (context.Context, v1.HeadscaleServiceClient, *grpc. address := cfg.CLI.Address - // If the address is not set, we assume that we are on the server hosting headscale. + // If the address is not set, we assume that we are on the server hosting hscontrol. if address == "" { log.Debug(). Str("socket", cfg.UnixSocket). @@ -98,7 +98,7 @@ func getHeadscaleCLIClient() (context.Context, v1.HeadscaleServiceClient, *grpc. grpcOptions = append( grpcOptions, grpc.WithTransportCredentials(insecure.NewCredentials()), - grpc.WithContextDialer(headscale.GrpcSocketDialer), + grpc.WithContextDialer(hscontrol.GrpcSocketDialer), ) } else { // If we are not connecting to a local server, require an API key for authentication diff --git a/cmd/headscale/headscale_test.go b/cmd/headscale/headscale_test.go index c7b332a..1b98731 100644 --- a/cmd/headscale/headscale_test.go +++ b/cmd/headscale/headscale_test.go @@ -7,7 +7,7 @@ import ( "strings" "testing" - "github.com/juanfont/headscale" + "github.com/juanfont/headscale/hscontrol" "github.com/spf13/viper" "gopkg.in/check.v1" ) @@ -50,7 +50,7 @@ func (*Suite) TestConfigFileLoading(c *check.C) { } // Load example config, it should load without validation errors - err = headscale.LoadConfig(cfgFile, true) + err = hscontrol.LoadConfig(cfgFile, true) c.Assert(err, check.IsNil) // Test that config file was interpreted correctly @@ -64,7 +64,7 @@ func (*Suite) TestConfigFileLoading(c *check.C) { c.Assert(viper.GetString("tls_letsencrypt_challenge_type"), check.Equals, "HTTP-01") c.Assert(viper.GetStringSlice("dns_config.nameservers")[0], check.Equals, "1.1.1.1") c.Assert( - headscale.GetFileMode("unix_socket_permission"), + hscontrol.GetFileMode("unix_socket_permission"), check.Equals, fs.FileMode(0o770), ) @@ -93,7 +93,7 @@ func (*Suite) TestConfigLoading(c *check.C) { } // Load example config, it should load without validation errors - err = headscale.LoadConfig(tmpDir, false) + err = hscontrol.LoadConfig(tmpDir, false) c.Assert(err, check.IsNil) // Test that config file was interpreted correctly @@ -107,7 +107,7 @@ func (*Suite) TestConfigLoading(c *check.C) { c.Assert(viper.GetString("tls_letsencrypt_challenge_type"), check.Equals, "HTTP-01") c.Assert(viper.GetStringSlice("dns_config.nameservers")[0], check.Equals, "1.1.1.1") c.Assert( - headscale.GetFileMode("unix_socket_permission"), + hscontrol.GetFileMode("unix_socket_permission"), check.Equals, fs.FileMode(0o770), ) @@ -137,10 +137,10 @@ func (*Suite) TestDNSConfigLoading(c *check.C) { } // Load example config, it should load without validation errors - err = headscale.LoadConfig(tmpDir, false) + err = hscontrol.LoadConfig(tmpDir, false) c.Assert(err, check.IsNil) - dnsConfig, baseDomain := headscale.GetDNSConfig() + dnsConfig, baseDomain := hscontrol.GetDNSConfig() c.Assert(dnsConfig.Nameservers[0].String(), check.Equals, "1.1.1.1") c.Assert(dnsConfig.Resolvers[0].Addr, check.Equals, "1.1.1.1") @@ -172,7 +172,7 @@ noise: writeConfig(c, tmpDir, configYaml) // Check configuration validation errors (1) - err = headscale.LoadConfig(tmpDir, false) + err = hscontrol.LoadConfig(tmpDir, false) c.Assert(err, check.NotNil) // check.Matches can not handle multiline strings tmp := strings.ReplaceAll(err.Error(), "\n", "***") @@ -201,6 +201,6 @@ tls_letsencrypt_hostname: example.com tls_letsencrypt_challenge_type: TLS-ALPN-01 `) writeConfig(c, tmpDir, configYaml) - err = headscale.LoadConfig(tmpDir, false) + err = hscontrol.LoadConfig(tmpDir, false) c.Assert(err, check.IsNil) }