From 7bf5b48d9f62bd4a4786561041dbd56c8aef82db Mon Sep 17 00:00:00 2001 From: Deon Thomas Date: Tue, 10 May 2022 14:19:05 -0400 Subject: [PATCH] import from headscale, use NowFromTZEnv to get time. --- cmd/headscale/cli/api_key.go | 4 +--- cmd/headscale/cli/preauthkeys.go | 5 ++--- cmd/headscale/headscale.go | 4 ++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/cmd/headscale/cli/api_key.go b/cmd/headscale/cli/api_key.go index aea16b61..b6cbeaa9 100644 --- a/cmd/headscale/cli/api_key.go +++ b/cmd/headscale/cli/api_key.go @@ -10,7 +10,6 @@ import ( "github.com/pterm/pterm" "github.com/rs/zerolog/log" "github.com/spf13/cobra" - "github.com/spf13/viper" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -120,8 +119,7 @@ If you loose a key, create a new one and revoke (expire) the old one.`, request := &v1.CreateApiKeyRequest{} duration, _ := cmd.Flags().GetDuration("expiration") - location, _ := time.LoadLocation(viper.GetString("TZ")) - expiration := time.Now().In(location).Add(duration) + expiration := headscale.NowFromTZEnv().Add(duration) log.Trace().Dur("expiration", duration).Msg("expiration has been set") diff --git a/cmd/headscale/cli/preauthkeys.go b/cmd/headscale/cli/preauthkeys.go index 2e9c49d3..5cba6b14 100644 --- a/cmd/headscale/cli/preauthkeys.go +++ b/cmd/headscale/cli/preauthkeys.go @@ -5,11 +5,11 @@ import ( "strconv" "time" + "github.com/juanfont/headscale" v1 "github.com/juanfont/headscale/gen/go/headscale/v1" "github.com/pterm/pterm" "github.com/rs/zerolog/log" "github.com/spf13/cobra" - "github.com/spf13/viper" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -150,8 +150,7 @@ var createPreAuthKeyCmd = &cobra.Command{ } duration, _ := cmd.Flags().GetDuration("expiration") - location, _ := time.LoadLocation(viper.GetString("TZ")) - expiration := time.Now().In(location).Add(duration) + expiration := headscale.NowFromTZEnv().Add(duration) log.Trace().Dur("expiration", duration).Msg("expiration has been set") diff --git a/cmd/headscale/headscale.go b/cmd/headscale/headscale.go index b7509566..b39dae17 100644 --- a/cmd/headscale/headscale.go +++ b/cmd/headscale/headscale.go @@ -7,6 +7,7 @@ import ( "time" "github.com/efekarakus/termcolor" + "github.com/juanfont/headscale" "github.com/juanfont/headscale/cmd/headscale/cli" "github.com/rs/zerolog" "github.com/rs/zerolog/log" @@ -45,8 +46,7 @@ func main() { } zerolog.TimestampFunc = func() time.Time { - location, _ := time.LoadLocation(viper.GetString("TZ")) - return time.Now().In(location) + return headscale.NowFromTZEnv() } log.Logger = log.Output(zerolog.ConsoleWriter{