Skip to content

Commit

Permalink
Send SBOM w/ xeol.io event (#83)
Browse files Browse the repository at this point in the history
Signed-off-by: Benji Visser <benji@093b.org>
  • Loading branch information
noqcks authored Jul 25, 2023
1 parent 4d68006 commit f9638b7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
13 changes: 13 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package cmd

import (
"bytes"
"encoding/base64"
"errors"
"fmt"
"os"
"sync"
"time"

"github.com/CycloneDX/cyclonedx-go"
"github.com/anchore/stereoscope"
"github.com/anchore/syft/syft/formats/common/cyclonedxhelpers"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/syft/syft/source"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -322,12 +326,21 @@ func startWorker(userInput string, failOnEolFound bool, eolMatchDate time.Time)
}

if appConfig.APIKey != "" {
buf := new(bytes.Buffer)
bom := cyclonedxhelpers.ToFormatModel(*sbom)
enc := cyclonedx.NewBOMEncoder(buf, cyclonedx.BOMFileFormatJSON)
if err := enc.Encode(bom); err != nil {
errs <- fmt.Errorf("failed to encode sbom: %w", err)
return
}

if err := x.SendEvent(report.XeolEventPayload{
Matches: allMatches.Sorted(),
Packages: packages,
Context: pkgContext,
AppConfig: appConfig,
ImageName: sbom.Source.ImageMetadata.UserInput,
Sbom: base64.StdEncoding.EncodeToString(buf.Bytes()),
}); err != nil {
errs <- fmt.Errorf("failed to send eol event: %w", err)
return
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/xeol-io/xeol
go 1.18

require (
github.com/CycloneDX/cyclonedx-go v0.7.1
github.com/Masterminds/semver v1.5.0
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
github.com/adrg/xdg v0.4.0
Expand Down Expand Up @@ -56,7 +57,6 @@ require (
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
cloud.google.com/go/storage v1.28.1 // indirect
github.com/CycloneDX/cyclonedx-go v0.7.1 // indirect
github.com/DataDog/zstd v1.4.5 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions xeol/report/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ type XeolEventPayload struct {
Context pkg.Context
AppConfig interface{}
ImageName string
Sbom string
}

0 comments on commit f9638b7

Please sign in to comment.