Files
mstore/cmd/mstorectl/imagecmd/checkimgs.go
T
2026-03-30 23:12:02 +02:00

52 lines
1.2 KiB
Go

/*
* 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
}