Skip to content

Commit

Permalink
workaround defectdojo expecting a non-empty scanstarttime for their e…
Browse files Browse the repository at this point in the history
…ngagments
  • Loading branch information
northdpole committed Oct 31, 2024
1 parent e6c1327 commit 4e4fdb9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions components/consumers/defectdojo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package main
import (
"flag"
"log"
"log/slog"
"strconv"
"time"

v1 "github.com/smithy-security/smithy/api/proto/v1"
"github.com/smithy-security/smithy/components/consumers"
"github.com/smithy-security/smithy/components/consumers/defectdojo/client"
"github.com/smithy-security/smithy/pkg/enumtransformers"
"github.com/smithy-security/smithy/pkg/templating"
"google.golang.org/protobuf/types/known/timestamppb"
)

// DojoTimeFormat is the time format accepted by defect dojo.
Expand All @@ -27,6 +30,14 @@ var (
issueTemplate string
)

func getEngagementTime(engagementTime *timestamppb.Timestamp, scanID string) string {
if time.Time.IsZero(engagementTime.AsTime()) {
slog.Error("sanStartTime is zero for scan", slog.String("id", scanID))
engagementTime = timestamppb.New(time.Now())
}
return engagementTime.AsTime().Format(DojoTimeFormat)
}

func handleRawResults(product int, dojoClient *client.Client, responses []*v1.LaunchToolResponse) error {
if len(responses) == 0 {
log.Println("No tool responses provided")
Expand All @@ -39,7 +50,7 @@ func handleRawResults(product int, dojoClient *client.Client, responses []*v1.La
tags := []string{"SmithyScan", "RawScan", scanUUID}

engagement, err := dojoClient.CreateEngagement( // with current architecture, all responses should have the same scaninfo
scanUUID, responses[0].GetScanInfo().GetScanStartTime().AsTime().Format(DojoTimeFormat), tags, int32(product))
scanUUID, getEngagementTime(responses[0].GetScanInfo().GetScanStartTime(), responses[0].GetScanInfo().ScanUuid), tags, int32(product))
if err != nil {
return err
}
Expand Down Expand Up @@ -91,9 +102,9 @@ func handleEnrichedResults(product int, dojoClient *client.Client, responses []*
log.Fatalln("Non-uuid scan", responses)
}
tags := []string{"SmithyScan", "EnrichedScan", scanUUID}

engagement, err := dojoClient.CreateEngagement( // with current architecture, all responses should have the same scaninfo
scanUUID,
responses[0].GetOriginalResults().GetScanInfo().GetScanStartTime().AsTime().Format(DojoTimeFormat), tags, int32(product))
scanUUID, getEngagementTime(responses[0].GetOriginalResults().GetScanInfo().GetScanStartTime(), responses[0].GetOriginalResults().GetScanInfo().ScanUuid), tags, int32(product))
if err != nil {
log.Println("could not create Engagement, err:", err)
return err
Expand Down

0 comments on commit 4e4fdb9

Please sign in to comment.