mirror of https://github.com/docker/cli.git
Merge pull request #4541 from thaJeztah/cli_registry_cleanup
cli/registry/client: remove some redundant conditions
This commit is contained in:
commit
28dfb13e39
|
@ -31,17 +31,9 @@ func fetchManifest(ctx context.Context, repo distribution.Repository, ref refere
|
||||||
switch v := manifest.(type) {
|
switch v := manifest.(type) {
|
||||||
// Removed Schema 1 support
|
// Removed Schema 1 support
|
||||||
case *schema2.DeserializedManifest:
|
case *schema2.DeserializedManifest:
|
||||||
imageManifest, err := pullManifestSchemaV2(ctx, ref, repo, *v)
|
return pullManifestSchemaV2(ctx, ref, repo, *v)
|
||||||
if err != nil {
|
|
||||||
return types.ImageManifest{}, err
|
|
||||||
}
|
|
||||||
return imageManifest, nil
|
|
||||||
case *ocischema.DeserializedManifest:
|
case *ocischema.DeserializedManifest:
|
||||||
imageManifest, err := pullManifestOCISchema(ctx, ref, repo, *v)
|
return pullManifestOCISchema(ctx, ref, repo, *v)
|
||||||
if err != nil {
|
|
||||||
return types.ImageManifest{}, err
|
|
||||||
}
|
|
||||||
return imageManifest, nil
|
|
||||||
case *manifestlist.DeserializedManifestList:
|
case *manifestlist.DeserializedManifestList:
|
||||||
return types.ImageManifest{}, errors.Errorf("%s is a manifest list", ref)
|
return types.ImageManifest{}, errors.Errorf("%s is a manifest list", ref)
|
||||||
}
|
}
|
||||||
|
@ -56,11 +48,7 @@ func fetchList(ctx context.Context, repo distribution.Repository, ref reference.
|
||||||
|
|
||||||
switch v := manifest.(type) {
|
switch v := manifest.(type) {
|
||||||
case *manifestlist.DeserializedManifestList:
|
case *manifestlist.DeserializedManifestList:
|
||||||
imageManifests, err := pullManifestList(ctx, ref, repo, *v)
|
return pullManifestList(ctx, ref, repo, *v)
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return imageManifests, nil
|
|
||||||
default:
|
default:
|
||||||
return nil, errors.Errorf("unsupported manifest format: %v", v)
|
return nil, errors.Errorf("unsupported manifest format: %v", v)
|
||||||
}
|
}
|
||||||
|
@ -154,11 +142,8 @@ func validateManifestDigest(ref reference.Named, mfst distribution.Manifest) (oc
|
||||||
}
|
}
|
||||||
|
|
||||||
// If pull by digest, then verify the manifest digest.
|
// If pull by digest, then verify the manifest digest.
|
||||||
if digested, isDigested := ref.(reference.Canonical); isDigested {
|
if digested, isDigested := ref.(reference.Canonical); isDigested && digested.Digest() != desc.Digest {
|
||||||
if digested.Digest() != desc.Digest {
|
return ocispec.Descriptor{}, errors.Errorf("manifest verification failed for digest %s", digested.Digest())
|
||||||
err := errors.Errorf("manifest verification failed for digest %s", digested.Digest())
|
|
||||||
return ocispec.Descriptor{}, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return desc, nil
|
return desc, nil
|
||||||
|
@ -167,12 +152,11 @@ func validateManifestDigest(ref reference.Named, mfst distribution.Manifest) (oc
|
||||||
// pullManifestList handles "manifest lists" which point to various
|
// pullManifestList handles "manifest lists" which point to various
|
||||||
// platform-specific manifests.
|
// platform-specific manifests.
|
||||||
func pullManifestList(ctx context.Context, ref reference.Named, repo distribution.Repository, mfstList manifestlist.DeserializedManifestList) ([]types.ImageManifest, error) {
|
func pullManifestList(ctx context.Context, ref reference.Named, repo distribution.Repository, mfstList manifestlist.DeserializedManifestList) ([]types.ImageManifest, error) {
|
||||||
infos := []types.ImageManifest{}
|
|
||||||
|
|
||||||
if _, err := validateManifestDigest(ref, mfstList); err != nil {
|
if _, err := validateManifestDigest(ref, mfstList); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infos := make([]types.ImageManifest, 0, len(mfstList.Manifests))
|
||||||
for _, manifestDescriptor := range mfstList.Manifests {
|
for _, manifestDescriptor := range mfstList.Manifests {
|
||||||
manSvc, err := repo.Manifests(ctx)
|
manSvc, err := repo.Manifests(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -217,12 +201,12 @@ func continueOnError(err error) bool {
|
||||||
}
|
}
|
||||||
return continueOnError(v[0])
|
return continueOnError(v[0])
|
||||||
case errcode.Error:
|
case errcode.Error:
|
||||||
e := err.(errcode.Error)
|
switch e := err.(errcode.Error); e.Code {
|
||||||
switch e.Code {
|
|
||||||
case errcode.ErrorCodeUnauthorized, v2.ErrorCodeManifestUnknown, v2.ErrorCodeNameUnknown:
|
case errcode.ErrorCodeUnauthorized, v2.ErrorCodeManifestUnknown, v2.ErrorCodeNameUnknown:
|
||||||
return true
|
return true
|
||||||
|
default:
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
case *distclient.UnexpectedHTTPResponseError:
|
case *distclient.UnexpectedHTTPResponseError:
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue