added minimal image checker

This commit is contained in:
2026-03-30 23:12:02 +02:00
parent 856ea529a7
commit 1c894e190d
12 changed files with 341 additions and 16 deletions
+51
View File
@@ -0,0 +1,51 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*/
package imagecmd
import (
"context"
"time"
"github.com/spf13/cobra"
"mstore/pkg/repocli"
)
// CheckImages
type CheckImagesParams struct {
Imagepath string
}
type CheckImagesResult struct {
Repos []string `json:"repos"`
}
func (util *ImageUtil) CheckImages(cmd *cobra.Command, args []string) {
util.checkImagesParams.Imagepath = args[0]
res, err := util.checkImages(&util.commonImageParams, &util.checkImagesParams)
printResponse(res, err)
}
func (util *ImageUtil) checkImages(common *CommonImageParams, params *CheckImagesParams) (*CheckImagesResult, error) {
var err error
res := &CheckImagesResult{
Repos: make([]string, 0),
}
timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout)
ref, err := repocli.NewReferer(params.Imagepath)
if err != nil {
return res, err
}
ref.SetUserinfo(common.Username, common.Password)
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
cli := repocli.NewClient(nil, mw)
opres, err := cli.CheckImages(ctx, ref.Raw())
if err != nil {
return res, err
}
res.Repos = opres
return res, err
}
+10
View File
@@ -20,6 +20,7 @@ type ImageUtil struct {
pullImageParams PullImageParams
pushImageParams PushImageParams
deleteImageParams DeleteImageParams
checkImagesParams CheckImagesParams
commonImageParams CommonImageParams
}
@@ -107,6 +108,15 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
}
subCmd.AddCommand(catalogImagesCmd)
// CheckFiles
var checkImagesCmd = &cobra.Command{
Use: "check [user:pass@]hostname[:port][/path:tag]",
Short: "Check containet image",
Args: cobra.ExactArgs(1),
Run: util.CheckImages,
}
subCmd.AddCommand(checkImagesCmd)
return subCmd
}