Skip to content

Commit

Permalink
add function to get reporting info by app slug
Browse files Browse the repository at this point in the history
  • Loading branch information
Siva Manivannan committed Dec 5, 2023
1 parent bfc9eff commit 60c8ce2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/replicatedapp/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ func GetLatestLicenseForHelm(licenseID string) (*LicenseData, error) {
return licenseData, nil
}

func getLicenseById(licenseID string) (*kotsv1beta1.License, error) {

allLicenses, err := store.GetStore().GetAllAppLicenses()
if err != nil {
return nil, errors.Wrap(err, "failed to get all app licenses")
}

for _, l := range allLicenses {
if l.Spec.LicenseID == licenseID {
return l, nil
}
}

return nil, nil
}

func getLicenseFromAPI(url string, licenseID string) (*LicenseData, error) {
req, err := util.NewRequest("GET", url, nil)
if err != nil {
Expand All @@ -68,6 +84,16 @@ func getLicenseFromAPI(url string, licenseID string) (*LicenseData, error) {

req.SetBasicAuth(licenseID, licenseID)

l, err := getLicenseById(licenseID)
if err != nil {
return nil, errors.Wrap(err, "failed to get license by id")
}

if l != nil {
reportingInfo := reporting.GetReportingInfoByAppSlug(l.Spec.AppSlug)
reporting.InjectReportingInfoHeaders(req, reportingInfo)
}

resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, errors.Wrap(err, "failed to execute get request")
Expand Down
9 changes: 9 additions & 0 deletions pkg/reporting/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ func GetReporter() Reporter {
return reporter
}

func GetReportingInfoByAppSlug(appSlug string) *types.ReportingInfo {
appID, err := store.GetStore().GetAppIDFromSlug(appSlug)
if err != nil {
logger.Debugf("failed to get app id from slug: %v", err.Error())
}

return GetReportingInfo(appID)
}

func GetReportingInfo(appID string) *types.ReportingInfo {
if os.Getenv("USE_MOCK_REPORTING") == "1" {
return &types.ReportingInfo{
Expand Down

0 comments on commit 60c8ce2

Please sign in to comment.