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 <scott@r6by.com>
pull/8626/head
Scott Rigby 5 years ago
parent 87e4622ee2
commit daee7d5cc1
No known key found for this signature in database
GPG Key ID: C7C6FBB5B91C1155

@ -106,7 +106,14 @@ type hubSearchWriter struct {
func newHubSearchWriter(results []monocular.SearchResult, endpoint string, columnWidth uint) *hubSearchWriter { func newHubSearchWriter(results []monocular.SearchResult, endpoint string, columnWidth uint) *hubSearchWriter {
var elements []hubChartElement var elements []hubChartElement
for _, r := range results { for _, r := range results {
// Backwards compatibility for Monocular
url := endpoint + "/charts/" + r.ID 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}) elements = append(elements, hubChartElement{url, r.Relationships.LatestChartVersion.Data.Version, r.Relationships.LatestChartVersion.Data.AppVersion, r.Attributes.Description})
} }
return &hubSearchWriter{elements, columnWidth} return &hubSearchWriter{elements, columnWidth}

@ -40,12 +40,18 @@ const SearchPath = "api/chartsvc/v1/charts/search"
// SearchResult represents an individual chart result // SearchResult represents an individual chart result
type SearchResult struct { type SearchResult struct {
ID string `json:"id"` ID string `json:"id"`
ArtifactHub ArtifactHub `json:"artifactHub"`
Type string `json:"type"` Type string `json:"type"`
Attributes Chart `json:"attributes"` Attributes Chart `json:"attributes"`
Links Links `json:"links"` Links Links `json:"links"`
Relationships Relationships `json:"relationships"` 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 // Chart is the attributes for the chart
type Chart struct { type Chart struct {
Name string `json:"name"` Name string `json:"name"`

Loading…
Cancel
Save