From ead8b68a03370e1fbb991ebf152a4125e275fc11 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sat, 12 Feb 2022 19:42:55 +0000 Subject: [PATCH] Fix lint --- cmd/headscale/cli/api_key.go | 10 +++++----- cmd/headscale/cli/pterm_style.go | 3 +-- utils.go | 9 +++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/headscale/cli/api_key.go b/cmd/headscale/cli/api_key.go index fcce6905..975149ff 100644 --- a/cmd/headscale/cli/api_key.go +++ b/cmd/headscale/cli/api_key.go @@ -14,8 +14,8 @@ import ( ) const ( - // 90 days - DefaultApiKeyExpiry = 90 * 24 * time.Hour + // 90 days. + DefaultAPIKeyExpiry = 90 * 24 * time.Hour ) func init() { @@ -23,7 +23,7 @@ func init() { apiKeysCmd.AddCommand(listAPIKeys) createAPIKeyCmd.Flags(). - DurationP("expiration", "e", DefaultApiKeyExpiry, "Human-readable expiration of the key (30m, 24h, 365d...)") + DurationP("expiration", "e", DefaultAPIKeyExpiry, "Human-readable expiration of the key (30m, 24h, 365d...)") apiKeysCmd.AddCommand(createAPIKeyCmd) @@ -104,8 +104,8 @@ var createAPIKeyCmd = &cobra.Command{ Use: "create", Short: "Creates a new Api key", Long: ` -Creates a new Api key, the Api key is only visible on creation -and cannot be retrieved again. +Creates a new Api key, the Api key is only visible on creation +and cannot be retrieved again. If you loose a key, create a new one and revoke (expire) the old one.`, Run: func(cmd *cobra.Command, args []string) { output, _ := cmd.Flags().GetString("output") diff --git a/cmd/headscale/cli/pterm_style.go b/cmd/headscale/cli/pterm_style.go index e2678182..85fd050b 100644 --- a/cmd/headscale/cli/pterm_style.go +++ b/cmd/headscale/cli/pterm_style.go @@ -8,9 +8,8 @@ import ( func ColourTime(date time.Time) string { dateStr := date.Format("2006-01-02 15:04:05") - now := time.Now() - if date.After(now) { + if date.After(time.Now()) { dateStr = pterm.LightGreen(dateStr) } else { dateStr = pterm.LightRed(dateStr) diff --git a/utils.go b/utils.go index 562cede6..a6be8cc4 100644 --- a/utils.go +++ b/utils.go @@ -286,14 +286,14 @@ func containsIPPrefix(prefixes []netaddr.IPPrefix, prefix netaddr.IPPrefix) bool // number generator fails to function correctly, in which // case the caller should not continue. func GenerateRandomBytes(n int) ([]byte, error) { - b := make([]byte, n) - _, err := rand.Read(b) + bytes := make([]byte, n) + // Note that err == nil only if we read len(b) bytes. - if err != nil { + if _, err := rand.Read(bytes); err != nil { return nil, err } - return b, nil + return bytes, nil } // GenerateRandomStringURLSafe returns a URL-safe, base64 encoded @@ -303,5 +303,6 @@ func GenerateRandomBytes(n int) ([]byte, error) { // case the caller should not continue. func GenerateRandomStringURLSafe(n int) (string, error) { b, err := GenerateRandomBytes(n) + return base64.RawURLEncoding.EncodeToString(b), err }