working commit
This commit is contained in:
@@ -11,6 +11,9 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"mstore/pkg/client"
|
||||
@@ -18,6 +21,24 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func packUserinfo(resurseuri, username, password string) (string, error) {
|
||||
var err error
|
||||
var res string
|
||||
if !strings.Contains(resurseuri, "://") {
|
||||
resurseuri = "https://" + resurseuri
|
||||
}
|
||||
uri, err := url.Parse(resurseuri)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
uri.Path = path.Clean(uri.Path)
|
||||
if username != "" && password != "" {
|
||||
uri.User = url.UserPassword(username, password)
|
||||
}
|
||||
res = uri.String()
|
||||
return res, err
|
||||
}
|
||||
|
||||
func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
const defaultTimeout uint64 = 30 // Second
|
||||
|
||||
@@ -101,10 +122,17 @@ func (util *ImageUtil) imageInfo(params *ImageInfoParams) (*ImageInfoResult, err
|
||||
res := &ImageInfoResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
cli := client.NewClientWithAuth(params.Username, params.Password)
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
opres, err := cli.ImageInfo(ctx, params.Imagepath, timeout)
|
||||
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
opres, err := cli.ImageInfo(ctx, params.Imagepath, timeout)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.ImageInfo = opres
|
||||
return res, err
|
||||
}
|
||||
@@ -131,10 +159,16 @@ func (util *ImageUtil) pullImage(params *PullImageParams) (*PullImageResult, err
|
||||
ctx := context.Background()
|
||||
res := &PullImageResult{}
|
||||
|
||||
cli := client.NewClientWithAuth(params.Username, params.Password)
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = cli.PullImage(ctx, params.Imagepath, params.Filepath, timeout)
|
||||
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
@@ -159,9 +193,15 @@ func (util *ImageUtil) pushImage(params *PushImageParams) (*PushImageResult, err
|
||||
ctx := context.Background()
|
||||
res := &PushImageResult{}
|
||||
|
||||
cli := client.NewClientWithAuth(params.Username, params.Password)
|
||||
cli := client.NewClient()
|
||||
timeout := time.Duration(params.Timeout) * time.Second
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, params.Username, params.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
err = cli.PushImage(ctx, params.Filepath, params.Imagepath, timeout)
|
||||
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user