From 4801aa26cf42ef12ef87c9e9f7af78a2538f8d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D0=B5=D0=B3=20=D0=91=D0=BE=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD?= Date: Mon, 9 Mar 2026 12:37:54 +0200 Subject: [PATCH] working commit --- Makefile.am | 4 - Makefile.in | 10 +- app/config/variant.go | 2 +- cmd/mstorectl/imagecmd/catimages.go | 57 ++++++ cmd/mstorectl/imagecmd/delimage.go | 53 +++++ cmd/mstorectl/imagecmd/imagecmd.go | 296 ---------------------------- cmd/mstorectl/imagecmd/imageconf.go | 59 ++++++ cmd/mstorectl/imagecmd/imageman.go | 81 ++++++++ cmd/mstorectl/imagecmd/imagetags.go | 57 ++++++ cmd/mstorectl/imagecmd/pullimage.go | 65 ++++++ cmd/mstorectl/imagecmd/pushimage.go | 54 +++++ pkg/client/{ => attic}/account.go | 0 pkg/client/{ => attic}/grant.go | 0 pkg/client/{ => attic}/httpcall.go | 0 pkg/client/{ => attic}/service.go | 0 15 files changed, 431 insertions(+), 307 deletions(-) create mode 100644 cmd/mstorectl/imagecmd/catimages.go create mode 100644 cmd/mstorectl/imagecmd/delimage.go create mode 100644 cmd/mstorectl/imagecmd/imageconf.go create mode 100644 cmd/mstorectl/imagecmd/imageman.go create mode 100644 cmd/mstorectl/imagecmd/imagetags.go create mode 100644 cmd/mstorectl/imagecmd/pullimage.go create mode 100644 cmd/mstorectl/imagecmd/pushimage.go rename pkg/client/{ => attic}/account.go (100%) rename pkg/client/{ => attic}/grant.go (100%) rename pkg/client/{ => attic}/httpcall.go (100%) rename pkg/client/{ => attic}/service.go (100%) diff --git a/Makefile.am b/Makefile.am index d897a67..28e2348 100644 --- a/Makefile.am +++ b/Makefile.am @@ -150,17 +150,13 @@ EXTRA_mstored_SOURCES += \ pkg/auxutar/utar.go \ pkg/auxuuid/uuid.go \ pkg/auxx509/x509cert.go \ - pkg/client/account.go \ pkg/client/client.go \ - pkg/client/grant.go \ - pkg/client/httpcall.go \ pkg/client/imageaux.go \ pkg/client/imagedelete.go \ pkg/client/imageinfo.go \ pkg/client/imagepull.go \ pkg/client/imagepush.go \ pkg/client/servaux.go \ - pkg/client/service.go \ pkg/descr/account.go \ pkg/descr/blob.go \ pkg/descr/file.go \ diff --git a/Makefile.in b/Makefile.in index 80f9673..a73ce35 100644 --- a/Makefile.in +++ b/Makefile.in @@ -432,12 +432,10 @@ EXTRA_mstored_SOURCES = cmd/mstored/starter/starter.go \ pkg/auxtool/fileex.go pkg/auxtool/randstr.go \ pkg/auxtool/tmpfile.go pkg/auxtool/unixnow.go \ pkg/auxutar/utar.go pkg/auxuuid/uuid.go \ - pkg/auxx509/x509cert.go pkg/client/account.go \ - pkg/client/client.go pkg/client/grant.go \ - pkg/client/httpcall.go pkg/client/imageaux.go \ - pkg/client/imagedelete.go pkg/client/imageinfo.go \ - pkg/client/imagepull.go pkg/client/imagepush.go \ - pkg/client/servaux.go pkg/client/service.go \ + pkg/auxx509/x509cert.go pkg/client/client.go \ + pkg/client/imageaux.go pkg/client/imagedelete.go \ + pkg/client/imageinfo.go pkg/client/imagepull.go \ + pkg/client/imagepush.go pkg/client/servaux.go \ pkg/descr/account.go pkg/descr/blob.go pkg/descr/file.go \ pkg/descr/grant.go pkg/descr/manifest.go pkg/descr/server.go \ pkg/digest/digest.go pkg/filecli/authbas.go \ diff --git a/app/config/variant.go b/app/config/variant.go index 39b7e57..e6225b5 100644 --- a/app/config/variant.go +++ b/app/config/variant.go @@ -6,5 +6,5 @@ const ( logdir = "/home/ziggi/mstore2/tmp/log" datadir = "/home/ziggi/mstore2/tmp/data" version = "0.2.0" - srvname = "mstored" + srvname = "mstored" ) diff --git a/cmd/mstorectl/imagecmd/catimages.go b/cmd/mstorectl/imagecmd/catimages.go new file mode 100644 index 0000000..61dbdb1 --- /dev/null +++ b/cmd/mstorectl/imagecmd/catimages.go @@ -0,0 +1,57 @@ +/* + * 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" + "time" + + "github.com/spf13/cobra" + + "mstore/pkg/client" +) + +// CatalogImages +type CatalogImagesParams struct { + Source string +} + +type CatalogImagesResult struct { + Repositories []string `json:"repositories"` +} + +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{ + Repositories: 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.Repositories = opres + return res, err +} diff --git a/cmd/mstorectl/imagecmd/delimage.go b/cmd/mstorectl/imagecmd/delimage.go new file mode 100644 index 0000000..d88b1b4 --- /dev/null +++ b/cmd/mstorectl/imagecmd/delimage.go @@ -0,0 +1,53 @@ +/* + * 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" + "time" + + "github.com/spf13/cobra" + + "mstore/pkg/client" +) + +// DeleteImage +type DeleteImageParams struct { + Imagepath string +} + +type DeleteImageResult struct { +} + +func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) { + util.deleteImageParams.Imagepath = args[0] + res, err := util.deleteImage(&util.commonImageParams, &util.deleteImageParams) + printResponse(res, err) +} + +func (util *ImageUtil) deleteImage(common *CommonImageParams, params *DeleteImageParams) (*DeleteImageResult, error) { + var err error + res := &DeleteImageResult{} + 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) + err = cli.DeleteImage(ctx, params.Imagepath) + if err != nil { + return res, err + } + return res, err +} diff --git a/cmd/mstorectl/imagecmd/imagecmd.go b/cmd/mstorectl/imagecmd/imagecmd.go index 464eea1..bf0b71f 100644 --- a/cmd/mstorectl/imagecmd/imagecmd.go +++ b/cmd/mstorectl/imagecmd/imagecmd.go @@ -10,22 +10,12 @@ package imagecmd import ( - "context" - "encoding/json" - "fmt" "net/url" - "os" "path" "strings" - "time" "github.com/spf13/cobra" "github.com/spf13/viper" - - "mstore/pkg/client" - "mstore/pkg/repocli" - - ocispec "github.com/opencontainers/image-spec/specs-go/v1" ) func packUserinfo(resurseuri, username, password string) (string, error) { @@ -150,289 +140,3 @@ type CommonImageParams struct { Password string SkipTLSVerify bool } - -// PushImage -type PushImageParams struct { - Imagepath string - Filepath string -} - -type PushImageResult struct{} - -func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) { - util.pushImageParams.Filepath = args[0] - util.pushImageParams.Imagepath = args[1] - - res, err := util.pushImage(&util.commonImageParams, &util.pushImageParams) - printResponse(res, err) -} - -func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImageParams) (*PushImageResult, error) { - var err error - ctx := context.Background() - res := &PushImageResult{} - - 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.PushImage(ctx, params.Filepath, params.Imagepath) - if err != nil { - return res, err - } - return res, err -} - -// 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 -} - -// DeleteImage -type DeleteImageParams struct { - Imagepath string -} - -type DeleteImageResult struct { -} - -func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) { - util.deleteImageParams.Imagepath = args[0] - res, err := util.deleteImage(&util.commonImageParams, &util.deleteImageParams) - printResponse(res, err) -} - -func (util *ImageUtil) deleteImage(common *CommonImageParams, params *DeleteImageParams) (*DeleteImageResult, error) { - var err error - res := &DeleteImageResult{} - 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) - err = cli.DeleteImage(ctx, params.Imagepath) - if err != nil { - return res, err - } - return res, err -} - -// ImageManifest -type ImageManifestParams struct { - Imagepath string -} - -type ImageManifestResult struct { - Index *ocispec.Index `json:"index,omitempty"` - Manifest *ocispec.Manifest `json:"manifest,omitempty"` -} - -func (util *ImageUtil) ImageManifest(cmd *cobra.Command, args []string) { - util.imageManifestParams.Imagepath = args[0] - res, err := util.imageManifest(&util.commonImageParams, &util.imageManifestParams) - printResponse(res, err) -} - -func (util *ImageUtil) imageManifest(common *CommonImageParams, params *ImageManifestParams) (*ImageManifestResult, error) { - var err error - res := &ImageManifestResult{ - Index: &ocispec.Index{}, - Manifest: &ocispec.Manifest{}, - } - params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password) - if err != nil { - return res, err - } - timeout := time.Duration(common.Timeout) * time.Second - ctx, _ := context.WithTimeout(context.Background(), timeout) - ref, err := repocli.ParseReference(params.Imagepath) - if err != nil { - return res, err - } - mw := repocli.NewBasicAuthMiddleware(ref.Userinfo()) - cli := repocli.NewClientWithTransport(nil, mw) - exists, mime, man, err := cli.GetManifest(ctx, ref.Repo(), ref.Tag()) - if !exists { - err = fmt.Errorf("Manifest not found") - return res, err - - } - switch mime { - case repocli.MediaTypeDDMLv2, repocli.MediaTypeOIIv1: - err = json.Unmarshal(man, res.Index) - if err != nil { - return res, err - } - case repocli.MediaTypeDDMv2, repocli.MediaTypeOIMv1: - err = json.Unmarshal(man, res.Manifest) - if err != nil { - return res, err - } - default: - err = fmt.Errorf("Unknown content type: %s", mime) - return res, err - } - 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 { - Repositories []string `json:"repositories"` -} - -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{ - Repositories: 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.Repositories = opres - return res, err -} diff --git a/cmd/mstorectl/imagecmd/imageconf.go b/cmd/mstorectl/imagecmd/imageconf.go new file mode 100644 index 0000000..2fd5dd7 --- /dev/null +++ b/cmd/mstorectl/imagecmd/imageconf.go @@ -0,0 +1,59 @@ +/* + * 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" + "time" + + "github.com/spf13/cobra" + + "mstore/pkg/client" + + ocispec "github.com/opencontainers/image-spec/specs-go/v1" +) + +// 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 +} diff --git a/cmd/mstorectl/imagecmd/imageman.go b/cmd/mstorectl/imagecmd/imageman.go new file mode 100644 index 0000000..e13db87 --- /dev/null +++ b/cmd/mstorectl/imagecmd/imageman.go @@ -0,0 +1,81 @@ +/* + * 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" + "encoding/json" + "fmt" + "time" + + "github.com/spf13/cobra" + + "mstore/pkg/repocli" + + ocispec "github.com/opencontainers/image-spec/specs-go/v1" +) + +// ImageManifest +type ImageManifestParams struct { + Imagepath string +} + +type ImageManifestResult struct { + Index *ocispec.Index `json:"index,omitempty"` + Manifest *ocispec.Manifest `json:"manifest,omitempty"` +} + +func (util *ImageUtil) ImageManifest(cmd *cobra.Command, args []string) { + util.imageManifestParams.Imagepath = args[0] + res, err := util.imageManifest(&util.commonImageParams, &util.imageManifestParams) + printResponse(res, err) +} + +func (util *ImageUtil) imageManifest(common *CommonImageParams, params *ImageManifestParams) (*ImageManifestResult, error) { + var err error + res := &ImageManifestResult{ + Index: &ocispec.Index{}, + Manifest: &ocispec.Manifest{}, + } + params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password) + if err != nil { + return res, err + } + timeout := time.Duration(common.Timeout) * time.Second + ctx, _ := context.WithTimeout(context.Background(), timeout) + ref, err := repocli.ParseReference(params.Imagepath) + if err != nil { + return res, err + } + mw := repocli.NewBasicAuthMiddleware(ref.Userinfo()) + cli := repocli.NewClientWithTransport(nil, mw) + exists, mime, man, err := cli.GetManifest(ctx, ref.Repo(), ref.Tag()) + if !exists { + err = fmt.Errorf("Manifest not found") + return res, err + + } + switch mime { + case repocli.MediaTypeDDMLv2, repocli.MediaTypeOIIv1: + err = json.Unmarshal(man, res.Index) + if err != nil { + return res, err + } + case repocli.MediaTypeDDMv2, repocli.MediaTypeOIMv1: + err = json.Unmarshal(man, res.Manifest) + if err != nil { + return res, err + } + default: + err = fmt.Errorf("Unknown content type: %s", mime) + return res, err + } + return res, err +} diff --git a/cmd/mstorectl/imagecmd/imagetags.go b/cmd/mstorectl/imagecmd/imagetags.go new file mode 100644 index 0000000..500eb4e --- /dev/null +++ b/cmd/mstorectl/imagecmd/imagetags.go @@ -0,0 +1,57 @@ +/* + * 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" + "time" + + "github.com/spf13/cobra" + + "mstore/pkg/client" +) + +// 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 +} diff --git a/cmd/mstorectl/imagecmd/pullimage.go b/cmd/mstorectl/imagecmd/pullimage.go new file mode 100644 index 0000000..35a6b84 --- /dev/null +++ b/cmd/mstorectl/imagecmd/pullimage.go @@ -0,0 +1,65 @@ +/* + * 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 +} diff --git a/cmd/mstorectl/imagecmd/pushimage.go b/cmd/mstorectl/imagecmd/pushimage.go new file mode 100644 index 0000000..803521e --- /dev/null +++ b/cmd/mstorectl/imagecmd/pushimage.go @@ -0,0 +1,54 @@ +/* + * 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" + "time" + + "github.com/spf13/cobra" + + "mstore/pkg/client" +) + +// PushImage +type PushImageParams struct { + Imagepath string + Filepath string +} + +type PushImageResult struct{} + +func (util *ImageUtil) PushImage(cmd *cobra.Command, args []string) { + util.pushImageParams.Filepath = args[0] + util.pushImageParams.Imagepath = args[1] + + res, err := util.pushImage(&util.commonImageParams, &util.pushImageParams) + printResponse(res, err) +} + +func (util *ImageUtil) pushImage(common *CommonImageParams, params *PushImageParams) (*PushImageResult, error) { + var err error + ctx := context.Background() + res := &PushImageResult{} + + 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.PushImage(ctx, params.Filepath, params.Imagepath) + if err != nil { + return res, err + } + return res, err +} diff --git a/pkg/client/account.go b/pkg/client/attic/account.go similarity index 100% rename from pkg/client/account.go rename to pkg/client/attic/account.go diff --git a/pkg/client/grant.go b/pkg/client/attic/grant.go similarity index 100% rename from pkg/client/grant.go rename to pkg/client/attic/grant.go diff --git a/pkg/client/httpcall.go b/pkg/client/attic/httpcall.go similarity index 100% rename from pkg/client/httpcall.go rename to pkg/client/attic/httpcall.go diff --git a/pkg/client/service.go b/pkg/client/attic/service.go similarity index 100% rename from pkg/client/service.go rename to pkg/client/attic/service.go