Skip to content

Commit a723aed

Browse files
Add OCI functions fort signing
1 parent c394a5a commit a723aed

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

oci.jq

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,51 @@ def sort_manifests:
8787
sort_by(.platform | sort_split_platform)
8888
| sort_attestations
8989
;
90+
91+
# https://github.com/opencontainers/image-spec/blob/v1.1.0/image-index.md
92+
def validate_oci_index_media_type:
93+
if . != "application/vnd.oci.image.index.v1+json" then
94+
error("unsupported index mediaType: \(.)")
95+
else . end
96+
;
97+
98+
def validate_oci_index:
99+
if .schemaVersion != 2 then
100+
error("unsupported index schemaVersion: \(.schemaVersion)")
101+
else . end
102+
| .mediaType
103+
|= if . then # TODO drop this conditional (BuildKit 0.14+): https://github.com/moby/buildkit/issues/4595
104+
validate_oci_index_media_type
105+
else . end
106+
;
107+
108+
# https://github.com/opencontainers/image-spec/blob/v1.1.0/image-layout.md#oci-layout-file
109+
def validate_oci_layout_file:
110+
if .imageLayoutVersion != "1.0.0" then
111+
error("unsupported imageLayoutVersion: \(.imageLayoutVersion)")
112+
else . end
113+
;
114+
115+
# https://github.com/opencontainers/image-spec/blob/v1.1.0/image-layout.md#indexjson-file
116+
def validate_oci_layout_index:
117+
validate_oci_index
118+
| .manifests
119+
| if length != 1 then
120+
error("expected only one manifests entry, not \(length)")
121+
else . end
122+
| .[0]
123+
| if .size < 0 then
124+
error("invalid descriptor size: \(.size)")
125+
else . end
126+
# TODO validate .digest somehow (`crane validate`?) - would also be good to validate all descriptors recursively
127+
| .mediaType | validate_oci_index_media_type
128+
;
129+
130+
# input: array of 'oci-layout' file contents followed by 'index.json' file contents (`jq -s 'validate_oci_layout' dir/oci-layout dir/index.json`)
131+
def validate_oci_layout:
132+
if length != 2 then
133+
error("unexpected input: expecting single-document 'oci-layout' and 'index.json'")
134+
else . end
135+
| .[0] |= validate_oci_layout_file
136+
| .[1] |= validate_oci_layout_index
137+
;

0 commit comments

Comments
 (0)