From 823f0362e93852126c0152ed7afc1d0bd186ed1f Mon Sep 17 00:00:00 2001 From: rinao12 <121787861+rinao12@users.noreply.github.com> Date: Wed, 24 Jul 2024 12:24:49 +0300 Subject: [PATCH] fixed registry connection issue with proxy repositories --- registries/harbor/harbor.go | 18 ++++++++++-------- registries/harbor/harbor_test.go | 10 ++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/registries/harbor/harbor.go b/registries/harbor/harbor.go index 058ea1d..572c175 100644 --- a/registries/harbor/harbor.go +++ b/registries/harbor/harbor.go @@ -34,6 +34,11 @@ type HarborRegistry struct { defaultregistry.DefaultRegistry } +type RepositoryInfo struct { + registryName string + repositoryName string +} + func (*HarborRegistry) GetMaxPageSize() int { //Harbor limits page size to 100 elements return 100 @@ -81,12 +86,9 @@ func (h *HarborRegistry) Catalog(ctx context.Context, pagination common.Paginati } func (h *HarborRegistry) List(repoName string, pagination common.PaginationOption, options ...remote.Option) ([]string, *common.PaginationOption, error) { - repo, err := common.MakeRepoWithRegistry(repoName, h.Registry) - if err != nil { - return nil, nil, err - } + repo := RepositoryInfo{registryName: h.Registry.RegistryStr(), repositoryName: repoName} //create list tag request - req, err := h.listTagsRequest(*repo, strconv.Itoa(pagination.Size), pagination.Cursor) + req, err := h.listTagsRequest(repo, strconv.Itoa(pagination.Size), pagination.Cursor) if err != nil { return nil, nil, err } @@ -217,11 +219,11 @@ func (h *HarborRegistry) repositoriesRequest(pageSize string, pageNum string) (* return req, nil } -func (h *HarborRegistry) listTagsRequest(repo name.Repository, size string, cursor string) (*http.Request, error) { +func (h *HarborRegistry) listTagsRequest(repo RepositoryInfo, size string, cursor string) (*http.Request, error) { uri := &url.URL{ Scheme: h.requestScheme(), - Host: repo.Registry.RegistryStr(), - Path: fmt.Sprintf("/v2/%s/tags/list", repo.RepositoryStr()), + Host: repo.registryName, + Path: fmt.Sprintf("/v2/%s/tags/list", repo.repositoryName), } if size != "0" { diff --git a/registries/harbor/harbor_test.go b/registries/harbor/harbor_test.go index ac3da74..c47374f 100644 --- a/registries/harbor/harbor_test.go +++ b/registries/harbor/harbor_test.go @@ -196,9 +196,8 @@ func TestInsecureRequest(t *testing.T) { assert.Nil(t, err) assert.Equal(t, "https", req.URL.Scheme) //test list tags request scheme - repoData, err := name.NewRepository("repo") - assert.Nil(t, err) - repoData.Registry = registry + repoData := RepositoryInfo{repositoryName: "repo"} + repoData.registryName = registry.RegistryStr() req, err = harbor.listTagsRequest(repoData, "0", "") assert.Nil(t, err) assert.Equal(t, "https", req.URL.Scheme) @@ -217,9 +216,8 @@ func TestInsecureRequest(t *testing.T) { assert.Nil(t, err) assert.Equal(t, "http", req.URL.Scheme) //test list tags request scheme - repoData, err = name.NewRepository("repo") - assert.Nil(t, err) - repoData.Registry = registry + repoData = RepositoryInfo{repositoryName: "repo"} + repoData.registryName = registry.RegistryStr() req, err = harbor.listTagsRequest(repoData, "0", "") assert.Nil(t, err) assert.Equal(t, "http", req.URL.Scheme)