Skip to content

Commit

Permalink
Merge pull request #1503 from cehrig/cehrig/ipsec-healthcheck-directi…
Browse files Browse the repository at this point in the history
…on-and-rate

MT / MWAN: Adds IPsec tunnel healthcheck direction & rate parameters
  • Loading branch information
jacobbednarz committed Feb 23, 2024
2 parents 71b3ac0 + 14b3cea commit c15d2fc
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .changelog/1503.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
magic-transit: Adds IPsec tunnel healthcheck direction & rate parameters
```
62 changes: 62 additions & 0 deletions magic_transit_ipsec_tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,68 @@ func TestCreateMagicTransitIPsecTunnels(t *testing.T) {
}
}

func TestCreateMagicTransitIPsecTunnelsWithHealthcheck(t *testing.T) {
setup()
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprint(w, `{
"success": true,
"errors": [],
"messages": [],
"result": {
"ipsec_tunnels": [
{
"id": "c4a7362d577a6c3019a474fd6f485821",
"created_on": "2017-06-14T00:00:00Z",
"modified_on": "2017-06-14T05:20:00Z",
"name": "IPsec_1",
"customer_endpoint": "203.0.113.1",
"cloudflare_endpoint": "203.0.113.2",
"interface_address": "192.0.2.0/31",
"description": "Tunnel for ISP X",
"health_check": {
"enabled": true,
"type": "reply",
"rate": "mid",
"direction": "bidirectional"
}
}
]
}
}`)
}

mux.HandleFunc("/accounts/"+testAccountID+"/magic/ipsec_tunnels", handler)

createdOn, _ := time.Parse(time.RFC3339, "2017-06-14T00:00:00Z")
modifiedOn, _ := time.Parse(time.RFC3339, "2017-06-14T05:20:00Z")

want := []MagicTransitIPsecTunnel{{
ID: "c4a7362d577a6c3019a474fd6f485821",
CreatedOn: &createdOn,
ModifiedOn: &modifiedOn,
Name: "IPsec_1",
CustomerEndpoint: "203.0.113.1",
CloudflareEndpoint: "203.0.113.2",
InterfaceAddress: "192.0.2.0/31",
Description: "Tunnel for ISP X",
HealthCheck: &MagicTransitTunnelHealthcheck{
Enabled: true,
Type: "reply",
Rate: "mid",
Direction: "bidirectional",
},
}}

actual, err := client.CreateMagicTransitIPsecTunnels(context.Background(), testAccountID, want)
if assert.NoError(t, err) {
assert.Equal(t, want, actual)
}
}

func TestUpdateMagicTransitIPsecTunnel(t *testing.T) {
setup()
defer teardown()
Expand Down
8 changes: 5 additions & 3 deletions magic_transit_tunnel_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cloudflare

// MagicTransitTunnelHealthcheck contains information about a tunnel health check.
type MagicTransitTunnelHealthcheck struct {
Enabled bool `json:"enabled"`
Target string `json:"target,omitempty"`
Type string `json:"type,omitempty"`
Enabled bool `json:"enabled"`
Target string `json:"target,omitempty"`
Type string `json:"type,omitempty"`
Rate string `json:"rate,omitempty"`
Direction string `json:"direction,omitempty"`
}

0 comments on commit c15d2fc

Please sign in to comment.