2022-07-15 06:10:51 -05:00
|
|
|
package search
|
|
|
|
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
|
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
2022-12-12 17:09:34 -05:00
|
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.22
|
2022-07-15 06:10:51 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-12-09 14:40:06 -05:00
|
|
|
"github.com/vektah/gqlparser/v2/gqlerror"
|
2023-01-10 13:45:15 -05:00
|
|
|
zerr "zotregistry.io/zot/errors"
|
2022-07-15 06:10:51 -05:00
|
|
|
"zotregistry.io/zot/pkg/extensions/search/common"
|
|
|
|
"zotregistry.io/zot/pkg/extensions/search/gql_generated"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CVEListForImage is the resolver for the CVEListForImage field.
|
2023-01-24 18:03:10 -05:00
|
|
|
func (r *queryResolver) CVEListForImage(ctx context.Context, image string, requestedPage *gql_generated.PageInput) (*gql_generated.CVEResultForImage, error) {
|
2023-01-10 13:45:15 -05:00
|
|
|
if r.cveInfo == nil {
|
|
|
|
return &gql_generated.CVEResultForImage{}, zerr.ErrCVESearchDisabled
|
|
|
|
}
|
|
|
|
|
2023-01-24 18:03:10 -05:00
|
|
|
return getCVEListForImage(ctx, image, r.cveInfo, requestedPage, r.log)
|
2022-07-15 06:10:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImageListForCve is the resolver for the ImageListForCVE field.
|
2023-02-15 14:34:07 -05:00
|
|
|
func (r *queryResolver) ImageListForCve(ctx context.Context, id string, requestedPage *gql_generated.PageInput) (*gql_generated.PaginatedImagesResult, error) {
|
2023-01-10 13:45:15 -05:00
|
|
|
if r.cveInfo == nil {
|
2023-02-15 14:34:07 -05:00
|
|
|
return &gql_generated.PaginatedImagesResult{}, zerr.ErrCVESearchDisabled
|
2022-07-15 06:10:51 -05:00
|
|
|
}
|
|
|
|
|
2023-01-20 15:09:40 -05:00
|
|
|
return getImageListForCVE(ctx, id, r.cveInfo, requestedPage, r.repoDB, r.log)
|
2022-07-15 06:10:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImageListWithCVEFixed is the resolver for the ImageListWithCVEFixed field.
|
2023-02-15 14:34:07 -05:00
|
|
|
func (r *queryResolver) ImageListWithCVEFixed(ctx context.Context, id string, image string, requestedPage *gql_generated.PageInput) (*gql_generated.PaginatedImagesResult, error) {
|
2023-01-10 13:45:15 -05:00
|
|
|
if r.cveInfo == nil {
|
2023-02-15 14:34:07 -05:00
|
|
|
return &gql_generated.PaginatedImagesResult{}, zerr.ErrCVESearchDisabled
|
2022-01-19 10:57:10 -05:00
|
|
|
}
|
2022-07-15 06:10:51 -05:00
|
|
|
|
2023-01-20 15:09:40 -05:00
|
|
|
return getImageListWithCVEFixed(ctx, id, image, r.cveInfo, requestedPage, r.repoDB, r.log)
|
2022-07-15 06:10:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImageListForDigest is the resolver for the ImageListForDigest field.
|
2023-02-15 14:34:07 -05:00
|
|
|
func (r *queryResolver) ImageListForDigest(ctx context.Context, id string, requestedPage *gql_generated.PageInput) (*gql_generated.PaginatedImagesResult, error) {
|
2022-07-15 06:10:51 -05:00
|
|
|
r.log.Info().Msg("extracting repositories")
|
|
|
|
|
2023-01-17 17:31:54 -05:00
|
|
|
imgResultForDigest, err := getImageListForDigest(ctx, id, r.repoDB, r.cveInfo, requestedPage)
|
2022-07-15 06:10:51 -05:00
|
|
|
|
2023-01-17 17:31:54 -05:00
|
|
|
return imgResultForDigest, err
|
2022-07-15 06:10:51 -05:00
|
|
|
}
|
|
|
|
|
2022-07-29 10:33:34 -05:00
|
|
|
// RepoListWithNewestImage is the resolver for the RepoListWithNewestImage field.
|
2023-01-18 17:20:55 -05:00
|
|
|
func (r *queryResolver) RepoListWithNewestImage(ctx context.Context, requestedPage *gql_generated.PageInput) (*gql_generated.PaginatedReposResult, error) {
|
2022-07-15 06:10:51 -05:00
|
|
|
r.log.Info().Msg("extension api: finding image list")
|
|
|
|
|
2023-01-18 17:20:55 -05:00
|
|
|
paginatedReposResult, err := repoListWithNewestImage(ctx, r.cveInfo, r.log, requestedPage, r.repoDB)
|
2022-09-13 09:20:44 -05:00
|
|
|
if err != nil {
|
2023-01-09 15:37:44 -05:00
|
|
|
r.log.Error().Err(err).Msg("unable to retrieve repo list")
|
2022-09-13 09:20:44 -05:00
|
|
|
|
2023-01-18 17:20:55 -05:00
|
|
|
return paginatedReposResult, err
|
2022-09-13 09:20:44 -05:00
|
|
|
}
|
|
|
|
|
2023-01-18 17:20:55 -05:00
|
|
|
return paginatedReposResult, nil
|
2022-07-15 06:10:51 -05:00
|
|
|
}
|
|
|
|
|
2022-01-19 10:57:10 -05:00
|
|
|
// ImageList is the resolver for the ImageList field.
|
2023-02-15 14:34:07 -05:00
|
|
|
func (r *queryResolver) ImageList(ctx context.Context, repo string, requestedPage *gql_generated.PageInput) (*gql_generated.PaginatedImagesResult, error) {
|
2022-01-19 10:57:10 -05:00
|
|
|
r.log.Info().Msg("extension api: getting a list of all images")
|
|
|
|
|
2023-01-23 12:45:11 -05:00
|
|
|
imageList, err := getImageList(ctx, repo, r.repoDB, r.cveInfo, requestedPage, r.log)
|
2022-01-19 10:57:10 -05:00
|
|
|
if err != nil {
|
2023-01-23 12:45:11 -05:00
|
|
|
r.log.Error().Err(err).Msgf("unable to retrieve image list for repo: %s", repo)
|
2022-01-19 10:57:10 -05:00
|
|
|
|
|
|
|
return imageList, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return imageList, nil
|
|
|
|
}
|
|
|
|
|
2022-07-15 06:10:51 -05:00
|
|
|
// ExpandedRepoInfo is the resolver for the ExpandedRepoInfo field.
|
|
|
|
func (r *queryResolver) ExpandedRepoInfo(ctx context.Context, repo string) (*gql_generated.RepoInfo, error) {
|
2023-01-09 15:37:44 -05:00
|
|
|
repoInfo, err := expandedRepoInfo(ctx, repo, r.repoDB, r.cveInfo, r.log)
|
2022-07-29 09:51:10 -05:00
|
|
|
|
2023-01-09 15:37:44 -05:00
|
|
|
return repoInfo, err
|
2022-07-15 06:10:51 -05:00
|
|
|
}
|
|
|
|
|
2022-07-12 07:58:04 -05:00
|
|
|
// GlobalSearch is the resolver for the GlobalSearch field.
|
2023-01-09 15:37:44 -05:00
|
|
|
func (r *queryResolver) GlobalSearch(ctx context.Context, query string, filter *gql_generated.Filter, requestedPage *gql_generated.PageInput) (*gql_generated.GlobalSearchResult, error) {
|
|
|
|
if err := validateGlobalSearchInput(query, filter, requestedPage); err != nil {
|
2022-07-12 07:58:04 -05:00
|
|
|
return &gql_generated.GlobalSearchResult{}, err
|
|
|
|
}
|
|
|
|
|
2023-01-09 15:37:44 -05:00
|
|
|
query = cleanQuery(query)
|
|
|
|
filter = cleanFilter(filter)
|
2022-08-16 03:57:09 -05:00
|
|
|
|
2023-01-18 17:20:55 -05:00
|
|
|
paginatedReposResult, images, layers, err := globalSearch(ctx, query, r.repoDB, filter, requestedPage, r.cveInfo, r.log)
|
2022-07-12 07:58:04 -05:00
|
|
|
|
|
|
|
return &gql_generated.GlobalSearchResult{
|
2023-01-18 17:20:55 -05:00
|
|
|
Page: paginatedReposResult.Page,
|
2022-07-12 07:58:04 -05:00
|
|
|
Images: images,
|
2023-01-18 17:20:55 -05:00
|
|
|
Repos: paginatedReposResult.Results,
|
2022-07-12 07:58:04 -05:00
|
|
|
Layers: layers,
|
2023-01-09 15:37:44 -05:00
|
|
|
}, err
|
2022-07-12 07:58:04 -05:00
|
|
|
}
|
|
|
|
|
2022-09-23 11:23:31 -05:00
|
|
|
// DependencyListForImage is the resolver for the DependencyListForImage field.
|
2023-02-27 14:23:18 -05:00
|
|
|
func (r *queryResolver) DerivedImageList(ctx context.Context, image string, digest *string, requestedPage *gql_generated.PageInput) (*gql_generated.PaginatedImagesResult, error) {
|
|
|
|
derivedList, err := derivedImageList(ctx, image, digest, r.repoDB, requestedPage, r.cveInfo, r.log)
|
2022-09-23 11:23:31 -05:00
|
|
|
|
2023-01-25 17:06:02 -05:00
|
|
|
return derivedList, err
|
2022-09-23 11:23:31 -05:00
|
|
|
}
|
|
|
|
|
2022-09-22 14:08:58 -05:00
|
|
|
// BaseImageList is the resolver for the BaseImageList field.
|
2023-02-27 14:23:18 -05:00
|
|
|
func (r *queryResolver) BaseImageList(ctx context.Context, image string, digest *string, requestedPage *gql_generated.PageInput) (*gql_generated.PaginatedImagesResult, error) {
|
|
|
|
imageList, err := baseImageList(ctx, image, digest, r.repoDB, requestedPage, r.cveInfo, r.log)
|
2022-09-22 14:08:58 -05:00
|
|
|
|
2023-01-25 17:06:02 -05:00
|
|
|
return imageList, err
|
2022-09-22 14:08:58 -05:00
|
|
|
}
|
|
|
|
|
2022-09-30 12:32:32 -05:00
|
|
|
// Image is the resolver for the Image field.
|
|
|
|
func (r *queryResolver) Image(ctx context.Context, image string) (*gql_generated.ImageSummary, error) {
|
|
|
|
repo, tag := common.GetImageDirAndTag(image)
|
|
|
|
|
2022-12-09 14:40:06 -05:00
|
|
|
if tag == "" {
|
|
|
|
return &gql_generated.ImageSummary{}, gqlerror.Errorf("no reference provided")
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:23:18 -05:00
|
|
|
return getImageSummary(ctx, repo, tag, nil, r.repoDB, r.cveInfo, r.log)
|
2022-09-30 12:32:32 -05:00
|
|
|
}
|
|
|
|
|
2022-11-23 13:53:28 -05:00
|
|
|
// Referrers is the resolver for the Referrers field.
|
2023-01-26 13:13:12 -05:00
|
|
|
func (r *queryResolver) Referrers(ctx context.Context, repo string, digest string, typeArg []string) ([]*gql_generated.Referrer, error) {
|
2022-11-23 13:53:28 -05:00
|
|
|
store := r.storeController.GetImageStore(repo)
|
|
|
|
|
|
|
|
referrers, err := getReferrers(store, repo, digest, typeArg, r.log)
|
|
|
|
if err != nil {
|
|
|
|
r.log.Error().Err(err).Msg("unable to get referrers from default store")
|
|
|
|
|
|
|
|
return []*gql_generated.Referrer{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return referrers, nil
|
|
|
|
}
|
|
|
|
|
2022-07-15 06:10:51 -05:00
|
|
|
// Query returns gql_generated.QueryResolver implementation.
|
|
|
|
func (r *Resolver) Query() gql_generated.QueryResolver { return &queryResolver{r} }
|
|
|
|
|
|
|
|
type queryResolver struct{ *Resolver }
|