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{