-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add ForEachResource and CollectResources utils functions #48729
Add ForEachResource and CollectResources utils functions #48729
Conversation
2847c4a
to
4866a7b
Compare
3d824c9
to
795dc1f
Compare
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.
Nice
var options ForEachOptions | ||
for _, opt := range opts { | ||
opt(&options) | ||
} |
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: set default pageSize if not provided with WithPageSize
? its usually apidefaults.DefaultChunkSize
value used as default.
should we also validate the pagesize provided with WithPageSize
?
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.
The 0 value is valid as page side. I it will mean that the server will use default page size and it is commonly used patter in our codebase for instance
teleport/tool/tctl/common/acl_command.go
Line 121 in fa97b8f
page, nextKey, err = client.AccessListClient().ListAccessLists(ctx, 0, nextKey) |
04b3d2a
to
fdf7981
Compare
@smallinsky See the table below for backport results.
|
What
This PR introduces the helper functions
ForEachResource
andCollectResources
, which handle pagination automatically. These functions support the following function signatures:like: ListStaticHostUsers, ListOktaAssignments, ListAppSessions
or like: ListPermissionSets, ListAccountAssignments with signature:
Why
These helper functions simplify resource collection by eliminating the need for manually handling pagination logic. Instead of writing code like this:
which is prone to bugs e.g.,
nextKey
users can now simply call:
This approach minimizes potential errors and makes code more concise and readable.