@@ -20,34 +20,30 @@ import (
2020)
2121
2222const (
23- // max request size is 500KB, so set max to 490Kb for buffer room
24- // maxSizeBytes = 490000
25- // max list size imposed by Nightfall API
26- // maxListSize = 50000
2723 contentChunkByteSize = 1024
2824 // max number of items that can be sent to Nightfall API at a time
2925 maxItemsForAPIReq = 479
3026 // timeout for the total time spent sending scan requests and receiving responses for a diff
3127 defaultTimeout = time .Minute * 20
3228 // maximum attempts to Nightfall API upon receiving 429 Too Many Requests before failing
33- MaxScanAttempts = 5
29+ maxScanAttempts = 5
3430 // initial delay before re-attempting scan request
35- initialDelay = time .Second * 1
31+ initialDelay = time .Second
3632)
3733
38- // Client client which uses Nightfall API
39- // to determine findings from input strings
34+ // Client uses the Nightfall API to scan text for findings
4035type Client struct {
4136 APIClient interface {
4237 ScanText (ctx context.Context , request * nf.ScanTextRequest ) (* nf.ScanTextResponse , error )
4338 }
44- DetectionRuleUUIDs []uuid.UUID
45- DetectionRules []nf.DetectionRule
46- MaxNumberRoutines int
47- InitialRetryDelay time.Duration
48- TokenExclusionList []string
49- FileInclusionList []string
50- FileExclusionList []string
39+ DetectionRuleUUIDs []uuid.UUID
40+ DetectionRules []nf.DetectionRule
41+ MaxNumberRoutines int
42+ InitialRetryDelay time.Duration
43+ TokenExclusionList []string
44+ FileInclusionList []string
45+ FileExclusionList []string
46+ DefaultRedactionConfig * nf.RedactionConfig
5147}
5248
5349func NewClient (config nightfallconfig.Config ) (* Client , error ) {
@@ -56,14 +52,15 @@ func NewClient(config nightfallconfig.Config) (*Client, error) {
5652 return nil , err
5753 }
5854 return & Client {
59- APIClient : client ,
60- DetectionRuleUUIDs : config .NightfallDetectionRuleUUIDs ,
61- DetectionRules : config .NightfallDetectionRules ,
62- MaxNumberRoutines : config .NightfallMaxNumberRoutines ,
63- InitialRetryDelay : initialDelay ,
64- TokenExclusionList : config .TokenExclusionList ,
65- FileInclusionList : config .FileInclusionList ,
66- FileExclusionList : config .FileExclusionList ,
55+ APIClient : client ,
56+ DetectionRuleUUIDs : config .NightfallDetectionRuleUUIDs ,
57+ DetectionRules : config .NightfallDetectionRules ,
58+ MaxNumberRoutines : config .NightfallMaxNumberRoutines ,
59+ InitialRetryDelay : initialDelay ,
60+ TokenExclusionList : config .TokenExclusionList ,
61+ FileInclusionList : config .FileInclusionList ,
62+ FileExclusionList : config .FileExclusionList ,
63+ DefaultRedactionConfig : config .DefaultRedactionConfig ,
6764 }, nil
6865}
6966
@@ -73,31 +70,17 @@ type contentToScan struct {
7370 LineNumber int
7471}
7572
76- func blurContent (content string ) string {
77- contentRune := []rune (content )
78- blurredContent := string (contentRune [:2 ])
79- blurLength := 8
80- if len (contentRune [2 :]) < blurLength {
81- blurLength = len (contentRune [2 :])
82- }
83- for i := 0 ; i < blurLength ; i ++ {
84- blurredContent += "*"
85- }
86- return blurredContent
87- }
88-
8973func getCommentMsg (finding * nf.Finding ) string {
90- if finding .Finding == "" || finding .Detector . DisplayName == "" {
74+ if finding .Finding == "" && finding .RedactedFinding == "" {
9175 return ""
9276 }
9377
94- blurredContent := finding .RedactedFinding
95- if blurredContent == "" {
96- // by default use asterisks, so we don't spread data further
97- blurredContent = blurContent (finding .Finding )
78+ content := finding .RedactedFinding
79+ if content == "" {
80+ content = finding .Finding
9881 }
9982
100- return fmt .Sprintf ("Suspicious content detected (%s , type %s )" , blurredContent , finding .Detector .DisplayName )
83+ return fmt .Sprintf ("Suspicious content detected (%q , type %q )" , content , finding .Detector .DisplayName )
10184}
10285
10386func getCommentTitle (finding * nf.Finding ) string {
@@ -219,8 +202,9 @@ func (n *Client) buildScanRequest(items []string) *nf.ScanTextRequest {
219202 return & nf.ScanTextRequest {
220203 Payload : items ,
221204 Config : & nf.Config {
222- DetectionRules : n .DetectionRules ,
223- DetectionRuleUUIDs : ruleUUIDStrs ,
205+ DetectionRules : n .DetectionRules ,
206+ DetectionRuleUUIDs : ruleUUIDStrs ,
207+ DefaultRedactionConfig : n .DefaultRedactionConfig ,
224208 },
225209 }
226210}
@@ -371,8 +355,8 @@ func compileGlobs(globPatterns []string, logger logger.Logger) []glob.Glob {
371355}
372356
373357func matchGlob (filePath string , globs []glob.Glob ) bool {
374- for _ , glob := range globs {
375- if glob .Match (filePath ) {
358+ for _ , g := range globs {
359+ if g .Match (filePath ) {
376360 return true
377361 }
378362 }
0 commit comments