Skip to content

Commit

Permalink
Fix conflicts & re-run fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
lgarber-akamai committed Jul 10, 2024
2 parents 8d41d43 + ea893ef commit f6208f6
Show file tree
Hide file tree
Showing 147 changed files with 13,800 additions and 11,629 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release-cross-repo-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
uses: actions/checkout@v4
with:
repository: linode/terraform-provider-linode
fetch-depth: 0
submodules: 'recursive'

- name: Set up Go
uses: actions/setup-go@v5
Expand Down
2 changes: 1 addition & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func TestDebugLogSanitization(t *testing.T) {
Label string `json:"label"`
}

var testResp = instanceResponse{
testResp := instanceResponse{
ID: 100,
Region: "test-central",
Label: "this-is-a-test-linode",
Expand Down
21 changes: 7 additions & 14 deletions firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package linodego

import (
"context"
"encoding/json"
"fmt"
)

// NetworkProtocol enum type
Expand Down Expand Up @@ -43,27 +41,22 @@ type FirewallRuleSet struct {

// GetFirewallRules gets the FirewallRuleSet for the given Firewall.
func (c *Client) GetFirewallRules(ctx context.Context, firewallID int) (*FirewallRuleSet, error) {
e := fmt.Sprintf("networking/firewalls/%d/rules", firewallID)
req := c.R(ctx).SetResult(&FirewallRuleSet{})
r, err := coupleAPIErrors(req.Get(e))
e := formatAPIPath("networking/firewalls/%d/rules", firewallID)
response, err := doGETRequest[FirewallRuleSet](ctx, c, e)
if err != nil {
return nil, err
}
return r.Result().(*FirewallRuleSet), nil

return response, nil
}

// UpdateFirewallRules updates the FirewallRuleSet for the given Firewall
func (c *Client) UpdateFirewallRules(ctx context.Context, firewallID int, rules FirewallRuleSet) (*FirewallRuleSet, error) {
body, err := json.Marshal(rules)
e := formatAPIPath("networking/firewalls/%d/rules", firewallID)
response, err := doPUTRequest[FirewallRuleSet](ctx, c, e, rules)
if err != nil {
return nil, err
}

e := fmt.Sprintf("networking/firewalls/%d/rules", firewallID)
req := c.R(ctx).SetResult(&FirewallRuleSet{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Put(e))
if err != nil {
return nil, err
}
return r.Result().(*FirewallRuleSet), nil
return response, nil
}
61 changes: 12 additions & 49 deletions firewalls.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package linodego
import (
"context"
"encoding/json"
"fmt"
"time"

"github.com/go-resty/resty/v2"
"github.com/linode/linodego/internal/parseabletime"
)

Expand Down Expand Up @@ -82,87 +80,52 @@ func (f *Firewall) UnmarshalJSON(b []byte) error {
return nil
}

// FirewallsPagedResponse represents a Linode API response for listing of Cloud Firewalls
type FirewallsPagedResponse struct {
*PageOptions
Data []Firewall `json:"data"`
}

func (FirewallsPagedResponse) endpoint(_ ...any) string {
return "networking/firewalls"
}

func (resp *FirewallsPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(FirewallsPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*FirewallsPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}

// ListFirewalls returns a paginated list of Cloud Firewalls
func (c *Client) ListFirewalls(ctx context.Context, opts *ListOptions) ([]Firewall, error) {
response := FirewallsPagedResponse{}

err := c.listHelper(ctx, &response, opts)
response, err := getPaginatedResults[Firewall](ctx, c, "networking/firewalls", opts)
if err != nil {
return nil, err
}

return response.Data, nil
return response, nil
}

// CreateFirewall creates a single Firewall with at least one set of inbound or outbound rules
func (c *Client) CreateFirewall(ctx context.Context, opts FirewallCreateOptions) (*Firewall, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}

e := "networking/firewalls"
req := c.R(ctx).SetResult(&Firewall{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Post(e))
response, err := doPOSTRequest[Firewall](ctx, c, e, opts)
if err != nil {
return nil, err
}

return r.Result().(*Firewall), nil
return response, nil
}

// GetFirewall gets a single Firewall with the provided ID
func (c *Client) GetFirewall(ctx context.Context, firewallID int) (*Firewall, error) {
e := fmt.Sprintf("networking/firewalls/%d", firewallID)
req := c.R(ctx).SetResult(&Firewall{})
r, err := coupleAPIErrors(req.Get(e))
e := formatAPIPath("networking/firewalls/%d", firewallID)
response, err := doGETRequest[Firewall](ctx, c, e)
if err != nil {
return nil, err
}

return r.Result().(*Firewall), nil
return response, nil
}

// UpdateFirewall updates a Firewall with the given ID
func (c *Client) UpdateFirewall(ctx context.Context, firewallID int, opts FirewallUpdateOptions) (*Firewall, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}

e := fmt.Sprintf("networking/firewalls/%d", firewallID)
req := c.R(ctx).SetResult(&Firewall{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Put(e))
e := formatAPIPath("networking/firewalls/%d", firewallID)
response, err := doPUTRequest[Firewall](ctx, c, e, opts)
if err != nil {
return nil, err
}

return r.Result().(*Firewall), nil
return response, nil
}

// DeleteFirewall deletes a single Firewall with the provided ID
func (c *Client) DeleteFirewall(ctx context.Context, firewallID int) error {
e := fmt.Sprintf("networking/firewalls/%d", firewallID)
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
e := formatAPIPath("networking/firewalls/%d", firewallID)
err := doDELETERequest(ctx, c, e)
return err
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/go-resty/resty/v2 v2.13.1
github.com/google/go-cmp v0.6.0
github.com/jarcoal/httpmock v1.3.1
golang.org/x/net v0.26.0
golang.org/x/net v0.27.0
golang.org/x/oauth2 v0.21.0
golang.org/x/text v0.16.0
gopkg.in/ini.v1 v1.66.6
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys=
golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
47 changes: 47 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc=
cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46 h1:lsxEuwrXEAokXB9qhlbKWPpo3KMLZQ5WB5WLQRW1uq0=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a h1:idn718Q4B6AGu/h5Sxe66HYVdqdGu2l9Iebqhi/AEoA=
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
github.com/creack/pty v1.1.9 h1:uDmaGzcdjhF4i/plgjmEsriH11Y0o7RKapEf/LDaM3w=
github.com/evanphx/json-patch v4.12.0+incompatible h1:4onqiflcdA9EOZ4RxV643DvftH5pOlLGNtQ5lPWQu84=
github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/google/btree v1.0.1 h1:gK4Kx5IaGY9CD5sPJ36FHiBJ6ZXl0kilRiiCj+jdYp4=
github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9uaxA=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 h1:pdN6V1QBWetyv/0+wjACpqVH+eVULgEjkurDLq3goeM=
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
github.com/kisielk/errcheck v1.5.0 h1:e8esj/e4R+SAOwFwN+n3zr0nYeCyeweozKfO23MvHzY=
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
github.com/kr/pty v1.1.1 h1:VkoXIwSboBpnk99O/KFauAEILuNHv5DVFKZMBN/gUgw=
github.com/moby/spdystream v0.2.0 h1:cjW1zVyyoiM0T7b6UoySUFqzXMoqRckQtXwGPiBhOM8=
github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c=
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5 h1:8Q0qkMVC/MmWkpIdlvZgcv2o2jrlF6zqVOh7W5YHdMA=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/peterbourgon/diskv v2.0.1+incompatible h1:UBdAOUP5p4RWqPBg048CAvpKN+vxiaj6gdUUzhl4XmI=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 h1:H2TDz8ibqkAF6YGhCdN3jS9O0/s90v0rJh3X/OLHEUk=
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01 h1:pWEwq4Asjm4vjW7vcsmijwBhOr1/shsbSYiWXmNGlks=
k8s.io/gengo v0.0.0-20230829151522-9cce18d56c01/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
57 changes: 19 additions & 38 deletions instance_config_interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package linodego

import (
"context"
"encoding/json"
"fmt"
)

// InstanceConfigInterface contains information about a configuration's network interface
Expand Down Expand Up @@ -109,19 +107,13 @@ func (c *Client) AppendInstanceConfigInterface(
configID int,
opts InstanceConfigInterfaceCreateOptions,
) (*InstanceConfigInterface, error) {
body, err := json.Marshal(opts)
e := formatAPIPath("/linode/instances/%d/configs/%d/interfaces", linodeID, configID)
response, err := doPOSTRequest[InstanceConfigInterface](ctx, c, e, opts)
if err != nil {
return nil, err
}

req := c.R(ctx).SetResult(&InstanceConfigInterface{}).SetBody(string(body))
e := fmt.Sprintf("/linode/instances/%d/configs/%d/interfaces", linodeID, configID)
r, err := coupleAPIErrors(req.Post(e))
if err != nil {
return nil, err
}

return r.Result().(*InstanceConfigInterface), nil
return response, nil
}

func (c *Client) GetInstanceConfigInterface(
Expand All @@ -130,36 +122,36 @@ func (c *Client) GetInstanceConfigInterface(
configID int,
interfaceID int,
) (*InstanceConfigInterface, error) {
e := fmt.Sprintf(
e := formatAPIPath(
"linode/instances/%d/configs/%d/interfaces/%d",
linodeID,
configID,
interfaceID,
)
req := c.R(ctx).SetResult(&InstanceConfigInterface{})
r, err := coupleAPIErrors(req.Get(e))
response, err := doGETRequest[InstanceConfigInterface](ctx, c, e)
if err != nil {
return nil, err
}
return r.Result().(*InstanceConfigInterface), nil

return response, nil
}

func (c *Client) ListInstanceConfigInterfaces(
ctx context.Context,
linodeID int,
configID int,
) ([]InstanceConfigInterface, error) {
e := fmt.Sprintf(
e := formatAPIPath(
"linode/instances/%d/configs/%d/interfaces",
linodeID,
configID,
)
req := c.R(ctx).SetResult([]InstanceConfigInterface{})
r, err := coupleAPIErrors(req.Get(e))
response, err := doGETRequest[[]InstanceConfigInterface](ctx, c, e)
if err != nil {
return nil, err
}
return *r.Result().(*[]InstanceConfigInterface), nil

return *response, nil
}

func (c *Client) UpdateInstanceConfigInterface(
Expand All @@ -169,23 +161,18 @@ func (c *Client) UpdateInstanceConfigInterface(
interfaceID int,
opts InstanceConfigInterfaceUpdateOptions,
) (*InstanceConfigInterface, error) {
body, err := json.Marshal(opts)
if err != nil {
return nil, err
}

e := fmt.Sprintf(
e := formatAPIPath(
"linode/instances/%d/configs/%d/interfaces/%d",
linodeID,
configID,
interfaceID,
)
req := c.R(ctx).SetResult(&InstanceConfigInterface{}).SetBody(string(body))
r, err := coupleAPIErrors(req.Put(e))
response, err := doPUTRequest[InstanceConfigInterface](ctx, c, e, opts)
if err != nil {
return nil, err
}
return r.Result().(*InstanceConfigInterface), nil

return response, nil
}

func (c *Client) DeleteInstanceConfigInterface(
Expand All @@ -194,13 +181,13 @@ func (c *Client) DeleteInstanceConfigInterface(
configID int,
interfaceID int,
) error {
e := fmt.Sprintf(
e := formatAPIPath(
"linode/instances/%d/configs/%d/interfaces/%d",
linodeID,
configID,
interfaceID,
)
_, err := coupleAPIErrors(c.R(ctx).Delete(e))
err := doDELETERequest(ctx, c, e)
return err
}

Expand All @@ -210,18 +197,12 @@ func (c *Client) ReorderInstanceConfigInterfaces(
configID int,
opts InstanceConfigInterfacesReorderOptions,
) error {
body, err := json.Marshal(opts)
if err != nil {
return err
}
e := fmt.Sprintf(
e := formatAPIPath(
"linode/instances/%d/configs/%d/interfaces/order",
linodeID,
configID,
)

req := c.R(ctx).SetBody(string(body))
_, err = coupleAPIErrors(req.Post(e))
_, err := doPOSTRequest[OAuthClient](ctx, c, e, opts)

return err
}
Loading

0 comments on commit f6208f6

Please sign in to comment.