Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update detector type when classification #1149

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion new/detector/composition/java/java.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
java "github.com/bearer/bearer/new/language/implementation/java"
"github.com/bearer/bearer/new/language/tree"
languagetypes "github.com/bearer/bearer/new/language/types"
reporttypes "github.com/bearer/bearer/pkg/report/detectors"
)

type Composition struct {
Expand Down Expand Up @@ -112,7 +113,7 @@ func New(
}()
}

detector, err := datatype.New(lang, classifier.Schema)
detector, err := datatype.New(reporttypes.DetectorJava, lang, classifier.Schema)
if err != nil {
composition.Close()
return nil, fmt.Errorf("failed to create datatype detector: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion new/detector/composition/javascript/javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/bearer/bearer/new/language/implementation/javascript"
"github.com/bearer/bearer/new/language/tree"
languagetypes "github.com/bearer/bearer/new/language/types"
reporttypes "github.com/bearer/bearer/pkg/report/detectors"
)

type Composition struct {
Expand Down Expand Up @@ -112,7 +113,7 @@ func New(
}()
}

detector, err := datatype.New(lang, classifier.Schema)
detector, err := datatype.New(reporttypes.DetectorJavascript, lang, classifier.Schema)
if err != nil {
composition.Close()
return nil, fmt.Errorf("failed to create datatype detector: %s", err)
Expand Down
3 changes: 2 additions & 1 deletion new/detector/composition/ruby/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/bearer/bearer/new/language/implementation/ruby"
"github.com/bearer/bearer/new/language/tree"
languagetypes "github.com/bearer/bearer/new/language/types"
reporttypes "github.com/bearer/bearer/pkg/report/detectors"
)

type Composition struct {
Expand Down Expand Up @@ -111,7 +112,7 @@ func New(
}()
}

detector, err := datatype.New(lang, classifier.Schema)
detector, err := datatype.New(reporttypes.DetectorRuby, lang, classifier.Schema)
if err != nil {
composition.Close()
return nil, fmt.Errorf("failed to create datatype detector: %s", err)
Expand Down
12 changes: 7 additions & 5 deletions new/detector/implementation/generic/datatype/datatype.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ type Property struct {
}

type datatypeDetector struct {
detectorType detectors.Type
types.DetectorBase
classifier *classificationschema.Classifier
}

func New(lang languagetypes.Language, classifier *classificationschema.Classifier) (types.Detector, error) {
func New(detectorType detectors.Type, lang languagetypes.Language, classifier *classificationschema.Classifier) (types.Detector, error) {
return &datatypeDetector{
classifier: classifier,
detectorType: detectorType,
classifier: classifier,
}, nil
}

Expand Down Expand Up @@ -73,7 +75,7 @@ func (detector *datatypeDetector) classifyObject(
) (Data, classificationschema.Classification, bool) {
objectData := detection.Data.(generictypes.Object)

classification := detector.classifier.Classify(buildClassificationRequest(filename, name, objectData))
classification := detector.classifier.Classify(buildClassificationRequest(detector.detectorType, filename, name, objectData))
containsValidClassification := classification.Classification.Decision.State == classify.Valid

properties := make([]Property, len(objectData.Properties))
Expand Down Expand Up @@ -140,7 +142,7 @@ func (detector *datatypeDetector) classifyProperty(
containsValidClassification || propertyClassification.Decision.State == classify.Valid
}

func buildClassificationRequest(filename, name string, data generictypes.Object) classificationschema.ClassificationRequest {
func buildClassificationRequest(detectorType detectors.Type, filename, name string, data generictypes.Object) classificationschema.ClassificationRequest {
var properties []*classificationschema.ClassificationRequestDetection

for _, property := range data.Properties {
Expand All @@ -156,7 +158,7 @@ func buildClassificationRequest(filename, name string, data generictypes.Object)
SimpleType: schema.SimpleTypeUnknown,
Properties: properties,
},
DetectorType: detectors.DetectorRuby,
DetectorType: detectorType,
Filename: filename,
}
}