working commit

This commit is contained in:
2026-03-10 12:52:12 +02:00
parent d0a5fab362
commit d1ef1fbe50
42 changed files with 242 additions and 426 deletions
+6 -7
View File
@@ -15,7 +15,7 @@ import (
"github.com/spf13/cobra"
"mstore/pkg/client"
"mstore/pkg/repocli"
)
// CatalogImages
@@ -38,17 +38,16 @@ func (util *ImageUtil) catalogImages(common *CommonImageParams, params *CatalogI
res := &CatalogImagesResult{
Repositories: make([]string, 0),
}
ctx := context.Background()
cli := client.NewClient(common.SkipTLSVerify)
timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout)
params.Source, err = packUserinfo(params.Source, common.Username, common.Password)
ref, err := repocli.NewReferer(params.Source)
if err != nil {
return res, err
}
ctx, _ = context.WithTimeout(ctx, timeout)
opres, err := cli.CatalogImages(ctx, params.Source)
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
cli := repocli.NewClient(nil, mw)
opres, err := cli.GetCatalog(ctx, ref.Raw())
if err != nil {
return res, err
}
+7 -6
View File
@@ -15,7 +15,7 @@ import (
"github.com/spf13/cobra"
"mstore/pkg/client"
"mstore/pkg/repocli"
)
// DeleteImage
@@ -35,19 +35,20 @@ func (util *ImageUtil) DeleteImage(cmd *cobra.Command, args []string) {
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
ctx, _ := context.WithTimeout(context.Background(), timeout)
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
ref, err := repocli.NewReferer(params.Imagepath)
if err != nil {
return res, err
}
ctx, _ = context.WithTimeout(ctx, timeout)
err = cli.DeleteImage(ctx, params.Imagepath)
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
cli := repocli.NewClient(nil, mw)
_, err = cli.DeleteImage(ctx, ref.Raw())
if err != nil {
return res, err
}
return res, err
}
-59
View File
@@ -1,59 +0,0 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* 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
}
+3 -4
View File
@@ -15,11 +15,10 @@ import (
"fmt"
"time"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/spf13/cobra"
"mstore/pkg/repocli"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// ImageManifest
@@ -55,8 +54,8 @@ func (util *ImageUtil) imageManifest(common *CommonImageParams, params *ImageMan
return res, err
}
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
cli := repocli.NewClientWithTransport(nil, mw)
exists, mime, man, err := cli.GetManifest(ctx, ref.Repo(), ref.Tag())
cli := repocli.NewClient(nil, mw)
exists, mime, man, err := cli.GetRawManifest(ctx, ref.Repo())
if !exists {
err = fmt.Errorf("Manifest not found")
return res, err
+6 -6
View File
@@ -15,7 +15,7 @@ import (
"github.com/spf13/cobra"
"mstore/pkg/client"
"mstore/pkg/repocli"
)
// ImageTags
@@ -38,17 +38,17 @@ func (util *ImageUtil) imageTags(common *CommonImageParams, params *ImageTagsPar
res := &ImageTagsResult{
ImageTags: make([]string, 0),
}
ctx := context.Background()
cli := client.NewClient(common.SkipTLSVerify)
timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout)
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
ref, err := repocli.NewReferer(params.Imagepath)
if err != nil {
return res, err
}
ctx, _ = context.WithTimeout(ctx, timeout)
opres, err := cli.ImageTags(ctx, params.Imagepath)
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
cli := repocli.NewClient(nil, mw)
opres, err := cli.GetTags(ctx, ref.Raw())
if err != nil {
return res, err
}
-65
View File
@@ -1,65 +0,0 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* 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
}
-54
View File
@@ -1,54 +0,0 @@
/*
* Copyright 2026 Oleg Borodin <onborodin@gmail.com>
*
* 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
}