github.com/dtroyer-salad/og2/v2@v2.0.0-20240412154159-c47231610877/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 ocispec "github.com/opencontainers/image-spec/specs-go/v1" 22 "oras.land/oras-go/v2/internal/docker" 23 "oras.land/oras-go/v2/internal/spec" 24 ) 25 26 // defaultManifestMediaTypes contains the default set of manifests media types. 27 var defaultManifestMediaTypes = []string{ 28 docker.MediaTypeManifest, 29 docker.MediaTypeManifestList, 30 ocispec.MediaTypeImageManifest, 31 ocispec.MediaTypeImageIndex, 32 spec.MediaTypeArtifactManifest, 33 } 34 35 // defaultManifestAcceptHeader is the default set in the `Accept` header for 36 // resolving manifests from tags. 37 var defaultManifestAcceptHeader = strings.Join(defaultManifestMediaTypes, ", ") 38 39 // isManifest determines if the given descriptor points to a manifest. 40 func isManifest(manifestMediaTypes []string, desc ocispec.Descriptor) bool { 41 if len(manifestMediaTypes) == 0 { 42 manifestMediaTypes = defaultManifestMediaTypes 43 } 44 for _, mediaType := range manifestMediaTypes { 45 if desc.MediaType == mediaType { 46 return true 47 } 48 } 49 return false 50 } 51 52 // manifestAcceptHeader generates the set in the `Accept` header for resolving 53 // manifests from tags. 54 func manifestAcceptHeader(manifestMediaTypes []string) string { 55 if len(manifestMediaTypes) == 0 { 56 return defaultManifestAcceptHeader 57 } 58 return strings.Join(manifestMediaTypes, ", ") 59 }