Skip to content

Commit

Permalink
Merge branch 'master' into errorHandlingForRegistry
Browse files Browse the repository at this point in the history
Signed-off-by: Shlok Mishra <99207534+Jougan-0@users.noreply.github.com>
  • Loading branch information
Jougan-0 authored Jun 17, 2024
2 parents 13c80bb + b08551c commit 43f8927
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 40 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
9 changes: 5 additions & 4 deletions generators/github/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package github
import (
"bufio"
"fmt"
"github.com/layer5io/meshkit/generators/models"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/helm"
"github.com/layer5io/meshkit/utils/walker"
"net/url"
"os"
"path/filepath"
"strings"

"github.com/layer5io/meshkit/generators/models"
"github.com/layer5io/meshkit/utils"
"github.com/layer5io/meshkit/utils/helm"
"github.com/layer5io/meshkit/utils/walker"
)

type GitRepo struct {
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ require (
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.16.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,8 @@ golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
Expand Down Expand Up @@ -974,8 +974,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down Expand Up @@ -1038,16 +1038,16 @@ golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
Expand Down
2 changes: 1 addition & 1 deletion helpers/component_info.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "meshkit",
"type": "library",
"next_error_code": 11243
"next_error_code": 11245
}
102 changes: 102 additions & 0 deletions models/catalog/v1alpha1/catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package v1alpha1

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

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

// CatalogData defines model for catalog_data.
type CatalogData struct {
ContentClass ContentClass `json:"content_class,omitempty"`
//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 == "" &&
cd.ContentClass.String() != "")
}

type ContentClass string

const (
Official ContentClass = "official"
Verified ContentClass = "verified"
Project ContentClass = "project"
Community ContentClass = "community"
)

func (c ContentClass) String() string {
switch c {
case Official:
return "official"
case Verified:
return "verified"
case Project:
return "Project"
case Community:
fallthrough
default:
return "community"
}
}

func GetCatalogClasses() []ContentClass {
return []ContentClass{
Official,
Verified,
Project,
Community,
}
}
2 changes: 1 addition & 1 deletion models/meshmodel/entity/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

const (
ErrUpdateEntityStatusCode = ""
ErrUpdateEntityStatusCode = "meshkit-11243"
)

func ErrUpdateEntityStatus(err error, entity string, status EntityStatus) error {
Expand Down
16 changes: 9 additions & 7 deletions models/meshmodel/registry/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
)

var (
ErrUnknownHostCode = "meshkit-11146"
ErrEmptySchemaCode = "meshkit-11098"
ErrMarshalingRegisteryAttemptsCode = "meshkit-11099"
ErrWritingRegisteryAttemptsCode = "meshkit-11100"
ErrRegisteringEntityCode = "meshkit-11101"
ErrUnknownHostInMapCode = "meshkit-11102"
ErrCreatingUserDataDirectoryCode = "meshkit-11103"

ErrUnknownHostCode = "replace_me"
ErrEmptySchemaCode = "replace_me"
ErrMarshalingRegisteryAttemptsCode = "replace_me"
ErrWritingRegisteryAttemptsCode = "replace_me"
ErrRegisteringEntityCode = "replace_me"
ErrUnknownHostInMapCode = "replace_me"
ErrCreatingUserDataDirectoryCode = "replace_me"

)

func ErrUnknownHost(err error) error {
Expand Down
42 changes: 42 additions & 0 deletions utils/archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package utils

import (
"archive/tar"
"bytes"
)

type TarWriter struct {
Writer *tar.Writer
Buffer *bytes.Buffer
}

func NewTarWriter() *TarWriter {
buffer := bytes.Buffer{}
return &TarWriter{
Writer: tar.NewWriter(&buffer),
Buffer: &buffer,
}
}

func (tw *TarWriter) Compress(name string, data []byte) error {
header := tar.Header{
Name: name,
Size: int64(len(data)),
Mode: 777,
}
err := tw.Writer.WriteHeader(&header)
if err != nil {
return ErrCompressToTarGZ(err, "")
}

_, err = tw.Writer.Write(data)
if err != nil {
return ErrCompressToTarGZ(err, "")
}
return nil
}

func (tw *TarWriter) Close() {
_ = tw.Writer.Flush()
_ = tw.Writer.Close()
}
69 changes: 69 additions & 0 deletions utils/catalog/artifacthub_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package catalog

type ContainersImage struct {
Name string `yaml:"name,omitempty"`
Image string `yaml:"image,omitempty"`
Whitelisted string `yaml:"whitelisted,omitempty"`
}

type Link struct {
Name string `yaml:"name,omitempty"`
URL string `yaml:"url,omitempty"`
}

type Change struct {
Kind string `yaml:"kind,omitempty"`
Description string `yaml:"description,omitempty"`
Links []Link `yaml:"links,omitempty"`
}

type Maintainer struct {
Name string `yaml:"name,omitempty"`
Email string `yaml:"email,omitempty"`
}

type Provider struct {
Name string `yaml:"name,omitempty"`
}

type Recommendation struct {
URL string `yaml:"url,omitempty"`
}

type Screenshot struct {
Title string `yaml:"title,omitempty"`
URL string `yaml:"url,omitempty"`
}

type ArtifactHubMetadata struct {
Version string `yaml:"version,omitempty"`
Name string `yaml:"name,omitempty"`
DisplayName string `yaml:"displayName,omitempty"`
CreatedAt string `yaml:"createdAt,omitempty"`
Description string `yaml:"description,omitempty"`
LogoPath string `yaml:"logoPath,omitempty"`
LogoURL string `yaml:"logoURL,omitempty"`
Digest string `yaml:"digest,omitempty"`
License string `yaml:"license,omitempty"`
HomeURL string `yaml:"homeURL,omitempty"`
AppVersion string `yaml:"appVersion,omitempty"`
ContainersImages []ContainersImage `yaml:"containersImages,omitempty"`
ContainsSecurityUpdates string `yaml:"containsSecurityUpdates,omitempty"`
Operator string `yaml:"operator,omitempty"`
Deprecated string `yaml:"deprecated,omitempty"`
Prerelease string `yaml:"prerelease,omitempty"`
Keywords []string `yaml:"keywords,omitempty"`
Links []Link `yaml:"links,omitempty"`
Readme string `yaml:"readme,omitempty"`
Install string `yaml:"install,omitempty"`
Changes []Change `yaml:"changes,omitempty"`
Maintainers []Maintainer `yaml:"maintainers,omitempty"`
Provider Provider `yaml:"provider,omitempty"`
Ignore []string `yaml:"ignore,omitempty"`
Recommendations []Recommendation `yaml:"recommendations,omitempty"`
Screenshots []Screenshot `yaml:"screenshots,omitempty"`
Annotations struct {
Key1 string `yaml:"key1,omitempty"`
Key2 string `yaml:"key2,omitempty"`
} `yaml:"annotations,omitempty"`
}
Loading

0 comments on commit 43f8927

Please sign in to comment.