Skip to content

Commit

Permalink
Merge pull request #870 from replicatedhq/fix-support-bundle-communit…
Browse files Browse the repository at this point in the history
…y-license-type

fix license type in support bundle
  • Loading branch information
sgalsaleh committed Jul 28, 2020
2 parents fabbbbb + f1a902b commit 83f6b65
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 85 deletions.
98 changes: 42 additions & 56 deletions kotsadm/pkg/handlers/troubleshoot.go
Expand Up @@ -40,18 +40,17 @@ import (
)

type GetSupportBundleResponse struct {
ID string `json:"id"`
Slug string `json:"slug"`
AppID string `json:"appId"`
Name string `json:"name"`
Size float64 `json:"size"`
Status string `json:"status"`
TreeIndex string `json:"treeIndex"`
CreatedAt time.Time `json:"createdAt"`
UploadedAt *time.Time `json:"uploadedAt"`
IsArchived bool `json:"isArchived"`
LicenseType string `json:"licenseType,omitempty"`
Analysis *types.SupportBundleAnalysis `json:"analysis"`
ID string `json:"id"`
Slug string `json:"slug"`
AppID string `json:"appId"`
Name string `json:"name"`
Size float64 `json:"size"`
Status string `json:"status"`
TreeIndex string `json:"treeIndex"`
CreatedAt time.Time `json:"createdAt"`
UploadedAt *time.Time `json:"uploadedAt"`
IsArchived bool `json:"isArchived"`
Analysis *types.SupportBundleAnalysis `json:"analysis"`
}

type GetSupportBundleFilesResponse struct {
Expand All @@ -65,17 +64,16 @@ type ListSupportBundlesResponse struct {
SupportBundles []ResponseSupportBundle `json:"supportBundles"`
}
type ResponseSupportBundle struct {
ID string `json:"id"`
Slug string `json:"slug"`
AppID string `json:"appId"`
Name string `json:"name"`
Size float64 `json:"size"`
Status string `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UploadedAt *time.Time `json:"uploadedAt"`
IsArchived bool `json:"isArchived"`
LicenseType string `json:"licenseType,omitempty"`
Analysis *types.SupportBundleAnalysis `json:"analysis"`
ID string `json:"id"`
Slug string `json:"slug"`
AppID string `json:"appId"`
Name string `json:"name"`
Size float64 `json:"size"`
Status string `json:"status"`
CreatedAt time.Time `json:"createdAt"`
UploadedAt *time.Time `json:"uploadedAt"`
IsArchived bool `json:"isArchived"`
Analysis *types.SupportBundleAnalysis `json:"analysis"`
}

type GetSupportBundleRedactionsResponse struct {
Expand Down Expand Up @@ -120,29 +118,23 @@ func GetSupportBundle(w http.ResponseWriter, r *http.Request) {
return
}

licenseType, err := supportbundle.GetLicenseType(bundle.ID)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get license type for bundle %s", bundle.Slug))
}

analysis, err := supportbundle.GetBundleAnalysis(bundle.ID)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get analysis for bundle %s", bundle.Slug))
}

getSupportBundleResponse := GetSupportBundleResponse{
ID: bundle.ID,
Slug: bundle.Slug,
AppID: bundle.AppID,
Name: bundle.Name,
Size: bundle.Size,
Status: bundle.Status,
TreeIndex: bundle.TreeIndex,
CreatedAt: bundle.CreatedAt,
UploadedAt: bundle.UploadedAt,
IsArchived: bundle.IsArchived,
LicenseType: licenseType,
Analysis: analysis,
ID: bundle.ID,
Slug: bundle.Slug,
AppID: bundle.AppID,
Name: bundle.Name,
Size: bundle.Size,
Status: bundle.Status,
TreeIndex: bundle.TreeIndex,
CreatedAt: bundle.CreatedAt,
UploadedAt: bundle.UploadedAt,
IsArchived: bundle.IsArchived,
Analysis: analysis,
}

JSON(w, 200, getSupportBundleResponse)
Expand Down Expand Up @@ -233,28 +225,22 @@ func ListSupportBundles(w http.ResponseWriter, r *http.Request) {

responseSupportBundles := []ResponseSupportBundle{}
for _, bundle := range supportBundles {
licenseType, err := supportbundle.GetLicenseType(bundle.ID)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get license type for bundle %s", bundle.Slug))
}

analysis, err := supportbundle.GetBundleAnalysis(bundle.ID)
if err != nil {
logger.Error(errors.Wrapf(err, "failed to get analysis for bundle %s", bundle.Slug))
}

responseSupportBundle := ResponseSupportBundle{
ID: bundle.ID,
Slug: bundle.Slug,
AppID: bundle.AppID,
Name: bundle.Name,
Size: bundle.Size,
Status: bundle.Status,
CreatedAt: bundle.CreatedAt,
UploadedAt: bundle.UploadedAt,
IsArchived: bundle.IsArchived,
LicenseType: licenseType,
Analysis: analysis,
ID: bundle.ID,
Slug: bundle.Slug,
AppID: bundle.AppID,
Name: bundle.Name,
Size: bundle.Size,
Status: bundle.Status,
CreatedAt: bundle.CreatedAt,
UploadedAt: bundle.UploadedAt,
IsArchived: bundle.IsArchived,
Analysis: analysis,
}

responseSupportBundles = append(responseSupportBundles, responseSupportBundle)
Expand Down
28 changes: 0 additions & 28 deletions kotsadm/pkg/supportbundle/supportbundle.go
Expand Up @@ -14,9 +14,7 @@ import (
"github.com/pkg/errors"
"github.com/replicatedhq/kots/kotsadm/pkg/persistence"
"github.com/replicatedhq/kots/kotsadm/pkg/supportbundle/types"
kotsv1beta1 "github.com/replicatedhq/kots/kotskinds/apis/kots/v1beta1"
"github.com/segmentio/ksuid"
"k8s.io/client-go/kubernetes/scheme"
)

func List(appID string) ([]*types.SupportBundle, error) {
Expand Down Expand Up @@ -189,29 +187,3 @@ func GetFilesContents(bundleID string, filenames []string) (map[string][]byte, e

return files, nil
}

func GetLicenseType(id string) (string, error) {
db := persistence.MustGetPGSession()
query := `SELECT app_version.kots_license FROM supportbundle LEFT JOIN app_version ON supportbundle.watch_id = app_version.app_id where supportbundle.id = $1`
row := db.QueryRow(query, id)

var licenseStr sql.NullString
if err := row.Scan(&licenseStr); err != nil {
if err == sql.ErrNoRows {
return "", nil
}
return "", errors.Wrap(err, "failed to scan")
}

if licenseStr.Valid {
decode := scheme.Codecs.UniversalDeserializer().Decode
obj, _, err := decode([]byte(licenseStr.String), nil, nil)
if err != nil {
return "", errors.Wrap(err, "failed to decode license yaml")
}
license := obj.(*kotsv1beta1.License)
return license.Spec.LicenseType, nil
}

return "", nil
}
Expand Up @@ -131,7 +131,7 @@ export class SupportBundleAnalysis extends React.Component {
</div>
</div>
</div>
{bundle.licenseType === "community" &&
{watch.licenseType === "community" &&
<div className="flex">
<div className="CommunityLicenseBundle--wrapper flex flex1 alignItems--center">
<div className="flex flex-auto">
Expand Down
1 change: 1 addition & 0 deletions kotsadm/web/src/queries/AppsQueries.js
Expand Up @@ -125,6 +125,7 @@ export const getKotsAppRaw = `
isGitOpsSupported
allowRollback
allowSnapshots
licenseType
updateCheckerSpec
currentVersion {
title
Expand Down

0 comments on commit 83f6b65

Please sign in to comment.