From 11605667b6751063deb20f343918adb9e4a6640d Mon Sep 17 00:00:00 2001 From: Siva Manivannan Date: Mon, 18 Dec 2023 15:07:23 -0600 Subject: [PATCH] store not initialized error --- pkg/persistence/persistence.go | 4 ++++ pkg/replicatedapp/api.go | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/pkg/persistence/persistence.go b/pkg/persistence/persistence.go index a8282fa130..758f27c316 100644 --- a/pkg/persistence/persistence.go +++ b/pkg/persistence/persistence.go @@ -7,6 +7,10 @@ var ( uri string ) +func IsDBInitialized() bool { + return db != nil +} + func SetDB(database *gorqlite.Connection) { db = database } diff --git a/pkg/replicatedapp/api.go b/pkg/replicatedapp/api.go index 7d2942f271..d3e195b846 100644 --- a/pkg/replicatedapp/api.go +++ b/pkg/replicatedapp/api.go @@ -12,6 +12,7 @@ import ( "github.com/pkg/errors" apptypes "github.com/replicatedhq/kots/pkg/app/types" "github.com/replicatedhq/kots/pkg/logger" + "github.com/replicatedhq/kots/pkg/persistence" "github.com/replicatedhq/kots/pkg/reporting" "github.com/replicatedhq/kots/pkg/store" "github.com/replicatedhq/kots/pkg/util" @@ -60,14 +61,14 @@ func GetLatestLicenseForHelm(licenseID string) (*LicenseData, error) { return licenseData, nil } -func getAppIdFromLicenseId(licenseID string) (string, error) { - apps, err := store.GetStore().ListInstalledApps() +func getAppIdFromLicenseId(s store.Store, licenseID string) (string, error) { + apps, err := s.ListInstalledApps() if err != nil { return "", errors.Wrap(err, "failed to get all app licenses") } for _, a := range apps { - l, err := store.GetStore().GetLatestLicenseForApp(a.ID) + l, err := s.GetLatestLicenseForApp(a.ID) if err != nil { return "", errors.Wrap(err, "failed to get latest license for app") } @@ -88,14 +89,16 @@ func getLicenseFromAPI(url string, licenseID string) (*LicenseData, error) { req.SetBasicAuth(licenseID, licenseID) - appId, err := getAppIdFromLicenseId(licenseID) - if err != nil { - return nil, errors.Wrap(err, "failed to get license by id") - } + if persistence.IsDBInitialized() { + appId, err := getAppIdFromLicenseId(store.GetStore(), licenseID) + if err != nil { + return nil, errors.Wrap(err, "failed to get license by id") + } - if appId != "" { - reportingInfo := reporting.GetReportingInfo(appId) - reporting.InjectReportingInfoHeaders(req, reportingInfo) + if appId != "" { + reportingInfo := reporting.GetReportingInfo(appId) + reporting.InjectReportingInfoHeaders(req, reportingInfo) + } } resp, err := http.DefaultClient.Do(req)