-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Labels
enhancementIncremental improvement to existing featuresIncremental improvement to existing features
Description
I have started using Witness to produce attestations for builds, and now I would like to be able to parse those attestations to extract relevant metadata to display in other systems.
I didn't really know where to start so I looked into in-toto spec and landed on:
Parsing the attestation.Collection
feels very tedious, and I hope there is a better way.
// parse the manifest envelope
var envelope dsse.Envelope
err := json.Unmarshal(att, &envelope)
if err != nil {
return fmt.Errorf("failed to artefact: %w", err)
}
if envelope.PayloadType != "application/vnd.in-toto+json" {
return fmt.Errorf("cant't decode payload type %s", envelope.PayloadType)
}
var statement intoto.Statement
err = protojson.Unmarshal(envelope.Payload, &statement)
if err != nil {
return fmt.Errorf("failed to unmarshal statement payload: %w", err)
}
if statement.PredicateType != attestation.CollectionType {
return fmt.Errorf("expected '%s' type, got %s", attestation.CollectionType, statement.PredicateType)
}
jsonPredicate, err := statement.Predicate.MarshalJSON()
if err != nil {
return fmt.Errorf("failed to remarshal predicate: %w", err)
}
var collection attestation.Collection
err = json.Unmarshal(jsonPredicate, &collection)
if err != nil {
return fmt.Errorf("failed to collection predicate: %w", err)
}
Even at that point, I was not able to directly parse individual attestation because of the following error:
failed to collection predicate: attestation not found: https://witness.dev/attestations/gitlab/v0.1
This seems to be caused by the attestationsByType
map being empty.
All this leads me to deliver that this is not the intended way to parse attestation with the library.
Metadata
Metadata
Assignees
Labels
enhancementIncremental improvement to existing featuresIncremental improvement to existing features