Skip to content

Commit

Permalink
add content to dataflow
Browse files Browse the repository at this point in the history
  • Loading branch information
cfabianski committed Nov 15, 2024
1 parent 995f697 commit 5d30fdc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion pkg/report/output/dataflow/risks/risks.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (holder *Holder) AddRiskPresence(detection detections.Detection) {
StartColumnNumber: *detection.Source.StartColumnNumber,
EndLineNumber: *detection.Source.EndLineNumber,
EndColumnNumber: *detection.Source.EndColumnNumber,
Content: &content,
}
} else {
// parent can be nil
Expand Down Expand Up @@ -194,7 +195,7 @@ func (holder *Holder) addDatatype(
// create datatype source entry if it doesn't exist
sourceKey := "undefined_source"
if schema.Source != nil {
sourceKey = schema.Source.Content
sourceKey = *schema.Source.Content
}

if _, exists := line.source[sourceKey]; !exists {
Expand Down
2 changes: 2 additions & 0 deletions pkg/report/schema/datatype/datatype.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ func dataTypeToSchema[D DataTypable](report detections.ReportDetection, detectio
var sourceSchema *schema.Source

if parent != nil {
parentContent := parent.Content()
sourceSchema = &schema.Source{
Content: &parentContent,
StartLineNumber: parent.StartLineNumber(),
StartColumnNumber: parent.StartColumnNumber(),
EndLineNumber: parent.EndLineNumber(),
Expand Down
10 changes: 5 additions & 5 deletions pkg/report/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ type Schema struct {

type Source struct {
// This is the starting line number, the very beginning of what's used by the custom detection
StartLineNumber int `json:"start_line_number,omitempty" yaml:"start_line_number,omitempty"`
StartColumnNumber int `json:"start_column_number,omitempty" yaml:"start_column_number,omitempty"`
EndLineNumber int `json:"end_line_number,omitempty" yaml:"end_line_number,omitempty"`
EndColumnNumber int `json:"end_column_number,omitempty" yaml:"end_column_number,omitempty"`
Content string `json:"content,omitempty" yaml:"content,omitempty"`
StartLineNumber int `json:"start_line_number,omitempty" yaml:"start_line_number,omitempty"`
StartColumnNumber int `json:"start_column_number,omitempty" yaml:"start_column_number,omitempty"`
EndLineNumber int `json:"end_line_number,omitempty" yaml:"end_line_number,omitempty"`
EndColumnNumber int `json:"end_column_number,omitempty" yaml:"end_column_number,omitempty"`
Content *string `json:"content,omitempty" yaml:"content,omitempty"`
}

type ReportSchema interface {
Expand Down
9 changes: 6 additions & 3 deletions pkg/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (scanner *Scanner) Scan(
}

for _, detection := range expectedDetections {
value := ""
detectorType := detectors.Type(detection.RuleID)
report.AddDetection(reportdetections.TypeExpectedDetection,
detectorType,
Expand All @@ -82,7 +83,7 @@ func (scanner *Scanner) Scan(
EndLineNumber: detection.MatchNode.ContentEnd.Line,
StartColumnNumber: detection.MatchNode.ContentStart.Column,
EndColumnNumber: detection.MatchNode.ContentEnd.Column,
Content: "",
Content: &value,
})
}

Expand Down Expand Up @@ -113,7 +114,7 @@ func (scanner *Scanner) Scan(
EndLineNumber: detection.MatchNode.ContentEnd.Line,
StartColumnNumber: detection.MatchNode.ContentStart.Column,
EndColumnNumber: detection.MatchNode.ContentEnd.Column,
Content: value,
Content: &value,
})
}

Expand Down Expand Up @@ -144,6 +145,8 @@ func reportDatatypeDetection(
data := datatypeDetection.Data.(datatype.Data)

for _, property := range data.Properties {
detectionContent := detection.MatchNode.Content()

report.AddDetection(
reportdetections.TypeCustomClassified,
detectorType,
Expand All @@ -167,7 +170,7 @@ func reportDatatypeDetection(
EndLineNumber: detection.MatchNode.ContentEnd.Line,
StartColumnNumber: detection.MatchNode.ContentStart.Column,
EndColumnNumber: detection.MatchNode.ContentEnd.Column,
Content: detection.MatchNode.Content(),
Content: &detectionContent,
},
},
)
Expand Down

0 comments on commit 5d30fdc

Please sign in to comment.