-
Notifications
You must be signed in to change notification settings - Fork 24
feature: Add ListOrganizations & GetOrganizationDetails tfe tools #64
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
base: feature/tfenterprise-long-lived
Are you sure you want to change the base?
feature: Add ListOrganizations & GetOrganizationDetails tfe tools #64
Conversation
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.
I've tested this locally, it works great however I can't truly test the pagination feature which is where my comments are coming from.
allOrgs = append(allOrgs, orgList.Items...) | ||
totalCount = orgList.TotalCount | ||
|
||
if len(allOrgs) >= totalCount || len(orgList.Items) == 0 { |
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.
Why is it necessary to check len(allOrgs) >= totalCount
? Wouldn't this always trigger on the first iteration since we are comparing the totalCount of the list with the same length list of orgList.Items
?
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.
len(allOrgs) >= totalCount
is used to determine when we've collected all organizations across paginated responses. Since orgList.Items
only contains the current page's results, we need to track the total across all pages. This check ensures we stop once we've fetched everything based on the totalCount value returned by the API.
The len(orgList.Items) == 0
check is an additional safeguard in case the API doesn't return the full count or if something unexpected happens (like a partial page).
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.
ah okay so allOrgs just represents what's on the page while totalCount is the total organization count across all pages.
Can we include a comment on this or maybe rename to be clearer?
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.
Updated variable names to make it clearer.
pageNumber := 1 | ||
totalCount := 0 | ||
|
||
// Iterate through all pages to collect all organizations |
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.
this should be done in a separate PR but we should look into how we can have single pagination implementation for use across all tools since I imagine we'll be running into pagination constantly.
Edit: created a issue here
Changes
HCP_TFE_TOKEN
andHCP_TFE_ADDRESS
environment variables.