Skip to content

Commit

Permalink
[NVSHAS-9507] Fix JFrog fetch tag issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
pohanhuangtw committed Nov 20, 2024
1 parent 9a5c189 commit 7e6ba57
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
24 changes: 23 additions & 1 deletion controller/scan/jfrog.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ func getSubdomainFromRepo(repo string) (string, string) {
return "", ""
}

// Only be called by in jfrog, since the api is not working for it, create it as a callback function.
func (r *jfrog) GetArtifactoryTags(repositoryStr string, rc *scanUtils.RegClient) ([]string, error) {
tags := make([]string, 0)
var err error
parts := strings.Split(repositoryStr, "/")
if len(parts) != 2 {
log.WithFields(log.Fields{"repository": repositoryStr}).Error("Invalid input format")
return tags, err
}

key := parts[0]
repository := parts[1]

url := r.url("/artifactory/api/docker/%s/v2/%s/tags/list", key, repository)
return rc.FetchTagsPaginated(url, repositoryStr)
}

func (r *jfrog) GetTagList(domain, repo, tag string) ([]string, error) {
smd.scanLog.Debug()

Expand All @@ -232,7 +249,12 @@ func (r *jfrog) GetTagList(domain, repo, tag string) ([]string, error) {
}
repo = subRepo
}
return rc.Tags(repo)

if tags, err := rc.Tags(repo); len(tags) > 0 {
return tags, err
}

return r.GetArtifactoryTags(repo, rc)
}

func (r *jfrog) GetAllImages() (map[share.CLUSImage][]string, error) {
Expand Down
14 changes: 9 additions & 5 deletions share/scan/registry/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ type tagsResponse struct {
Tags []string `json:"tags"`
}

func (r *Registry) Tags(repository string) ([]string, error) {
url := r.url("/v2/%s/tags/list", repository)
func (r *Registry) FetchTagsPaginated(url, repositoryStr string) ([]string, error) {
tags := make([]string, 0)

var response tagsResponse
var err error

r.Client.SetTimeout(longTimeout)
for {
log.WithFields(log.Fields{"url": url, "repository": repository}).Debug()
log.WithFields(log.Fields{"url": url, "repository": repositoryStr}).Debug()
url, err = r.getPaginatedJson(url, &response)
switch err {
case ErrNoMorePages:
Expand All @@ -27,7 +25,13 @@ func (r *Registry) Tags(repository string) ([]string, error) {
tags = append(tags, response.Tags...)
continue
default:
return tags, nil
log.WithFields(log.Fields{"error": err, "url": url}).Error("Failed to fetch tags")
return tags, err
}
}
}

func (r *Registry) Tags(repository string) ([]string, error) {
url := r.url("/v2/%s/tags/list", repository)
return r.FetchTagsPaginated(url, repository)
}

0 comments on commit 7e6ba57

Please sign in to comment.