Skip to content

Commit

Permalink
Merge branch 'master' into fixes-more-pagination-requests
Browse files Browse the repository at this point in the history
  • Loading branch information
auyer authored Feb 29, 2024
2 parents daf962c + 0156ecb commit 12ecd72
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .changelog/1497.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dlp: add support for Context Awareness in DLP profiles
```
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
```
3 changes: 3 additions & 0 deletions .changelog/1506.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
registrar: Fix request method to call domain list endpoint from POST to GET
```
22 changes: 20 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
## 0.89.0 (Unreleased)
## 0.90.0 (Unreleased)

## 0.88.0 (February 14th, 2023)
ENHANCEMENTS:

* dlp: add support for Context Awareness in DLP profiles ([#1497](https://github.com/cloudflare/cloudflare-go/issues/1497))

## 0.89.0 (February 28th, 2024)

NOTES:

* zaraz: replace deprecated neoEvents with Actions on Zaraz Config tools schema ([#1490](https://github.com/cloudflare/cloudflare-go/issues/1490))

ENHANCEMENTS:

* magic-transit: Adds IPsec tunnel healthcheck direction & rate parameters ([#1503](https://github.com/cloudflare/cloudflare-go/issues/1503))

BUG FIXES:

* registrar: Fix request method to call domain list endpoint from POST to GET ([#1506](https://github.com/cloudflare/cloudflare-go/issues/1506))

## 0.88.0 (February 14th, 2024)

ENHANCEMENTS:

Expand Down
25 changes: 19 additions & 6 deletions dlp_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,30 @@ type DLPEntry struct {
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}

// Content types to exclude from context analysis and return all matches.
type DLPContextAwarenessSkip struct {
// Return all matches, regardless of context analysis result, if the data is a file.
Files *bool `json:"files,omitempty"`
}

// Scan the context of predefined entries to only return matches surrounded by keywords.
type DLPContextAwareness struct {
Enabled *bool `json:"enabled,omitempty"`
Skip DLPContextAwarenessSkip `json:"skip"`
}

// DLPProfile represents a DLP Profile, which contains a set
// of entries.
type DLPProfile struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
AllowedMatchCount int `json:"allowed_match_count"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
AllowedMatchCount int `json:"allowed_match_count"`
ContextAwareness DLPContextAwareness `json:"context_awareness,omitempty"`

// The following fields are omitted for predefined DLP
// profiles
// profiles.
Entries []DLPEntry `json:"entries,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
Expand Down
66 changes: 57 additions & 9 deletions dlp_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ func TestDLPProfiles(t *testing.T) {
}
],
"type": "predefined",
"allowed_match_count": 0
"allowed_match_count": 0,
"context_awareness": {
"enabled": true,
"skip": {
"files": true
}
}
},
{
"id": "29678c26-a191-428d-9f63-6e20a4a636a4",
Expand All @@ -69,7 +75,13 @@ func TestDLPProfiles(t *testing.T) {
"updated_at": "2022-10-18T08:00:57Z",
"type": "custom",
"description": "just a custom profile example",
"allowed_match_count": 1
"allowed_match_count": 1,
"context_awareness": {
"enabled": false,
"skip": {
"files": false
}
}
}
]
}
Expand All @@ -86,6 +98,12 @@ func TestDLPProfiles(t *testing.T) {
Type: "predefined",
Description: "",
AllowedMatchCount: 0,
ContextAwareness: DLPContextAwareness{
Enabled: BoolPtr(true),
Skip: DLPContextAwarenessSkip{
Files: BoolPtr(true),
},
},
Entries: []DLPEntry{
{
ID: "111b9d4b-a5c6-40f0-957d-9d53b25dd84a",
Expand All @@ -108,6 +126,12 @@ func TestDLPProfiles(t *testing.T) {
Type: "custom",
Description: "just a custom profile example",
AllowedMatchCount: 1,
ContextAwareness: DLPContextAwareness{
Enabled: BoolPtr(false),
Skip: DLPContextAwarenessSkip{
Files: BoolPtr(false),
},
},
Entries: []DLPEntry{
{
ID: "ef79b054-12d4-4067-bb30-b85f6267b91c",
Expand Down Expand Up @@ -167,7 +191,13 @@ func TestGetDLPProfile(t *testing.T) {
"updated_at": "2022-10-18T08:00:57Z",
"type": "custom",
"description": "just a custom profile example",
"allowed_match_count": 42
"allowed_match_count": 42,
"context_awareness": {
"enabled": false,
"skip": {
"files": false
}
}
}
}`)
}
Expand All @@ -181,6 +211,12 @@ func TestGetDLPProfile(t *testing.T) {
Type: "custom",
Description: "just a custom profile example",
AllowedMatchCount: 42,
ContextAwareness: DLPContextAwareness{
Enabled: BoolPtr(false),
Skip: DLPContextAwarenessSkip{
Files: BoolPtr(false),
},
},
Entries: []DLPEntry{
{
ID: "ef79b054-12d4-4067-bb30-b85f6267b91c",
Expand Down Expand Up @@ -533,16 +569,29 @@ func TestUpdateDLPPredefinedProfile(t *testing.T) {
],
"type": "predefined",
"description": "example predefined profile",
"allowed_match_count": 0
"allowed_match_count": 0,
"context_awareness": {
"enabled": true,
"skip": {
"files": true
}
}
}
}`)
}

want := DLPProfile{
ID: "29678c26-a191-428d-9f63-6e20a4a636a4",
Name: "Example predefined profile",
Type: "predefined",
Description: "example predefined profile",
ID: "29678c26-a191-428d-9f63-6e20a4a636a4",
Name: "Example predefined profile",
Type: "predefined",
Description: "example predefined profile",
AllowedMatchCount: 0,
ContextAwareness: DLPContextAwareness{
Enabled: BoolPtr(true),
Skip: DLPContextAwarenessSkip{
Files: BoolPtr(true),
},
},
Entries: []DLPEntry{
{
ID: "ef79b054-12d4-4067-bb30-b85f6267b91c",
Expand All @@ -552,7 +601,6 @@ func TestUpdateDLPPredefinedProfile(t *testing.T) {
Enabled: BoolPtr(true),
},
},
AllowedMatchCount: 0,
}

mux.HandleFunc("/accounts/"+testAccountID+"/dlp/profiles/predefined/29678c26-a191-428d-9f63-6e20a4a636a4", handler)
Expand Down
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"`
}
2 changes: 1 addition & 1 deletion registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (api *API) RegistrarDomain(ctx context.Context, accountID, domainName strin
func (api *API) RegistrarDomains(ctx context.Context, accountID string) ([]RegistrarDomain, error) {
uri := fmt.Sprintf("/accounts/%s/registrar/domains", accountID)

res, err := api.makeRequestContext(ctx, http.MethodPost, uri, nil)
res, err := api.makeRequestContext(ctx, http.MethodGet, uri, nil)
if err != nil {
return []RegistrarDomain{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion registrar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestRegistrarDomains(t *testing.T) {
defer teardown()

handler := func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, http.MethodPost, r.Method, "Expected method 'POST', got %s", r.Method)
assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
w.Header().Set("content-type", "application/json")
fmt.Fprintf(w, `{
"success": true,
Expand Down

0 comments on commit 12ecd72

Please sign in to comment.