client rebuilding in progress
This commit is contained in:
@@ -11,6 +11,8 @@ package command
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
@@ -21,6 +23,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"mstore/pkg/client"
|
||||
"mstore/pkg/repocli"
|
||||
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
@@ -268,33 +271,55 @@ type ImageManifestParams struct {
|
||||
}
|
||||
|
||||
type ImageManifestResult struct {
|
||||
ImageManifest any `json:"imageManifest"`
|
||||
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.imageInfo(&util.commonImageParams, &util.imageManifestParams)
|
||||
res, err := util.imageManifest(&util.commonImageParams, &util.imageManifestParams)
|
||||
printResponse(res, err)
|
||||
}
|
||||
|
||||
func (util *ImageUtil) imageInfo(common *CommonImageParams, params *ImageManifestParams) (*ImageManifestResult, error) {
|
||||
func (util *ImageUtil) imageManifest(common *CommonImageParams, params *ImageManifestParams) (*ImageManifestResult, error) {
|
||||
var err error
|
||||
res := &ImageManifestResult{}
|
||||
ctx := context.Background()
|
||||
|
||||
cli := client.NewClient(common.SkipTLSVerify)
|
||||
timeout := time.Duration(common.Timeout) * time.Second
|
||||
|
||||
res := &ImageManifestResult{
|
||||
Index: &ocispec.Index{},
|
||||
Manifest: &ocispec.Manifest{},
|
||||
}
|
||||
params.Imagepath, err = packUserinfo(params.Imagepath, common.Username, common.Password)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
ctx, _ = context.WithTimeout(ctx, timeout)
|
||||
opres, err := cli.ImageManifest(ctx, params.Imagepath)
|
||||
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
|
||||
}
|
||||
res.ImageManifest = opres
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user