Skip to content

Commit

Permalink
Merge branch 'master' into MUzairS15/artifacthub-pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohd Uzair authored Jun 12, 2024
2 parents 76348fe + 93397db commit 66d0e5c
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 8 deletions.
4 changes: 2 additions & 2 deletions generators/artifacthub/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"gopkg.in/yaml.v2"
)

const ArtifactHubAPIEndpint = "https://artifacthub.io/api/v1"
const ArtifactHubAPIEndpoint = "https://artifacthub.io/api/v1"
const ArtifactHubChartUrlFieldName = "content_url"
const AhHelmExporterEndpoint = ArtifactHubAPIEndpint + "/helm-exporter"
const AhHelmExporterEndpoint = ArtifactHubAPIEndpoint + "/helm-exporter"

// internal representation of artifacthub package
// it contains information we need to identify a package using ArtifactHub API
Expand Down
25 changes: 19 additions & 6 deletions generators/artifacthub/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"

"github.com/layer5io/meshkit/utils/manifests"
)
Expand All @@ -20,18 +21,30 @@ const AhTextSearchQueryFieldName = "ts_query_web"

func GetAhPackagesWithName(name string) ([]AhPackage, error) {
pkgs := make([]AhPackage, 0)
url := fmt.Sprintf("%s/packages/search?%s=%s&", ArtifactHubAPIEndpint, AhTextSearchQueryFieldName, name)
// add params

// Construct URL with encoded query parameters
baseURL, err := url.Parse(fmt.Sprintf("%s/packages/search", ArtifactHubAPIEndpoint))
if err != nil {
return nil, ErrGetAhPackage(err)
}

query := url.Values{}
query.Add(AhTextSearchQueryFieldName, name)

for key, val := range AhApiSearchParams {
url = fmt.Sprintf("%s%s=%s&", url, key, val)
query.Add(key, val)
}
// get packages
resp, err := http.Get(url)

baseURL.RawQuery = query.Encode()
finalURL := baseURL.String()

// Get packages
resp, err := http.Get(finalURL)
if err != nil {
return nil, ErrGetAhPackage(err)
}
if resp.StatusCode != 200 {
err = fmt.Errorf("status code %d for %s", resp.StatusCode, url)
err = fmt.Errorf("status code %d for %s", resp.StatusCode, finalURL)
return nil, ErrGetAhPackage(err)
}
defer resp.Body.Close()
Expand Down
67 changes: 67 additions & 0 deletions models/catalog/v1beta1/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package v1beta1

import (
"database/sql/driver"
"encoding/json"

"github.com/layer5io/meshkit/utils"
)

// CatalogData defines model for catalog_data.
type CatalogData struct {
//Tracks the specific content version that has been made available in the Catalog
PublishedVersion string `json:"published_version"`

// Compatibility A list of technologies included in or implicated by this design; a list of relevant technology tags.
Compatibility []CatalogDataCompatibility `json:"compatibility"`

// PatternCaveats Specific stipulations to consider and known behaviors to be aware of when using this design.
PatternCaveats string `json:"pattern_caveats"`

// PatternInfo Purpose of the design along with its intended and unintended uses.
PatternInfo string `json:"pattern_info"`

// Contains reference to the dark and light mode snapshots of the catalog.
SnapshotURL []string `json:"imageURL,omitempty"` // this will require updating exisitng catalog data as well. updated the json tag to match previous key name, so changes will not be required in exisitng catgalogs

// Type Categorization of the type of design or operational flow depicted in this design.
Type CatalogDataType `json:"type"`
}

func (cd *CatalogData) Scan(value interface{}) error {
if value == nil {
cd = &CatalogData{}
return nil
}
data, err := utils.Cast[[]byte](value)
if err != nil {
return err
}

err = json.Unmarshal([]byte(data), cd)
if err != nil {
return utils.ErrUnmarshal(err)
}
return nil
}

func (cd CatalogData) Value() (driver.Value, error) {
marshaledValue, err := json.Marshal(cd)
if err != nil {
return nil, utils.ErrMarshal(err)
}
return marshaledValue, nil
}

// CatalogDataCompatibility defines model for CatalogData.Compatibility.
type CatalogDataCompatibility string

// CatalogDataType Categorization of the type of design or operational flow depicted in this design.
type CatalogDataType string

func (cd *CatalogData) IsNil() bool {
return cd == nil || (len(cd.Compatibility) == 0 &&
cd.PatternCaveats == "" &&
cd.PatternInfo == "" &&
cd.Type == "")
}

0 comments on commit 66d0e5c

Please sign in to comment.