@@ -329,10 +329,13 @@ func (s *Source) scanWorkspace(ctx context.Context, chunksChan chan *sources.Chu
329
329
// scanCollection scans a collection and all its items, folders, and requests.
330
330
// locally scoped Metadata is updated as we drill down into the collection.
331
331
func (s * Source ) scanCollection (ctx context.Context , chunksChan chan * sources.Chunk , metadata Metadata , collection Collection ) {
332
- ctx . Logger (). V ( 2 ). Info ( "starting to scan collection" ,
332
+ ctx = context . WithValues ( ctx ,
333
333
"collection_name" , collection .Info .Name ,
334
334
"collection_uuid" , collection .Info .Uid ,
335
- "variable_count" , len (collection .Variables ))
335
+ )
336
+ ctx .Logger ().V (2 ).Info ("starting to scan collection" ,
337
+ "variable_count" , len (collection .Variables ),
338
+ )
336
339
metadata .CollectionInfo = collection .Info
337
340
metadata .Type = COLLECTION_TYPE
338
341
s .attemptToAddKeyword (collection .Info .Name )
@@ -354,32 +357,34 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch
354
357
s .scanAuth (ctx , chunksChan , metadata , collection .Auth , URL {})
355
358
356
359
ctx .Logger ().V (3 ).Info ("Scanning events in collection" ,
357
- "collection_uid" , collection .Info .Uid ,
358
360
"event_count" , len (collection .Events ),
359
361
)
360
362
for _ , event := range collection .Events {
361
363
s .scanEvent (ctx , chunksChan , metadata , event )
362
364
}
363
365
364
366
ctx .Logger ().V (3 ).Info ("Scanning items in collection" ,
365
- "collection_uid" , collection .Info .Uid ,
366
367
"item_ids" , fp .Map (func (i Item ) string { return i .Id })(collection .Items ),
367
368
)
368
369
for _ , item := range collection .Items {
369
- s .scanItem (ctx , chunksChan , collection , metadata , item , "" )
370
+ seenItemIds := make (map [string ]struct {})
371
+ s .scanItem (ctx , chunksChan , collection , metadata , item , "" , seenItemIds )
370
372
}
371
-
372
373
}
373
374
374
- func (s * Source ) scanItem (ctx context.Context , chunksChan chan * sources.Chunk , collection Collection , metadata Metadata , item Item , parentItemId string ) {
375
+ func (s * Source ) scanItem (ctx context.Context , chunksChan chan * sources.Chunk , collection Collection , metadata Metadata , item Item , parentItemId string , seenItemIds map [string ]struct {}) {
376
+ ctx = context .WithValue (ctx , "item_uid" , item .Uid )
377
+
375
378
ctx .Logger ().V (3 ).Info ("Starting to scan item" ,
376
- "item_uid" , item .Uid ,
377
379
"item_parent_item_id" , parentItemId ,
378
380
"item_descendent_item_uids" , fp .Map (func (i Item ) string { return i .Uid })(item .Items ),
379
381
"item_event_count" , len (item .Events ),
380
382
"item_response_count" , len (item .Response ),
381
383
"item_variable_count" , len (item .Variable ),
382
384
)
385
+
386
+ seenItemIds [item .Uid ] = struct {}{}
387
+
383
388
s .attemptToAddKeyword (item .Name )
384
389
385
390
// override the base collection metadata with item-specific metadata
@@ -397,7 +402,13 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
397
402
}
398
403
// recurse through the folders
399
404
for _ , subItem := range item .Items {
400
- s .scanItem (ctx , chunksChan , collection , metadata , subItem , item .Uid )
405
+ if _ , ok := seenItemIds [subItem .Uid ]; ok {
406
+ ctx .Logger ().Info ("Skipping already-seen item" ,
407
+ "seen_item_id" , subItem .Uid ,
408
+ )
409
+ continue
410
+ }
411
+ s .scanItem (ctx , chunksChan , collection , metadata , subItem , item .Uid , seenItemIds )
401
412
}
402
413
403
414
// The assignment of the folder ID to be the current item UID is due to wanting to assume that your current item is a folder unless you have request data inside of your item.
@@ -463,7 +474,8 @@ func (s *Source) scanEvent(ctx context.Context, chunksChan chan *sources.Chunk,
463
474
metadata .LocationType = source_metadatapb .PostmanLocationType_COLLECTION_SCRIPT
464
475
}
465
476
466
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (metadata , data , DefaultMaxRecursionDepth )), metadata )
477
+ ctx = context .WithValue (ctx , "event_listen" , event .Listen )
478
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , metadata , data , DefaultMaxRecursionDepth )), metadata )
467
479
metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
468
480
}
469
481
@@ -561,7 +573,7 @@ func (s *Source) scanAuth(ctx context.Context, chunksChan chan *sources.Chunk, m
561
573
} else if strings .Contains (m .Type , COLLECTION_TYPE ) {
562
574
m .LocationType = source_metadatapb .PostmanLocationType_COLLECTION_AUTHORIZATION
563
575
}
564
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (m , authData , DefaultMaxRecursionDepth )), m )
576
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , m , authData , DefaultMaxRecursionDepth )), m )
565
577
m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
566
578
}
567
579
@@ -591,7 +603,7 @@ func (s *Source) scanHTTPRequest(ctx context.Context, chunksChan chan *sources.C
591
603
metadata .Type = originalType + " > header"
592
604
metadata .Link = metadata .Link + "?tab=headers"
593
605
metadata .LocationType = source_metadatapb .PostmanLocationType_REQUEST_HEADER
594
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (metadata , strings .Join (r .HeaderString , " " ), DefaultMaxRecursionDepth )), metadata )
606
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , metadata , strings .Join (r .HeaderString , " " ), DefaultMaxRecursionDepth )), metadata )
595
607
metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
596
608
}
597
609
@@ -600,7 +612,7 @@ func (s *Source) scanHTTPRequest(ctx context.Context, chunksChan chan *sources.C
600
612
// Note: query parameters are handled separately
601
613
u := fmt .Sprintf ("%s://%s/%s" , r .URL .Protocol , strings .Join (r .URL .Host , "." ), strings .Join (r .URL .Path , "/" ))
602
614
metadata .LocationType = source_metadatapb .PostmanLocationType_REQUEST_URL
603
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (metadata , u , DefaultMaxRecursionDepth )), metadata )
615
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , metadata , u , DefaultMaxRecursionDepth )), metadata )
604
616
metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
605
617
}
606
618
@@ -655,13 +667,13 @@ func (s *Source) scanRequestBody(ctx context.Context, chunksChan chan *sources.C
655
667
m .Type = originalType + " > raw"
656
668
data := b .Raw
657
669
m .LocationType = source_metadatapb .PostmanLocationType_REQUEST_BODY_RAW
658
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (m , data , DefaultMaxRecursionDepth )), m )
670
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , m , data , DefaultMaxRecursionDepth )), m )
659
671
m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
660
672
case "graphql" :
661
673
m .Type = originalType + " > graphql"
662
674
data := b .GraphQL .Query + " " + b .GraphQL .Variables
663
675
m .LocationType = source_metadatapb .PostmanLocationType_REQUEST_BODY_GRAPHQL
664
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (m , data , DefaultMaxRecursionDepth )), m )
676
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , m , data , DefaultMaxRecursionDepth )), m )
665
677
m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
666
678
}
667
679
}
@@ -687,15 +699,15 @@ func (s *Source) scanHTTPResponse(ctx context.Context, chunksChan chan *sources.
687
699
m .Type = originalType + " > response header"
688
700
// TODO Note: for now, links to Postman responses do not include a more granular tab for the params/header/body, but when they do, we will need to update the metadata.Link info
689
701
m .LocationType = source_metadatapb .PostmanLocationType_RESPONSE_HEADER
690
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (m , strings .Join (response .HeaderString , " " ), DefaultMaxRecursionDepth )), m )
702
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , m , strings .Join (response .HeaderString , " " ), DefaultMaxRecursionDepth )), m )
691
703
m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
692
704
}
693
705
694
706
// Body in a response is just a string
695
707
if response .Body != "" {
696
708
m .Type = originalType + " > response body"
697
709
m .LocationType = source_metadatapb .PostmanLocationType_RESPONSE_BODY
698
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (m , response .Body , DefaultMaxRecursionDepth )), m )
710
+ s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstituteSet (ctx , m , response .Body , DefaultMaxRecursionDepth )), m )
699
711
m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
700
712
}
701
713
@@ -728,7 +740,7 @@ func (s *Source) scanVariableData(ctx context.Context, chunksChan chan *sources.
728
740
if valStr == "" {
729
741
continue
730
742
}
731
- values = append (values , s .buildSubstituteSet (m , valStr , DefaultMaxRecursionDepth )... )
743
+ values = append (values , s .buildSubstituteSet (ctx , m , valStr , DefaultMaxRecursionDepth )... )
732
744
}
733
745
734
746
m .FieldType = m .Type + " variables"
0 commit comments