Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowed_match_count to DLP profiles #1193

Merged
merged 3 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/1193.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
dlp_profile: Add new allowed_match_count field to profiles
```
9 changes: 5 additions & 4 deletions dlp_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ type DLPEntry 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"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
Description string `json:"description,omitempty"`
AllowedMatchCount uint `json:"allowed_match_count"`

// The following fields are omitted for predefined DLP
// profiles
Expand Down
67 changes: 42 additions & 25 deletions dlp_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func TestDLPProfiles(t *testing.T) {
"type": "predefined"
}
],
"type": "predefined"
"type": "predefined",
"allowed_match_count": 0
},
{
"id": "29678c26-a191-428d-9f63-6e20a4a636a4",
Expand All @@ -66,7 +67,8 @@ func TestDLPProfiles(t *testing.T) {
"created_at": "2022-10-18T08:00:56Z",
"updated_at": "2022-10-18T08:00:57Z",
"type": "custom",
"description": "just a custom profile example"
"description": "just a custom profile example",
"allowed_match_count": 1
}
]
}
Expand All @@ -78,10 +80,11 @@ func TestDLPProfiles(t *testing.T) {

want := []DLPProfile{
{
ID: "d658f520-6ecb-4a34-a725-ba37243c2d28",
Name: "U.S. Social Security Numbers",
Type: "predefined",
Description: "",
ID: "d658f520-6ecb-4a34-a725-ba37243c2d28",
Name: "U.S. Social Security Numbers",
Type: "predefined",
Description: "",
AllowedMatchCount: 0,
Entries: []DLPEntry{
{
ID: "111b9d4b-a5c6-40f0-957d-9d53b25dd84a",
Expand All @@ -99,10 +102,11 @@ func TestDLPProfiles(t *testing.T) {
},
},
{
ID: "29678c26-a191-428d-9f63-6e20a4a636a4",
Name: "Example Custom Profile",
Type: "custom",
Description: "just a custom profile example",
ID: "29678c26-a191-428d-9f63-6e20a4a636a4",
Name: "Example Custom Profile",
Type: "custom",
Description: "just a custom profile example",
AllowedMatchCount: 1,
Entries: []DLPEntry{
{
ID: "ef79b054-12d4-4067-bb30-b85f6267b91c",
Expand Down Expand Up @@ -161,7 +165,8 @@ func TestGetDLPProfile(t *testing.T) {
"created_at": "2022-10-18T08:00:56Z",
"updated_at": "2022-10-18T08:00:57Z",
"type": "custom",
"description": "just a custom profile example"
"description": "just a custom profile example",
"allowed_match_count": 42
}
}`)
}
Expand All @@ -170,10 +175,11 @@ func TestGetDLPProfile(t *testing.T) {
updatedAt, _ := time.Parse(time.RFC3339, "2022-10-18T08:00:57Z")

want := DLPProfile{
ID: "29678c26-a191-428d-9f63-6e20a4a636a4",
Name: "Example Custom Profile",
Type: "custom",
Description: "just a custom profile example",
ID: "29678c26-a191-428d-9f63-6e20a4a636a4",
Name: "Example Custom Profile",
Type: "custom",
Description: "just a custom profile example",
AllowedMatchCount: 42,
Entries: []DLPEntry{
{
ID: "ef79b054-12d4-4067-bb30-b85f6267b91c",
Expand Down Expand Up @@ -238,7 +244,8 @@ func TestCreateDLPCustomProfiles(t *testing.T) {
"created_at": "2022-10-18T08:00:56Z",
"updated_at": "2022-10-18T08:00:57Z",
"type": "custom",
"description": "`+requestProfile.Description+`"
"description": "`+requestProfile.Description+`",
"allowed_match_count": 0
}]
}`)
}
Expand Down Expand Up @@ -267,8 +274,9 @@ func TestCreateDLPCustomProfiles(t *testing.T) {
UpdatedAt: &updatedAt,
},
},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
AllowedMatchCount: 0,
},
}

Expand All @@ -289,6 +297,7 @@ func TestCreateDLPCustomProfiles(t *testing.T) {
},
},
},
AllowedMatchCount: 0,
},
}
actual, err := client.CreateDLPProfiles(context.Background(), AccountIdentifier(testAccountID), CreateDLPProfilesParams{Profiles: profiles, Type: "custom"})
Expand Down Expand Up @@ -334,7 +343,8 @@ func TestCreateDLPCustomProfile(t *testing.T) {
"created_at": "2022-10-18T08:00:56Z",
"updated_at": "2022-10-18T08:00:57Z",
"type": "custom",
"description": "`+requestProfile.Description+`"
"description": "`+requestProfile.Description+`",
"allowed_match_count": 0
}]
}`)
}
Expand Down Expand Up @@ -363,8 +373,9 @@ func TestCreateDLPCustomProfile(t *testing.T) {
UpdatedAt: &updatedAt,
},
},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
AllowedMatchCount: 0,
}}

mux.HandleFunc("/accounts/"+testAccountID+"/dlp/profiles/custom", handler)
Expand All @@ -382,6 +393,7 @@ func TestCreateDLPCustomProfile(t *testing.T) {
},
},
},
AllowedMatchCount: 0,
}}

actual, err := client.CreateDLPProfiles(context.Background(), AccountIdentifier(testAccountID), CreateDLPProfilesParams{
Expand Down Expand Up @@ -429,7 +441,8 @@ func TestUpdateDLPCustomProfile(t *testing.T) {
"created_at": "2022-10-18T08:00:56Z",
"updated_at": "2022-10-18T08:00:57Z",
"type": "custom",
"description": "`+requestProfile.Description+`"
"description": "`+requestProfile.Description+`",
"allowed_match_count": 0
}
}`)
}
Expand Down Expand Up @@ -458,8 +471,9 @@ func TestUpdateDLPCustomProfile(t *testing.T) {
UpdatedAt: &updatedAt,
},
},
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
CreatedAt: &createdAt,
UpdatedAt: &updatedAt,
AllowedMatchCount: 0,
}

mux.HandleFunc("/accounts/"+testAccountID+"/dlp/profiles/custom/29678c26-a191-428d-9f63-6e20a4a636a4", handler)
Expand All @@ -477,6 +491,7 @@ func TestUpdateDLPCustomProfile(t *testing.T) {
},
},
},
AllowedMatchCount: 0,
}
actual, err := client.UpdateDLPProfile(context.Background(), AccountIdentifier(testAccountID), UpdateDLPProfileParams{
ProfileID: "29678c26-a191-428d-9f63-6e20a4a636a4",
Expand Down Expand Up @@ -516,7 +531,8 @@ func TestUpdateDLPPredefinedProfile(t *testing.T) {
}
],
"type": "predefined",
"description": "example predefined profile"
"description": "example predefined profile",
"allowed_match_count": 0
}
}`)
}
Expand All @@ -535,6 +551,7 @@ 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