Skip to content

Commit

Permalink
Merge pull request #180 from Charliekenney23/update-firewall-endpoints
Browse files Browse the repository at this point in the history
omit empty IPv4, IPv6 lists in firewall rules updates
  • Loading branch information
0xch4z authored Feb 16, 2021
2 parents 7d82557 + 7278d53 commit b570692
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 68 deletions.
4 changes: 2 additions & 2 deletions firewall_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ const (

// NetworkAddresses are arrays of ipv4 and v6 addresses
type NetworkAddresses struct {
IPv4 []string `json:"ipv4"`
IPv6 []string `json:"ipv6"`
IPv4 []string `json:"ipv4,omitempty"`
IPv6 []string `json:"ipv6,omitempty"`
}

// A FirewallRule is a whitelist of ports, protocols, and addresses for which traffic should be allowed.
Expand Down
2 changes: 1 addition & 1 deletion test/integration/firewall_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ func TestUpdateFirewallRules(t *testing.T) {
Protocol: "TCP",
Addresses: linodego.NetworkAddresses{
IPv4: []string{"0.0.0.0/0"},
IPv6: []string{"::0/0"},
},
},
},
Outbound: []linodego.FirewallRule{},
}

if _, err := client.UpdateFirewallRules(context.Background(), firewall.ID, newRules); err != nil {
Expand Down
84 changes: 19 additions & 65 deletions test/integration/fixtures/TestUpdateFirewallRules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@
version: 1
interactions:
- request:
body: '{"label":"label","rules":{"inbound":[{"ports":"22","protocol":"TCP","addresses":{"ipv4":["10.20.30.40/0"],"ipv6":["1234::5678/0"]}}],"outbound":[{"ports":"22","protocol":"TCP","addresses":{"ipv4":["10.20.30.40/0"],"ipv6":["1234::5678/0"]}}]},"tags":["testing"],"devices":{}}'
body: '{"label":"label","rules":{"inbound":[{"ports":"22","protocol":"TCP","addresses":{"ipv4":["0.0.0.0/0"],"ipv6":["1234::5678/0"]}}],"outbound":[{"ports":"22","protocol":"TCP","addresses":{"ipv4":["0.0.0.0/0"],"ipv6":["1234::5678/0"]}}]},"tags":["testing"],"devices":{}}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego 0.12.0 https://github.com/linode/linodego
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/networking/firewalls
method: POST
response:
body: '{"id": 223, "label": "label", "created": "2018-01-02T03:04:05", "updated":
"2018-01-02T03:04:05", "status": "enabled", "rules": {"inbound": [{"ports":
"22", "protocol": "TCP", "addresses": {"ipv4": ["10.20.30.40/0"], "ipv6": ["1234::5678/0"]}}],
"outbound": [{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["10.20.30.40/0"],
"ipv6": ["1234::5678/0"]}}]}, "tags": ["testing"]}'
body: '{"id": 2403, "label": "label", "created": "2018-01-02T03:04:05", "updated": "2018-01-02T03:04:05", "status": "enabled", "rules": {"inbound": [{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["0.0.0.0/0"], "ipv6": ["1234::5678/0"]}}], "outbound": [{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["0.0.0.0/0"], "ipv6": ["1234::5678/0"]}}]}, "tags": ["testing"]}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -33,15 +29,11 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "363"
- "362"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Date:
- Tue, 19 May 2020 16:41:15 GMT
Retry-After:
- "92"
Server:
- nginx
Strict-Transport-Security:
Expand All @@ -58,33 +50,26 @@ interactions:
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "1600"
X-Ratelimit-Remaining:
- "1595"
X-Ratelimit-Reset:
- "1589906568"
X-Spec-Version:
- 4.65.1
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
code: 200
duration: ""
- request:
body: '{"inbound":[{"ports":"22","protocol":"TCP","addresses":{"ipv4":["10.20.30.40/0"],"ipv6":["1234::5678/0"]}}]}'
body: '{"inbound":[{"ports":"22","protocol":"TCP","addresses":{"ipv4":["0.0.0.0/0"]}}]}'
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- linodego 0.12.0 https://github.com/linode/linodego
url: https://api.linode.com/v4beta/networking/firewalls/223/rules
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/networking/firewalls/2403/rules
method: PUT
response:
body: '{"inbound": [{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["10.20.30.40/0"],
"ipv6": ["1234::5678/0"]}}]}'
body: '{"inbound": [{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["0.0.0.0/0"]}}], "outbound": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -99,15 +84,11 @@ interactions:
Cache-Control:
- private, max-age=60, s-maxage=60
Content-Length:
- "106"
- "103"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Date:
- Tue, 19 May 2020 16:41:15 GMT
Retry-After:
- "92"
Server:
- nginx
Strict-Transport-Security:
Expand All @@ -124,13 +105,7 @@ interactions:
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "1600"
X-Ratelimit-Remaining:
- "1594"
X-Ratelimit-Reset:
- "1589906568"
X-Spec-Version:
- 4.65.1
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -145,12 +120,11 @@ interactions:
Content-Type:
- application/json
User-Agent:
- linodego 0.12.0 https://github.com/linode/linodego
url: https://api.linode.com/v4beta/networking/firewalls/223/rules
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/networking/firewalls/2403/rules
method: GET
response:
body: '{"inbound": [{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["10.20.30.40/0"],
"ipv6": ["1234::5678/0"]}}]}'
body: '{"inbound": [{"ports": "22", "protocol": "TCP", "addresses": {"ipv4": ["0.0.0.0/0"]}}], "outbound": []}'
headers:
Access-Control-Allow-Credentials:
- "true"
Expand All @@ -166,15 +140,11 @@ interactions:
- private, max-age=0, s-maxage=0, no-cache, no-store
- private, max-age=60, s-maxage=60
Content-Length:
- "106"
- "103"
Content-Security-Policy:
- default-src 'none'
Content-Type:
- application/json
Date:
- Tue, 19 May 2020 16:41:16 GMT
Retry-After:
- "92"
Server:
- nginx
Strict-Transport-Security:
Expand All @@ -192,13 +162,7 @@ interactions:
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "1600"
X-Ratelimit-Remaining:
- "1593"
X-Ratelimit-Reset:
- "1589906569"
X-Spec-Version:
- 4.65.1
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand All @@ -213,8 +177,8 @@ interactions:
Content-Type:
- application/json
User-Agent:
- linodego 0.12.0 https://github.com/linode/linodego
url: https://api.linode.com/v4beta/networking/firewalls/223
- linodego https://github.com/linode/linodego
url: https://api.linode.com/v4beta/networking/firewalls/2403
method: DELETE
response:
body: '{}'
Expand All @@ -237,10 +201,6 @@ interactions:
- default-src 'none'
Content-Type:
- application/json
Date:
- Tue, 19 May 2020 16:41:16 GMT
Retry-After:
- "91"
Server:
- nginx
Strict-Transport-Security:
Expand All @@ -257,13 +217,7 @@ interactions:
X-Oauth-Scopes:
- '*'
X-Ratelimit-Limit:
- "1600"
X-Ratelimit-Remaining:
- "1592"
X-Ratelimit-Reset:
- "1589906568"
X-Spec-Version:
- 4.65.1
- "800"
X-Xss-Protection:
- 1; mode=block
status: 200 OK
Expand Down

0 comments on commit b570692

Please sign in to comment.