working commit
This commit is contained in:
@@ -21,6 +21,8 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"mstore/pkg/client"
|
||||
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
func packUserinfo(resurseuri, username, password string) (string, error) {
|
||||
@@ -71,15 +73,6 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
}
|
||||
subCmd.AddCommand(pushImageCmd)
|
||||
|
||||
// ImageInfo
|
||||
var imageInfoCmd = &cobra.Command{
|
||||
Use: "info [user:pass@]hostname[:port]/path:tag",
|
||||
Short: "Show container image info",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.ImageInfo,
|
||||
}
|
||||
subCmd.AddCommand(imageInfoCmd)
|
||||
|
||||
// PullImage
|
||||
var pullImageCmd = &cobra.Command{
|
||||
Use: "pull [user:pass@]hostname[:port]/path:tag filename",
|
||||
@@ -98,11 +91,50 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command {
|
||||
}
|
||||
subCmd.AddCommand(deleteImageCmd)
|
||||
|
||||
// ImageManifest
|
||||
var imageManifestCmd = &cobra.Command{
|
||||
Use: "manifest [user:pass@]hostname[:port]/path:tag",
|
||||
Short: "Show container image manifest info",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.ImageManifest,
|
||||
}
|
||||
subCmd.AddCommand(imageManifestCmd)
|
||||
|
||||
// Imagetags
|
||||
var imageTagsCmd = &cobra.Command{
|
||||
Use: "tags [user:pass@]hostname[:port]/path:tag",
|
||||
Short: "List container tags",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.ImageTags,
|
||||
}
|
||||
subCmd.AddCommand(imageTagsCmd)
|
||||
|
||||
// ImageConfig
|
||||
var imageConfigCmd = &cobra.Command{
|
||||
Use: "config [user:pass@]hostname[:port]/path:tag",
|
||||
Short: "Show container image config info",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.ImageConfig,
|
||||
}
|
||||
subCmd.AddCommand(imageConfigCmd)
|
||||
// CatalogImages
|
||||
var catalogImagesCmd = &cobra.Command{
|
||||
Use: "catalog [user:pass@]hostname[:port]",
|
||||
Short: "List image repositories",
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: util.CatalogImages,
|
||||
}
|
||||
subCmd.AddCommand(catalogImagesCmd)
|
||||
|
||||
return subCmd
|
||||
}
|
||||
|
||||
type ImageUtil struct {
|
||||
imageInfoParams ImageInfoParams
|
||||
imageManifestParams ImageManifestParams
|
||||
imageTagsParams ImageTagsParams
|
||||
imageConfigParams ImageConfigParams
|
||||
catalogImagesParams CatalogImagesParams
|
||||
|
||||
pullImageParams PullImageParams
|
||||
pushImageParams PushImageParams
|
||||
deleteImageParams DeleteImageParams
|
||||
@@ -151,42 +183,6 @@ func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImagePar
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ImageInfo
|
||||
type ImageInfoParams struct {
|
||||
Imagepath string
|
||||
}
|
||||
|
||||
type ImageInfoResult struct {
|
||||
ImageInfo *client.ImageDescr `yaml:"imageInfo"`
|
||||
}
|
||||
|
||||
func (util *ImageUtil) ImageInfo(cmd *cobra.Command, args []string) {
|
||||
util.imageInfoParams.Imagepath = args[0]
|
||||
res, err := util.imageInfo(&util.commonImageParams, &util.imageInfoParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) imageInfo(common *CommonImageParams, params *ImageInfoParams) (*ImageInfoResult, error) {
|
||||
var err error
|
||||
res := &ImageInfoResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
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)
|
||||
opres, err := cli.ImageInfo(ctx, params.Imagepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.ImageInfo = opres
|
||||
return res, err
|
||||
}
|
||||
|
||||
// PullImage
|
||||
type PullImageParams struct {
|
||||
Imagepath string
|
||||
@@ -194,8 +190,8 @@ type PullImageParams struct {
|
||||
}
|
||||
|
||||
type PullImageResult struct {
|
||||
Filepath string `yaml:"filepath"`
|
||||
Size int64 `yaml:"size"`
|
||||
Filepath string `json:"filepath"`
|
||||
Size int64 `json:"size"`
|
||||
}
|
||||
|
||||
func (util *ImageUtil) PullImage(cmd *cobra.Command, args []string) {
|
||||
@@ -265,3 +261,153 @@ func (util *ImageUtil) deleteImage(common *CommonImageParams, params *DeleteImag
|
||||
}
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ImageManifest
|
||||
type ImageManifestParams struct {
|
||||
Imagepath string
|
||||
}
|
||||
|
||||
type ImageManifestResult struct {
|
||||
ImageManifest any `json:"imageManifest"`
|
||||
}
|
||||
|
||||
func (util *ImageUtil) ImageManifest(cmd *cobra.Command, args []string) {
|
||||
util.imageManifestParams.Imagepath = args[0]
|
||||
res, err := util.imageInfo(&util.commonImageParams, &util.imageManifestParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) imageInfo(common *CommonImageParams, params *ImageManifestParams) (*ImageManifestResult, error) {
|
||||
var err error
|
||||
res := &ImageManifestResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
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)
|
||||
opres, err := cli.ImageManifest(ctx, params.Imagepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.ImageManifest = opres
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ImageTags
|
||||
type ImageTagsParams struct {
|
||||
Imagepath string
|
||||
}
|
||||
|
||||
type ImageTagsResult struct {
|
||||
ImageTags []string `json:"imageTags"`
|
||||
}
|
||||
|
||||
func (util *ImageUtil) ImageTags(cmd *cobra.Command, args []string) {
|
||||
util.imageTagsParams.Imagepath = args[0]
|
||||
res, err := util.imageTags(&util.commonImageParams, &util.imageTagsParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) imageTags(common *CommonImageParams, params *ImageTagsParams) (*ImageTagsResult, error) {
|
||||
var err error
|
||||
res := &ImageTagsResult{
|
||||
ImageTags: make([]string, 0),
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
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)
|
||||
opres, err := cli.ImageTags(ctx, params.Imagepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.ImageTags = opres
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ImageConfig
|
||||
type ImageConfigParams struct {
|
||||
Imagepath string
|
||||
}
|
||||
|
||||
type ImageConfigResult struct {
|
||||
ImageConfig *ocispec.Image `json:"imageConfig"`
|
||||
}
|
||||
|
||||
func (util *ImageUtil) ImageConfig(cmd *cobra.Command, args []string) {
|
||||
util.imageConfigParams.Imagepath = args[0]
|
||||
res, err := util.imageConfig(&util.commonImageParams, &util.imageConfigParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) imageConfig(common *CommonImageParams, params *ImageConfigParams) (*ImageConfigResult, error) {
|
||||
var err error
|
||||
res := &ImageConfigResult{
|
||||
ImageConfig: &ocispec.Image{},
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
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)
|
||||
opres, err := cli.ImageConfig(ctx, params.Imagepath)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.ImageConfig = opres
|
||||
return res, err
|
||||
}
|
||||
|
||||
// CatalogImages
|
||||
type CatalogImagesParams struct {
|
||||
Source string
|
||||
}
|
||||
|
||||
type CatalogImagesResult struct {
|
||||
CatalogImages []string `json:"imageConfig"`
|
||||
}
|
||||
|
||||
func (util *ImageUtil) CatalogImages(cmd *cobra.Command, args []string) {
|
||||
util.catalogImagesParams.Source = args[0]
|
||||
res, err := util.catalogImages(&util.commonImageParams, &util.catalogImagesParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) catalogImages(common *CommonImageParams, params *CatalogImagesParams) (*CatalogImagesResult, error) {
|
||||
var err error
|
||||
res := &CatalogImagesResult{
|
||||
CatalogImages: make([]string, 0),
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
cli := client.NewClient(common.SkipTLSVerify)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
|
||||
params.Source, err = packUserinfo(params.Source, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
ctx, _ = context.WithTimeout(ctx, timeout)
|
||||
opres, err := cli.CatalogImages(ctx, params.Source)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
res.CatalogImages = opres
|
||||
return res, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user