Skip to content

Commit

Permalink
[chore] - fix import name clashes (trufflesecurity#2143)
Browse files Browse the repository at this point in the history
* fix import name clashes

* fix missing var
  • Loading branch information
ahrav authored Dec 1, 2023
1 parent e7ccfc2 commit 52ffab1
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions hack/snifftest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func main() {
selectedScanners := map[string]detectors.Detector{}
allScanners := getAllScanners()

decoders := decoders.DefaultDecoders()
allDecoders := decoders.DefaultDecoders()

input := strings.ToLower(*scanCmdDetector)
if input == "all" {
Expand Down Expand Up @@ -121,7 +121,7 @@ func main() {

for chunk := range chunksChan {
for name, scanner := range selectedScanners {
for _, dec := range decoders {
for _, dec := range allDecoders {
decoded := dec.FromChunk(&sources.Chunk{Data: chunk.Data})
if decoded != nil {
foundKeyword := false
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,11 +591,11 @@ func printAverageDetectorTime(e *engine.Engine) {

// detectorTypeToSet is a helper function to convert a slice of detector IDs into a set.
func detectorTypeToSet(detectors []config.DetectorID) map[config.DetectorID]struct{} {
output := make(map[config.DetectorID]struct{}, len(detectors))
out := make(map[config.DetectorID]struct{}, len(detectors))
for _, d := range detectors {
output[d] = struct{}{}
out[d] = struct{}{}
}
return output
return out
}

// getWithDetectorID is a helper function to get a value from a map using a
Expand Down
16 changes: 8 additions & 8 deletions pkg/common/glob/glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ func (f *Filter) ShouldInclude(object string) bool {
// shouldIncludeFromExclude checks for explicitly excluded paths. This should
// only be called when the include list is empty.
func (f *Filter) shouldIncludeFromExclude(object string) bool {
for _, glob := range f.exclude {
if glob.Match(object) {
for _, g := range f.exclude {
if g.Match(object) {
return false
}
}
Expand All @@ -91,8 +91,8 @@ func (f *Filter) shouldIncludeFromExclude(object string) bool {
// shouldIncludeFromInclude checks for explicitly included paths. This should
// only be called when the exclude list is empty.
func (f *Filter) shouldIncludeFromInclude(object string) bool {
for _, glob := range f.include {
if glob.Match(object) {
for _, g := range f.include {
if g.Match(object) {
return true
}
}
Expand All @@ -104,14 +104,14 @@ func (f *Filter) shouldIncludeFromInclude(object string) bool {
func (f *Filter) shouldIncludeFromBoth(object string) (bool, error) {
// Exclude takes precedence. If we find the object in the exclude list,
// we should not match.
for _, glob := range f.exclude {
if glob.Match(object) {
for _, g := range f.exclude {
if g.Match(object) {
return false, nil
}
}
// If we find the object in the include list, we should match.
for _, glob := range f.include {
if glob.Match(object) {
for _, g := range f.include {
if g.Match(object) {
return true, nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func NewYAML(input []byte) (*Config, error) {
return nil, err
}
// Convert the structured YAML into detectors.
var detectors []detectors.Detector
var d []detectors.Detector
for _, detectorConfig := range messages.Detectors {
detector, err := custom_detectors.NewWebhookCustomRegex(detectorConfig)
if err != nil {
return nil, err
}
detectors = append(detectors, detector)
d = append(d, detector)
}
return &Config{
Detectors: detectors,
Detectors: d,
}, nil
}
6 changes: 3 additions & 3 deletions pkg/config/detectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ func ParseDetectors(input string) ([]DetectorID, error) {
if item == "" {
continue
}
detectors, ok := specialGroups[strings.ToLower(item)]
allDetectors, ok := specialGroups[strings.ToLower(item)]
if !ok {
var err error
detectors, err = asRange(item)
allDetectors, err = asRange(item)
if err != nil {
return nil, err
}
}
for _, d := range detectors {
for _, d := range allDetectors {
if _, ok := seenDetector[d]; ok {
continue
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/detectors/pusherchannelkey/pusherchannelkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,22 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
payload := strings.NewReader(stringPayload)
_bodyMD5 := md5.New()
_bodyMD5.Write([]byte(stringPayload))
md5 := hex.EncodeToString(_bodyMD5.Sum(nil))
hash := hex.EncodeToString(_bodyMD5.Sum(nil))

timestamp := strconv.FormatInt(time.Now().Unix(), 10)
params := url.Values{
"auth_key": {reskeyMatch},
"auth_timestamp": {timestamp},
"auth_version": {auth_version},
"body_md5": {md5},
"body_md5": {hash},
}

usecd, _ := url.QueryUnescape(params.Encode())

stringToSign := strings.Join([]string{method, path, usecd}, "\n")
signature := hex.EncodeToString(hmacBytes([]byte(stringToSign), []byte(ressecretMatch)))

md5Str := "https://api-ap1.pusher.com/apps/" + resappMatch + "/events?auth_key=" + reskeyMatch + "&auth_signature=" + signature + "&auth_timestamp=" + timestamp + "&auth_version=1.0&body_md5=" + md5
md5Str := "https://api-ap1.pusher.com/apps/" + resappMatch + "/events?auth_key=" + reskeyMatch + "&auth_signature=" + signature + "&auth_timestamp=" + timestamp + "&auth_version=1.0&body_md5=" + hash

req, err := http.NewRequestWithContext(ctx, method, md5Str, payload)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,13 @@ func WithVerify(verify bool) Option {
}

func filterDetectors(filterFunc func(detectors.Detector) bool, input []detectors.Detector) []detectors.Detector {
var output []detectors.Detector
var out []detectors.Detector
for _, detector := range input {
if filterFunc(detector) {
output = append(output, detector)
out = append(out, detector)
}
}
return output
return out
}

// HasFoundResults returns true if any results are found.
Expand Down
22 changes: 11 additions & 11 deletions pkg/sources/s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ func (s *Source) Init(aCtx context.Context, name string, jobId sources.JobID, so
}

func (s *Source) Validate(ctx context.Context) []error {
var errors []error
var errs []error
visitor := func(c context.Context, defaultRegionClient *s3.S3, roleArn string, buckets []string) {
roleErrs := s.validateBucketAccess(c, defaultRegionClient, roleArn, buckets)
if len(roleErrs) > 0 {
errors = append(errors, roleErrs...)
errs = append(errs, roleErrs...)
}
}

err := s.visitRoles(ctx, visitor)
if err != nil {
errors = append(errors, err)
errs = append(errs, err)
}

return errors
return errs
}

// setMaxObjectSize sets the maximum size of objects that will be scanned. If
Expand Down Expand Up @@ -421,16 +421,16 @@ func (s *Source) pageChunker(ctx context.Context, client *s3.S3, chunksChan chan
func (s *Source) validateBucketAccess(ctx context.Context, client *s3.S3, roleArn string, buckets []string) []error {
shouldHaveAccessToAllBuckets := roleArn == ""
wasAbleToListAnyBucket := false
var errors []error
var errs []error

for _, bucket := range buckets {
if common.IsDone(ctx) {
return append(errors, ctx.Err())
return append(errs, ctx.Err())
}

regionalClient, err := s.getRegionalClientForBucket(ctx, client, roleArn, bucket)
if err != nil {
errors = append(errors, fmt.Errorf("could not get regional client for bucket %q: %w", bucket, err))
errs = append(errs, fmt.Errorf("could not get regional client for bucket %q: %w", bucket, err))
continue
}

Expand All @@ -439,19 +439,19 @@ func (s *Source) validateBucketAccess(ctx context.Context, client *s3.S3, roleAr
if err == nil {
wasAbleToListAnyBucket = true
} else if shouldHaveAccessToAllBuckets {
errors = append(errors, fmt.Errorf("could not list objects in bucket %q: %w", bucket, err))
errs = append(errs, fmt.Errorf("could not list objects in bucket %q: %w", bucket, err))
}
}

if !wasAbleToListAnyBucket {
if roleArn == "" {
errors = append(errors, fmt.Errorf("could not list objects in any bucket"))
errs = append(errs, fmt.Errorf("could not list objects in any bucket"))
} else {
errors = append(errors, fmt.Errorf("role %q could not list objects in any bucket", roleArn))
errs = append(errs, fmt.Errorf("role %q could not list objects in any bucket", roleArn))
}
}

return errors
return errs
}

func (s *Source) visitRoles(ctx context.Context, f func(c context.Context, defaultRegionClient *s3.S3, roleArn string, buckets []string)) error {
Expand Down
16 changes: 8 additions & 8 deletions pkg/sources/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ func NewSyslog(sourceType sourcespb.SourceType, jobID sources.JobID, sourceID so

// Validate validates the configuration of the source.
func (s *Source) Validate(ctx context.Context) []error {
var errors []error
var errs []error

if s.conn.TlsCert != nilString || s.conn.TlsKey != nilString {
if s.conn.TlsCert == nilString || s.conn.TlsKey == nilString {
errors = append(errors, fmt.Errorf("tls cert and key must both be set"))
errs = append(errs, fmt.Errorf("tls cert and key must both be set"))
}
if _, err := tls.LoadX509KeyPair(s.conn.TlsCert, s.conn.TlsKey); err != nil {
errors = append(errors, fmt.Errorf("error loading tls cert and key: %s", err))
errs = append(errs, fmt.Errorf("error loading tls cert and key: %s", err))
}
}

Expand All @@ -81,24 +81,24 @@ func (s *Source) Validate(ctx context.Context) []error {
case "tcp":
srv, err := net.Listen(s.conn.Protocol, s.conn.ListenAddress)
if err != nil {
errors = append(errors, fmt.Errorf("error listening on tcp socket: %s", err))
errs = append(errs, fmt.Errorf("error listening on tcp socket: %s", err))
}
srv.Close()
case "udp":
srv, err := net.ListenPacket(s.conn.Protocol, s.conn.ListenAddress)
if err != nil {
errors = append(errors, fmt.Errorf("error listening on udp socket: %s", err))
errs = append(errs, fmt.Errorf("error listening on udp socket: %s", err))
}
srv.Close()
}
}
if s.conn.Protocol != "tcp" && s.conn.Protocol != "udp" {
errors = append(errors, fmt.Errorf("protocol must be 'tcp' or 'udp', got: %s", s.conn.Protocol))
errs = append(errs, fmt.Errorf("protocol must be 'tcp' or 'udp', got: %s", s.conn.Protocol))
}
if s.conn.Format != "rfc5424" && s.conn.Format != "rfc3164" {
errors = append(errors, fmt.Errorf("format must be 'rfc5424' or 'rfc3164', got: %s", s.conn.Format))
errs = append(errs, fmt.Errorf("format must be 'rfc5424' or 'rfc3164', got: %s", s.conn.Format))
}
return errors
return errs
}

// Ensure the Source satisfies the interface at compile time.
Expand Down

0 comments on commit 52ffab1

Please sign in to comment.