From c50f900861d52f386f3e65d846f587c1985b829e Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Mon, 10 Jun 2024 18:58:56 +0530 Subject: [PATCH 1/3] handle query more gracefully w/signoff Signed-off-by: Jougan-0 --- generators/artifacthub/scanner.go | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/generators/artifacthub/scanner.go b/generators/artifacthub/scanner.go index e976992a..907404c3 100644 --- a/generators/artifacthub/scanner.go +++ b/generators/artifacthub/scanner.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "net/url" "github.com/layer5io/meshkit/utils/manifests" ) @@ -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", ArtifactHubAPIEndpint)) + 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() From ef3078b9793ed7cb75a31fdb1530fd7f84cb32cd Mon Sep 17 00:00:00 2001 From: Shlok Mishra <99207534+Jougan-0@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:32:19 +0530 Subject: [PATCH 2/3] Update generators/artifacthub/scanner.go Co-authored-by: Mohd Uzair Signed-off-by: Shlok Mishra <99207534+Jougan-0@users.noreply.github.com> --- generators/artifacthub/scanner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/artifacthub/scanner.go b/generators/artifacthub/scanner.go index 907404c3..12adc18f 100644 --- a/generators/artifacthub/scanner.go +++ b/generators/artifacthub/scanner.go @@ -23,7 +23,7 @@ func GetAhPackagesWithName(name string) ([]AhPackage, error) { pkgs := make([]AhPackage, 0) // Construct URL with encoded query parameters - baseURL, err := url.Parse(fmt.Sprintf("%s/packages/search", ArtifactHubAPIEndpint)) + baseURL, err := url.Parse(fmt.Sprintf("%s/packages/search", ArtifactHubAPIEndpoint)) if err != nil { return nil, ErrGetAhPackage(err) } From 5594a61fc6420373157a94d502d772f8f3f5f8d1 Mon Sep 17 00:00:00 2001 From: Jougan-0 Date: Tue, 11 Jun 2024 18:39:02 +0530 Subject: [PATCH 3/3] fix typo w/signoff Signed-off-by: Jougan-0 --- generators/artifacthub/package.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/artifacthub/package.go b/generators/artifacthub/package.go index e9dee8bf..848b0374 100644 --- a/generators/artifacthub/package.go +++ b/generators/artifacthub/package.go @@ -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