Skip to content

Commit

Permalink
DLP-1479: made ContextAwareness a pointer
Browse files Browse the repository at this point in the history
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 <mattdavis@cloudflare.com>
  • Loading branch information
MattDavis00 committed Mar 1, 2024
1 parent 31db1d5 commit 3e6f51f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 22 deletions.
14 changes: 8 additions & 6 deletions dlp_profile.go
Expand Up @@ -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.
Expand Down
21 changes: 5 additions & 16 deletions dlp_profile_test.go
Expand Up @@ -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
}
]
}
Expand All @@ -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),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 3e6f51f

Please sign in to comment.