Skip to content

Commit 3b5dd3b

Browse files
authored
Upgrade to go-fastly version 11. (#1514)
go-fastly version 11 requires a context.Context object to be passed as the first argument in all of the API functions it exports. This commit modifies all of the code in the CLI to pass context.TODO() in that case, since the CLI does not use context objects for any other purpose. The CLI also has an internal 'interface' which maps to the complete set of API functions in the 'fastly' namespace exported by go-fastly, and hundreds of 'mock' functions used in the CLI test suite. Those have also been updated, and along the way many inconsistencies in those function signatures were corrected. go-fastly version 11 removed a deprecated set of product enablement API functions, so the `fastly products` command has been updated to use the new API functions. The tests for the `fastly products` command no longer mock the API calls as they no longer exist, and the new `fastly product` command which will appear in the next release will provide full test coverage of the CLI's use of the new product enablement API functions. There are no functional changes in this commit, and the entire test suite still passes. At least 80% of the changes in this commit were produced using [comby](https://comby.dev/). 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? ### Changes to Core Features: * [X] Have you added an explanation of what your changes do and why you'd like us to include them? * [X] Have you written new tests for your core changes, as applicable? * [X] Have you successfully run tests with your changes locally?
1 parent 288e57d commit 3b5dd3b

469 files changed

Lines changed: 3663 additions & 3361 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Bug fixes:
1212

1313
### Dependencies:
14+
- build(deps): `github.com/fastly/go-fastly/v11` from 10 to 111 ([#14XX](https://github.com/fastly/cli/pull/14XX))
1415
- build(deps): `golang.org/x/sys` from 0.33.0 to 0.34.0 ([#1508](https://github.com/fastly/cli/pull/1508))
1516
- build(deps): `golang.org/x/term` from 0.32.0 to 0.33.0 ([#1508](https://github.com/fastly/cli/pull/1508))
1617
- build(deps): `golang.org/x/crypto` from 0.39.0 to 0.40.0 ([#1508](https://github.com/fastly/cli/pull/1508))

go.mod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
)
2828

2929
require (
30-
github.com/fastly/go-fastly/v10 v10.5.1
30+
github.com/fastly/go-fastly/v11 v11.2.0
3131
github.com/hashicorp/cap v0.9.0
3232
github.com/kennygrant/sanitize v1.2.4
3333
github.com/otiai10/copy v1.14.1
@@ -43,7 +43,6 @@ require (
4343
github.com/dnaeon/go-vcr v1.2.0 // indirect
4444
github.com/go-jose/go-jose/v4 v4.0.5 // indirect
4545
github.com/kr/pretty v0.3.1 // indirect
46-
github.com/mitchellh/go-ps v1.0.0 // indirect
4746
github.com/otiai10/mint v1.6.3 // indirect
4847
github.com/rogpeppe/go-internal v1.14.1 // indirect
4948
github.com/stretchr/testify v1.10.0 // indirect
@@ -81,4 +80,7 @@ require (
8180
gopkg.in/yaml.v3 v3.0.1 // indirect
8281
)
8382

84-
require 4d63.com/optional v0.2.0
83+
require (
84+
4d63.com/optional v0.2.0
85+
github.com/mitchellh/go-ps v1.0.0
86+
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5/go.mod h1:qssHWj6
2525
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
2626
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0 h1:aYo8nnk3ojoQkP5iErif5Xxv0Mo0Ga/FR5+ffl/7+Nk=
2727
github.com/dustinkirkland/golang-petname v0.0.0-20240428194347-eebcea082ee0/go.mod h1:8AuBTZBRSFqEYBPYULd+NN474/zZBLP+6WeT5S9xlAc=
28-
github.com/fastly/go-fastly/v10 v10.5.1 h1:mKtR8DQM0yt58J44pzUAoQlsxUFKK07V/Ui3KcuzOCQ=
29-
github.com/fastly/go-fastly/v10 v10.5.1/go.mod h1:GXFNVyufNV0E/0JdG932WE8YGYSL5/ar+sPnlhqprhQ=
28+
github.com/fastly/go-fastly/v11 v11.2.0 h1:4gFhs6dZ0HzNGpZ6XiCi1dwESCMD4je3+OENIcD7wJk=
29+
github.com/fastly/go-fastly/v11 v11.2.0/go.mod h1:yv1Tvz457kNCxyNaPi3J8Z3xUxeU8m1XN7O4a8OFLgc=
3030
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible h1:FhrXlfhgGCS+uc6YwyiFUt04alnjpoX7vgDKJxS6Qbk=
3131
github.com/fastly/kingpin v2.1.12-0.20191105091915-95d230a53780+incompatible/go.mod h1:U8UynVoU1SQaqD2I4ZqgYd5lx3A1ipQYn4aSt2Y5h6c=
3232
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=

pkg/api/interface.go

Lines changed: 395 additions & 398 deletions
Large diffs are not rendered by default.

pkg/app/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import (
1616
"github.com/hashicorp/cap/oidc"
1717
"github.com/skratchdot/open-golang/open"
1818

19-
"github.com/fastly/go-fastly/v10/fastly"
19+
"github.com/fastly/go-fastly/v11/fastly"
20+
2021
"github.com/fastly/kingpin"
2122

2223
"github.com/fastly/cli/pkg/api"

pkg/argparser/cmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import (
44
"fmt"
55
"io"
66

7-
"github.com/fastly/go-fastly/v10/fastly"
7+
"github.com/fastly/go-fastly/v11/fastly"
8+
89
"github.com/fastly/kingpin"
910

1011
"4d63.com/optional"

pkg/argparser/flags.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package argparser
22

33
import (
4+
"context"
45
"encoding/json"
56
"errors"
67
"fmt"
@@ -12,7 +13,8 @@ import (
1213
"strconv"
1314
"strings"
1415

15-
"github.com/fastly/go-fastly/v10/fastly"
16+
"github.com/fastly/go-fastly/v11/fastly"
17+
1618
"github.com/fastly/kingpin"
1719

1820
"github.com/fastly/cli/pkg/api"
@@ -114,7 +116,7 @@ type OptionalServiceVersion struct {
114116

115117
// Parse returns a service version based on the given user input.
116118
func (sv *OptionalServiceVersion) Parse(sid string, client api.Interface) (*fastly.Version, error) {
117-
vs, err := client.ListVersions(&fastly.ListVersionsInput{
119+
vs, err := client.ListVersions(context.TODO(), &fastly.ListVersionsInput{
118120
ServiceID: sid,
119121
})
120122
if err != nil {
@@ -159,7 +161,7 @@ type OptionalServiceNameID struct {
159161

160162
// Parse returns a service ID based off the given service name.
161163
func (sv *OptionalServiceNameID) Parse(client api.Interface) (serviceID string, err error) {
162-
paginator := client.GetServices(&fastly.GetServicesInput{})
164+
paginator := client.GetServices(context.TODO(), &fastly.GetServicesInput{})
163165
var services []*fastly.Service
164166
for paginator.HasNext() {
165167
data, err := paginator.GetNext()
@@ -228,7 +230,7 @@ func (ac *OptionalAutoClone) Parse(v *fastly.Version, sid string, verbose bool,
228230
}
229231
}
230232
if ac.Value && (v.Active != nil && *v.Active || v.Locked != nil && *v.Locked) {
231-
version, err := client.CloneVersion(&fastly.CloneVersionInput{
233+
version, err := client.CloneVersion(context.TODO(), &fastly.CloneVersionInput{
232234
ServiceID: sid,
233235
ServiceVersion: fastly.ToValue(v.Number),
234236
})

pkg/argparser/flags_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package argparser_test
22

33
import (
44
"bytes"
5+
"context"
56
"fmt"
67
"io"
78
"net/http"
@@ -10,7 +11,7 @@ import (
1011
"strings"
1112
"testing"
1213

13-
"github.com/fastly/go-fastly/v10/fastly"
14+
"github.com/fastly/go-fastly/v11/fastly"
1415

1516
"github.com/fastly/cli/pkg/argparser"
1617
"github.com/fastly/cli/pkg/manifest"
@@ -91,7 +92,7 @@ func TestOptionalServiceVersionParse(t *testing.T) {
9192
//
9293
// The first element is active, the second is locked, the third is
9394
// editable, the fourth is staged.
94-
func listVersions(i *fastly.ListVersionsInput) ([]*fastly.Version, error) {
95+
func listVersions(_ context.Context, i *fastly.ListVersionsInput) ([]*fastly.Version, error) {
9596
return []*fastly.Version{
9697
{
9798
ServiceID: fastly.ToPointer(i.ServiceID),
@@ -364,8 +365,8 @@ func TestServiceID(t *testing.T) {
364365
File: manifest.File{ServiceID: "123"},
365366
},
366367
API: mock.API{
367-
GetServicesFn: func(_ *fastly.GetServicesInput) *fastly.ListPaginator[fastly.Service] {
368-
return fastly.NewPaginator[fastly.Service](&mock.HTTPClient{
368+
GetServicesFn: func(ctx context.Context, _ *fastly.GetServicesInput) *fastly.ListPaginator[fastly.Service] {
369+
return fastly.NewPaginator[fastly.Service](ctx, &mock.HTTPClient{
369370
Errors: []error{nil},
370371
Responses: []*http.Response{
371372
{
@@ -383,8 +384,8 @@ func TestServiceID(t *testing.T) {
383384
ServiceName: argparser.OptionalServiceNameID{argparser.OptionalString{Optional: argparser.Optional{WasSet: true}, Value: "bar"}},
384385
Data: manifest.Data{},
385386
API: mock.API{
386-
GetServicesFn: func(_ *fastly.GetServicesInput) *fastly.ListPaginator[fastly.Service] {
387-
return fastly.NewPaginator[fastly.Service](&mock.HTTPClient{
387+
GetServicesFn: func(ctx context.Context, _ *fastly.GetServicesInput) *fastly.ListPaginator[fastly.Service] {
388+
return fastly.NewPaginator[fastly.Service](ctx, &mock.HTTPClient{
388389
Errors: []error{nil},
389390
Responses: []*http.Response{
390391
{
@@ -441,8 +442,8 @@ func TestContent(t *testing.T) {
441442
}
442443

443444
// cloneVersionResult returns a function which returns a specific cloned version.
444-
func cloneVersionResult(version int) func(i *fastly.CloneVersionInput) (*fastly.Version, error) {
445-
return func(i *fastly.CloneVersionInput) (*fastly.Version, error) {
445+
func cloneVersionResult(version int) func(_ context.Context, i *fastly.CloneVersionInput) (*fastly.Version, error) {
446+
return func(_ context.Context, i *fastly.CloneVersionInput) (*fastly.Version, error) {
446447
return &fastly.Version{
447448
ServiceID: fastly.ToPointer(i.ServiceID),
448449
Number: fastly.ToPointer(version),

pkg/commands/acl/acl_test.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package acl_test
22

33
import (
4+
"context"
45
"testing"
56

6-
"github.com/fastly/go-fastly/v10/fastly"
7+
"github.com/fastly/go-fastly/v11/fastly"
78

89
root "github.com/fastly/cli/pkg/commands/acl"
910
"github.com/fastly/cli/pkg/mock"
@@ -47,7 +48,7 @@ func TestACLCreate(t *testing.T) {
4748
Name: "validate CreateACL API error",
4849
API: mock.API{
4950
ListVersionsFn: testutil.ListVersions,
50-
CreateACLFn: func(_ *fastly.CreateACLInput) (*fastly.ACL, error) {
51+
CreateACLFn: func(_ context.Context, _ *fastly.CreateACLInput) (*fastly.ACL, error) {
5152
return nil, testutil.Err
5253
},
5354
},
@@ -58,7 +59,7 @@ func TestACLCreate(t *testing.T) {
5859
Name: "validate CreateACL API success",
5960
API: mock.API{
6061
ListVersionsFn: testutil.ListVersions,
61-
CreateACLFn: func(i *fastly.CreateACLInput) (*fastly.ACL, error) {
62+
CreateACLFn: func(_ context.Context, i *fastly.CreateACLInput) (*fastly.ACL, error) {
6263
return &fastly.ACL{
6364
ACLID: fastly.ToPointer("456"),
6465
Name: i.Name,
@@ -75,7 +76,7 @@ func TestACLCreate(t *testing.T) {
7576
API: mock.API{
7677
ListVersionsFn: testutil.ListVersions,
7778
CloneVersionFn: testutil.CloneVersionResult(4),
78-
CreateACLFn: func(i *fastly.CreateACLInput) (*fastly.ACL, error) {
79+
CreateACLFn: func(_ context.Context, i *fastly.CreateACLInput) (*fastly.ACL, error) {
7980
return &fastly.ACL{
8081
ACLID: fastly.ToPointer("456"),
8182
Name: i.Name,
@@ -129,7 +130,7 @@ func TestACLDelete(t *testing.T) {
129130
Name: "validate DeleteACL API error",
130131
API: mock.API{
131132
ListVersionsFn: testutil.ListVersions,
132-
DeleteACLFn: func(_ *fastly.DeleteACLInput) error {
133+
DeleteACLFn: func(_ context.Context, _ *fastly.DeleteACLInput) error {
133134
return testutil.Err
134135
},
135136
},
@@ -140,7 +141,7 @@ func TestACLDelete(t *testing.T) {
140141
Name: "validate DeleteACL API success",
141142
API: mock.API{
142143
ListVersionsFn: testutil.ListVersions,
143-
DeleteACLFn: func(_ *fastly.DeleteACLInput) error {
144+
DeleteACLFn: func(_ context.Context, _ *fastly.DeleteACLInput) error {
144145
return nil
145146
},
146147
},
@@ -152,7 +153,7 @@ func TestACLDelete(t *testing.T) {
152153
API: mock.API{
153154
ListVersionsFn: testutil.ListVersions,
154155
CloneVersionFn: testutil.CloneVersionResult(4),
155-
DeleteACLFn: func(_ *fastly.DeleteACLInput) error {
156+
DeleteACLFn: func(_ context.Context, _ *fastly.DeleteACLInput) error {
156157
return nil
157158
},
158159
},
@@ -185,7 +186,7 @@ func TestACLDescribe(t *testing.T) {
185186
Name: "validate GetACL API error",
186187
API: mock.API{
187188
ListVersionsFn: testutil.ListVersions,
188-
GetACLFn: func(_ *fastly.GetACLInput) (*fastly.ACL, error) {
189+
GetACLFn: func(_ context.Context, _ *fastly.GetACLInput) (*fastly.ACL, error) {
189190
return nil, testutil.Err
190191
},
191192
},
@@ -230,7 +231,7 @@ func TestACLList(t *testing.T) {
230231
Name: "validate ListACLs API error",
231232
API: mock.API{
232233
ListVersionsFn: testutil.ListVersions,
233-
ListACLsFn: func(_ *fastly.ListACLsInput) ([]*fastly.ACL, error) {
234+
ListACLsFn: func(_ context.Context, _ *fastly.ListACLsInput) ([]*fastly.ACL, error) {
234235
return nil, testutil.Err
235236
},
236237
},
@@ -311,7 +312,7 @@ func TestACLUpdate(t *testing.T) {
311312
Name: "validate UpdateACL API error",
312313
API: mock.API{
313314
ListVersionsFn: testutil.ListVersions,
314-
UpdateACLFn: func(_ *fastly.UpdateACLInput) (*fastly.ACL, error) {
315+
UpdateACLFn: func(_ context.Context, _ *fastly.UpdateACLInput) (*fastly.ACL, error) {
315316
return nil, testutil.Err
316317
},
317318
},
@@ -322,7 +323,7 @@ func TestACLUpdate(t *testing.T) {
322323
Name: "validate UpdateACL API success",
323324
API: mock.API{
324325
ListVersionsFn: testutil.ListVersions,
325-
UpdateACLFn: func(i *fastly.UpdateACLInput) (*fastly.ACL, error) {
326+
UpdateACLFn: func(_ context.Context, i *fastly.UpdateACLInput) (*fastly.ACL, error) {
326327
return &fastly.ACL{
327328
ACLID: fastly.ToPointer("456"),
328329
Name: i.NewName,
@@ -339,7 +340,7 @@ func TestACLUpdate(t *testing.T) {
339340
API: mock.API{
340341
ListVersionsFn: testutil.ListVersions,
341342
CloneVersionFn: testutil.CloneVersionResult(4),
342-
UpdateACLFn: func(i *fastly.UpdateACLInput) (*fastly.ACL, error) {
343+
UpdateACLFn: func(_ context.Context, i *fastly.UpdateACLInput) (*fastly.ACL, error) {
343344
return &fastly.ACL{
344345
ACLID: fastly.ToPointer("456"),
345346
Name: i.NewName,
@@ -356,7 +357,7 @@ func TestACLUpdate(t *testing.T) {
356357
testutil.RunCLIScenarios(t, []string{root.CommandName, "update"}, scenarios)
357358
}
358359

359-
func getACL(i *fastly.GetACLInput) (*fastly.ACL, error) {
360+
func getACL(_ context.Context, i *fastly.GetACLInput) (*fastly.ACL, error) {
360361
t := testutil.Date
361362

362363
return &fastly.ACL{
@@ -371,7 +372,7 @@ func getACL(i *fastly.GetACLInput) (*fastly.ACL, error) {
371372
}, nil
372373
}
373374

374-
func listACLs(i *fastly.ListACLsInput) ([]*fastly.ACL, error) {
375+
func listACLs(_ context.Context, i *fastly.ListACLsInput) ([]*fastly.ACL, error) {
375376
t := testutil.Date
376377
vs := []*fastly.ACL{
377378
{

pkg/commands/acl/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package acl
22

33
import (
4+
"context"
45
"io"
56

6-
"github.com/fastly/go-fastly/v10/fastly"
7+
"github.com/fastly/go-fastly/v11/fastly"
78

89
"4d63.com/optional"
910

@@ -86,7 +87,7 @@ func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
8687
}
8788

8889
input := c.constructInput(serviceID, fastly.ToValue(serviceVersion.Number))
89-
a, err := c.Globals.APIClient.CreateACL(input)
90+
a, err := c.Globals.APIClient.CreateACL(context.TODO(), input)
9091
if err != nil {
9192
c.Globals.ErrLog.AddWithContext(err, map[string]any{
9293
"Service ID": serviceID,

0 commit comments

Comments
 (0)