working commit
This commit is contained in:
@@ -1,34 +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 accountcmd
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"path"
|
||||
"strings"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user