From daee7d5cc15688bcc23afc26eb796e4cef0c96df Mon Sep 17 00:00:00 2001 From: Scott Rigby Date: Sat, 22 Aug 2020 16:17:23 -0400 Subject: [PATCH] Add struct for Artifact Hub data, and return correct URL for both artifact hub instances and backwards compatibility for Monocular search API Signed-off-by: Scott Rigby --- cmd/helm/search_hub.go | 7 +++++++ internal/monocular/search.go | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/cmd/helm/search_hub.go b/cmd/helm/search_hub.go index 8a2bd95fd..6310f735e 100644 --- a/cmd/helm/search_hub.go +++ b/cmd/helm/search_hub.go @@ -106,7 +106,14 @@ type hubSearchWriter struct { func newHubSearchWriter(results []monocular.SearchResult, endpoint string, columnWidth uint) *hubSearchWriter { var elements []hubChartElement for _, r := range results { + // Backwards compatibility for Monocular url := endpoint + "/charts/" + r.ID + + // Check for artifactHub compatibility + if r.ArtifactHub.PackageURL != "" { + url = r.ArtifactHub.PackageURL + } + elements = append(elements, hubChartElement{url, r.Relationships.LatestChartVersion.Data.Version, r.Relationships.LatestChartVersion.Data.AppVersion, r.Attributes.Description}) } return &hubSearchWriter{elements, columnWidth} diff --git a/internal/monocular/search.go b/internal/monocular/search.go index 10e1f2136..3082ff361 100644 --- a/internal/monocular/search.go +++ b/internal/monocular/search.go @@ -40,12 +40,18 @@ const SearchPath = "api/chartsvc/v1/charts/search" // SearchResult represents an individual chart result type SearchResult struct { ID string `json:"id"` + ArtifactHub ArtifactHub `json:"artifactHub"` Type string `json:"type"` Attributes Chart `json:"attributes"` Links Links `json:"links"` Relationships Relationships `json:"relationships"` } +// ArtifactHub represents data specific to Artifact Hub instances +type ArtifactHub struct { + PackageURL string `json:"packageUrl"` +} + // Chart is the attributes for the chart type Chart struct { Name string `json:"name"`