Skip to content

Commit 47e7b7c

Browse files
authored
Split out detector types into separate proto file in order to narrow CODEOWNERS scope (#4871)
We want to move the detector types out of the Scanning team purview. So I split off detector types into its own proto file (so that file detector_type.proto can be owned by the Integrations team), regenerated the pb files with "make protos", and made the detector files use the new generated detector_type.pb.go. Included the new detector_type.proto file in CODEOWNERS and made CODEOWNERS categories that contain larger teams be towards the top so that more fine grained ownership is filtered properly.
1 parent 9bfdb3e commit 47e7b7c

File tree

1,802 files changed

+12190
-12062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,802 files changed

+12190
-12062
lines changed

CODEOWNERS

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# catch-all
22
* @trufflesecurity/product-eng
33

4+
# Shared
5+
pkg/decoders/ @trufflesecurity/Scanning @trufflesecurity/OSS
6+
pkg/engine/ @trufflesecurity/Scanning @trufflesecurity/OSS
7+
pkg/gitparse/ @trufflesecurity/Scanning @trufflesecurity/OSS
8+
pkg/giturl/ @trufflesecurity/Scanning @trufflesecurity/OSS
9+
pkg/handlers/ @trufflesecurity/Scanning @trufflesecurity/OSS
10+
pkg/iobuf/ @trufflesecurity/Scanning @trufflesecurity/OSS
11+
pkg/sanitizer/ @trufflesecurity/Scanning @trufflesecurity/OSS
12+
proto/ @trufflesecurity/Scanning @trufflesecurity/Integrations
13+
414
# Scanning
515
pkg/sources/ @trufflesecurity/Scanning
616
pkg/writers/ @trufflesecurity/Scanning
@@ -18,16 +28,7 @@ pkg/sources/jenkins/ @trufflesecurity/Integrations
1828
pkg/sources/postman/ @trufflesecurity/Integrations
1929
pkg/sources/s3/ @trufflesecurity/Integrations
2030
pkg/sources/travisci/ @trufflesecurity/Integrations
21-
22-
# Shared
23-
pkg/decoders/ @trufflesecurity/Scanning @trufflesecurity/OSS
24-
pkg/engine/ @trufflesecurity/Scanning @trufflesecurity/OSS
25-
pkg/gitparse/ @trufflesecurity/Scanning @trufflesecurity/OSS
26-
pkg/giturl/ @trufflesecurity/Scanning @trufflesecurity/OSS
27-
pkg/handlers/ @trufflesecurity/Scanning @trufflesecurity/OSS
28-
pkg/iobuf/ @trufflesecurity/Scanning @trufflesecurity/OSS
29-
pkg/sanitizer/ @trufflesecurity/Scanning @trufflesecurity/OSS
30-
proto/ @trufflesecurity/Scanning @trufflesecurity/Integrations
31+
proto/detector_type.proto @trufflesecurity/Integrations
3132

3233
# OSS
3334
pkg/detectors/ @trufflesecurity/OSS

hack/docs/Adding_Detectors_Internal.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Note: Be sure to update the tests to reference the new secret values in GSM, or
6363

6464
### Creating a new Secret Scanner
6565

66-
1. Identify the Secret Detector name from the [/proto/detectors.proto](/proto/detectors.proto) `DetectorType` enum.
66+
1. Identify the Secret Detector name from the [/proto/detector_type.proto](/proto/detector_type.proto) `DetectorType` enum.
6767

6868
2. Generate the Secret Detector
6969

@@ -154,7 +154,7 @@ Do not embed test credentials in the test code. Instead, use GCP Secrets Manager
154154
```bash
155155
dos2unix ./scripts/gen_proto.sh
156156
```
157-
5. Open [/proto/detectors.proto](/proto/detectors.proto) file and add new detectors then save it. Make sure Docker is running and run this in Ubuntu command line.
157+
5. Open [/proto/detector_type.proto](/proto/detector_type.proto) file and add new detectors then save it. Make sure Docker is running and run this in Ubuntu command line.
158158
```bash
159159
make protos
160160
```

hack/docs/Adding_Detectors_external.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Note: Be sure to update the tests to reference the new secret values in GSM, or
5959

6060
### Creating a new Secret Detector
6161

62-
1. Add a new Secret Detector enum to the [`DetectorType` list here](/proto/detectors.proto).
62+
1. Add a new Secret Detector enum to the [`DetectorType` list here](/proto/detector_type.proto).
6363

6464
2. Run `make protos` to update the `.pb` files.
6565

@@ -71,7 +71,7 @@ Note: Be sure to update the tests to reference the new secret values in GSM, or
7171
```
7272
4. Add the Secret Detector to TruffleHog's Default Detectors
7373

74-
Add the secret scanner to the [`pkg/engine/defaults/defaults.go`](https://github.com/trufflesecurity/trufflehog/blob/main/pkg/engine/defaults/defaults.go) file like [`github.com/trufflesecurity/trufflehog/v3/pkg/detectors/<detector_name>`](https://github.com/trufflesecurity/trufflehog/blob/b71ea27a696bdf1c3141f637fda4ee4936c2f2d6/pkg/engine/defaults/defaults.go#L9) and
74+
Add the secret scanner to the [`pkg/engine/defaults/defaults.go`](https://github.com/trufflesecurity/trufflehog/blob/main/pkg/engine/defaults/defaults.go) file like [`github.com/trufflesecurity/trufflehog/v3/pkg/detectors/<detector_name>`](https://github.com/trufflesecurity/trufflehog/blob/b71ea27a696bdf1c3141f637fda4ee4936c2f2d6/pkg/engine/defaults/defaults.go#L9) and
7575
[`<detector_name>.Scanner{}`](https://github.com/trufflesecurity/trufflehog/blob/b71ea27a696bdf1c3141f637fda4ee4936c2f2d6/pkg/engine/defaults/defaults.go#L1546)
7676

7777
5. Complete the Secret Detector.
@@ -117,15 +117,15 @@ To ensure the quality of your PR, make sure your tests are passing with verified
117117
4. Found and unverified (indeterminately due to an unexpected API response)
118118
5. Not found
119119

120-
Make any necessary updates to the tests. Note there might not be any changes required as the tests generated by the `go run hack/generate/generate.go` command are pretty good.
120+
Make any necessary updates to the tests. Note there might not be any changes required as the tests generated by the `go run hack/generate/generate.go` command are pretty good.
121121
[Here is an exemplary test file for a detector which covers all 5 test cases](https://github.com/trufflesecurity/trufflehog/blob/6f9065b0aae981133a7fa3431c17a5c6213be226/pkg/detectors/browserstack/browserstack_test.go).
122122

123123
4. Now run the tests and check to make sure they are passing ✔️!
124124
```bash
125125
go test ./pkg/detectors/<detector> -tags=detectors
126126
```
127127

128-
If the tests are passing, feel free to open a PR!
128+
If the tests are passing, feel free to open a PR!
129129

130130

131131

@@ -157,8 +157,7 @@ For example, consider a hypothetical authentication endpoint that returns `200 O
157157
```bash
158158
dos2unix ./scripts/gen_proto.sh
159159
```
160-
5. Open [/proto/detectors.proto](/proto/detectors.proto) file and add new detectors then save it. Make sure Docker is running and run this in Ubuntu command line.
160+
5. Open [/proto/detector_type.proto](/proto/detector_type.proto) file and add new detectors then save it. Make sure Docker is running and run this in Ubuntu command line.
161161
```bash
162162
make protos
163163
```
164-

pkg/config/detectors.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import (
88
"strings"
99

1010
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
11-
dpb "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
11+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
1212
)
1313

1414
var (
1515
specialGroups = map[string][]DetectorID{
1616
"all": allDetectors(),
1717
}
1818

19-
detectorTypeValue = make(map[string]dpb.DetectorType, len(dpb.DetectorType_value))
20-
validDetectors = make(map[dpb.DetectorType]struct{}, len(dpb.DetectorType_value))
21-
maxDetectorType dpb.DetectorType
19+
detectorTypeValue = make(map[string]detector_typepb.DetectorType, len(detector_typepb.DetectorType_value))
20+
validDetectors = make(map[detector_typepb.DetectorType]struct{}, len(detector_typepb.DetectorType_value))
21+
maxDetectorType detector_typepb.DetectorType
2222
)
2323

2424
// Setup package local global variables.
2525
func init() {
26-
for k, v := range dpb.DetectorType_value {
27-
dt := dpb.DetectorType(v)
26+
for k, v := range detector_typepb.DetectorType_value {
27+
dt := detector_typepb.DetectorType(v)
2828
detectorTypeValue[strings.ToLower(k)] = dt
2929
validDetectors[dt] = struct{}{}
3030
if dt > maxDetectorType {
@@ -37,7 +37,7 @@ func init() {
3737
// way for users to identify detectors, whether unique or not. A DetectorID
3838
// with Version = 0 indicates all possible versions of a detector.
3939
type DetectorID struct {
40-
ID dpb.DetectorType
40+
ID detector_typepb.DetectorType
4141
Version int
4242
}
4343

@@ -117,7 +117,7 @@ func ParseVerifierEndpoints(verifierURLs map[string]string) (map[DetectorID][]st
117117
}
118118

119119
func (id DetectorID) String() string {
120-
name := dpb.DetectorType_name[int32(id.ID)]
120+
name := detector_typepb.DetectorType_name[int32(id.ID)]
121121
if name == "" {
122122
name = "<invalid ID>"
123123
}
@@ -129,9 +129,9 @@ func (id DetectorID) String() string {
129129

130130
// allDetectors returns an ordered slice of all detector types.
131131
func allDetectors() []DetectorID {
132-
all := make([]DetectorID, 0, len(dpb.DetectorType_name))
133-
for id := range dpb.DetectorType_name {
134-
all = append(all, DetectorID{ID: dpb.DetectorType(id)})
132+
all := make([]DetectorID, 0, len(detector_typepb.DetectorType_name))
133+
for id := range detector_typepb.DetectorType_name {
134+
all = append(all, DetectorID{ID: detector_typepb.DetectorType(id)})
135135
}
136136
sort.Slice(all, func(i, j int) bool { return all[i].ID < all[j].ID })
137137
return all
@@ -173,7 +173,7 @@ func asRange(input string) ([]DetectorID, error) {
173173
return nil, fmt.Errorf("versions within ranges are not supported: %s", input)
174174
}
175175

176-
step := dpb.DetectorType(1)
176+
step := detector_typepb.DetectorType(1)
177177
if dtStart.ID > dtEnd.ID {
178178
step = -1
179179
}
@@ -212,7 +212,7 @@ func asDetectorID(input string) (DetectorID, error) {
212212
}
213213
// Check if it's a detector ID.
214214
if i, err := strconv.ParseInt(input, 10, 32); err == nil {
215-
dt := dpb.DetectorType(i)
215+
dt := detector_typepb.DetectorType(i)
216216
if _, ok := validDetectors[dt]; !ok {
217217
return DetectorID{}, fmt.Errorf("invalid detector ID: %s", input)
218218
}

pkg/config/detectors_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"testing"
55

66
"github.com/stretchr/testify/assert"
7-
dpb "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
7+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
88
)
99

1010
func TestDetectorParsing(t *testing.T) {
@@ -15,22 +15,22 @@ func TestDetectorParsing(t *testing.T) {
1515
"all": {"AlL", allDetectors()},
1616
"trailing range": {"0-", allDetectors()},
1717
"all after 1": {"1-", allDetectors()[1:]},
18-
"named and valid range": {"aWs,8-9", []DetectorID{{ID: dpb.DetectorType_AWS}, {ID: dpb.DetectorType_Github}, {ID: dpb.DetectorType_Gitlab}}},
18+
"named and valid range": {"aWs,8-9", []DetectorID{{ID: detector_typepb.DetectorType_AWS}, {ID: detector_typepb.DetectorType_Github}, {ID: detector_typepb.DetectorType_Gitlab}}},
1919
"duplicate order preserved": {"9, 8, 9", []DetectorID{{ID: 9}, {ID: 8}}},
20-
"named range": {"github - gitlab", []DetectorID{{ID: dpb.DetectorType_Github}, {ID: dpb.DetectorType_Gitlab}}},
20+
"named range": {"github - gitlab", []DetectorID{{ID: detector_typepb.DetectorType_Github}, {ID: detector_typepb.DetectorType_Gitlab}}},
2121
"range preserved": {"8-9, 7-10", []DetectorID{{ID: 8}, {ID: 9}, {ID: 7}, {ID: 10}}},
2222
"reverse range": {"9-8", []DetectorID{{ID: 9}, {ID: 8}}},
2323
"range preserved with all": {"10-,all", append(allDetectors()[10:], allDetectors()[:10]...)},
2424
"empty list item": {"8, ,9", []DetectorID{{ID: 8}, {ID: 9}}},
2525
"invalid end range": {"0-1337", nil},
2626
"invalid name": {"foo", nil},
2727
"negative": {"-1", nil},
28-
"github.v1": {"github.v1", []DetectorID{{ID: dpb.DetectorType_Github, Version: 1}}},
29-
"gitlab.v100": {"gitlab.v100", []DetectorID{{ID: dpb.DetectorType_Gitlab, Version: 100}}},
28+
"github.v1": {"github.v1", []DetectorID{{ID: detector_typepb.DetectorType_Github, Version: 1}}},
29+
"gitlab.v100": {"gitlab.v100", []DetectorID{{ID: detector_typepb.DetectorType_Gitlab, Version: 100}}},
3030
"range with versions": {"github.v2 - gitlab.v1", nil},
3131
"invalid version no v": {"gitlab.2", nil},
3232
"invalid version no number": {"gitlab.github", nil},
33-
"capital V is fine": {"GiTlAb.V2", []DetectorID{{ID: dpb.DetectorType_Gitlab, Version: 2}}},
33+
"capital V is fine": {"GiTlAb.V2", []DetectorID{{ID: detector_typepb.DetectorType_Gitlab, Version: 2}}},
3434
"id number with version": {"8.v2", []DetectorID{{ID: 8, Version: 2}}},
3535
}
3636

pkg/custom_detectors/custom_detectors.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1717
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
1818
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/custom_detectorspb"
19-
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
19+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
2020
)
2121

2222
// The maximum number of matches from one chunk. This const is used when
@@ -222,7 +222,7 @@ func (c *CustomRegexWebhook) createResults(ctx context.Context, match map[string
222222
}
223223

224224
result := detectors.Result{
225-
DetectorType: detectorspb.DetectorType_CustomRegex,
225+
DetectorType: detector_typepb.DetectorType_CustomRegex,
226226
DetectorName: c.GetName(),
227227
ExtraData: map[string]string{},
228228
}
@@ -398,8 +398,8 @@ func permutateMatches(regexMatches map[string][][]string) []map[string][]string
398398
return matches
399399
}
400400

401-
func (c *CustomRegexWebhook) Type() detectorspb.DetectorType {
402-
return detectorspb.DetectorType_CustomRegex
401+
func (c *CustomRegexWebhook) Type() detector_typepb.DetectorType {
402+
return detector_typepb.DetectorType_CustomRegex
403403
}
404404

405405
const defaultDescription = "This is a user-defined detector with no description provided."

pkg/custom_detectors/custom_detectors_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
1313
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/custom_detectorspb"
14-
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
14+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
1515
"github.com/trufflesecurity/trufflehog/v3/pkg/protoyaml"
1616
)
1717

@@ -317,7 +317,7 @@ func TestDetectorValidations(t *testing.T) {
317317
},
318318
want: []detectors.Result{
319319
{
320-
DetectorType: detectorspb.DetectorType_CustomRegex,
320+
DetectorType: detector_typepb.DetectorType_CustomRegex,
321321
DetectorName: "test",
322322
Verified: false,
323323
Raw: []byte("MyStr0ngP@ssword!"),
@@ -364,7 +364,7 @@ func TestDetectorValidations(t *testing.T) {
364364
},
365365
want: []detectors.Result{
366366
{
367-
DetectorType: detectorspb.DetectorType_CustomRegex,
367+
DetectorType: detector_typepb.DetectorType_CustomRegex,
368368
DetectorName: "test",
369369
Verified: false,
370370
Raw: []byte("MyStrongPassword!"),
@@ -411,7 +411,7 @@ func TestDetectorValidations(t *testing.T) {
411411
},
412412
want: []detectors.Result{
413413
{
414-
DetectorType: detectorspb.DetectorType_CustomRegex,
414+
DetectorType: detector_typepb.DetectorType_CustomRegex,
415415
DetectorName: "test",
416416
Verified: false,
417417
Raw: []byte("MyStrongPassword!"),
@@ -458,7 +458,7 @@ func TestDetectorValidations(t *testing.T) {
458458
},
459459
want: []detectors.Result{
460460
{
461-
DetectorType: detectorspb.DetectorType_CustomRegex,
461+
DetectorType: detector_typepb.DetectorType_CustomRegex,
462462
DetectorName: "test",
463463
Verified: false,
464464
Raw: []byte("MyStr@ngP@ssword!"),
@@ -506,7 +506,7 @@ func TestDetectorValidations(t *testing.T) {
506506
},
507507
want: []detectors.Result{
508508
{
509-
DetectorType: detectorspb.DetectorType_CustomRegex,
509+
DetectorType: detector_typepb.DetectorType_CustomRegex,
510510
DetectorName: "test",
511511
Verified: false,
512512
Raw: []byte("MyStrongP@ssword"),
@@ -554,7 +554,7 @@ func TestDetectorValidations(t *testing.T) {
554554
},
555555
want: []detectors.Result{
556556
{
557-
DetectorType: detectorspb.DetectorType_CustomRegex,
557+
DetectorType: detector_typepb.DetectorType_CustomRegex,
558558
DetectorName: "test",
559559
Verified: false,
560560
Raw: []byte("mystrongp@ssword"),
@@ -590,7 +590,7 @@ func TestDetectorValidations(t *testing.T) {
590590
},
591591
want: []detectors.Result{
592592
{
593-
DetectorType: detectorspb.DetectorType_CustomRegex,
593+
DetectorType: detector_typepb.DetectorType_CustomRegex,
594594
DetectorName: "test",
595595
Verified: false,
596596
Raw: []byte("c392c9837d69b44c764cbf260b-e6184MyStrongP@ssword"),

pkg/detectors/abstract/abstract.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1111
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
12-
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
12+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
1313
)
1414

1515
type Scanner struct {
@@ -51,7 +51,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5151
resMatch := strings.TrimSpace(match[1])
5252

5353
s1 := detectors.Result{
54-
DetectorType: detectorspb.DetectorType_Abstract,
54+
DetectorType: detector_typepb.DetectorType_Abstract,
5555
Raw: []byte(resMatch),
5656
}
5757

@@ -92,8 +92,8 @@ func verifyAbstract(ctx context.Context, client *http.Client, resMatch string) (
9292
}
9393
}
9494

95-
func (s Scanner) Type() detectorspb.DetectorType {
96-
return detectorspb.DetectorType_Abstract
95+
func (s Scanner) Type() detector_typepb.DetectorType {
96+
return detector_typepb.DetectorType_Abstract
9797
}
9898

9999
func (s Scanner) Description() string {

pkg/detectors/abstract/abstract_integration_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1616
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
17-
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
17+
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detector_typepb"
1818
)
1919

2020
func TestAbstract_FromChunk(t *testing.T) {
@@ -49,7 +49,7 @@ func TestAbstract_FromChunk(t *testing.T) {
4949
},
5050
want: []detectors.Result{
5151
{
52-
DetectorType: detectorspb.DetectorType_Abstract,
52+
DetectorType: detector_typepb.DetectorType_Abstract,
5353
Verified: true,
5454
},
5555
},
@@ -65,7 +65,7 @@ func TestAbstract_FromChunk(t *testing.T) {
6565
},
6666
want: func() []detectors.Result {
6767
r := detectors.Result{
68-
DetectorType: detectorspb.DetectorType_Abstract,
68+
DetectorType: detector_typepb.DetectorType_Abstract,
6969
Verified: false,
7070
}
7171
r.SetVerificationError(context.DeadlineExceeded)
@@ -83,7 +83,7 @@ func TestAbstract_FromChunk(t *testing.T) {
8383
},
8484
want: func() []detectors.Result {
8585
r := detectors.Result{
86-
DetectorType: detectorspb.DetectorType_Abstract,
86+
DetectorType: detector_typepb.DetectorType_Abstract,
8787
Verified: false,
8888
}
8989
r.SetVerificationError(fmt.Errorf("unexpected HTTP response status 500"))
@@ -101,7 +101,7 @@ func TestAbstract_FromChunk(t *testing.T) {
101101
},
102102
want: []detectors.Result{
103103
{
104-
DetectorType: detectorspb.DetectorType_Abstract,
104+
DetectorType: detector_typepb.DetectorType_Abstract,
105105
Verified: false,
106106
},
107107
},

0 commit comments

Comments
 (0)