Skip to content

Commit

Permalink
Update Hub ClI to use /v1 api's as preview api will be removed
Browse files Browse the repository at this point in the history
Signed-off-by: Puneet Punamiya <ppunamiy@redhat.com>
  • Loading branch information
PuneetPunamiya committed Jan 28, 2022
1 parent ec969c3 commit be6dbc1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions api/pkg/cli/hub/get_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ func (c *client) GetResource(opt ResourceOption) ResourceResult {
func (opt ResourceOption) Endpoint() string {
if opt.Version != "" {
// API: /resource/<catalog>/<kind>/<name>/<version>
return fmt.Sprintf("/resource/%s/%s/%s/%s", opt.Catalog, opt.Kind, opt.Name, opt.Version)
return fmt.Sprintf("/v1/resource/%s/%s/%s/%s", opt.Catalog, opt.Kind, opt.Name, opt.Version)
}
if opt.PipelineVersion != "" {
opt.PipelineVersion = strings.TrimLeft(opt.PipelineVersion, "v")
// API: /resource/<catalog>/<kind>/<name>?pipelinesversion=<version>
return fmt.Sprintf("/resource/%s/%s/%s?pipelinesversion=%s", opt.Catalog, opt.Kind, opt.Name, opt.PipelineVersion)
return fmt.Sprintf("/v1/resource/%s/%s/%s?pipelinesversion=%s", opt.Catalog, opt.Kind, opt.Name, opt.PipelineVersion)
}
// API: /resource/<catalog>/<kind>/<name>
return fmt.Sprintf("/resource/%s/%s/%s", opt.Catalog, opt.Kind, opt.Name)
return fmt.Sprintf("/v1/resource/%s/%s/%s", opt.Catalog, opt.Kind, opt.Name)
}

func (rr *ResourceResult) unmarshalData() error {
Expand Down
6 changes: 3 additions & 3 deletions api/pkg/cli/hub/get_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ func TestGetResourceEndpoint(t *testing.T) {
Kind: "task",
}
url := opt.Endpoint()
assert.Equal(t, "/resource/tekton/task/abc", url)
assert.Equal(t, "/v1/resource/tekton/task/abc", url)

opt.PipelineVersion = "0.17"
url = opt.Endpoint()
assert.Equal(t, "/resource/tekton/task/abc?pipelinesversion=0.17", url)
assert.Equal(t, "/v1/resource/tekton/task/abc?pipelinesversion=0.17", url)

opt.Version = "0.1.1"
url = opt.Endpoint()
assert.Equal(t, "/resource/tekton/task/abc/0.1.1", url)
assert.Equal(t, "/v1/resource/tekton/task/abc/0.1.1", url)
}
2 changes: 1 addition & 1 deletion api/pkg/cli/hub/get_resource_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *client) GetResourceVersions(opt ResourceOption) ResourceVersionResult {

// Endpoint computes the endpoint url using input provided
func resVersionsEndpoint(rID uint) string {
return fmt.Sprintf("/resource/%s/versions", strconv.FormatUint(uint64(rID), 10))
return fmt.Sprintf("/v1/resource/%s/versions", strconv.FormatUint(uint64(rID), 10))
}

func (rvr *ResourceVersionResult) unmarshalData() error {
Expand Down
2 changes: 1 addition & 1 deletion api/pkg/cli/hub/get_resource_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ import (

func TestGetResourceVersionEndpoint(t *testing.T) {
url := resVersionsEndpoint(43)
assert.Equal(t, "/resource/43/versions", url)
assert.Equal(t, "/v1/resource/43/versions", url)
}
2 changes: 1 addition & 1 deletion api/pkg/cli/hub/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (so SearchOption) Endpoint() string {

v.Set("match", so.Match)

return "/query?" + v.Encode()
return "/v1/query?" + v.Encode()
}

func addArraytoURL(param string, arr []string, v url.Values) {
Expand Down
4 changes: 2 additions & 2 deletions api/pkg/cli/hub/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestEndpoint(t *testing.T) {
}

url := opt.Endpoint()
assert.Equal(t, "/query?limit=100&match=contains", url)
assert.Equal(t, "/v1/query?limit=100&match=contains", url)

opt = SearchOption{
Name: "res",
Expand All @@ -37,5 +37,5 @@ func TestEndpoint(t *testing.T) {
Match: "contains",
}
url = opt.Endpoint()
assert.Equal(t, "/query?kinds=k1&kinds=k2&kinds=k3&match=contains&name=res&tags=t1&tags=t2", url)
assert.Equal(t, "/v1/query?kinds=k1&kinds=k2&kinds=k3&match=contains&name=res&tags=t1&tags=t2", url)
}

0 comments on commit be6dbc1

Please sign in to comment.