Skip to content

Commit eb51ff0

Browse files
committed
TUN-5262: Allow to configure max fetch size for listing queries
This can be useful/important for accounts with many tunnels that exceed the 1000 default page size. There are various tunnel subcommands that use listing underneath, so we make that flag a tunnel one, rather than adding it to each subcommand.
1 parent 3f4407c commit eb51ff0

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

cmd/cloudflared/tunnel/cmd.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,12 @@ func tunnelFlags(shouldHide bool) []cli.Flag {
646646
Value: "https://api.trycloudflare.com",
647647
Hidden: true,
648648
}),
649+
&cli.UintFlag{
650+
Name: "max-fetch-size",
651+
Usage: `The maximum number of results that cloudflared can fetch from Cloudflare API for any listing operations needed`,
652+
EnvVars: []string{"TUNNEL_MAX_FETCH_SIZE"},
653+
Hidden: true,
654+
},
649655
selectProtocolFlag,
650656
overwriteDNSFlag,
651657
}...)

cmd/cloudflared/tunnel/subcommand_context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ func (sc *subcommandContext) tunnelActive(name string) (*tunnelstore.Tunnel, boo
336336
filter := tunnelstore.NewFilter()
337337
filter.NoDeleted()
338338
filter.ByName(name)
339+
if maxFetch := sc.c.Uint("max-fetch-size"); maxFetch > 0 {
340+
filter.MaxFetchSize(maxFetch)
341+
}
342+
339343
tunnels, err := sc.list(filter)
340344
if err != nil {
341345
return nil, false, err
@@ -385,6 +389,10 @@ func (sc *subcommandContext) findIDs(inputs []string) ([]uuid.UUID, error) {
385389
// First, look up all tunnels the user has
386390
filter := tunnelstore.NewFilter()
387391
filter.NoDeleted()
392+
if maxFetch := sc.c.Uint("max-fetch-size"); maxFetch > 0 {
393+
filter.MaxFetchSize(maxFetch)
394+
}
395+
388396
tunnels, err := sc.list(filter)
389397
if err != nil {
390398
return nil, err

cmd/cloudflared/tunnel/subcommands.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ func listCommand(c *cli.Context) error {
277277
}
278278
filter.ByTunnelID(tunnelID)
279279
}
280+
if maxFetch := c.Uint("max-fetch-size"); maxFetch > 0 {
281+
filter.MaxFetchSize(maxFetch)
282+
}
280283

281284
tunnels, err := sc.list(filter)
282285
if err != nil {

tunnelstore/filter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tunnelstore
22

33
import (
44
"net/url"
5+
"strconv"
56
"time"
67

78
"github.com/google/uuid"
@@ -45,6 +46,10 @@ func (f *Filter) ByTunnelID(tunnelID uuid.UUID) {
4546
f.queryParams.Set("uuid", tunnelID.String())
4647
}
4748

49+
func (f *Filter) MaxFetchSize(max uint) {
50+
f.queryParams.Set("per_page", strconv.Itoa(int(max)))
51+
}
52+
4853
func (f Filter) encode() string {
4954
return f.queryParams.Encode()
5055
}

0 commit comments

Comments
 (0)