Skip to content

Commit

Permalink
fix: Adjust attestation output to include attestor configuration.
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Glastra <[email protected]>
  • Loading branch information
matglas committed Apr 12, 2024
1 parent 45f5f10 commit 3e451ed
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions attestation/product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "*"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 3e451ed

Please sign in to comment.