Skip to content

Commit

Permalink
rpk: change expiry check for free_trial
Browse files Browse the repository at this point in the history
If it's a free trial license the expiry warning
check threshold will be set to 15days instead of
30 for the rest of license types.

Fixes DEVEX-36
  • Loading branch information
r-vasquez committed Oct 29, 2024
1 parent ffd7c28 commit 76dec5a
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/go/rpk/pkg/cli/cluster/license/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package license
import (
"fmt"
"os"
"strings"
"time"

"github.com/redpanda-data/common-go/rpadmin"
Expand Down Expand Up @@ -133,17 +134,21 @@ func printTextLicenseInfo(resp infoResponse) {
if *resp.Expired {
tw.Print("License expired:", *resp.Expired)
}
checkLicenseExpiry(resp.ExpiresUnix)
checkLicenseExpiry(resp.ExpiresUnix, resp.Type)
}
out.Section("LICENSE INFORMATION")
tw.Flush()
}

func checkLicenseExpiry(expiresUnix int64) {
func checkLicenseExpiry(expiresUnix int64, licenseType string) {
ut := time.Unix(expiresUnix, 0)
daysLeft := int(time.Until(ut).Hours() / 24)

if daysLeft < 30 && !ut.Before(time.Now()) {
dayThreshold := 30
if strings.EqualFold(licenseType, "free_trial") {
dayThreshold = 15
}
if daysLeft < dayThreshold && !ut.Before(time.Now()) {
fmt.Fprintf(os.Stderr, "WARNING: your license will expire soon.\n\n")
}
}

0 comments on commit 76dec5a

Please sign in to comment.