Skip to content

Commit

Permalink
refactor & fix for path name (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibreakthecloud authored Jul 3, 2024
1 parent 7fe0e98 commit ec2907e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/deepfence/SecretScanner

go 1.21.0

toolchain go1.22.0
go 1.22.0

replace github.com/deepfence/agent-plugins-grpc => ./agent-plugins-grpc

Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"path"
"runtime"
"strconv"
"sync/atomic"
"time"

"github.com/deepfence/SecretScanner/core"
Expand Down Expand Up @@ -100,6 +101,7 @@ func runOnce(ctx context.Context, filters config.Filters, format string) {

scanCtx := tasks.ScanContext{
Context: ctx,
IsAlive: atomic.Bool{},
}

scan.Scan(&scanCtx, nodeType, filters, "", node_id, "", func(sf output.SecretFound, s string) {
Expand Down Expand Up @@ -157,7 +159,6 @@ func runOnce(ctx context.Context, filters config.Filters, format string) {
}

func main() {

log.SetOutput(os.Stderr)
log.SetLevel(log.InfoLevel)
log.SetReportCaller(true)
Expand All @@ -183,7 +184,7 @@ func main() {
if *socketPath != "" {
err := server.RunServer(ctx, *socketPath, PLUGIN_NAME)
if err != nil {
log.Fatal("main: failed to serve: %v", err)
log.Fatalf("main: failed to serve: %v", err)
}
} else {
extCfg := config.Config2Filter(core.GetSession().ExtractorConfig)
Expand Down
11 changes: 6 additions & 5 deletions scan/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func Scan(ctx *tasks.ScanContext,
wg.Add(1)
go func() {
defer wg.Done()
for malwares := range results {
for _, malware := range malwares {
outputFn(malware, scanID)
for secrets := range results {
for _, secret := range secrets {
outputFn(secret, scanID)
}
}
}()
Expand All @@ -96,12 +96,13 @@ func Scan(ctx *tasks.ScanContext,
return
}
}
m, err := scanFile(f.Content, f.Filename, filepath.Base(f.Filename), filepath.Ext(f.Filename), "")
logrus.Infof("Scanning file: %v", f.Filename)
s, err := scanFile(f.Content, f.Filename, filepath.Base(f.Filename), filepath.Ext(f.Filename), "")
if err != nil {
logrus.Infof("file: %v, err: %v", f.Filename, err)
}

results <- m
results <- s
})

close(results)
Expand Down
4 changes: 2 additions & 2 deletions signature/signatures.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func MatchPatternSignatures(contents io.ReadSeeker, path string, filename string
SeverityScore: signature.SeverityScore,
MatchFromByte: indexes[0],
MatchToByte: indexes[1],
CompleteFilename: filename,
CompleteFilename: path,
})
break
}
Expand Down Expand Up @@ -150,7 +150,7 @@ func MatchSimpleSignatures(contents io.ReadSeeker, path string, filename string,
SeverityScore: signature.SeverityScore,
MatchFromByte: indexes[0],
MatchToByte: indexes[1],
CompleteFilename: filename,
CompleteFilename: path,
})
}
}
Expand Down

0 comments on commit ec2907e

Please sign in to comment.