Skip to content

Commit

Permalink
chore: make engine pluggable
Browse files Browse the repository at this point in the history
  • Loading branch information
didroe committed May 30, 2024
1 parent 184316e commit 0b3a04a
Show file tree
Hide file tree
Showing 1,736 changed files with 3,221 additions and 2,912 deletions.
2 changes: 1 addition & 1 deletion .envrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export GOOGLE_APP=''
export REDIS_INIT="true"
export GOOGLE_MAX_ATTEMPT="5"
export BEARER_EXECUTABLE_PATH="./bearer"
export GITHUB_WORKSPACE="/path/to/bearer/project"
export GITHUB_WORKSPACE="$PWD"
export SCAN_DIR=/Users/username/OWASP
export BEARER_DISABLE_VERSION_CHECK=true
export BEARER_DISABLE_DEFAULT_RULES=true
Expand Down
10 changes: 2 additions & 8 deletions cmd/bearer/bearer.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package main

import (
"os"

"github.com/bearer/bearer/cmd/bearer/build"
"github.com/bearer/bearer/internal/commands"
"github.com/bearer/bearer/external/run"
)

func main() {
app := commands.NewApp(build.Version, build.CommitSHA)
if err := app.Execute(); err != nil {
// error messages are printed by the framework
os.Exit(1)
}
run.Run(build.Version, build.CommitSHA, run.NewEngine(run.DefaultLanguages()))
}
2 changes: 1 addition & 1 deletion e2e/flags/report_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"

"github.com/bearer/bearer/e2e/internal/testhelper"
"github.com/bearer/bearer/internal/util/tmpfile"
"github.com/bearer/bearer/pkg/util/tmpfile"
"github.com/bradleyjkemp/cupaloy"
)

Expand Down
97 changes: 97 additions & 0 deletions external/run/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package run

import (
"os"
"regexp"

"github.com/bearer/bearer/pkg/classification/schema"
"github.com/bearer/bearer/pkg/commands"
"github.com/bearer/bearer/pkg/engine"
"github.com/bearer/bearer/pkg/engine/implementation"
"github.com/bearer/bearer/pkg/languages"
"github.com/bearer/bearer/pkg/scanner/ast/query"
"github.com/bearer/bearer/pkg/scanner/ast/tree"
"github.com/bearer/bearer/pkg/scanner/detectors/common"
"github.com/bearer/bearer/pkg/scanner/detectors/types"
"github.com/bearer/bearer/pkg/scanner/language"
"github.com/bearer/bearer/pkg/scanner/ruleset"
"github.com/bearer/bearer/pkg/util/regex"
"github.com/bearer/bearer/pkg/util/stringutil"
)

type Object = common.Object
type Property = common.Property
type String = common.String

type Engine = engine.Engine

type Analyzer = language.Analyzer
type Language = language.Language
type Pattern = language.Pattern
type PatternBase = language.PatternBase
type PatternVariable = language.PatternVariable
type Scope = language.Scope

type Query = query.Query
type Set = query.Set

type Rule = ruleset.Rule

type Classifier = schema.Classifier

type Builder = tree.Builder
type Node = tree.Node

type Context = types.Context
type Detection = types.Detection
type Detector = types.Detector
type DetectorBase = types.DetectorBase

var BuiltinObjectRule = ruleset.BuiltinObjectRule
var BuiltinStringRule = ruleset.BuiltinStringRule

func GetNonVirtualObjects(detectorContext types.Context, node *tree.Node) ([]*types.Detection, error) {
return common.GetNonVirtualObjects(detectorContext, node)
}

func StripQuotes(input string) string {
return stringutil.StripQuotes(input)
}

func ConcatenateChildStrings(node *tree.Node, detectorContext types.Context) ([]interface{}, error) {
return common.ConcatenateChildStrings(node, detectorContext)
}

func ConcatenateAssignEquals(node *tree.Node, detectorContext types.Context) ([]interface{}, error) {
return common.ConcatenateAssignEquals(node, detectorContext)
}

func ProjectObject(node *tree.Node, detectorContext types.Context, objectNode *tree.Node, objectName string, propertyName string, isPropertyAccess bool) ([]interface{}, error) {
return common.ProjectObject(node, detectorContext, objectNode, objectName, propertyName, isPropertyAccess)
}

func ReplaceAllWithSubmatches(pattern *regexp.Regexp, input string, replace func(submatches []string) (string, error)) (string, error) {
return regex.ReplaceAllWithSubmatches(pattern, input, replace)
}

func NewScope(parent *language.Scope) *language.Scope {
return language.NewScope(parent)
}

func NewEngine(languages []Language) Engine {
return implementation.New(languages)
}

func DefaultLanguages() []Language {
return languages.Default()
}

func Run(version, commitSHA string, engine Engine) {
err := commands.NewApp(version, commitSHA, engine).Execute()
engine.Close()

if err != nil {
// error messages are printed by the framework
os.Exit(1)
}
}
26 changes: 0 additions & 26 deletions internal/commands/process/settings/regexp.go

This file was deleted.

142 changes: 0 additions & 142 deletions internal/commands/process/settings/ruleLoader.go

This file was deleted.

68 changes: 0 additions & 68 deletions internal/commands/process/settings/ruleValidator.go

This file was deleted.

Loading

0 comments on commit 0b3a04a

Please sign in to comment.