From 3e6f51f8d50bea52155c486cc8ddc628b9a2d30b Mon Sep 17 00:00:00 2001 From: Matt Davis Date: Fri, 1 Mar 2024 10:57:49 +0000 Subject: [PATCH] DLP-1479: made ContextAwareness a pointer This is to allow for easier optionality checks with == nil The parent context_awareness property is optional, if it is defined then all of the children are required. https://developers.cloudflare.com/api/operations/dlp-profiles-update-predefined-profile Signed-off-by: Matt Davis --- dlp_profile.go | 14 ++++++++------ dlp_profile_test.go | 21 +++++---------------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/dlp_profile.go b/dlp_profile.go index b53f84adba..e70d76de72 100644 --- a/dlp_profile.go +++ b/dlp_profile.go @@ -50,12 +50,14 @@ type DLPContextAwareness struct { // 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"` - ContextAwareness DLPContextAwareness `json:"context_awareness,omitempty"` + 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"` + + // Optional and can be omitted with a nil pointer + ContextAwareness *DLPContextAwareness `json:"context_awareness,omitempty"` // The following fields are omitted for predefined DLP // profiles. diff --git a/dlp_profile_test.go b/dlp_profile_test.go index 9a12c24a6d..67f014d5ab 100644 --- a/dlp_profile_test.go +++ b/dlp_profile_test.go @@ -75,13 +75,7 @@ func TestDLPProfiles(t *testing.T) { "updated_at": "2022-10-18T08:00:57Z", "type": "custom", "description": "just a custom profile example", - "allowed_match_count": 1, - "context_awareness": { - "enabled": false, - "skip": { - "files": false - } - } + "allowed_match_count": 1 } ] } @@ -98,7 +92,7 @@ func TestDLPProfiles(t *testing.T) { Type: "predefined", Description: "", AllowedMatchCount: 0, - ContextAwareness: DLPContextAwareness{ + ContextAwareness: &DLPContextAwareness{ Enabled: BoolPtr(true), Skip: DLPContextAwarenessSkip{ Files: BoolPtr(true), @@ -126,12 +120,7 @@ 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), - }, - }, + // Omit ContextAwareness to test ContextAwareness optionality Entries: []DLPEntry{ { ID: "ef79b054-12d4-4067-bb30-b85f6267b91c", @@ -211,7 +200,7 @@ func TestGetDLPProfile(t *testing.T) { Type: "custom", Description: "just a custom profile example", AllowedMatchCount: 42, - ContextAwareness: DLPContextAwareness{ + ContextAwareness: &DLPContextAwareness{ Enabled: BoolPtr(false), Skip: DLPContextAwarenessSkip{ Files: BoolPtr(false), @@ -586,7 +575,7 @@ func TestUpdateDLPPredefinedProfile(t *testing.T) { Type: "predefined", Description: "example predefined profile", AllowedMatchCount: 0, - ContextAwareness: DLPContextAwareness{ + ContextAwareness: &DLPContextAwareness{ Enabled: BoolPtr(true), Skip: DLPContextAwarenessSkip{ Files: BoolPtr(true),