[chore] - fix import name clashes (#2143)

* fix import name clashes

* fix missing var
This commit is contained in:
ahrav 2023-12-01 06:53:15 -08:00 committed by GitHub
parent e7ccfc2f4c
commit 52ffab1034
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 44 additions and 44 deletions

View file

@ -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" {
@ -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

View file

@ -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

View file

@ -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
}
}
@ -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
}
}
@ -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
}
}

View file

@ -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
}

View file

@ -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
}

View file

@ -84,14 +84,14 @@ 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())
@ -99,7 +99,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
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 {

View file

@ -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.

View file

@ -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
@ -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
}
@ -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 {

View file

@ -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))
}
}
@ -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.