Skip to content

Commit 66de8b5

Browse files
committed
jsonl -> json
1 parent 7d4945c commit 66de8b5

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

utils/convert_attestations.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828
bundle_path = Path(sys.argv[1])
2929
signer_identity = sys.argv[2]
3030

31-
for line in bundle_path.read_bytes().splitlines():
32-
dsse_envelope_payload = json.loads(line)['dsseEnvelope']['payload']
33-
subjects = json.loads(b64decode(dsse_envelope_payload))['subject']
34-
for subject in subjects:
35-
filename = subject['name']
36-
assert (DIST / filename).is_file()
37-
38-
# Convert attestation from Sigstore to PEP 740
39-
print(f'Converting attestation for {filename}')
40-
sigstore_bundle = Bundle.from_json(line)
41-
attestation = Attestation.from_bundle(sigstore_bundle)
42-
attestation_path = DIST / f'{filename}.publish.attestation'
43-
attestation_path.write_text(attestation.model_dump_json())
44-
print(f'Attestation for {filename} written to {attestation_path}')
45-
print()
46-
47-
# Validate attestation
48-
dist = Distribution.from_file(DIST / filename)
49-
attestation = Attestation.model_validate_json(attestation_path.read_bytes())
50-
identity = Identity(identity=signer_identity)
51-
attestation.verify(identity=identity, dist=dist)
52-
print(f'Verified {attestation_path}')
31+
bundle_content = bundle_path.read_bytes()
32+
dsse_envelope_payload = json.loads(bundle_content)['dsseEnvelope']['payload']
33+
subjects = json.loads(b64decode(dsse_envelope_payload))['subject']
34+
for subject in subjects:
35+
filename = subject['name']
36+
assert (DIST / filename).is_file()
37+
38+
# Convert attestation from Sigstore to PEP 740
39+
print(f'Converting attestation for {filename}')
40+
sigstore_bundle = Bundle.from_json(bundle_content)
41+
attestation = Attestation.from_bundle(sigstore_bundle)
42+
attestation_path = DIST / f'{filename}.publish.attestation'
43+
attestation_path.write_text(attestation.model_dump_json())
44+
print(f'Attestation for {filename} written to {attestation_path}')
45+
print()
46+
47+
# Validate attestation
48+
dist = Distribution.from_file(DIST / filename)
49+
attestation = Attestation.model_validate_json(attestation_path.read_bytes())
50+
identity = Identity(identity=signer_identity)
51+
attestation.verify(identity=identity, dist=dist)
52+
print(f'Verified {attestation_path}')

0 commit comments

Comments
 (0)