mirror of
https://github.com/project-zot/zot.git
synced 2026-06-15 11:37:56 +08:00
2402296e9a
* fix: migrate to Go module v2 for proper semantic versioning This change updates the module path from 'zotregistry.dev/zot' to 'zotregistry.dev/zot/v2' to comply with Go's semantic versioning rules. According to Go's module versioning requirements, major version v2+ must include the major version in the module path. The current module path 'zotregistry.dev/zot' only supports v0.x.x and v1.x.x versions, making existing v2.x.x tags (like v2.1.8) unusable. Changes: - Updated go.mod module path to zotregistry.dev/zot/v2 - Updated all internal import paths across 280+ Go source files - Updated configuration files (golangcilint.yaml, gqlgen.yml) - Updated README.md Go reference badge This fix enables proper use of existing v2.x.x Git tags and allows external packages to import zot v2+ versions without compatibility errors. Resolves: Go module import compatibility for v2+ versions Fixes: #3071 Signed-off-by: Luca Muscariello <muscariello@ieee.org> * fix: regenerate GraphQL files with updated v2 import paths The gqlgen tool needs to regenerate the GraphQL schema files after the module path change to use the new v2 imports. Signed-off-by: Luca Muscariello <muscariello@ieee.org> --------- Signed-off-by: Luca Muscariello <muscariello@ieee.org>
202 lines
5.5 KiB
Go
202 lines
5.5 KiB
Go
//go:build search
|
|
// +build search
|
|
|
|
package client
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
zerr "zotregistry.dev/zot/v2/errors"
|
|
zcommon "zotregistry.dev/zot/v2/pkg/common"
|
|
)
|
|
|
|
func NewImageListCommand(searchService SearchService) *cobra.Command {
|
|
imageListSortFlag := ImageListSortFlag(SortByAlphabeticAsc)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "list",
|
|
Short: "List all images",
|
|
Long: "List all images",
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
searchConfig, err := GetSearchConfigFromFlags(cmd, searchService)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := CheckExtEndPointQuery(searchConfig, ImageListQuery()); err == nil {
|
|
return SearchAllImagesGQL(searchConfig)
|
|
}
|
|
|
|
return SearchAllImages(searchConfig)
|
|
},
|
|
}
|
|
|
|
cmd.Flags().Var(&imageListSortFlag, SortByFlag,
|
|
fmt.Sprintf("Options for sorting the output: [%s]", ImageListSortOptionsStr()))
|
|
|
|
return cmd
|
|
}
|
|
|
|
func NewImageCVEListCommand(searchService SearchService) *cobra.Command {
|
|
var (
|
|
searchedCVEID string
|
|
cveListSortFlag = CVEListSortFlag(SortBySeverity)
|
|
)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "cve [repo]|[repo-name:tag]|[repo-name@digest]",
|
|
Short: "List all CVE's of the image",
|
|
Long: "List all CVE's of the image",
|
|
Args: OneImageWithRefArg,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
searchConfig, err := GetSearchConfigFromFlags(cmd, searchService)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := CheckExtEndPointQuery(searchConfig, CVEListForImageQuery()); err == nil {
|
|
image := args[0]
|
|
|
|
return SearchCVEForImageGQL(searchConfig, image, searchedCVEID)
|
|
} else {
|
|
return err
|
|
}
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&searchedCVEID, SearchedCVEID, "", "Search for a specific CVE by name/id")
|
|
cmd.Flags().Var(&cveListSortFlag, SortByFlag,
|
|
fmt.Sprintf("Options for sorting the output: [%s]", CVEListSortOptionsStr()))
|
|
|
|
return cmd
|
|
}
|
|
|
|
func NewImageDerivedCommand(searchService SearchService) *cobra.Command {
|
|
imageListSortFlag := ImageListSortFlag(SortByAlphabeticAsc)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "derived [repo-name:tag]|[repo-name@digest]",
|
|
Short: "List images that are derived from given image",
|
|
Long: "List images that are derived from given image",
|
|
Args: OneImageWithRefArg,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
searchConfig, err := GetSearchConfigFromFlags(cmd, searchService)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := CheckExtEndPointQuery(searchConfig, DerivedImageListQuery()); err == nil {
|
|
return SearchDerivedImageListGQL(searchConfig, args[0])
|
|
} else {
|
|
return err
|
|
}
|
|
},
|
|
}
|
|
|
|
cmd.Flags().Var(&imageListSortFlag, SortByFlag,
|
|
fmt.Sprintf("Options for sorting the output: [%s]", ImageListSortOptionsStr()))
|
|
|
|
return cmd
|
|
}
|
|
|
|
func NewImageBaseCommand(searchService SearchService) *cobra.Command {
|
|
imageListSortFlag := ImageListSortFlag(SortByAlphabeticAsc)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "base [repo-name:tag]|[repo-name@digest]",
|
|
Short: "List images that are base for the given image",
|
|
Long: "List images that are base for the given image",
|
|
Args: OneImageWithRefArg,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
searchConfig, err := GetSearchConfigFromFlags(cmd, searchService)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := CheckExtEndPointQuery(searchConfig, BaseImageListQuery()); err == nil {
|
|
return SearchBaseImageListGQL(searchConfig, args[0])
|
|
} else {
|
|
return err
|
|
}
|
|
},
|
|
}
|
|
|
|
cmd.Flags().Var(&imageListSortFlag, SortByFlag,
|
|
fmt.Sprintf("Options for sorting the output: [%s]", ImageListSortOptionsStr()))
|
|
|
|
return cmd
|
|
}
|
|
|
|
func NewImageDigestCommand(searchService SearchService) *cobra.Command {
|
|
imageListSortFlag := ImageListSortFlag(SortByAlphabeticAsc)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "digest [digest]",
|
|
Short: "List images that contain a blob(manifest, config or layer) with the given digest",
|
|
Long: "List images that contain a blob(manifest, config or layer) with the given digest",
|
|
Example: `zli image digest 8a1930f0
|
|
zli image digest sha256:8a1930f0...`,
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
searchConfig, err := GetSearchConfigFromFlags(cmd, searchService)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := CheckExtEndPointQuery(searchConfig, ImageListForDigestQuery()); err == nil {
|
|
return SearchImagesForDigestGQL(searchConfig, args[0])
|
|
} else {
|
|
return err
|
|
}
|
|
},
|
|
}
|
|
|
|
cmd.Flags().Var(&imageListSortFlag, SortByFlag,
|
|
fmt.Sprintf("Options for sorting the output: [%s]", ImageListSortOptionsStr()))
|
|
|
|
return cmd
|
|
}
|
|
|
|
func NewImageNameCommand(searchService SearchService) *cobra.Command {
|
|
imageListSortFlag := ImageListSortFlag(SortByAlphabeticAsc)
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "name [repo:tag]",
|
|
Short: "List image details by name",
|
|
Long: "List image details by name",
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
if err := cobra.ExactArgs(1)(cmd, args); err != nil {
|
|
return err
|
|
}
|
|
|
|
image := args[0]
|
|
|
|
if dir, _ := zcommon.GetImageDirAndTag(image); dir == "" {
|
|
return zerr.ErrInvalidRepoRefFormat
|
|
}
|
|
|
|
return nil
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
searchConfig, err := GetSearchConfigFromFlags(cmd, searchService)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := CheckExtEndPointQuery(searchConfig, ImageListQuery()); err == nil {
|
|
return SearchImageByNameGQL(searchConfig, args[0])
|
|
}
|
|
|
|
return SearchImageByName(searchConfig, args[0])
|
|
},
|
|
}
|
|
|
|
cmd.Flags().Var(&imageListSortFlag, SortByFlag,
|
|
fmt.Sprintf("Options for sorting the output: [%s]", ImageListSortOptionsStr()))
|
|
|
|
return cmd
|
|
}
|