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

feat: improve perf json #1539

Merged
merged 4 commits into from
Mar 14, 2024
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
2 changes: 1 addition & 1 deletion .envrc.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export SCAN_DIR=/Users/username/OWASP
export BEARER_DISABLE_VERSION_CHECK=true
export BEARER_DISABLE_DEFAULT_RULES=true
export BEARER_EXTERNAL_RULE_DIR=$PWD/../bearer-rules/rules
export BEARER_FORCE=true
# export BEARER_FORCE=true
# export BEARER_IGNORE_GIT=true
4 changes: 2 additions & 2 deletions .github/workflows/e2e_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
- synchronize
- reopened
paths-ignore:
- 'docs/**'
- "docs/**"
permissions:
contents: read
jobs:
Expand All @@ -23,7 +23,7 @@ jobs:
with:
go-version: 1.21
- name: Build binary for integration tests
run: go build -a -o ./bearer ./cmd/bearer/main.go
run: go build -a ./cmd/bearer/bearer.go
- name: Run tests
run: go test -v ./e2e/... -p 8
timeout-minutes: 10
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/version_comparison.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ on:
workflow_dispatch:
inputs:
baseRef:
description: 'Base CLI ref (tag/branch/SHA)'
description: "Base CLI ref (tag/branch/SHA)"
baseRulesRef:
description: 'Base rules ref'
description: "Base rules ref"
testRef:
description: 'Test CLI ref (tag/branch/SHA)'
description: "Test CLI ref (tag/branch/SHA)"
testRulesRef:
description: 'Test rules ref'
description: "Test rules ref"

jobs:
setup:
Expand All @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4
- id: load_repo_list
name: Load KPI repository list
run : |
run: |
echo "matrix=$(npx --yes json5 ./kpi_scan/kpi_repo_list.json5)" >> $GITHUB_OUTPUT
- name: Set up Go
uses: actions/setup-go@v5
Expand All @@ -49,7 +49,7 @@ jobs:
- name: Build base CLI
run: |
cd ./base-cli
go build -o ../bearer-comparison/base-bearer ./cmd/bearer/main.go
go build -o ../bearer-comparison/base-bearer ./cmd/bearer/bearer.go
- name: Checkout test CLI
uses: actions/checkout@v4
with:
Expand All @@ -65,7 +65,7 @@ jobs:
- name: Build test CLI
run: |
cd ./test-cli
go build -o ../bearer-comparison/test-bearer ./cmd/bearer/main.go
go build -o ../bearer-comparison/test-bearer ./cmd/bearer/bearer.go
- name: Cache CLIs and rules
uses: actions/cache/save@v4
with:
Expand Down Expand Up @@ -113,4 +113,3 @@ jobs:
| jq > test.json
- run: |
diff -u base.json test.json

4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ bearer-build

.DS_Store

# binaries
bearer

temp/

bearer

.envrc
/*.pprof
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/contributing/code.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Finally, we use [direnv](https://direnv.net/) to manage env vars in development.
To run Bearer CLI from source use the following command from the `bearer` directory:

```bash
go run ./cmd/bearer/main.go [COMMAND]
go run ./cmd/bearer/bearer.go [COMMAND]
```

Use commands and flags as normal in place of `[COMMAND]`.
Expand Down
2 changes: 1 addition & 1 deletion e2e/flags/.snapshots/TestOuputFlag
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[{"detector_type":"ruby","source":{"end_column_number":12,"end_line_number":1,"filename":"main.rb","full_filename":"","language":"Ruby","language_type":"programming","start_column_number":8,"start_line_number":1,"text":null},"type":"schema_classified","value":{"classification":{"decision":{"reason":"","state":""},"name":"info"},"field_name":"info","field_type":"","field_type_simple":"unknown","normalized_field_name":"info","normalized_object_name":"logger","object_name":"logger"}},{"detector_type":"ruby","source":{"end_column_number":36,"end_line_number":1,"filename":"main.rb","full_filename":"","language":"Ruby","language_type":"programming","start_column_number":31,"start_line_number":1,"text":null},"type":"schema_classified","value":{"classification":{"data_type":{"category":{"groups":{"172d90e3-cb9a-46b6-90e5-dd7169c3af54":{"name":"PII","uuid":"172d90e3-cb9a-46b6-90e5-dd7169c3af54"},"e1d3135b-3c0f-4b55-abce-19f27a26cbb3":{"name":"Personal Data","uuid":"e1d3135b-3c0f-4b55-abce-19f27a26cbb3"}},"name":"Contact","uuid":"cef587dd-76db-430b-9e18-7b031e1a193b"},"category_uuid":"cef587dd-76db-430b-9e18-7b031e1a193b","name":"Email Address","uuid":"22e24c62-82d3-4b72-827c-e261533331bd"},"decision":{"reason":"known_pattern","state":"valid"},"name":"email","subject_name":"User"},"field_name":"email","field_type":"","field_type_simple":"unknown","normalized_field_name":"email","normalized_object_name":"user","object_name":"user"}},{"filenames":["main.rb"],"type":"file_list"}]
[{"detector_type":"ruby","source":{"end_column_number":36,"end_line_number":1,"filename":"main.rb","full_filename":"","language":"Ruby","language_type":"programming","start_column_number":31,"start_line_number":1,"text":null},"type":"schema_classified","value":{"classification":{"data_type":{"category":{"groups":{"172d90e3-cb9a-46b6-90e5-dd7169c3af54":{"name":"PII","uuid":"172d90e3-cb9a-46b6-90e5-dd7169c3af54"},"e1d3135b-3c0f-4b55-abce-19f27a26cbb3":{"name":"Personal Data","uuid":"e1d3135b-3c0f-4b55-abce-19f27a26cbb3"}},"name":"Contact","uuid":"cef587dd-76db-430b-9e18-7b031e1a193b"},"category_uuid":"cef587dd-76db-430b-9e18-7b031e1a193b","name":"Email Address","uuid":"22e24c62-82d3-4b72-827c-e261533331bd"},"decision":{"reason":"known_pattern","state":"valid"},"name":"email","subject_name":"User"},"field_name":"email","field_type":"","field_type_simple":"unknown","normalized_field_name":"email","normalized_object_name":"user","object_name":"user"}},{"filenames":["main.rb"],"type":"file_list"}]

2 changes: 1 addition & 1 deletion e2e/internal/testhelper/testhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func CreateCommand(arguments []string) (*exec.Cmd, context.CancelFunc) {
if os.Getenv("USE_BINARY") != "" {
cmd = exec.CommandContext(ctx, executablePath(), arguments...)
} else {
arguments = append([]string{"run", GetCWD() + "/cmd/bearer/main.go"}, arguments...)
arguments = append([]string{"run", GetCWD() + "/cmd/bearer/bearer.go"}, arguments...)
cmd = exec.CommandContext(ctx, "go", arguments...)
}

Expand Down
12 changes: 8 additions & 4 deletions internal/report/schema/datatype/datatype.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/bearer/bearer/internal/report/detections"
"github.com/bearer/bearer/internal/report/detectors"
"github.com/bearer/bearer/internal/report/schema"
"github.com/bearer/bearer/internal/util/classify"
"github.com/bearer/bearer/internal/util/normalize_key"
"github.com/bearer/bearer/internal/util/pluralize"
)
Expand Down Expand Up @@ -195,6 +196,10 @@ func dataTypeToSchema[D DataTypable](report detections.ReportDetection, detectio
return
}

if classification, ok := dataType.GetClassification().(classificationschema.Classification); ok && classification.Decision.State != classify.Valid {
return
}

selfUUID := dataType.GetUUID()
if selfUUID == "" {
selfUUID = idGenerator.GenerateId()
Expand All @@ -213,10 +218,9 @@ func dataTypeToSchema[D DataTypable](report detections.ReportDetection, detectio
EndColumnNumber: parent.EndColumnNumber(),
}
}
normalizedObjectName := ""
normalizedFieldName := ""
normalizedObjectName = pluralize.Singular(strings.ToLower(parentName))
normalizedFieldName = pluralize.Singular(strings.ToLower(selfName))

normalizedObjectName := pluralize.Singular(strings.ToLower(parentName))
normalizedFieldName := pluralize.Singular(strings.ToLower(selfName))

report.AddDetection(
detectionType,
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ do_cleanup() {
trap do_cleanup 1 2 3 6

do_info "Building binary..."
go build -a -o ./bearer ./cmd/bearer/main.go || do_error "Failed to build binary"
go build -a ./cmd/bearer/bearer.go || do_error "Failed to build binary"

[ -f bearer ] || do_error "No binary found"

Expand Down
Loading