Skip to content
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 support for Pagination in Tunnels API #1206

Merged
merged 11 commits into from
Feb 16, 2023

Conversation

EngHabu
Copy link
Contributor

@EngHabu EngHabu commented Feb 10, 2023

Signed-off-by: Haytham Abuelfutuh haytham@afutuh.com

Description

GET Tunnels API supports pagination but the cloudflare-go client doesn't. I copied the way it's done from Zone Contexts into this API. Generally speaking I think all APIs that support pagination should ideally support ReqOptions

Example:

actual, err := client.Tunnels(context.Background(), AccountIdentifier(testAccountID),
		TunnelListParams{}, WithPagination(PaginationOptions{PerPage: 1, Page: 2}))

Has your change been tested?

Using the fork, we have deployed a service that syncs the status of the channels to a local DB and now is able to iterate through all tunnels we've (100+ in total)

Types of changes

What sort of change does your code introduce/modify?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • This change is using publicly documented (api.cloudflare.com or developers.cloudflare.com) and stable APIs.

Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 10, 2023

changelog detected ✅

@codecov-commenter
Copy link

codecov-commenter commented Feb 10, 2023

Codecov Report

Merging #1206 (21e905b) into master (c07adfc) will increase coverage by 0.02%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1206      +/-   ##
==========================================
+ Coverage   49.36%   49.39%   +0.02%     
==========================================
  Files         128      128              
  Lines       12430    12437       +7     
==========================================
+ Hits         6136     6143       +7     
  Misses       4890     4890              
  Partials     1404     1404              
Impacted Files Coverage Δ
dlp_profile.go 37.93% <ø> (ø)
dns.go 72.72% <ø> (ø)
tunnel.go 39.42% <100.00%> (+2.10%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
@EngHabu EngHabu marked this pull request as ready for review February 10, 2023 23:18
@jacobbednarz
Copy link
Member

thanks for the PR @EngHabu. this is conceptually where we want to be but the implementation is a little off with the other parts of the library. we have the next gen client docs that outline the way we want to handle these but in short:

  • methods will have at maximum, three parameters
  • pagination configuration is a part of the third and final parameter if supported
  • List style methods automatically paginate all results unless Page/PerPage are provided
  • query parameters are encoded using the struct fields, not manually

we have quite a quite methods now that implement this so check out

func (api *API) ListDNSRecords(ctx context.Context, rc *ResourceContainer, params ListDNSRecordsParams) ([]DNSRecord, *ResultInfo, error) {
if you're after prior art.

if you can swap to these conventions, i'm 👍 on getting this one merged.

@EngHabu
Copy link
Contributor Author

EngHabu commented Feb 13, 2023

@jacobbednarz, thank you for the response. Are you ok breaking the current signature by returning a 3rd value (ResultInfo)? or should I leave this part out?

Signed-off-by: Haytham Abuelfutuh <haytham@afutuh.com>
@jacobbednarz
Copy link
Member

yep, that's totally fine here since we're moving towards the expected conventions 👍

@EngHabu
Copy link
Contributor Author

EngHabu commented Feb 16, 2023

Can you take a look now, @jacobbednarz?

.changelog/1206.txt Outdated Show resolved Hide resolved
@jacobbednarz jacobbednarz merged commit 5ddad20 into cloudflare:master Feb 16, 2023
@jacobbednarz
Copy link
Member

thanks @EngHabu, appreciate it!

@github-actions github-actions bot added this to the v0.62.0 milestone Feb 16, 2023
github-actions bot pushed a commit that referenced this pull request Feb 16, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2023

This functionality has been released in v0.62.0.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants