Skip to content

Commit

Permalink
Migrate to Go-Fastly 2.0.0 (#169)
Browse files Browse the repository at this point in the history
* make compiler happy.

* fix other files

* fix domain update tests

* fix service update

* TODO/NOTE about client validation

* fix service update

* fix ftp update test

* ensure when we say 'all' we mean it, as PublicKey was missed out at some point

* fix failing tests due to vim deleting spaces at end of line

* Refactor Valid to WasSet for clarity/less ambiguity

* fix code after rebase of master

* Apply suggestions from code review

* go mod tidy

Co-authored-by: Patrick Hamann <[email protected]>
  • Loading branch information
Integralist and phamann authored Nov 24, 2020
1 parent cab7281 commit 782b9ed
Show file tree
Hide file tree
Showing 226 changed files with 3,580 additions and 3,508 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/blang/semver v3.5.1+incompatible
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0
github.com/fastly/go-fastly v1.18.0
github.com/fastly/go-fastly/v2 v2.0.0
github.com/fatih/color v1.7.0
github.com/frankban/quicktest v1.5.0 // indirect
github.com/google/go-cmp v0.3.1
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0 h1:9
github.com/dustinkirkland/golang-petname v0.0.0-20191129215211-8e5a1ed0cff0/go.mod h1:V+Qd57rJe8gd4eiGzZyg4h54VLHmYVVw54iMnlAMrF8=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/fastly/go-fastly v1.18.0 h1:fyVq/142VTFz5ZkNE5d57K+NkTmtwxt2K2Mh5sV5scg=
github.com/fastly/go-fastly v1.18.0/go.mod h1:fwYSSnZ6zEClwRS65T0f57Yh83Tc4gL12GgttQwJZfA=
github.com/fastly/go-fastly/v2 v2.0.0 h1:dCPOEbTXy8ic5CGj6YibPNvRYG01y15H7kHTlC4d57k=
github.com/fastly/go-fastly/v2 v2.0.0/go.mod h1:+gom+YR+9Q5I4biSk/ZjHQGWXxqpRxC3YDVYQcRpZwQ=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
Expand Down Expand Up @@ -137,6 +137,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down Expand Up @@ -168,9 +169,11 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
golang.org/x/tools v0.0.0-20190729092621-ff9f1409240a/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200624163319-25775e59acb7 h1:LqJsVIMDZN3D7MG8O2vT+ClouLDqeK3YkClIcDzImVs=
golang.org/x/tools v0.0.0-20200624163319-25775e59acb7/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20180810215634-df19058c872c h1:vTxShRUnK60yd8DZU+f95p1zSLj814+5CuEh7NjF2/Y=
Expand All @@ -195,4 +198,5 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.1-2020.1.4 h1:UoveltGrhghAA7ePc+e+QYDHXrBps2PqFZiHkGR/xK8=
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
6 changes: 5 additions & 1 deletion pkg/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package api
import (
"net/http"

"github.com/fastly/go-fastly/fastly"
"github.com/fastly/go-fastly/v2/fastly"
)

// HTTPClient models a concrete http.Client. It's a consumer contract for some
Expand All @@ -16,6 +16,10 @@ type HTTPClient interface {

// Interface models the methods of the Fastly API client that we use.
// It exists to allow for easier testing, in combination with Mock.
//
// TODO(integralist):
// There are missing methods such as GetVersion from this list so review in
// future the missing features in CLI and implement here.
type Interface interface {
GetTokenSelf() (*fastly.Token, error)

Expand Down
2 changes: 1 addition & 1 deletion pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import (
"github.com/fastly/cli/pkg/update"
"github.com/fastly/cli/pkg/version"
"github.com/fastly/cli/pkg/whoami"
"github.com/fastly/go-fastly/fastly"
"github.com/fastly/go-fastly/v2/fastly"
"gopkg.in/alecthomas/kingpin.v3-unstable"
)

Expand Down
2 changes: 1 addition & 1 deletion pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ COMMANDS
-s, --service-id=SERVICE-ID Service ID
service-version update --version=VERSION --comment=COMMENT [<flags>]
service-version update --version=VERSION [<flags>]
Update a Fastly service version
-s, --service-id=SERVICE-ID Service ID
Expand Down
60 changes: 30 additions & 30 deletions pkg/backend/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/fastly/cli/pkg/mock"
"github.com/fastly/cli/pkg/testutil"
"github.com/fastly/cli/pkg/update"
"github.com/fastly/go-fastly/fastly"
"github.com/fastly/go-fastly/v2/fastly"
)

func TestBackendCreate(t *testing.T) {
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestBackendUpdate(t *testing.T) {
wantError: errTest.Error(),
},
{
args: []string{"backend", "update", "--service-id", "123", "--version", "1", "--name", "www.test.com", "--new-name", "www.example.com"},
args: []string{"backend", "update", "--service-id", "123", "--version", "1", "--name", "www.test.com", "--new-name", "www.example.com", "--comment", ""},
api: mock.API{
GetBackendFn: getBackendOK,
UpdateBackendFn: updateBackendOK,
Expand Down Expand Up @@ -259,10 +259,10 @@ var errTest = errors.New("fixture error")

func createBackendOK(i *fastly.CreateBackendInput) (*fastly.Backend, error) {
return &fastly.Backend{
ServiceID: i.Service,
Version: i.Version,
Name: i.Name,
Comment: i.Comment,
ServiceID: i.ServiceID,
ServiceVersion: i.ServiceVersion,
Name: i.Name,
Comment: i.Comment,
}, nil
}

Expand All @@ -272,21 +272,21 @@ func createBackendError(i *fastly.CreateBackendInput) (*fastly.Backend, error) {

func listBackendsOK(i *fastly.ListBackendsInput) ([]*fastly.Backend, error) {
return []*fastly.Backend{
&fastly.Backend{
ServiceID: i.Service,
Version: i.Version,
Name: "test.com",
Address: "www.test.com",
Port: 80,
Comment: "test",
{
ServiceID: i.ServiceID,
ServiceVersion: i.ServiceVersion,
Name: "test.com",
Address: "www.test.com",
Port: 80,
Comment: "test",
},
&fastly.Backend{
ServiceID: i.Service,
Version: i.Version,
Name: "example.com",
Address: "www.example.com",
Port: 443,
Comment: "example",
{
ServiceID: i.ServiceID,
ServiceVersion: i.ServiceVersion,
Name: "example.com",
Address: "www.example.com",
Port: 443,
Comment: "example",
},
}, nil
}
Expand Down Expand Up @@ -358,12 +358,12 @@ var listBackendsVerboseOutput = strings.Join([]string{

func getBackendOK(i *fastly.GetBackendInput) (*fastly.Backend, error) {
return &fastly.Backend{
ServiceID: i.Service,
Version: i.Version,
Name: "test.com",
Address: "www.test.com",
Port: 80,
Comment: "test",
ServiceID: i.ServiceID,
ServiceVersion: i.ServiceVersion,
Name: "test.com",
Address: "www.test.com",
Port: 80,
Comment: "test",
}, nil
}

Expand Down Expand Up @@ -401,10 +401,10 @@ var describeBackendOutput = strings.Join([]string{

func updateBackendOK(i *fastly.UpdateBackendInput) (*fastly.Backend, error) {
return &fastly.Backend{
ServiceID: i.Service,
Version: i.Version,
Name: i.NewName,
Comment: i.Comment,
ServiceID: i.ServiceID,
ServiceVersion: i.ServiceVersion,
Name: *i.NewName,
Comment: *i.Comment,
}, nil
}

Expand Down
14 changes: 7 additions & 7 deletions pkg/backend/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/fastly"
"github.com/fastly/go-fastly/v2/fastly"
)

// CreateCommand calls the Fastly API to create backends.
Expand All @@ -27,8 +27,8 @@ func NewCreateCommand(parent common.Registerer, globals *config.Data) *CreateCom
c.Globals = globals
c.CmdClause = parent.Command("create", "Create a backend on a Fastly service version").Alias("add")

c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.Service)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.Version)
c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion)
c.CmdClause.Flag("name", "Backend name").Short('n').Required().StringVar(&c.Input.Name)
c.CmdClause.Flag("address", "A hostname, IPv4, or IPv6 address for the backend").Required().StringVar(&c.Input.Address)

Expand Down Expand Up @@ -63,15 +63,15 @@ func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error {
// Sadly, go-fastly uses custom a `Compatibool` type as a boolean value that
// marshalls to 0/1 instead of true/false for compatability with the API.
// Therefore, we need to cast our real flag bool to a fastly.Compatibool.
c.Input.AutoLoadbalance = fastly.CBool(c.AutoLoadbalance)
c.Input.UseSSL = fastly.CBool(c.UseSSL)
c.Input.SSLCheckCert = fastly.CBool(c.SSLCheckCert)
c.Input.AutoLoadbalance = fastly.Compatibool(c.AutoLoadbalance)
c.Input.UseSSL = fastly.Compatibool(c.UseSSL)
c.Input.SSLCheckCert = fastly.Compatibool(c.SSLCheckCert)

b, err := c.Globals.Client.CreateBackend(&c.Input)
if err != nil {
return err
}

text.Success(out, "Created backend %s (service %s version %d)", b.Name, b.ServiceID, b.Version)
text.Success(out, "Created backend %s (service %s version %d)", b.Name, b.ServiceID, b.ServiceVersion)
return nil
}
8 changes: 4 additions & 4 deletions pkg/backend/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/fastly"
"github.com/fastly/go-fastly/v2/fastly"
)

// DeleteCommand calls the Fastly API to delete backends.
Expand All @@ -20,8 +20,8 @@ func NewDeleteCommand(parent common.Registerer, globals *config.Data) *DeleteCom
var c DeleteCommand
c.Globals = globals
c.CmdClause = parent.Command("delete", "Delete a backend on a Fastly service version").Alias("remove")
c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.Service)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.Version)
c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion)
c.CmdClause.Flag("name", "Backend name").Short('n').Required().StringVar(&c.Input.Name)
return &c
}
Expand All @@ -32,6 +32,6 @@ func (c *DeleteCommand) Exec(in io.Reader, out io.Writer) error {
return err
}

text.Success(out, "Deleted backend %s (service %s version %d)", c.Input.Name, c.Input.Service, c.Input.Version)
text.Success(out, "Deleted backend %s (service %s version %d)", c.Input.Name, c.Input.ServiceID, c.Input.ServiceVersion)
return nil
}
8 changes: 4 additions & 4 deletions pkg/backend/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/fastly"
"github.com/fastly/go-fastly/v2/fastly"
)

// DescribeCommand calls the Fastly API to describe a backend.
Expand All @@ -21,8 +21,8 @@ func NewDescribeCommand(parent common.Registerer, globals *config.Data) *Describ
var c DescribeCommand
c.Globals = globals
c.CmdClause = parent.Command("describe", "Show detailed information about a backend on a Fastly service version").Alias("get")
c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.Service)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.Version)
c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion)
c.CmdClause.Flag("name", "Name of backend").Short('n').Required().StringVar(&c.Input.Name)
return &c
}
Expand All @@ -35,7 +35,7 @@ func (c *DescribeCommand) Exec(in io.Reader, out io.Writer) error {
}

fmt.Fprintf(out, "Service ID: %s\n", backend.ServiceID)
fmt.Fprintf(out, "Version: %d\n", backend.Version)
fmt.Fprintf(out, "Version: %d\n", backend.ServiceVersion)
text.PrintBackend(out, "", backend)

return nil
Expand Down
12 changes: 6 additions & 6 deletions pkg/backend/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/config"
"github.com/fastly/cli/pkg/text"
"github.com/fastly/go-fastly/fastly"
"github.com/fastly/go-fastly/v2/fastly"
)

// ListCommand calls the Fastly API to list backends.
Expand All @@ -21,8 +21,8 @@ func NewListCommand(parent common.Registerer, globals *config.Data) *ListCommand
var c ListCommand
c.Globals = globals
c.CmdClause = parent.Command("list", "List backends on a Fastly service version")
c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.Service)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.Version)
c.CmdClause.Flag("service-id", "Service ID").Short('s').Required().StringVar(&c.Input.ServiceID)
c.CmdClause.Flag("version", "Number of service version").Required().IntVar(&c.Input.ServiceVersion)
return &c
}

Expand All @@ -37,14 +37,14 @@ func (c *ListCommand) Exec(in io.Reader, out io.Writer) error {
tw := text.NewTable(out)
tw.AddHeader("SERVICE", "VERSION", "NAME", "ADDRESS", "PORT", "COMMENT")
for _, backend := range backends {
tw.AddLine(backend.ServiceID, backend.Version, backend.Name, backend.Address, backend.Port, backend.Comment)
tw.AddLine(backend.ServiceID, backend.ServiceVersion, backend.Name, backend.Address, backend.Port, backend.Comment)
}
tw.Print()
return nil
}

fmt.Fprintf(out, "Service ID: %s\n", c.Input.Service)
fmt.Fprintf(out, "Version: %d\n", c.Input.Version)
fmt.Fprintf(out, "Service ID: %s\n", c.Input.ServiceID)
fmt.Fprintf(out, "Version: %d\n", c.Input.ServiceVersion)
for i, backend := range backends {
fmt.Fprintf(out, "\tBackend %d/%d\n", i+1, len(backends))
text.PrintBackend(out, "\t\t", backend)
Expand Down
Loading

0 comments on commit 782b9ed

Please sign in to comment.