Skip to content

Commit

Permalink
chore: Add conditional configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Glastra <[email protected]>
  • Loading branch information
matglas authored and jkjell committed Aug 11, 2024
1 parent dbd93f6 commit 67bd420
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
15 changes: 11 additions & 4 deletions attestation/material/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 17 additions & 13 deletions attestation/product/product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -117,21 +117,17 @@ 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 {
IncludeGlob string `json:"includeGlob"`
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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 67bd420

Please sign in to comment.