@@ -27,7 +27,6 @@ import (
27
27
const (
28
28
SourceType = sourcespb .SourceType_SOURCE_TYPE_POSTMAN
29
29
LINK_BASE_URL = "https://go.postman.co/"
30
- GLOBAL_TYPE = "globals"
31
30
ENVIRONMENT_TYPE = "environment"
32
31
AUTH_TYPE = "authorization"
33
32
REQUEST_TYPE = "request"
@@ -147,7 +146,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk, _ .
147
146
if err = json .Unmarshal (contents , & env ); err != nil {
148
147
return err
149
148
}
150
- s .scanVariableData (ctx , chunksChan , Metadata {EnvironmentName : env .ID , fromLocal : true , Link : envPath }, env )
149
+ s .scanVariableData (ctx , chunksChan , Metadata {EnvironmentID : env .ID , EnvironmentName : env . Name , fromLocal : true , Link : envPath , LocationType : source_metadatapb . PostmanLocationType_ENVIRONMENT_VARIABLE }, env )
151
150
}
152
151
153
152
// Scan local workspaces
@@ -230,7 +229,9 @@ func (s *Source) scanLocalWorkspace(ctx context.Context, chunksChan chan *source
230
229
231
230
for _ , environment := range workspace .EnvironmentsRaw {
232
231
metadata .Link = strings .TrimSuffix (path .Base (filePath ), path .Ext (filePath )) + "/environments/" + environment .ID + ".json"
232
+ metadata .LocationType = source_metadatapb .PostmanLocationType_ENVIRONMENT_VARIABLE
233
233
s .scanVariableData (ctx , chunksChan , metadata , environment )
234
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
234
235
}
235
236
for _ , collection := range workspace .CollectionsRaw {
236
237
metadata .Link = strings .TrimSuffix (path .Base (filePath ), path .Ext (filePath )) + "/collections/" + collection .Info .PostmanID + ".json"
@@ -265,13 +266,20 @@ func (s *Source) scanWorkspace(ctx context.Context, chunksChan chan *sources.Chu
265
266
metadata .Link = LINK_BASE_URL + "environments/" + envID .UUID
266
267
metadata .FullID = envVars .ID
267
268
metadata .EnvironmentID = envID .UUID
269
+ metadata .EnvironmentName = envVars .Name
268
270
269
271
ctx .Logger ().V (2 ).Info ("scanning environment vars" , "environment_uuid" , metadata .FullID )
270
272
for _ , word := range strings .Split (envVars .Name , " " ) {
271
273
s .attemptToAddKeyword (word )
272
274
}
273
-
275
+ metadata . LocationType = source_metadatapb . PostmanLocationType_ENVIRONMENT_VARIABLE
274
276
s .scanVariableData (ctx , chunksChan , metadata , envVars )
277
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
278
+ metadata .Type = ""
279
+ metadata .Link = ""
280
+ metadata .FullID = ""
281
+ metadata .EnvironmentID = ""
282
+ metadata .EnvironmentName = ""
275
283
ctx .Logger ().V (2 ).Info ("finished scanning environment vars" , "environment_uuid" , metadata .FullID )
276
284
}
277
285
ctx .Logger ().V (2 ).Info ("finished scanning environments" )
@@ -305,11 +313,13 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch
305
313
metadata .Link = LINK_BASE_URL + COLLECTION_TYPE + "/" + metadata .FullID
306
314
}
307
315
316
+ metadata .LocationType = source_metadatapb .PostmanLocationType_COLLECTION_VARIABLE
308
317
// variables must be scanned first before drilling down into the folders and events
309
318
// because we need to pick up the substitutions from the top level collection variables
310
319
s .scanVariableData (ctx , chunksChan , metadata , VariableData {
311
320
KeyValues : collection .Variables ,
312
321
})
322
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
313
323
314
324
for _ , event := range collection .Events {
315
325
s .scanEvent (ctx , chunksChan , metadata , event )
@@ -345,6 +355,7 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
345
355
346
356
// check if there are any requests in the folder
347
357
if item .Request .Method != "" {
358
+ metadata .FolderName = strings .Replace (metadata .FolderName , (" > " + item .Name ), "" , - 1 )
348
359
metadata .RequestID = item .ID
349
360
metadata .RequestName = item .Name
350
361
metadata .Type = REQUEST_TYPE
@@ -368,8 +379,16 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
368
379
s .scanEvent (ctx , chunksChan , metadata , event )
369
380
}
370
381
382
+ if metadata .RequestID != "" {
383
+ metadata .LocationType = source_metadatapb .PostmanLocationType_REQUEST_AUTHORIZATION
384
+ } else if metadata .FolderID != "" {
385
+ metadata .LocationType = source_metadatapb .PostmanLocationType_FOLDER_AUTHORIZATION
386
+ } else if metadata .CollectionInfo .UID != "" {
387
+ metadata .LocationType = source_metadatapb .PostmanLocationType_COLLECTION_AUTHORIZATION
388
+ }
371
389
// an auth all by its lonesome could be inherited to subfolders and requests
372
390
s .scanAuth (ctx , chunksChan , metadata , item .Auth , item .Request .URL )
391
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
373
392
}
374
393
375
394
func (s * Source ) scanEvent (ctx context.Context , chunksChan chan * sources.Chunk , metadata Metadata , event Event ) {
@@ -378,15 +397,24 @@ func (s *Source) scanEvent(ctx context.Context, chunksChan chan *sources.Chunk,
378
397
379
398
// Prep direct links. Ignore updating link if it's a local JSON file
380
399
if ! metadata .fromLocal {
381
- metadata .Link = LINK_BASE_URL + metadata .Type + "/" + metadata .FullID
400
+ metadata .Link = LINK_BASE_URL + ( strings . Replace ( metadata .Type , " > event" , "" , - 1 )) + "/" + metadata .FullID
382
401
if event .Listen == "prerequest" {
383
402
metadata .Link += "?tab=pre-request-scripts"
384
403
} else {
385
404
metadata .Link += "?tab=tests"
386
405
}
387
406
}
388
407
408
+ if strings .Contains (metadata .Type , REQUEST_TYPE ) {
409
+ metadata .LocationType = source_metadatapb .PostmanLocationType_REQUEST_SCRIPT
410
+ } else if strings .Contains (metadata .Type , FOLDER_TYPE ) {
411
+ metadata .LocationType = source_metadatapb .PostmanLocationType_FOLDER_SCRIPT
412
+ } else if strings .Contains (metadata .Type , COLLECTION_TYPE ) {
413
+ metadata .LocationType = source_metadatapb .PostmanLocationType_COLLECTION_SCRIPT
414
+ }
415
+
389
416
s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstitueSet (metadata , data )), metadata )
417
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
390
418
}
391
419
392
420
func (s * Source ) scanAuth (ctx context.Context , chunksChan chan * sources.Chunk , m Metadata , auth Auth , u URL ) {
@@ -471,7 +499,16 @@ func (s *Source) scanAuth(ctx context.Context, chunksChan chan *sources.Chunk, m
471
499
s .attemptToAddKeyword (authData )
472
500
473
501
m .FieldType = AUTH_TYPE
502
+
503
+ if strings .Contains (m .Type , REQUEST_TYPE ) {
504
+ m .LocationType = source_metadatapb .PostmanLocationType_REQUEST_AUTHORIZATION
505
+ } else if strings .Contains (m .Type , FOLDER_TYPE ) {
506
+ m .LocationType = source_metadatapb .PostmanLocationType_FOLDER_AUTHORIZATION
507
+ } else if strings .Contains (m .Type , COLLECTION_TYPE ) {
508
+ m .LocationType = source_metadatapb .PostmanLocationType_COLLECTION_AUTHORIZATION
509
+ }
474
510
s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstitueSet (m , authData )), m )
511
+ m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
475
512
}
476
513
477
514
func (s * Source ) scanHTTPRequest (ctx context.Context , chunksChan chan * sources.Chunk , metadata Metadata , r Request ) {
@@ -484,66 +521,38 @@ func (s *Source) scanHTTPRequest(ctx context.Context, chunksChan chan *sources.C
484
521
KeyValues : r .Header ,
485
522
}
486
523
metadata .Type = originalType + " > header"
524
+ metadata .LocationType = source_metadatapb .PostmanLocationType_REQUEST_HEADER
487
525
s .scanVariableData (ctx , chunksChan , metadata , vars )
526
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
488
527
}
489
528
490
529
if r .URL .Raw != "" {
491
530
metadata .Type = originalType + " > request URL (no query parameters)"
492
531
// Note: query parameters are handled separately
493
532
u := fmt .Sprintf ("%s://%s/%s" , r .URL .Protocol , strings .Join (r .URL .Host , "." ), strings .Join (r .URL .Path , "/" ))
533
+ metadata .LocationType = source_metadatapb .PostmanLocationType_REQUEST_URL
494
534
s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstitueSet (metadata , u )), metadata )
535
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
495
536
}
496
537
497
538
if len (r .URL .Query ) > 0 {
498
539
vars := VariableData {
499
540
KeyValues : r .URL .Query ,
500
541
}
501
542
metadata .Type = originalType + " > GET parameters (query)"
543
+ metadata .LocationType = source_metadatapb .PostmanLocationType_REQUEST_QUERY_PARAMETER
502
544
s .scanVariableData (ctx , chunksChan , metadata , vars )
545
+ metadata .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
503
546
}
504
547
505
548
if r .Auth .Type != "" {
506
549
metadata .Type = originalType + " > request auth"
507
550
s .scanAuth (ctx , chunksChan , metadata , r .Auth , r .URL )
508
551
}
509
552
510
- if r .Body .Mode != "" {
511
- metadata .Type = originalType + " > body"
512
- s .scanBody (ctx , chunksChan , metadata , r .Body )
513
- }
514
- }
515
-
516
- func (s * Source ) scanBody (ctx context.Context , chunksChan chan * sources.Chunk , m Metadata , b Body ) {
517
- if ! m .fromLocal {
518
- m .Link = m .Link + "?tab=body"
519
- }
520
- originalType := m .Type
521
- switch b .Mode {
522
- case "formdata" :
523
- m .Type = originalType + " > form data"
524
- vars := VariableData {
525
- KeyValues : b .FormData ,
526
- }
527
- s .scanVariableData (ctx , chunksChan , m , vars )
528
- case "urlencoded" :
529
- m .Type = originalType + " > url encoded"
530
- vars := VariableData {
531
- KeyValues : b .URLEncoded ,
532
- }
533
- s .scanVariableData (ctx , chunksChan , m , vars )
534
- case "raw" , "graphql" :
535
- data := b .Raw
536
- if b .Mode == "graphql" {
537
- m .Type = originalType + " > graphql"
538
- data = b .GraphQL .Query + " " + b .GraphQL .Variables
539
- }
540
- if b .Mode == "raw" {
541
- m .Type = originalType + " > raw"
542
- }
543
- s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstitueSet (m , data )), m )
544
- default :
545
- break
546
- }
553
+ // We would scan the body, but currently the body has different radio buttons that can be scanned but only the selected one is scanned. The unselected radio button options can still
554
+ // have secrets in them but will not be scanned. The selction of the radio button will also change the secret metadata for that particular scanning pass and can create confusion for
555
+ // the user as to the status of a secret. We will reimplement at some point.
547
556
}
548
557
549
558
func (s * Source ) scanHTTPResponse (ctx context.Context , chunksChan chan * sources.Chunk , m Metadata , response Response ) {
@@ -558,13 +567,17 @@ func (s *Source) scanHTTPResponse(ctx context.Context, chunksChan chan *sources.
558
567
KeyValues : response .Header ,
559
568
}
560
569
m .Type = originalType + " > response header"
570
+ m .LocationType = source_metadatapb .PostmanLocationType_RESPONSE_HEADER
561
571
s .scanVariableData (ctx , chunksChan , m , vars )
572
+ m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
562
573
}
563
574
564
575
// Body in a response is just a string
565
576
if response .Body != "" {
566
577
m .Type = originalType + " > response body"
578
+ m .LocationType = source_metadatapb .PostmanLocationType_RESPONSE_BODY
567
579
s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (s .buildSubstitueSet (m , response .Body )), m )
580
+ m .LocationType = source_metadatapb .PostmanLocationType_UNKNOWN_POSTMAN
568
581
}
569
582
570
583
if response .OriginalRequest .Method != "" {
@@ -600,14 +613,22 @@ func (s *Source) scanVariableData(ctx context.Context, chunksChan chan *sources.
600
613
}
601
614
602
615
m .FieldType = m .Type + " variables"
616
+ switch m .FieldType {
617
+ case "request > GET parameters (query) variables" :
618
+ m .Link = m .Link + "?tab=params"
619
+ case "request > header variables" :
620
+ m .Link = m .Link + "?tab=headers"
621
+ }
603
622
s .scanData (ctx , chunksChan , s .formatAndInjectKeywords (values ), m )
604
623
}
605
624
606
625
func (s * Source ) scanData (ctx context.Context , chunksChan chan * sources.Chunk , data string , metadata Metadata ) {
607
626
if data == "" {
608
627
return
609
628
}
610
- metadata .FieldType = metadata .Type
629
+ if metadata .FieldType == "" {
630
+ metadata .FieldType = metadata .Type
631
+ }
611
632
612
633
chunksChan <- & sources.Chunk {
613
634
SourceType : s .Type (),
@@ -630,8 +651,7 @@ func (s *Source) scanData(ctx context.Context, chunksChan chan *sources.Chunk, d
630
651
FolderId : metadata .FolderID ,
631
652
FolderName : metadata .FolderName ,
632
653
FieldType : metadata .FieldType ,
633
- FieldName : metadata .FieldName ,
634
- VariableType : metadata .VarType ,
654
+ LocationType : metadata .LocationType ,
635
655
},
636
656
},
637
657
},
0 commit comments