-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Draft] Add pagination client support to project and violations endpoint #25
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bd74700
WIP to add client support for pagination
b1f809a
WIP to add client support for pagination - WORKING LOGIC
326383a
cleanup code
d93016a
fix tests for get all projects
a36eb2c
use get all projects instead
7ed3f94
moved pages to url as query params
walihann 8acef7e
fix test for new logic
1ddc2aa
simplify project call path
bdef4e1
update violation policy pulling with pagination
538244b
use new policy pull func in exporter
24bcf7d
add TODO item
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,12 +56,39 @@ type ViolationAnalysis struct { | |
IsSuppressed bool `json:"isSuppressed,omitempty"` | ||
} | ||
|
||
// GetAllViolations returns violations for the entire portfolio. Suppressed | ||
// violations are omitted unless suppressed is true | ||
func (c *Client) GetAllViolations(suppressed bool) ([]*PolicyViolation, error) { | ||
// dependency track per default only returns a 100 items per get, therefore we need to iterate over all PolicyViolation pages to get all PolicyViolation | ||
|
||
// all PolicyViolation found in pagination | ||
allPolicyViolations := []*PolicyViolation{} | ||
// the last project found in the last pagination page result | ||
lastPaginationPage := 1 | ||
// state var to show if all PolicyViolation projects where found | ||
foundAll := false | ||
|
||
for !foundAll { | ||
req, err := c.GetViolations(suppressed, lastPaginationPage, 100) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(req) == 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The number of total items will not necessarily be a multiple of 100, which means the 'last page' will have less than 100 results. If we change this check to |
||
foundAll = true | ||
break | ||
} | ||
allPolicyViolations = append(allPolicyViolations, req...) | ||
lastPaginationPage++ | ||
} | ||
return allPolicyViolations, nil | ||
} | ||
|
||
// GetViolations returns violations for the entire portfolio. Suppressed | ||
// violations are omitted unless suppressed is true | ||
func (c *Client) GetViolations(suppressed bool) ([]*PolicyViolation, error) { | ||
func (c *Client) GetViolations(suppressed bool, pageNumber int, pageSize int) ([]*PolicyViolation, error) { | ||
params := url.Values{} | ||
params.Add("suppressed", strconv.FormatBool(suppressed)) | ||
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/v1/violation?%s", params.Encode()), nil) | ||
req, err := c.newRequest(http.MethodGet, fmt.Sprintf("/api/v1/violation?%s&pageSize=%d&pageNumber=%d", params.Encode(), pageSize, pageNumber), nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I don't think the comments are necessary. I think it's clear enough from the code.