Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/oras/root/manifest/index/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ func enrichDescriptor(ctx context.Context, target oras.ReadOnlyTarget, desc ocis
return ocispec.Descriptor{}, err
}
desc.ArtifactType = manifest.ArtifactType
if desc.ArtifactType == "" && manifest.Config.MediaType != ocispec.MediaTypeImageConfig {
// Old-style artifacts predate the manifest artifactType field and
// convey their type through config.mediaType instead. Per the
// image-spec descriptor guidance, fall back to config.mediaType so
// the enriched descriptor still advertises an artifactType.
desc.ArtifactType = manifest.Config.MediaType
}
Comment thread
TerryHowe marked this conversation as resolved.
Outdated
} else if descriptor.IsIndex(desc) {
var index ocispec.Index
if err := json.Unmarshal(manifestBytes, &index); err != nil {
Expand Down
48 changes: 48 additions & 0 deletions cmd/oras/root/manifest/index/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,54 @@ func Test_enrichDescriptor(t *testing.T) {
},
wantErr: false,
},
{
name: "old-style artifact, artifactType falls back to config mediaType",
target: NewTestReadOnlyTarget(`intentionally not valid JSON`),
manifestBytes: []byte(`
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.example.config",
"digest": "sha256:dc889043956f34871cc04ae96e03efc29dfe2f582c26195a72dd4827f4dd830d",
"size": 28
},
"layers": []
}
`),
manifestMediaType: "application/vnd.oci.image.manifest.v1+json",
checkDesc: func(t *testing.T, gotDesc, _ ocispec.Descriptor) {
t.Helper()
if got, want := gotDesc.ArtifactType, "application/vnd.example.config"; got != want {
t.Errorf("ArtifactType = %s, want %s", got, want)
}
},
wantErr: false,
},
{
name: "empty artifactType with standard config type stays empty",
target: NewTestReadOnlyTarget(`intentionally not valid JSON`),
manifestBytes: []byte(`
{
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"digest": "sha256:dc889043956f34871cc04ae96e03efc29dfe2f582c26195a72dd4827f4dd830d",
"size": 28
},
"layers": []
}
`),
manifestMediaType: "application/vnd.oci.image.manifest.v1+json",
checkDesc: func(t *testing.T, gotDesc, _ ocispec.Descriptor) {
t.Helper()
if got, want := gotDesc.ArtifactType, ""; got != want {
t.Errorf("ArtifactType = %q, want empty", got)
}
},
wantErr: false,
},
{
name: "child of unrecognized type",
target: NewTestReadOnlyTarget("(unused)"),
Expand Down