Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
### Breaking:

### Bug Fixes:

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

### Enhancements:

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

### Dependencies:

- build(deps): `golang.org/x/net` from 0.50.0 to 0.51.0 ([#1674](https://github.com/fastly/cli/pull/1674))
- build(deps): `actions/upload-artifact` from 6 to 7 ([#1675](https://github.com/fastly/cli/pull/1675))
- build(deps): `actions/download-artifact` from 7 to 8 ([#1675](https://github.com/fastly/cli/pull/1675))
Expand Down
50 changes: 31 additions & 19 deletions pkg/commands/apisecurity/tags/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ type ListCommand struct {

// Required.
serviceName argparser.OptionalServiceNameID

// Optional.
limit argparser.OptionalInt
page argparser.OptionalInt
}

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

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

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

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

input := &operations.ListTagsInput{
ServiceID: &serviceID,
}

if c.limit.WasSet {
Comment thread
rcaril marked this conversation as resolved.
input.Limit = &c.limit.Value
}
if c.page.WasSet {
input.Page = &c.page.Value
}
for {
input.Page = &page
input.Limit = &limit

tags, err := operations.ListTags(context.TODO(), fc, input)
if err != nil {
c.Globals.ErrLog.Add(err)
return err
tags, err := operations.ListTags(context.TODO(), fc, input)
if err != nil {
c.Globals.ErrLog.AddWithContext(err, map[string]any{
"Service ID": serviceID,
"Page": page,
})
return err
}

if tags == nil || len(tags.Data) == 0 {
break
}

allTags = append(allTags, tags.Data...)

// Check if we've fetched all results
if len(allTags) >= tags.Meta.Total {
break
}

page++
}

if ok, err := c.WriteJSON(out, tags); ok {
if ok, err := c.WriteJSON(out, allTags); ok {
return err
}

text.PrintOperationTagsTbl(out, tags.Data)
text.PrintOperationTagsTbl(out, allTags)
return nil
}
4 changes: 2 additions & 2 deletions pkg/commands/apisecurity/tags/tags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func TestTagsList(t *testing.T) {
},
{
Name: "validate API success with pagination",
Args: fmt.Sprintf("--service-id %s --limit 10 --page 2", serviceID),
Args: fmt.Sprintf("--service-id %s", serviceID),
Client: &http.Client{
Transport: &testutil.MockRoundTripper{
Response: &http.Response{
Expand All @@ -336,7 +336,7 @@ func TestTagsList(t *testing.T) {
},
},
},
WantOutput: fstfmt.EncodeJSON(tagsObject),
WantOutput: fstfmt.EncodeJSON(tagsObject.Data),
},
}

Expand Down
Loading