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