working commit
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"mstore/pkg/auxtool"
|
||||
@@ -24,19 +25,26 @@ import (
|
||||
|
||||
// PullImage
|
||||
type PullImageParams struct {
|
||||
Imagepath string
|
||||
Filepath string
|
||||
Imagepath string
|
||||
Filepath string
|
||||
UseGoogleClient bool
|
||||
}
|
||||
|
||||
type PullImageResult struct {
|
||||
Filepath string `json:"filepath"`
|
||||
Size int64 `json:"size"`
|
||||
Size string `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)
|
||||
res := &PullImageResult{}
|
||||
var err error
|
||||
if util.pullImageParams.UseGoogleClient {
|
||||
res, err = util.gcrPullImage(&util.commonImageParams, &util.pullImageParams)
|
||||
} else {
|
||||
res, err = util.pullImage(&util.commonImageParams, &util.pullImageParams)
|
||||
}
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
@@ -73,20 +81,21 @@ func (util *ImageUtil) pullImage(common *CommonImageParams, params *PullImagePar
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Size = filestat.Size()
|
||||
size := filestat.Size()
|
||||
res.Size = humanize.Comma(size)
|
||||
res.Filepath = params.Filepath
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *ImageUtil) XXXpullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
|
||||
func (util *ImageUtil) gcrPullImage(common *CommonImageParams, params *PullImageParams) (*PullImageResult, error) {
|
||||
var err error
|
||||
|
||||
ctx := context.Background()
|
||||
res := &PullImageResult{}
|
||||
|
||||
cli := gcrcli.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
|
||||
@@ -100,7 +109,8 @@ func (util *ImageUtil) XXXpullImage(common *CommonImageParams, params *PullImage
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.Size = filestat.Size()
|
||||
size := filestat.Size()
|
||||
res.Size = humanize.Comma(size)
|
||||
res.Filepath = params.Filepath
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user