This commit is contained in:
Kristoffer Dalby 2022-02-12 19:42:55 +00:00
parent 3bb4c28c9a
commit ead8b68a03
3 changed files with 11 additions and 11 deletions

View file

@ -14,8 +14,8 @@ import (
) )
const ( const (
// 90 days // 90 days.
DefaultApiKeyExpiry = 90 * 24 * time.Hour DefaultAPIKeyExpiry = 90 * 24 * time.Hour
) )
func init() { func init() {
@ -23,7 +23,7 @@ func init() {
apiKeysCmd.AddCommand(listAPIKeys) apiKeysCmd.AddCommand(listAPIKeys)
createAPIKeyCmd.Flags(). 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) apiKeysCmd.AddCommand(createAPIKeyCmd)

View file

@ -8,9 +8,8 @@ import (
func ColourTime(date time.Time) string { func ColourTime(date time.Time) string {
dateStr := date.Format("2006-01-02 15:04:05") 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) dateStr = pterm.LightGreen(dateStr)
} else { } else {
dateStr = pterm.LightRed(dateStr) dateStr = pterm.LightRed(dateStr)

View file

@ -286,14 +286,14 @@ func containsIPPrefix(prefixes []netaddr.IPPrefix, prefix netaddr.IPPrefix) bool
// number generator fails to function correctly, in which // number generator fails to function correctly, in which
// case the caller should not continue. // case the caller should not continue.
func GenerateRandomBytes(n int) ([]byte, error) { func GenerateRandomBytes(n int) ([]byte, error) {
b := make([]byte, n) bytes := make([]byte, n)
_, err := rand.Read(b)
// Note that err == nil only if we read len(b) bytes. // 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 nil, err
} }
return b, nil return bytes, nil
} }
// GenerateRandomStringURLSafe returns a URL-safe, base64 encoded // GenerateRandomStringURLSafe returns a URL-safe, base64 encoded
@ -303,5 +303,6 @@ func GenerateRandomBytes(n int) ([]byte, error) {
// case the caller should not continue. // case the caller should not continue.
func GenerateRandomStringURLSafe(n int) (string, error) { func GenerateRandomStringURLSafe(n int) (string, error) {
b, err := GenerateRandomBytes(n) b, err := GenerateRandomBytes(n)
return base64.RawURLEncoding.EncodeToString(b), err return base64.RawURLEncoding.EncodeToString(b), err
} }