2022-07-12 07:58:04 -05:00
|
|
|
package mocks
|
|
|
|
|
|
|
|
import (
|
|
|
|
godigest "github.com/opencontainers/go-digest"
|
|
|
|
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
2022-10-20 11:39:20 -05:00
|
|
|
|
2024-01-31 23:34:07 -05:00
|
|
|
"zotregistry.dev/zot/pkg/common"
|
|
|
|
cvemodel "zotregistry.dev/zot/pkg/extensions/search/cve/model"
|
2022-07-12 07:58:04 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type OciLayoutUtilsMock struct {
|
2022-10-22 15:46:13 -05:00
|
|
|
GetImageManifestFn func(repo string, reference string) (ispec.Manifest, godigest.Digest, error)
|
|
|
|
GetImageManifestsFn func(repo string) ([]ispec.Descriptor, error)
|
|
|
|
GetImageBlobManifestFn func(repo string, digest godigest.Digest) (ispec.Manifest, error)
|
|
|
|
GetImageInfoFn func(repo string, digest godigest.Digest) (ispec.Image, error)
|
2023-04-18 13:07:47 -05:00
|
|
|
GetImageTagsWithTimestampFn func(repo string) ([]cvemodel.TagInfo, error)
|
2022-07-19 08:16:15 -05:00
|
|
|
GetImagePlatformFn func(imageInfo ispec.Image) (string, string)
|
2022-07-12 07:58:04 -05:00
|
|
|
GetImageManifestSizeFn func(repo string, manifestDigest godigest.Digest) int64
|
|
|
|
GetImageConfigSizeFn func(repo string, manifestDigest godigest.Digest) int64
|
2023-04-18 13:07:47 -05:00
|
|
|
GetRepoLastUpdatedFn func(repo string) (cvemodel.TagInfo, error)
|
2022-07-12 07:58:04 -05:00
|
|
|
GetExpandedRepoInfoFn func(name string) (common.RepoInfo, error)
|
2022-07-19 08:16:15 -05:00
|
|
|
GetImageConfigInfoFn func(repo string, manifestDigest godigest.Digest) (ispec.Image, error)
|
2022-08-02 10:58:30 -05:00
|
|
|
CheckManifestSignatureFn func(name string, digest godigest.Digest) bool
|
2022-09-22 14:08:58 -05:00
|
|
|
GetRepositoriesFn func() ([]string, error)
|
|
|
|
}
|
|
|
|
|
2022-10-22 15:46:13 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetImageManifest(repo string, reference string,
|
|
|
|
) (ispec.Manifest, godigest.Digest, error) {
|
2022-09-30 12:32:32 -05:00
|
|
|
if olum.GetImageManifestFn != nil {
|
|
|
|
return olum.GetImageManifestFn(repo, reference)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ispec.Manifest{}, "", nil
|
|
|
|
}
|
|
|
|
|
2022-09-22 14:08:58 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetRepositories() ([]string, error) {
|
2022-09-28 13:39:54 -05:00
|
|
|
if olum.GetRepositoriesFn != nil {
|
2022-09-22 14:08:58 -05:00
|
|
|
return olum.GetRepositoriesFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
return []string{}, nil
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
2022-10-22 15:46:13 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetImageManifests(repo string) ([]ispec.Descriptor, error) {
|
2022-08-02 10:58:30 -05:00
|
|
|
if olum.GetImageManifestsFn != nil {
|
2022-10-22 15:46:13 -05:00
|
|
|
return olum.GetImageManifestsFn(repo)
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return []ispec.Descriptor{}, nil
|
|
|
|
}
|
|
|
|
|
2022-10-22 15:46:13 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetImageBlobManifest(repo string, digest godigest.Digest) (ispec.Manifest, error) {
|
2022-07-12 07:58:04 -05:00
|
|
|
if olum.GetImageBlobManifestFn != nil {
|
2022-10-22 15:46:13 -05:00
|
|
|
return olum.GetImageBlobManifestFn(repo, digest)
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
2022-10-22 15:46:13 -05:00
|
|
|
return ispec.Manifest{}, nil
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
2022-10-22 15:46:13 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetImageInfo(repo string, digest godigest.Digest) (ispec.Image, error) {
|
2022-07-12 07:58:04 -05:00
|
|
|
if olum.GetImageInfoFn != nil {
|
2022-10-22 15:46:13 -05:00
|
|
|
return olum.GetImageInfoFn(repo, digest)
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return ispec.Image{}, nil
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetImageTagsWithTimestamp(repo string) ([]cvemodel.TagInfo, error) {
|
2022-07-12 07:58:04 -05:00
|
|
|
if olum.GetImageTagsWithTimestampFn != nil {
|
|
|
|
return olum.GetImageTagsWithTimestampFn(repo)
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
return []cvemodel.TagInfo{}, nil
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
2022-07-19 08:16:15 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetImagePlatform(imageInfo ispec.Image) (string, string) {
|
2022-07-12 07:58:04 -05:00
|
|
|
if olum.GetImagePlatformFn != nil {
|
2022-07-19 08:16:15 -05:00
|
|
|
return olum.GetImagePlatformFn(imageInfo)
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return "", ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (olum OciLayoutUtilsMock) GetImageManifestSize(repo string, manifestDigest godigest.Digest) int64 {
|
|
|
|
if olum.GetImageManifestSizeFn != nil {
|
|
|
|
return olum.GetImageManifestSizeFn(repo, manifestDigest)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func (olum OciLayoutUtilsMock) GetImageConfigSize(repo string, manifestDigest godigest.Digest) int64 {
|
|
|
|
if olum.GetImageConfigSizeFn != nil {
|
|
|
|
return olum.GetImageConfigSizeFn(repo, manifestDigest)
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
func (olum OciLayoutUtilsMock) GetRepoLastUpdated(repo string) (cvemodel.TagInfo, error) {
|
2022-07-12 07:58:04 -05:00
|
|
|
if olum.GetRepoLastUpdatedFn != nil {
|
|
|
|
return olum.GetRepoLastUpdatedFn(repo)
|
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
return cvemodel.TagInfo{}, nil
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (olum OciLayoutUtilsMock) GetExpandedRepoInfo(name string) (common.RepoInfo, error) {
|
|
|
|
if olum.GetExpandedRepoInfoFn != nil {
|
|
|
|
return olum.GetExpandedRepoInfoFn(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return common.RepoInfo{}, nil
|
|
|
|
}
|
2022-07-19 08:16:15 -05:00
|
|
|
|
|
|
|
func (olum OciLayoutUtilsMock) GetImageConfigInfo(repo string, manifestDigest godigest.Digest) (ispec.Image, error) {
|
|
|
|
if olum.GetImageConfigInfoFn != nil {
|
|
|
|
return olum.GetImageConfigInfoFn(repo, manifestDigest)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ispec.Image{}, nil
|
|
|
|
}
|
2022-08-02 10:58:30 -05:00
|
|
|
|
|
|
|
func (olum OciLayoutUtilsMock) CheckManifestSignature(name string, digest godigest.Digest) bool {
|
|
|
|
if olum.CheckManifestSignatureFn != nil {
|
|
|
|
return olum.CheckManifestSignatureFn(name, digest)
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|