freeform querry api

Signed-off-by: Laurentiu Niculae <themelopeus@gmail.com>
This commit is contained in:
Laurentiu Niculae
2022-07-12 15:58:04 +03:00
committed by Ramkumar Chinchani
parent a31869f270
commit 7e3d063319
20 changed files with 3597 additions and 562 deletions
+289
View File
@@ -0,0 +1,289 @@
package mocks
import (
"io"
"time"
"github.com/opencontainers/go-digest"
artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1"
)
type MockedImageStore struct {
DirExistsFn func(d string) bool
RootDirFn func() string
InitRepoFn func(name string) error
ValidateRepoFn func(name string) (bool, error)
GetRepositoriesFn func() ([]string, error)
GetImageTagsFn func(repo string) ([]string, error)
GetImageManifestFn func(repo string, reference string) ([]byte, string, string, error)
PutImageManifestFn func(repo string, reference string, mediaType string, body []byte) (string, error)
DeleteImageManifestFn func(repo string, reference string) error
BlobUploadPathFn func(repo string, uuid string) string
NewBlobUploadFn func(repo string) (string, error)
GetBlobUploadFn func(repo string, uuid string) (int64, error)
BlobUploadInfoFn func(repo string, uuid string) (int64, error)
PutBlobChunkStreamedFn func(repo string, uuid string, body io.Reader) (int64, error)
PutBlobChunkFn func(repo string, uuid string, from int64, to int64, body io.Reader) (int64, error)
FinishBlobUploadFn func(repo string, uuid string, body io.Reader, digest string) error
FullBlobUploadFn func(repo string, body io.Reader, digest string) (string, int64, error)
DedupeBlobFn func(src string, dstDigest digest.Digest, dst string) error
DeleteBlobUploadFn func(repo string, uuid string) error
BlobPathFn func(repo string, digest digest.Digest) string
CheckBlobFn func(repo string, digest string) (bool, int64, error)
GetBlobFn func(repo string, digest string, mediaType string) (io.Reader, int64, error)
DeleteBlobFn func(repo string, digest string) error
GetIndexContentFn func(repo string) ([]byte, error)
GetBlobContentFn func(repo, digest string) ([]byte, error)
GetReferrersFn func(repo, digest string, mediaType string) ([]artifactspec.Descriptor, error)
URLForPathFn func(path string) (string, error)
RunGCRepoFn func(repo string)
}
func (is MockedImageStore) Lock(t *time.Time) {
}
func (is MockedImageStore) Unlock(t *time.Time) {
}
func (is MockedImageStore) RUnlock(t *time.Time) {
}
func (is MockedImageStore) RLock(t *time.Time) {
}
func (is MockedImageStore) DirExists(d string) bool {
if is.DirExistsFn != nil {
return is.DirExistsFn(d)
}
return true
}
func (is MockedImageStore) RootDir() string {
if is.RootDirFn != nil {
return is.RootDirFn()
}
return ""
}
func (is MockedImageStore) InitRepo(name string) error {
if is.InitRepoFn != nil {
return is.InitRepoFn(name)
}
return nil
}
func (is MockedImageStore) ValidateRepo(name string) (bool, error) {
if is.ValidateRepoFn != nil {
return is.ValidateRepoFn(name)
}
return true, nil
}
func (is MockedImageStore) GetRepositories() ([]string, error) {
if is.GetRepositoriesFn != nil {
return is.GetRepositoriesFn()
}
return []string{}, nil
}
func (is MockedImageStore) GetImageManifest(repo string, reference string) ([]byte, string, string, error) {
if is.GetImageManifestFn != nil {
return is.GetImageManifestFn(repo, reference)
}
return []byte{}, "", "", nil
}
func (is MockedImageStore) PutImageManifest(
repo string,
reference string,
mediaType string,
body []byte,
) (string, error) {
if is.PutImageManifestFn != nil {
return is.PutImageManifestFn(repo, reference, mediaType, body)
}
return "", nil
}
func (is MockedImageStore) GetImageTags(name string) ([]string, error) {
if is.GetImageTagsFn != nil {
return is.GetImageTagsFn(name)
}
return []string{}, nil
}
func (is MockedImageStore) DeleteImageManifest(name string, reference string) error {
if is.DeleteImageManifestFn != nil {
return is.DeleteImageManifestFn(name, reference)
}
return nil
}
func (is MockedImageStore) NewBlobUpload(repo string) (string, error) {
if is.NewBlobUploadFn != nil {
return is.NewBlobUploadFn(repo)
}
return "", nil
}
func (is MockedImageStore) GetBlobUpload(repo string, uuid string) (int64, error) {
if is.GetBlobUploadFn != nil {
return is.GetBlobUploadFn(repo, uuid)
}
return 0, nil
}
func (is MockedImageStore) BlobUploadInfo(repo string, uuid string) (int64, error) {
if is.BlobUploadInfoFn != nil {
return is.BlobUploadInfoFn(repo, uuid)
}
return 0, nil
}
func (is MockedImageStore) BlobUploadPath(repo string, uuid string) string {
if is.BlobUploadPathFn != nil {
return is.BlobUploadPathFn(repo, uuid)
}
return ""
}
func (is MockedImageStore) PutBlobChunkStreamed(repo string, uuid string, body io.Reader) (int64, error) {
if is.PutBlobChunkStreamedFn != nil {
return is.PutBlobChunkStreamedFn(repo, uuid, body)
}
return 0, nil
}
func (is MockedImageStore) PutBlobChunk(
repo string,
uuid string,
from int64,
to int64,
body io.Reader,
) (int64, error) {
if is.PutBlobChunkFn != nil {
return is.PutBlobChunkFn(repo, uuid, from, to, body)
}
return 0, nil
}
func (is MockedImageStore) FinishBlobUpload(repo string, uuid string, body io.Reader, digest string) error {
if is.FinishBlobUploadFn != nil {
return is.FinishBlobUploadFn(repo, uuid, body, digest)
}
return nil
}
func (is MockedImageStore) FullBlobUpload(repo string, body io.Reader, digest string) (string, int64, error) {
if is.FullBlobUploadFn != nil {
return is.FullBlobUploadFn(repo, body, digest)
}
return "", 0, nil
}
func (is MockedImageStore) DedupeBlob(src string, dstDigest digest.Digest, dst string) error {
if is.DedupeBlobFn != nil {
return is.DedupeBlobFn(src, dstDigest, dst)
}
return nil
}
func (is MockedImageStore) DeleteBlob(repo string, digest string) error {
if is.DeleteBlobFn != nil {
return is.DeleteBlobFn(repo, digest)
}
return nil
}
func (is MockedImageStore) BlobPath(repo string, digest digest.Digest) string {
if is.BlobPathFn != nil {
return is.BlobPathFn(repo, digest)
}
return ""
}
func (is MockedImageStore) CheckBlob(repo string, digest string) (bool, int64, error) {
if is.CheckBlobFn != nil {
return is.CheckBlobFn(repo, digest)
}
return true, 0, nil
}
func (is MockedImageStore) GetBlob(repo string, digest string, mediaType string) (io.Reader, int64, error) {
if is.GetBlobFn != nil {
return is.GetBlobFn(repo, digest, mediaType)
}
return &io.LimitedReader{}, 0, nil
}
func (is MockedImageStore) DeleteBlobUpload(repo string, digest string) error {
if is.DeleteBlobUploadFn != nil {
return is.DeleteBlobUploadFn(repo, digest)
}
return nil
}
func (is MockedImageStore) GetIndexContent(repo string) ([]byte, error) {
if is.GetIndexContentFn != nil {
return is.GetIndexContentFn(repo)
}
return []byte{}, nil
}
func (is MockedImageStore) GetBlobContent(repo string, digest string) ([]byte, error) {
if is.GetBlobContentFn != nil {
return is.GetBlobContentFn(repo, digest)
}
return []byte{}, nil
}
func (is MockedImageStore) GetReferrers(
repo string,
digest string,
mediaType string,
) ([]artifactspec.Descriptor, error) {
if is.GetReferrersFn != nil {
return is.GetReferrersFn(repo, digest, mediaType)
}
return []artifactspec.Descriptor{}, nil
}
func (is MockedImageStore) URLForPath(path string) (string, error) {
if is.URLForPathFn != nil {
return is.URLForPathFn(path)
}
return "", nil
}
func (is MockedImageStore) RunGCRepo(repo string) {
if is.RunGCRepoFn != nil {
is.RunGCRepoFn(repo)
}
}
+121
View File
@@ -0,0 +1,121 @@
package mocks
import (
"time"
v1 "github.com/google/go-containerregistry/pkg/v1"
godigest "github.com/opencontainers/go-digest"
ispec "github.com/opencontainers/image-spec/specs-go/v1"
"zotregistry.io/zot/pkg/extensions/search/common"
)
type OciLayoutUtilsMock struct {
GetImageManifestsFn func(image string) ([]ispec.Descriptor, error)
GetImageBlobManifestFn func(imageDir string, digest godigest.Digest) (v1.Manifest, error)
GetImageInfoFn func(imageDir string, hash v1.Hash) (ispec.Image, error)
IsValidImageFormatFn func(image string) (bool, error)
GetImageTagsWithTimestampFn func(repo string) ([]common.TagInfo, error)
GetImageLastUpdatedFn func(repo string, manifestDigest godigest.Digest) time.Time
GetImagePlatformFn func(repo string, manifestDigest godigest.Digest) (string, string)
GetImageVendorFn func(repo string, manifestDigest godigest.Digest) string
GetImageManifestSizeFn func(repo string, manifestDigest godigest.Digest) int64
GetImageConfigSizeFn func(repo string, manifestDigest godigest.Digest) int64
GetRepoLastUpdatedFn func(repo string) (time.Time, error)
GetExpandedRepoInfoFn func(name string) (common.RepoInfo, error)
}
func (olum OciLayoutUtilsMock) GetImageManifests(image string) ([]ispec.Descriptor, error) {
if olum.GetImageBlobManifestFn != nil {
return olum.GetImageManifestsFn(image)
}
return []ispec.Descriptor{}, nil
}
func (olum OciLayoutUtilsMock) GetImageBlobManifest(imageDir string, digest godigest.Digest) (v1.Manifest, error) {
if olum.GetImageBlobManifestFn != nil {
return olum.GetImageBlobManifestFn(imageDir, digest)
}
return v1.Manifest{}, nil
}
func (olum OciLayoutUtilsMock) GetImageInfo(imageDir string, hash v1.Hash) (ispec.Image, error) {
if olum.GetImageInfoFn != nil {
return olum.GetImageInfoFn(imageDir, hash)
}
return ispec.Image{}, nil
}
func (olum OciLayoutUtilsMock) IsValidImageFormat(image string) (bool, error) {
if olum.IsValidImageFormatFn != nil {
return olum.IsValidImageFormatFn(image)
}
return true, nil
}
func (olum OciLayoutUtilsMock) GetImageTagsWithTimestamp(repo string) ([]common.TagInfo, error) {
if olum.GetImageTagsWithTimestampFn != nil {
return olum.GetImageTagsWithTimestampFn(repo)
}
return []common.TagInfo{}, nil
}
func (olum OciLayoutUtilsMock) GetImageLastUpdated(repo string, manifestDigest godigest.Digest) time.Time {
if olum.GetImageLastUpdatedFn != nil {
return olum.GetImageLastUpdatedFn(repo, manifestDigest)
}
return time.Time{}
}
func (olum OciLayoutUtilsMock) GetImagePlatform(repo string, manifestDigest godigest.Digest) (string, string) {
if olum.GetImagePlatformFn != nil {
return olum.GetImagePlatformFn(repo, manifestDigest)
}
return "", ""
}
func (olum OciLayoutUtilsMock) GetImageVendor(repo string, manifestDigest godigest.Digest) string {
if olum.GetImageVendorFn != nil {
return olum.GetImageVendorFn(repo, manifestDigest)
}
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
}
func (olum OciLayoutUtilsMock) GetRepoLastUpdated(repo string) (time.Time, error) {
if olum.GetRepoLastUpdatedFn != nil {
return olum.GetRepoLastUpdatedFn(repo)
}
return time.Time{}, nil
}
func (olum OciLayoutUtilsMock) GetExpandedRepoInfo(name string) (common.RepoInfo, error) {
if olum.GetExpandedRepoInfoFn != nil {
return olum.GetExpandedRepoInfoFn(name)
}
return common.RepoInfo{}, nil
}
+186
View File
@@ -0,0 +1,186 @@
package mocks
import (
"context"
"io"
"io/ioutil"
"strings"
"time"
"github.com/docker/distribution/registry/storage/driver"
)
type StorageDriverMock struct {
NameFn func() string
GetContentFn func(ctx context.Context, path string) ([]byte, error)
PutContentFn func(ctx context.Context, path string, content []byte) error
ReaderFn func(ctx context.Context, path string, offset int64) (io.ReadCloser, error)
WriterFn func(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error)
StatFn func(ctx context.Context, path string) (driver.FileInfo, error)
ListFn func(ctx context.Context, path string) ([]string, error)
MoveFn func(ctx context.Context, sourcePath, destPath string) error
DeleteFn func(ctx context.Context, path string) error
WalkFn func(ctx context.Context, path string, f driver.WalkFn) error
}
// nolint: gochecknoglobals
var (
fileWriterSize = 12
fileInfoSize = 10
)
func (s *StorageDriverMock) Name() string {
if s != nil && s.NameFn != nil {
return s.NameFn()
}
return ""
}
func (s *StorageDriverMock) GetContent(ctx context.Context, path string) ([]byte, error) {
if s != nil && s.GetContentFn != nil {
return s.GetContentFn(ctx, path)
}
return []byte{}, nil
}
func (s *StorageDriverMock) PutContent(ctx context.Context, path string, content []byte) error {
if s != nil && s.PutContentFn != nil {
return s.PutContentFn(ctx, path, content)
}
return nil
}
func (s *StorageDriverMock) Reader(ctx context.Context, path string, offset int64) (io.ReadCloser, error) {
if s != nil && s.ReaderFn != nil {
return s.ReaderFn(ctx, path, offset)
}
return ioutil.NopCloser(strings.NewReader("")), nil
}
func (s *StorageDriverMock) Writer(ctx context.Context, path string, isAppend bool) (driver.FileWriter, error) {
if s != nil && s.WriterFn != nil {
return s.WriterFn(ctx, path, isAppend)
}
return &FileWriterMock{}, nil
}
func (s *StorageDriverMock) Stat(ctx context.Context, path string) (driver.FileInfo, error) {
if s != nil && s.StatFn != nil {
return s.StatFn(ctx, path)
}
return &FileInfoMock{}, nil
}
func (s *StorageDriverMock) List(ctx context.Context, path string) ([]string, error) {
if s != nil && s.ListFn != nil {
return s.ListFn(ctx, path)
}
return []string{"a"}, nil
}
func (s *StorageDriverMock) Move(ctx context.Context, sourcePath, destPath string) error {
if s != nil && s.MoveFn != nil {
return s.MoveFn(ctx, sourcePath, destPath)
}
return nil
}
func (s *StorageDriverMock) Delete(ctx context.Context, path string) error {
if s != nil && s.DeleteFn != nil {
return s.DeleteFn(ctx, path)
}
return nil
}
func (s *StorageDriverMock) URLFor(ctx context.Context, path string, options map[string]interface{}) (string, error) {
return "", nil
}
func (s *StorageDriverMock) Walk(ctx context.Context, path string, f driver.WalkFn) error {
if s != nil && s.WalkFn != nil {
return s.WalkFn(ctx, path, f)
}
return nil
}
type FileInfoMock struct {
IsDirFn func() bool
SizeFn func() int64
}
func (f *FileInfoMock) Path() string {
return ""
}
func (f *FileInfoMock) Size() int64 {
if f != nil && f.SizeFn != nil {
return f.SizeFn()
}
return int64(fileInfoSize)
}
func (f *FileInfoMock) ModTime() time.Time {
return time.Now()
}
func (f *FileInfoMock) IsDir() bool {
if f != nil && f.IsDirFn != nil {
return f.IsDirFn()
}
return true
}
type FileWriterMock struct {
WriteFn func([]byte) (int, error)
CancelFn func() error
CommitFn func() error
CloseFn func() error
}
func (f *FileWriterMock) Size() int64 {
return int64(fileWriterSize)
}
func (f *FileWriterMock) Cancel() error {
if f != nil && f.CancelFn != nil {
return f.CancelFn()
}
return nil
}
func (f *FileWriterMock) Commit() error {
if f != nil && f.CommitFn != nil {
return f.CommitFn()
}
return nil
}
func (f *FileWriterMock) Write(p []byte) (int, error) {
if f != nil && f.WriteFn != nil {
return f.WriteFn(p)
}
return 10, nil
}
func (f *FileWriterMock) Close() error {
if f != nil && f.CloseFn != nil {
return f.CloseFn()
}
return nil
}