added minimal image checker
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user