add trial license status to server status api

This commit is contained in:
abhishek9686 2024-01-23 10:34:45 +05:30
parent 2a4d04ceb6
commit 4fe282d5d7

View file

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