From 31fcdca726ae43be11e1d83e871470c96986a46c 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: Thu, 26 Mar 2026 21:08:25 +0200 Subject: [PATCH] working commit --- Makefile.am | 1 + cmd/mstorectl/accountcmd/acccmd.go | 4 ++ cmd/mstorectl/accountcmd/grantcmd.go | 22 ++++++----- cmd/mstorectl/filecmd/filecmd.go | 30 ++++++++------- cmd/mstorectl/imagecmd/imagecmd.go | 57 +++++++++++++++------------- cmd/mstorectl/util/util.go | 23 +++++------ 6 files changed, 77 insertions(+), 60 deletions(-) diff --git a/Makefile.am b/Makefile.am index 95bd42a..c2d7e99 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,3 +1,4 @@ + AUTOMAKE_OPTIONS = foreign no-dependencies no-installinfo SUBDIRS = mans diff --git a/cmd/mstorectl/accountcmd/acccmd.go b/cmd/mstorectl/accountcmd/acccmd.go index dc8d97b..070b5f2 100644 --- a/cmd/mstorectl/accountcmd/acccmd.go +++ b/cmd/mstorectl/accountcmd/acccmd.go @@ -13,6 +13,10 @@ const ( defaultHostname = "localhost:1025" ) +func NewAccountUtil() *AccountUtil { + return &AccountUtil{} +} + type AccountUtil struct { createAccountParams CreateAccountParams updateAccountParams UpdateAccountParams diff --git a/cmd/mstorectl/accountcmd/grantcmd.go b/cmd/mstorectl/accountcmd/grantcmd.go index 60b85a1..3c1ed82 100644 --- a/cmd/mstorectl/accountcmd/grantcmd.go +++ b/cmd/mstorectl/accountcmd/grantcmd.go @@ -8,6 +8,19 @@ import ( "github.com/spf13/viper" ) +type GrantUtil struct { + createGrantParams CreateGrantParams + updateGrantParams UpdateGrantParams + getGrantParams GetGrantParams + deleteGrantParams DeleteGrantParams + listGrantsParams ListGrantsParams + commonGrantParams CommonGrantParams +} + +func NewGrantUtil() *GrantUtil { + return &GrantUtil{} +} + func (util *GrantUtil) MakeGrantCmds() *cobra.Command { var subCmd = &cobra.Command{ Use: "grants", @@ -79,15 +92,6 @@ func (util *GrantUtil) MakeGrantCmds() *cobra.Command { return subCmd } -type GrantUtil struct { - createGrantParams CreateGrantParams - updateGrantParams UpdateGrantParams - getGrantParams GetGrantParams - deleteGrantParams DeleteGrantParams - listGrantsParams ListGrantsParams - commonGrantParams CommonGrantParams -} - type CommonGrantParams struct { Username string Password string diff --git a/cmd/mstorectl/filecmd/filecmd.go b/cmd/mstorectl/filecmd/filecmd.go index b58f6e4..16608ea 100644 --- a/cmd/mstorectl/filecmd/filecmd.go +++ b/cmd/mstorectl/filecmd/filecmd.go @@ -11,6 +11,23 @@ import ( "sigs.k8s.io/yaml" ) +type FileUtil struct { + fileInfoParams FileInfoParams + putFileParams PutFileParams + getFileParams GetFileParams + deleteFileParams DeleteFileParams + listFilesParams ListFilesParams + importFilesParams ImportFilesParams + exportFilesParams ExportFilesParams + deleteCollectionParams DeleteCollectionParams + listCollectionsParams ListCollectionsParams + commonFileParams CommonFileParams +} + +func NewFileUtil() *FileUtil { + return &FileUtil{} +} + func (util *FileUtil) MakeFileCmds() *cobra.Command { var subCmd = &cobra.Command{ Use: "files", @@ -152,19 +169,6 @@ func (util *FileUtil) MakeCollectionCmds() *cobra.Command { return subCmd } -type FileUtil struct { - fileInfoParams FileInfoParams - putFileParams PutFileParams - getFileParams GetFileParams - deleteFileParams DeleteFileParams - listFilesParams ListFilesParams - importFilesParams ImportFilesParams - exportFilesParams ExportFilesParams - deleteCollectionParams DeleteCollectionParams - listCollectionsParams ListCollectionsParams - commonFileParams CommonFileParams -} - type CommonFileParams struct { Username string Password string diff --git a/cmd/mstorectl/imagecmd/imagecmd.go b/cmd/mstorectl/imagecmd/imagecmd.go index ab8a113..6045bd9 100644 --- a/cmd/mstorectl/imagecmd/imagecmd.go +++ b/cmd/mstorectl/imagecmd/imagecmd.go @@ -13,22 +13,18 @@ import ( "github.com/spf13/viper" ) -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 +type ImageUtil struct { + imageManifestParams ImageManifestParams + imageTagsParams ImageTagsParams + catalogImagesParams CatalogImagesParams + pullImageParams PullImageParams + pushImageParams PushImageParams + deleteImageParams DeleteImageParams + commonImageParams CommonImageParams +} + +func NewImageUtil() *ImageUtil { + return &ImageUtil{} } func (util *ImageUtil) CreateImageCmds() *cobra.Command { @@ -114,20 +110,27 @@ func (util *ImageUtil) CreateImageCmds() *cobra.Command { return subCmd } -type ImageUtil struct { - imageManifestParams ImageManifestParams - imageTagsParams ImageTagsParams - catalogImagesParams CatalogImagesParams - - pullImageParams PullImageParams - pushImageParams PushImageParams - deleteImageParams DeleteImageParams - commonImageParams CommonImageParams -} - type CommonImageParams struct { Timeout uint64 Username string Password string SkipTLSVerify bool } + +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 +} diff --git a/cmd/mstorectl/util/util.go b/cmd/mstorectl/util/util.go index e301b44..e57d1e7 100644 --- a/cmd/mstorectl/util/util.go +++ b/cmd/mstorectl/util/util.go @@ -16,12 +16,6 @@ import ( ) type Util struct { - // TODO: delete mixed object and use simple object? - accountcmd.AccountUtil - filecmd.FileUtil - imagecmd.ImageUtil - accountcmd.GrantUtil - rootCmd *cobra.Command } @@ -43,11 +37,18 @@ func (util *Util) Build() error { } rootCmd.CompletionOptions.DisableDefaultCmd = true - rootCmd.AddCommand(util.MakeFileCmds()) - rootCmd.AddCommand(util.MakeCollectionCmds()) - rootCmd.AddCommand(util.CreateImageCmds()) - rootCmd.AddCommand(util.MakeAccountCmds()) - rootCmd.AddCommand(util.MakeGrantCmds()) + fileUtil := filecmd.NewFileUtil() + rootCmd.AddCommand(fileUtil.MakeFileCmds()) + rootCmd.AddCommand(fileUtil.MakeCollectionCmds()) + + imageUtil := imagecmd.NewImageUtil() + rootCmd.AddCommand(imageUtil.CreateImageCmds()) + + accountUtil := accountcmd.NewAccountUtil() + rootCmd.AddCommand(accountUtil.MakeAccountCmds()) + + grantUtil := accountcmd.NewGrantUtil() + rootCmd.AddCommand(grantUtil.MakeGrantCmds()) util.rootCmd = rootCmd