Skip to content

Commit

Permalink
Differentiate postman folder from request when at collection root (#3912
Browse files Browse the repository at this point in the history
)

* Modified scanItem to keep track of parent folder and eliminate folder info being identical to request info

* Use UID for parent ID and request ID for consistency

* Updated description of UID

* Added commentary for parent folder ID business
  • Loading branch information
casey-tran authored Feb 14, 2025
1 parent 709cd08 commit d50cafe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions pkg/sources/postman/postman.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,15 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch
}

for _, item := range collection.Items {
s.scanItem(ctx, chunksChan, collection, metadata, item)
s.scanItem(ctx, chunksChan, collection, metadata, item, "")
}

}

func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, collection Collection, metadata Metadata, item Item) {
func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, collection Collection, metadata Metadata, item Item, parentItemId string) {
s.attemptToAddKeyword(item.Name)

// override the base collection metadata with item-specific metadata
metadata.FolderID = item.ID
metadata.Type = FOLDER_TYPE
if metadata.FolderName != "" {
// keep track of the folder hierarchy
Expand All @@ -353,13 +352,22 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
}
// recurse through the folders
for _, subItem := range item.Items {
s.scanItem(ctx, chunksChan, collection, metadata, subItem)
s.scanItem(ctx, chunksChan, collection, metadata, subItem, item.UID)
}

// 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.
// If your current item is a folder, you will want the folder ID to match the UID of the current item.
// If your current item is a request, you will want the folder ID to match the UID of the parent folder.
// If the request is at the root of a collection and has no parent folder, the folder ID will be empty.
metadata.FolderID = item.UID
// check if there are any requests in the folder
if item.Request.Method != "" {
metadata.FolderName = strings.Replace(metadata.FolderName, (" > " + item.Name), "", -1)
metadata.RequestID = item.ID
metadata.FolderID = parentItemId
if metadata.FolderID == "" {
metadata.FolderName = ""
}
metadata.RequestID = item.UID
metadata.RequestName = item.Name
metadata.Type = REQUEST_TYPE
if item.UID != "" {
Expand All @@ -381,14 +389,6 @@ func (s *Source) scanItem(ctx context.Context, chunksChan chan *sources.Chunk, c
for _, event := range item.Events {
s.scanEvent(ctx, chunksChan, metadata, event)
}

if metadata.RequestID != "" {
metadata.LocationType = source_metadatapb.PostmanLocationType_REQUEST_AUTHORIZATION
} else if metadata.FolderID != "" {
metadata.LocationType = source_metadatapb.PostmanLocationType_FOLDER_AUTHORIZATION
} else if metadata.CollectionInfo.UID != "" {
metadata.LocationType = source_metadatapb.PostmanLocationType_COLLECTION_AUTHORIZATION
}
// an auth all by its lonesome could be inherited to subfolders and requests
s.scanAuth(ctx, chunksChan, metadata, item.Auth, item.Request.URL)
metadata.LocationType = source_metadatapb.PostmanLocationType_UNKNOWN_POSTMAN
Expand Down
2 changes: 1 addition & 1 deletion pkg/sources/postman/postman_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type Item struct {
Request Request `json:"request,omitempty"`
Response []Response `json:"response,omitempty"`
Description string `json:"description,omitempty"`
UID string `json:"uid,omitempty"` //Need to use this to get the collection via API
UID string `json:"uid,omitempty"` //Need to use this to get the collection via API. The UID is a concatenation of the ID and the user ID of whoever created the item.
}

type Auth struct {
Expand Down

0 comments on commit d50cafe

Please sign in to comment.