Skip to content

Commit

Permalink
fixed registry connection issue with proxy repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
rinao12 committed Jul 24, 2024
1 parent ad94185 commit 823f036
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 10 additions & 8 deletions registries/harbor/harbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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" {
Expand Down
10 changes: 4 additions & 6 deletions registries/harbor/harbor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 823f036

Please sign in to comment.