Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor metadb sorting pagination #1637

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/cli/search_cmd_referrers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import (
)

func ref[T any](input T) *T {
obj := input
ref := input

return &obj
return &ref
}

const (
Expand All @@ -46,7 +46,7 @@ func TestReferrersSearchers(t *testing.T) {
So(ok, ShouldBeFalse)
})

Convey("GetRepoRefference fails", func() {
Convey("GetRepoReference fails", func() {
conf := searchConfig{
params: map[string]*string{
"subject": ref("bad-subject"),
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestReferrersSearchers(t *testing.T) {
So(ok, ShouldBeFalse)
})

Convey("GetRepoRefference fails", func() {
Convey("GetRepoReference fails", func() {
conf := searchConfig{
params: map[string]*string{
"subject": ref("bad-subject"),
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/searcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ func (search referrerSearcherGQL) search(config searchConfig) (bool, error) {

username, password := getUsernameAndPassword(*config.user)

repo, ref, refIsTag, err := zcommon.GetRepoRefference(*config.params["subject"])
repo, ref, refIsTag, err := zcommon.GetRepoReference(*config.params["subject"])
if err != nil {
return true, err
}
Expand Down Expand Up @@ -692,7 +692,7 @@ func (search referrerSearcher) search(config searchConfig) (bool, error) {

username, password := getUsernameAndPassword(*config.user)

repo, ref, refIsTag, err := zcommon.GetRepoRefference(*config.params["subject"])
repo, ref, refIsTag, err := zcommon.GetRepoReference(*config.params["subject"])
if err != nil {
return true, err
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/fs"
"os"
"strings"
"syscall"
"time"
"unicode/utf8"
Expand Down Expand Up @@ -101,3 +102,13 @@ func MarshalThroughStruct(obj interface{}, throughStruct interface{}) ([]byte, e

return toJSON, nil
}

func ContainsStringIgnoreCase(strSlice []string, str string) bool {
for _, val := range strSlice {
if strings.EqualFold(val, str) {
return true
}
}

return false
}
4 changes: 2 additions & 2 deletions pkg/common/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

var imageTag string

if strings.Contains(imageName, ":") {

Check failure on line 18 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "strings.Contains(imageName, \":\")" was never evaluated
imageDir, imageTag, _ = strings.Cut(imageName, ":")
} else {
imageDir = imageName
Expand All @@ -29,7 +29,7 @@

var imageDigest string

if strings.Contains(imageName, "@") {

Check failure on line 32 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "strings.Contains(imageName, \"@\")" was once false but never true
imageDir, imageDigest, _ = strings.Cut(imageName, "@")
} else {
imageDir = imageName
Expand All @@ -40,7 +40,7 @@

// GetImageDirAndReference returns the repo, digest and isTag.
func GetImageDirAndReference(imageName string) (string, string, bool) {
if strings.Contains(imageName, "@") {

Check failure on line 43 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "strings.Contains(imageName, \"@\")" was never evaluated
repo, digest := GetImageDirAndDigest(imageName)

return repo, digest, false
Expand All @@ -52,7 +52,7 @@
}

func GetManifestArtifactType(manifestContent ispec.Manifest) string {
if manifestContent.ArtifactType != "" {

Check failure on line 55 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "manifestContent.ArtifactType != \"\"" was never evaluated
return manifestContent.ArtifactType
}

Expand All @@ -69,22 +69,22 @@
func GetImageLastUpdated(imageInfo ispec.Image) time.Time {
timeStamp := imageInfo.Created

if timeStamp != nil && !timeStamp.IsZero() {

Check failure on line 72 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "timeStamp != nil" was never evaluated

Check failure on line 72 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "timeStamp.IsZero()" was never evaluated
return *timeStamp
}

if len(imageInfo.History) > 0 {

Check failure on line 76 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "len(imageInfo.History) > 0" was never evaluated
timeStamp = imageInfo.History[len(imageInfo.History)-1].Created
}

if timeStamp == nil {

Check failure on line 80 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "timeStamp == nil" was never evaluated
timeStamp = &time.Time{}
}

return *timeStamp
}

// GetRepoRefference returns the components of a repoName:tag or repoName@digest string. If the format is wrong
// GetRepoReference returns the components of a repoName:tag or repoName@digest string. If the format is wrong
// an error is returned.
// The returned values have the following meaning:
//
Expand All @@ -95,13 +95,13 @@
// - bool: value for the statement: "the reference is a tag"
//
// - error: error value.
func GetRepoRefference(repo string) (string, string, bool, error) {
func GetRepoReference(repo string) (string, string, bool, error) {
repoName, digest, found := strings.Cut(repo, "@")

if !found {

Check failure on line 101 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "found" was never evaluated
repoName, tag, found := strings.Cut(repo, ":")

if !found {

Check failure on line 104 in pkg/common/oci.go

View workflow job for this annotation

GitHub Actions / coverage (linux, amd64)

condition "found" was never evaluated
return "", "", false, zerr.ErrInvalidRepoRefFormat
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/extensions/extension_mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func EnablePeriodicSignaturesVerification(config *config.Config, taskScheduler *

repos, err := metaDB.GetMultipleRepoMeta(ctx, func(repoMeta mTypes.RepoMetadata) bool {
return true
}, mTypes.PageInput{})
})
if err != nil {
return
}
Expand Down Expand Up @@ -297,9 +297,7 @@ func (gen *taskGeneratorSigValidity) Reset() {
gen.repoIndex = -1
ctx := context.Background()

repos, err := gen.metaDB.GetMultipleRepoMeta(ctx, func(repoMeta mTypes.RepoMetadata) bool {
return true
}, mTypes.PageInput{})
repos, err := gen.metaDB.GetMultipleRepoMeta(ctx, func(repoMeta mTypes.RepoMetadata) bool { return true })
if err != nil {
return
}
Expand Down
Loading
Loading