/* * Copyright 2026 Oleg Borodin * * This work is published and licensed under a Creative Commons * Attribution-NonCommercial-NoDerivatives 4.0 International License. * * Distribution of this work is permitted, but commercial use and * modifications are strictly prohibited. */ package imagecmd import ( "context" "os" "time" "github.com/spf13/cobra" "mstore/pkg/client" ) // PullImage type PullImageParams struct { Imagepath string Filepath string } type PullImageResult struct { Filepath string `json:"filepath"` Size int64 `json:"size"` } func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) { util.pullImageParams.Imagepath = args[0] util.pullImageParams.Filepath = args[1] res, err := util.pullImage(&util.commonImageParams, &util.pullImageParams) printResponse(res, err) } func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) { var err error ctx := context.Background() res := &PullImageResult{} cli := client.NewClient(common.SkipTLSVerify) timeout := time.Duration(common.Timeout) * time.Second params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password) if err != nil { return res, err } ctx, _ = context.WithTimeout(ctx, timeout) err = cli.PullImage(ctx, params.Imagepath, params.Filepath) if err != nil { return res, err } filestat, err := os.Stat(params.Filepath) if err != nil { return res, err } res.Size = filestat.Size() res.Filepath = params.Filepath return res, err }