From 4fe282d5d7850ba85b4cbbedaeb07211954dfd83 Mon Sep 17 00:00:00 2001 From: abhishek9686 Date: Tue, 23 Jan 2024 10:34:45 +0530 Subject: [PATCH] add trial license status to server status api --- controllers/server.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/controllers/server.go b/controllers/server.go index 6e10d456..c939706e 100644 --- a/controllers/server.go +++ b/controllers/server.go @@ -110,11 +110,12 @@ func getUsage(w http.ResponseWriter, _ *http.Request) { // 200: serverConfigResponse func getStatus(w http.ResponseWriter, r *http.Request) { type status struct { - DB bool `json:"db_connected"` - Broker bool `json:"broker_connected"` - LicenseError string `json:"license_error"` - IsPro bool `json:"is_pro"` - TrialEndDate time.Time `json:"trial_end_date"` + DB bool `json:"db_connected"` + Broker bool `json:"broker_connected"` + LicenseError string `json:"license_error"` + IsPro bool `json:"is_pro"` + TrialEndDate time.Time `json:"trial_end_date"` + IsOnTrialLicense bool `json:"is_on_trial_license"` } licenseErr := "" @@ -122,15 +123,23 @@ func getStatus(w http.ResponseWriter, r *http.Request) { licenseErr = servercfg.ErrLicenseValidation.Error() } var trialEndDate time.Time - if servercfg.GetLicenseKey() == "" || servercfg.GetNetmakerTenantID() == "" { - trialEndDate, _ = logic.GetTrialEndDate() + var err error + isOnTrial := false + if servercfg.IsPro && (servercfg.GetLicenseKey() == "" || servercfg.GetNetmakerTenantID() == "") { + trialEndDate, err = logic.GetTrialEndDate() + if err != nil { + slog.Error("failed to get trial end date", "error", err) + } else { + isOnTrial = true + } } currentServerStatus := status{ - DB: database.IsConnected(), - Broker: mq.IsConnected(), - LicenseError: licenseErr, - IsPro: servercfg.IsPro, - TrialEndDate: trialEndDate, + DB: database.IsConnected(), + Broker: mq.IsConnected(), + LicenseError: licenseErr, + IsPro: servercfg.IsPro, + TrialEndDate: trialEndDate, + IsOnTrialLicense: isOnTrial, } w.Header().Set("Content-Type", "application/json")