Skip to content

Commit

Permalink
store not initialized error
Browse files Browse the repository at this point in the history
  • Loading branch information
Siva Manivannan committed Dec 18, 2023
1 parent 4ffafd2 commit b1263f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
4 changes: 4 additions & 0 deletions pkg/persistence/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ var (
uri string
)

func IsInitialized() bool {
return db != nil
}

func SetDB(database *gorqlite.Connection) {
db = database
}
Expand Down
23 changes: 13 additions & 10 deletions pkg/replicatedapp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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.IsInitialized() {
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)
Expand Down

0 comments on commit b1263f4

Please sign in to comment.