Skip to content

Commit 7cd87f2

Browse files
Remove pagination and limit from tags list (#1698)
### Change summary Remove pagination from tags list command All Submissions: * [x] Have you followed the guidelines in our Contributing document? * [x] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change? <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### New Feature Submissions: * [x] Does your submission pass tests?
1 parent ad4049c commit 7cd87f2

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
### Breaking:
66

77
### Bug Fixes:
8+
89
- fix(stats): `stats historical` now returns write errors instead of silently swallowing them [#1678](https://github.com/fastly/cli/pull/1678)
910

1011
### Enhancements:
12+
1113
- feat(stats): add `--field` flag to `stats historical` to filter to a single stats field. [#1678](https://github.com/fastly/cli/pull/1678)
1214
- feat(stats): add `stats aggregate` subcommand for cross-service aggregated stats. [#1678](https://github.com/fastly/cli/pull/1678)
1315
- feat(stats): add `stats usage` subcommand for bandwidth/request usage, with `--by-service` breakdown. [#1678](https://github.com/fastly/cli/pull/1678)
@@ -19,6 +21,7 @@
1921
- feat(service/version): add support for service validation. [#1695](https://github.com/fastly/cli/pull/1695)
2022

2123
### Dependencies:
24+
2225
- build(deps): `golang.org/x/net` from 0.50.0 to 0.51.0 ([#1674](https://github.com/fastly/cli/pull/1674))
2326
- build(deps): `actions/upload-artifact` from 6 to 7 ([#1675](https://github.com/fastly/cli/pull/1675))
2427
- build(deps): `actions/download-artifact` from 7 to 8 ([#1675](https://github.com/fastly/cli/pull/1675))

pkg/commands/apisecurity/tags/list.go

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ type ListCommand struct {
2020

2121
// Required.
2222
serviceName argparser.OptionalServiceNameID
23-
24-
// Optional.
25-
limit argparser.OptionalInt
26-
page argparser.OptionalInt
2723
}
2824

2925
// NewListCommand returns a usable command registered under the parent.
@@ -36,7 +32,7 @@ func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand {
3632

3733
c.CmdClause = parent.Command("list", "List all operation tags")
3834

39-
// Optional.
35+
// Required.
4036
c.RegisterFlag(argparser.StringFlagOpts{
4137
Name: argparser.FlagServiceIDName,
4238
Description: argparser.FlagServiceIDDesc,
@@ -48,8 +44,6 @@ func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand {
4844
Description: argparser.FlagServiceNameDesc,
4945
Dst: &c.serviceName.Value,
5046
})
51-
c.CmdClause.Flag("limit", "Maximum number of tags to return per page").Action(c.limit.Set).IntVar(&c.limit.Value)
52-
c.CmdClause.Flag("page", "Page number to return").Action(c.page.Set).IntVar(&c.page.Value)
5347
c.RegisterFlagBool(c.JSONFlag())
5448

5549
return &c
@@ -77,28 +71,46 @@ func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
7771
if !ok {
7872
return errors.New("failed to convert interface to a fastly client")
7973
}
74+
// Auto-paginate through all results
75+
var allTags []operations.OperationTag
76+
page := 0
77+
limit := 100
8078

8179
input := &operations.ListTagsInput{
8280
ServiceID: &serviceID,
8381
}
8482

85-
if c.limit.WasSet {
86-
input.Limit = &c.limit.Value
87-
}
88-
if c.page.WasSet {
89-
input.Page = &c.page.Value
90-
}
83+
for {
84+
input.Page = &page
85+
input.Limit = &limit
9186

92-
tags, err := operations.ListTags(context.TODO(), fc, input)
93-
if err != nil {
94-
c.Globals.ErrLog.Add(err)
95-
return err
87+
tags, err := operations.ListTags(context.TODO(), fc, input)
88+
if err != nil {
89+
c.Globals.ErrLog.AddWithContext(err, map[string]any{
90+
"Service ID": serviceID,
91+
"Page": page,
92+
})
93+
return err
94+
}
95+
96+
if tags == nil || len(tags.Data) == 0 {
97+
break
98+
}
99+
100+
allTags = append(allTags, tags.Data...)
101+
102+
// Check if we've fetched all results
103+
if len(allTags) >= tags.Meta.Total {
104+
break
105+
}
106+
107+
page++
96108
}
97109

98-
if ok, err := c.WriteJSON(out, tags); ok {
110+
if ok, err := c.WriteJSON(out, allTags); ok {
99111
return err
100112
}
101113

102-
text.PrintOperationTagsTbl(out, tags.Data)
114+
text.PrintOperationTagsTbl(out, allTags)
103115
return nil
104116
}

pkg/commands/apisecurity/tags/tags_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func TestTagsList(t *testing.T) {
312312
},
313313
{
314314
Name: "validate API success with pagination",
315-
Args: fmt.Sprintf("--service-id %s --limit 10 --page 2", serviceID),
315+
Args: fmt.Sprintf("--service-id %s", serviceID),
316316
Client: &http.Client{
317317
Transport: &testutil.MockRoundTripper{
318318
Response: &http.Response{
@@ -336,7 +336,7 @@ func TestTagsList(t *testing.T) {
336336
},
337337
},
338338
},
339-
WantOutput: fstfmt.EncodeJSON(tagsObject),
339+
WantOutput: fstfmt.EncodeJSON(tagsObject.Data),
340340
},
341341
}
342342

0 commit comments

Comments
 (0)