reorder some source files

This commit is contained in:
2026-03-11 09:54:17 +02:00
parent 30fe237657
commit f4c9948c61
27 changed files with 283 additions and 2403 deletions
+59
View File
@@ -0,0 +1,59 @@
/*
* 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/gcrcli"
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 := gcrcli.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
}
+65
View File
@@ -0,0 +1,65 @@
/*
* 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/gcrcli"
)
// 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 := gcrcli.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
@@ -0,0 +1,54 @@
/*
* 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/gcrcli"
)
// 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 := gcrcli.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
}
+2 -2
View File
@@ -49,13 +49,13 @@ func (util *ImageUtil) imageManifest(common *CommonImageParams, params *ImageMan
}
timeout := time.Duration(common.Timeout) * time.Second
ctx, _ := context.WithTimeout(context.Background(), timeout)
ref, err := repocli.ParseReference(params.Imagepath)
ref, err := repocli.NewReferer(params.Imagepath)
if err != nil {
return res, err
}
mw := repocli.NewBasicAuthMiddleware(ref.Userinfo())
cli := repocli.NewClient(nil, mw)
exists, mime, man, err := cli.GetRawManifest(ctx, ref.Repo())
exists, mime, man, _, err := cli.GetRawManifest(ctx, ref.RawRepo())
if !exists {
err = fmt.Errorf("Manifest not found")
return res, err
+2 -1
View File
@@ -10,12 +10,13 @@
package main
import (
"mstore/cmd/mstorectl/util"
"os"
)
func main() {
var err error
util := NewUtil()
util := util.NewUtil()
err = util.Build()
if err != nil {
os.Exit(1)
@@ -7,7 +7,7 @@
* Distribution of this work is permitted, but commercial use and
* modifications are strictly prohibited.
*/
package main
package util
import (
"fmt"