diff --git a/attestation/material/material.go b/attestation/material/material.go index 7806d299..8f61d117 100644 --- a/attestation/material/material.go +++ b/attestation/material/material.go @@ -176,10 +176,17 @@ func (a *Attestor) Attest(ctx *attestation.AttestationContext) error { func (a *Attestor) MarshalJSON() ([]byte, error) { output := attestorJson{ Materials: a.materials, - Configuration: attestorConfiguration{ - IncludeGlob: a.includeGlob, - ExcludeGlob: a.excludeGlob, - }, + } + + if a.includeGlob != "" || a.excludeGlob != "" { + config := attestorConfiguration{} + + if a.includeGlob != "" { + config.IncludeGlob = a.includeGlob + } + if a.excludeGlob != "" { + config.ExcludeGlob = a.excludeGlob + } } return json.Marshal(output) diff --git a/attestation/product/product.go b/attestation/product/product.go index f61e3b08..465c003f 100644 --- a/attestation/product/product.go +++ b/attestation/product/product.go @@ -31,9 +31,9 @@ import ( ) const ( - Name = "product" - Type = "https://witness.dev/attestations/product/v0.2" - RunType = attestation.ProductRunType + ProductName = "product" + ProductType = "https://witness.dev/attestations/product/v0.2" + ProductRunType = attestation.ProductRunType defaultIncludeGlob = "*" defaultExcludeGlob = "" @@ -117,12 +117,9 @@ type Attestor struct { compiledExcludeGlob glob.Glob } -<<<<<<< HEAD -func fromDigestMap(workingDir string, digestMap map[string]cryptoutil.DigestSet) map[string]attestation.Product { -======= type attestorJson struct { Products map[string]attestation.Product `json:"products"` - Configuration *attestorConfiguration `json:"configuration,omitempty"` + Configuration *attestorConfiguration `json:"configuration,omitempty"` } type attestorConfiguration struct { @@ -130,8 +127,7 @@ type attestorConfiguration struct { ExcludeGlob string `json:"excludeGlob"` } -func fromDigestMap(digestMap map[string]cryptoutil.DigestSet) map[string]attestation.Product { ->>>>>>> 3ae6278 (fix: Adjust attestation output to include attestor configuration.) +func fromDigestMap(workingDir string, digestMap map[string]cryptoutil.DigestSet) map[string]attestation.Product { products := make(map[string]attestation.Product) for fileName, digestSet := range digestMap { filePath := filepath.Join(workingDir, fileName) @@ -225,10 +221,18 @@ func (a *Attestor) Attest(ctx *attestation.AttestationContext) error { func (a *Attestor) MarshalJSON() ([]byte, error) { output := attestorJson{ Products: a.products, - Configuration: attestorConfiguration{ - IncludeGlob: a.includeGlob, - ExcludeGlob: a.excludeGlob, - }, + } + + if a.includeGlob != "" || a.excludeGlob != "" { + config := attestorConfiguration{} + + if a.includeGlob != "" { + config.IncludeGlob = a.includeGlob + } + if a.excludeGlob != "" { + config.ExcludeGlob = a.excludeGlob + } + output.Configuration = &config } return json.Marshal(output)