@@ -22,6 +22,8 @@ import (
22
22
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
23
23
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
24
24
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
25
+
26
+ "github.com/repeale/fp-go"
25
27
)
26
28
27
29
const (
@@ -139,6 +141,7 @@ func (s *Source) Init(ctx context.Context, name string, jobId sources.JobID, sou
139
141
// Check out the postman UI to see what I mean.
140
142
// Metadata is used to track information that informs the source of the chunk (e.g. the workspace -> collection -> request -> variable hierarchy).
141
143
func (s * Source ) Chunks (ctx context.Context , chunksChan chan * sources.Chunk , _ ... sources.ChunkingTarget ) error {
144
+
142
145
// Scan local environments
143
146
for _ , envPath := range s .conn .EnvironmentPaths {
144
147
env := VariableData {}
@@ -255,6 +258,13 @@ func (s *Source) scanLocalWorkspace(ctx context.Context, chunksChan chan *source
255
258
}
256
259
257
260
func (s * Source ) scanWorkspace (ctx context.Context , chunksChan chan * sources.Chunk , workspace Workspace ) error {
261
+ ctx .Logger ().V (4 ).Info ("scanning workspace" ,
262
+ "workspace_id" , workspace .Id ,
263
+ "collection_uids" , fp .Map (func (i IdNameUid ) string { return i .Uid })(workspace .Collections ),
264
+ "environment_uids" , fp .Map (func (i IdNameUid ) string { return i .Uid })(workspace .Environments ),
265
+ "collection_raw_uids" , fp .Map (func (c Collection ) string { return c .Info .Uid })(workspace .CollectionsRaw ),
266
+ "environment_raw_ids" , fp .Map (func (v VariableData ) string { return v .Id })(workspace .EnvironmentsRaw ),
267
+ )
258
268
// reset keywords for each workspace
259
269
s .resetKeywords ()
260
270
s .attemptToAddKeyword (workspace .Name )
@@ -321,7 +331,10 @@ func (s *Source) scanWorkspace(ctx context.Context, chunksChan chan *sources.Chu
321
331
// scanCollection scans a collection and all its items, folders, and requests.
322
332
// locally scoped Metadata is updated as we drill down into the collection.
323
333
func (s * Source ) scanCollection (ctx context.Context , chunksChan chan * sources.Chunk , metadata Metadata , collection Collection ) {
324
- ctx .Logger ().V (2 ).Info ("starting to scan collection" , "collection_name" , collection .Info .Name , "collection_uuid" , collection .Info .Uid )
334
+ ctx .Logger ().V (2 ).Info ("starting to scan collection" ,
335
+ "collection_name" , collection .Info .Name ,
336
+ "collection_uuid" , collection .Info .Uid ,
337
+ "variable_count" , len (collection .Variables ))
325
338
metadata .CollectionInfo = collection .Info
326
339
metadata .Type = COLLECTION_TYPE
327
340
s .attemptToAddKeyword (collection .Info .Name )
@@ -342,17 +355,33 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch
342
355
// collections don't have URLs in the Postman API, but we can scan the Authorization section without it.
343
356
s .scanAuth (ctx , chunksChan , metadata , collection .Auth , URL {})
344
357
358
+ ctx .Logger ().V (4 ).Info ("Scanning events in collection" ,
359
+ "collection_uid" , collection .Info .Uid ,
360
+ "event_count" , len (collection .Events ),
361
+ )
345
362
for _ , event := range collection .Events {
346
363
s .scanEvent (ctx , chunksChan , metadata , event )
347
364
}
348
365
366
+ ctx .Logger ().V (4 ).Info ("Scanning items in collection" ,
367
+ "collection_uid" , collection .Info .Uid ,
368
+ "item_ids" , fp .Map (func (i Item ) string { return i .Id })(collection .Items ),
369
+ )
349
370
for _ , item := range collection .Items {
350
371
s .scanItem (ctx , chunksChan , collection , metadata , item , "" )
351
372
}
352
373
353
374
}
354
375
355
376
func (s * Source ) scanItem (ctx context.Context , chunksChan chan * sources.Chunk , collection Collection , metadata Metadata , item Item , parentItemId string ) {
377
+ ctx .Logger ().V (4 ).Info ("Starting to scan item" ,
378
+ "item_uid" , item .Uid ,
379
+ "item_parent_item_id" , parentItemId ,
380
+ "item_descendent_item_uids" , fp .Map (func (i Item ) string { return i .Uid })(item .Items ),
381
+ "item_event_count" , len (item .Events ),
382
+ "item_response_count" , len (item .Response ),
383
+ "item_variable_count" , len (item .Variable ),
384
+ )
356
385
s .attemptToAddKeyword (item .Name )
357
386
358
387
// override the base collection metadata with item-specific metadata
@@ -410,6 +439,8 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
410
439
// an auth all by its lonesome could be inherited to subfolders and requests
411
440
s .scanAuth (ctx , chunksChan , metadata , item .Auth , item .Request .URL )
412
441
metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
442
+
443
+ ctx .Logger ().V (4 ).Info ("Finished scanning item" , "item_uid" , item .Uid )
413
444
}
414
445
415
446
func (s * Source ) scanEvent (ctx context.Context , chunksChan chan * sources.Chunk , metadata Metadata , event Event ) {
@@ -537,6 +568,13 @@ func (s *Source) scanAuth(ctx context.Context, chunksChan chan *sources.Chunk, m
537
568
}
538
569
539
570
func (s * Source ) scanHTTPRequest (ctx context.Context , chunksChan chan * sources.Chunk , metadata Metadata , r Request ) {
571
+ ctx .Logger ().V (4 ).Info ("scanning http request" ,
572
+ "request_header_count" , len (r .HeaderKeyValue ),
573
+ "request_has_string_header" , r .HeaderString == nil ,
574
+ "request_url_query_param_count" , len (r .URL .Query ),
575
+ "request_url_path_param_count" , len (r .URL .Path ),
576
+ )
577
+
540
578
s .addKeywords (r .URL .Host )
541
579
originalType := metadata .Type
542
580
@@ -590,6 +628,10 @@ func (s *Source) scanHTTPRequest(ctx context.Context, chunksChan chan *sources.C
590
628
}
591
629
592
630
func (s * Source ) scanRequestBody (ctx context.Context , chunksChan chan * sources.Chunk , m Metadata , b Body ) {
631
+ ctx .Logger ().V (4 ).Info ("scanning request body" ,
632
+ "request_body_form_data_count" , len (b .FormData ),
633
+ "request_body_url_encoded_param_count" , len (b .URLEncoded ),
634
+ )
593
635
if ! m .fromLocal {
594
636
m .Link = m .Link + "?tab=body"
595
637
}
0 commit comments