Skip to content

Commit

Permalink
adding ip_type to firewall rules (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
ddymko authored Apr 26, 2022
1 parent e495a9f commit ed643e2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions firewall_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ type FireWallRuleServiceHandler struct {

// FirewallRule represents a Vultr firewall rule
type FirewallRule struct {
ID int `json:"id"`
Action string `json:"action"`
ID int `json:"id"`
Action string `json:"action"`
// Deprecated: Type should no longer be used. Instead, use IPType.
Type string `json:"type"`
IPType string `json:"ip_type"`
Protocol string `json:"protocol"`
Port string `json:"port"`
Subnet string `json:"subnet"`
Expand Down
9 changes: 6 additions & 3 deletions firewall_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestFireWallRuleServiceHandler_Create(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/firewalls/abc123/rules", func(writer http.ResponseWriter, request *http.Request) {
response := `{"firewall_rule":{"id":1,"type":"v4","action":"accept","protocol":"tcp","port":"80","subnet":"127.0.0.1","subnet_size":32,"source":"","notes":"thisisanote"}}`
response := `{"firewall_rule":{"id":1,"type":"v4","ip_type":"v4","action":"accept","protocol":"tcp","port":"80","subnet":"127.0.0.1","subnet_size":32,"source":"","notes":"thisisanote"}}`
fmt.Fprint(writer, response)
})

Expand All @@ -34,6 +34,7 @@ func TestFireWallRuleServiceHandler_Create(t *testing.T) {
ID: 1,
Action: "accept",
Type: "v4",
IPType: "v4",
Protocol: "tcp",
Port: "80",
Subnet: "127.0.0.1",
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestFireWallRuleServiceHandler_List(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/firewalls/abc123/rules", func(writer http.ResponseWriter, request *http.Request) {
response := `{"firewall_rules":[{"id":1,"type":"v4","action":"accept","protocol":"tcp","port":"22","subnet":"0.0.0.0","subnet_size":0,"source":"","notes":""}],"meta":{"total":5,"links":{"next":"","prev":""}}}`
response := `{"firewall_rules":[{"id":1,"type":"v4","ip_type":"v4","action":"accept","protocol":"tcp","port":"22","subnet":"0.0.0.0","subnet_size":0,"source":"","notes":""}],"meta":{"total":5,"links":{"next":"","prev":""}}}`
fmt.Fprint(writer, response)
})

Expand All @@ -81,6 +82,7 @@ func TestFireWallRuleServiceHandler_List(t *testing.T) {
ID: 1,
Action: "accept",
Type: "v4",
IPType: "v4",
Protocol: "tcp",
Port: "22",
Subnet: "0.0.0.0",
Expand Down Expand Up @@ -109,7 +111,7 @@ func TestFireWallRuleServiceHandler_Get(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/firewalls/abc123/rules/1", func(writer http.ResponseWriter, request *http.Request) {
response := `{"firewall_rule":{"id":1,"type":"v4","action":"accept","protocol":"tcp","port":"22","subnet":"0.0.0.0","subnet_size":0,"source":"","notes":""}}`
response := `{"firewall_rule":{"id":1,"type":"v4","ip_type":"v4","action":"accept","protocol":"tcp","port":"22","subnet":"0.0.0.0","subnet_size":0,"source":"","notes":""}}`
fmt.Fprint(writer, response)
})

Expand All @@ -122,6 +124,7 @@ func TestFireWallRuleServiceHandler_Get(t *testing.T) {
ID: 1,
Action: "accept",
Type: "v4",
IPType: "v4",
Protocol: "tcp",
Port: "22",
Subnet: "0.0.0.0",
Expand Down

0 comments on commit ed643e2

Please sign in to comment.