Skip to content

Commit 1fc8961

Browse files
authored
Removed global variable scanning implementationfor Postman (#3843)
1 parent eea7e06 commit 1fc8961

File tree

2 files changed

+5
-61
lines changed

2 files changed

+5
-61
lines changed

pkg/sources/postman/postman.go

+1-16
Original file line numberDiff line numberDiff line change
@@ -251,21 +251,6 @@ func (s *Source) scanWorkspace(ctx context.Context, chunksChan chan *sources.Chu
251251
Type: "workspace",
252252
}
253253

254-
// scan global variables
255-
ctx.Logger().V(2).Info("starting scanning global variables")
256-
globalVars, err := s.client.GetGlobalVariables(workspace.ID)
257-
if err != nil {
258-
// NOTE: global endpoint is finicky
259-
ctx.Logger().V(2).Error(err, "skipping global variables")
260-
}
261-
262-
metadata.Type = GLOBAL_TYPE
263-
metadata.Link = LINK_BASE_URL + "workspace/" + workspace.ID + "/" + GLOBAL_TYPE
264-
metadata.FullID = workspace.CreatedBy + "-" + globalVars.ID
265-
266-
s.scanVariableData(ctx, chunksChan, metadata, globalVars)
267-
ctx.Logger().V(2).Info("finished scanning global variables")
268-
269254
// gather and scan environment variables
270255
for _, envID := range workspace.Environments {
271256
envVars, err := s.client.GetEnvironmentVariables(envID.UUID)
@@ -293,7 +278,7 @@ func (s *Source) scanWorkspace(ctx context.Context, chunksChan chan *sources.Chu
293278

294279
// scan all the collections in the workspace.
295280
// at this point we have all the possible
296-
// substitutions from Global and Environment variables
281+
// substitutions from Environment variables
297282
for _, collectionID := range workspace.Collections {
298283
if shouldSkip(collectionID.UUID, s.conn.IncludeCollections, s.conn.ExcludeCollections) {
299284
continue

pkg/sources/postman/postman_client.go

+4-45
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,10 @@ import (
99
)
1010

1111
const (
12-
GLOBAL_VARS_URL = "https://www.postman.com/_api/workspace/%s/globals"
13-
//Note: This is an undocumented API endpoint. The office API endpoint keeps returning 502.
14-
//We'll shift this once that behavior is resolved and stable.
15-
//Official API Endpoint: "https://api.getpostman.com/workspaces/%s/global-variables"
16-
//GLOBAL_VARS_URL = "https://api.getpostman.com/workspaces/%s/global-variables"
17-
WORKSPACE_URL = "https://api.getpostman.com/workspaces/%s"
18-
ENVIRONMENTS_URL = "https://api.getpostman.com/environments/%s"
19-
COLLECTIONS_URL = "https://api.getpostman.com/collections/%s"
20-
21-
userAgent = "PostmanRuntime/7.26.8"
22-
alt_userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
23-
//Since we're using the undocumented API endpoint for global vars, we need a different user agent.
24-
//We'll shift this once that behavior is resolved and stable.
12+
WORKSPACE_URL = "https://api.getpostman.com/workspaces/%s"
13+
ENVIRONMENTS_URL = "https://api.getpostman.com/environments/%s"
14+
COLLECTIONS_URL = "https://api.getpostman.com/collections/%s"
15+
userAgent = "PostmanRuntime/7.26.8"
2516
defaultContentType = "*"
2617
)
2718

@@ -70,10 +61,6 @@ type Environment struct {
7061
VariableData `json:"environment"`
7162
}
7263

73-
type GlobalVars struct {
74-
VariableData `json:"data"`
75-
}
76-
7764
type Metadata struct {
7865
WorkspaceUUID string
7966
WorkspaceName string
@@ -88,7 +75,6 @@ type Metadata struct {
8875
Link string //direct link to the folder (could be .json file path)
8976
Type string //folder, request, etc.
9077
EnvironmentName string
91-
GlobalID string // might just be FullID, not sure
9278
VarType string
9379
FieldName string
9480
FieldType string
@@ -318,33 +304,6 @@ func (c *Client) GetWorkspace(workspaceUUID string) (Workspace, error) {
318304
return obj.Workspace, nil
319305
}
320306

321-
// GetGlobalVariables returns the global variables for a given workspace
322-
func (c *Client) GetGlobalVariables(workspace_uuid string) (VariableData, error) {
323-
obj := struct {
324-
VariableData VariableData `json:"data"`
325-
}{}
326-
327-
url := fmt.Sprintf(GLOBAL_VARS_URL, workspace_uuid)
328-
r, err := c.getPostmanReq(url, map[string]string{"User-Agent": alt_userAgent})
329-
if err != nil {
330-
err = fmt.Errorf("could not get global variables for workspace: %s", workspace_uuid)
331-
return VariableData{}, err
332-
}
333-
334-
body, err := io.ReadAll(r.Body)
335-
if err != nil {
336-
err = fmt.Errorf("could not read response body for workspace: %s", workspace_uuid)
337-
return VariableData{}, err
338-
}
339-
r.Body.Close()
340-
341-
if err := json.Unmarshal([]byte(body), &obj); err != nil {
342-
err = fmt.Errorf("could not unmarshal global variables JSON for workspace: %s", workspace_uuid)
343-
return VariableData{}, err
344-
}
345-
return obj.VariableData, nil
346-
}
347-
348307
// GetEnvironmentVariables returns the environment variables for a given environment
349308
func (c *Client) GetEnvironmentVariables(environment_uuid string) (VariableData, error) {
350309
obj := struct {

0 commit comments

Comments
 (0)