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 (
// 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)

View file

@ -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)

View file

@ -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
}