github.com/opcr-io/oras-go/v2@v2.0.0-20231122155130-eb4260d8a0ae/registry/remote/manifest.go (about) 1 /* 2 Copyright The ORAS Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 package remote 17 18 import ( 19 "strings" 20 21 "github.com/opcr-io/oras-go/v2/internal/docker" 22 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 23 ) 24 25 // defaultManifestMediaTypes contains the default set of manifests media types. 26 var defaultManifestMediaTypes = []string{ 27 docker.MediaTypeManifest, 28 docker.MediaTypeManifestList, 29 ocispec.MediaTypeImageManifest, 30 ocispec.MediaTypeImageIndex, 31 ocispec.MediaTypeArtifactManifest, 32 } 33 34 // defaultManifestAcceptHeader is the default set in the `Accept` header for 35 // resolving manifests from tags. 36 var defaultManifestAcceptHeader = strings.Join(defaultManifestMediaTypes, ", ") 37 38 // isManifest determines if the given descriptor points to a manifest. 39 func isManifest(manifestMediaTypes []string, desc ocispec.Descriptor) bool { 40 if len(manifestMediaTypes) == 0 { 41 manifestMediaTypes = defaultManifestMediaTypes 42 } 43 for _, mediaType := range manifestMediaTypes { 44 if desc.MediaType == mediaType { 45 return true 46 } 47 } 48 return false 49 } 50 51 // manifestAcceptHeader generates the set in the `Accept` header for resolving 52 // manifests from tags. 53 func manifestAcceptHeader(manifestMediaTypes []string) string { 54 if len(manifestMediaTypes) == 0 { 55 return defaultManifestAcceptHeader 56 } 57 return strings.Join(manifestMediaTypes, ", ") 58 }