From 713f5d6b7103cb7e2f0131c8d6615935a9b173ce Mon Sep 17 00:00:00 2001 From: Matthias Glastra Date: Fri, 12 Apr 2024 11:55:32 +0200 Subject: [PATCH] fix: Adjust attestation output to include attestor configuration. Signed-off-by: Matthias Glastra --- attestation/product/product.go | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/attestation/product/product.go b/attestation/product/product.go index cccf21e9..929642ce 100644 --- a/attestation/product/product.go +++ b/attestation/product/product.go @@ -32,7 +32,7 @@ import ( const ( Name = "product" - Type = "https://witness.dev/attestations/product/v0.1" + Type = "https://witness.dev/attestations/product/v0.2" RunType = attestation.ProductRunType defaultIncludeGlob = "*" @@ -103,6 +103,16 @@ type Attestor struct { compiledExcludeGlob glob.Glob } +type attestorJson struct { + Products map[string]attestation.Product `json:"products"` + Configuration attestorConfiguration `json:"configuration"` +} + +type attestorConfiguration struct { + IncludeGlob string `json:"includeGlob"` + ExcludeGlob string `json:"excludeGlob"` +} + func fromDigestMap(digestMap map[string]cryptoutil.DigestSet) map[string]attestation.Product { products := make(map[string]attestation.Product) for fileName, digestSet := range digestMap { @@ -174,16 +184,28 @@ func (a *Attestor) Attest(ctx *attestation.AttestationContext) error { } func (a *Attestor) MarshalJSON() ([]byte, error) { - return json.Marshal(a.products) + output := attestorJson{ + Products: a.products, + Configuration: attestorConfiguration{ + IncludeGlob: a.includeGlob, + ExcludeGlob: a.excludeGlob, + }, + } + + return json.Marshal(output) } func (a *Attestor) UnmarshalJSON(data []byte) error { - prods := make(map[string]attestation.Product) - if err := json.Unmarshal(data, &prods); err != nil { + attestation := attestorJson{ + Products: make(map[string]attestation.Product), + } + if err := json.Unmarshal(data, &attestation); err != nil { return err } - a.products = prods + a.products = attestation.Products + a.includeGlob = attestation.Configuration.IncludeGlob + a.excludeGlob = attestation.Configuration.ExcludeGlob return nil }