Skip to content

Commit e0e9e8a

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

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

oci.jq

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,52 @@ def sort_manifests:
8787
sort_by(.platform | sort_split_platform)
8888
| sort_attestations
8989
;
90+
91+
def index_type:
92+
if .mediaType != "application/vnd.oci.image.index.v1+json" and .mediaType then # TODO drop the second half of this validation: https://github.com/moby/buildkit/issues/4595
93+
error("unsupported index mediaType: " + .mediaType)
94+
else . end
95+
;
96+
97+
def validate_index_type:
98+
if .schemaVersion != 2 then
99+
error("unsupported schemaVersion: " + .schemaVersion)
100+
else . end
101+
| index_type
102+
;
103+
104+
# jq -s 'include "oci"; validate_oci_basic' dir/oci-layout dir/index.json
105+
def validate_oci_basic:
106+
if length != 2 then
107+
error("Unexpected oci-layout. Expecting 'oci-layout' and 'index.json'")
108+
else . end
109+
| .[0] |= (
110+
if .imageLayoutVersion != "1.0.0" then
111+
error("unsupported imageLayoutVersion: " + .imageLayoutVersion)
112+
else . end
113+
)
114+
| .[1] |= (
115+
. | validate_index_type
116+
| if .manifests | length != 1 then
117+
error("expected only one manifests entry, not " + (.manifests | length | tostring))
118+
else . end
119+
120+
| .manifests[0] |= (
121+
index_type
122+
# TODO validate .digest somehow (`crane validate`?) - would also be good to validate all descriptors recursively
123+
| if .size < 0 then
124+
error("invalid descriptor size: " + .size)
125+
else . end
126+
)
127+
)
128+
;
129+
130+
def imageDigest($os; $arch):
131+
if length != 1 then
132+
error("unexpected image index document count: " + (length | tostring))
133+
else .[0] end
134+
| validate_index_type
135+
| .manifests[]
136+
| select(.platform.os == $os and .platform.architecture == $arch)
137+
| .digest
138+
;

0 commit comments

Comments
 (0)