Skip to content

Commit

Permalink
Merge pull request #3224 from inanna-malick/inanna/DLP-1723
Browse files Browse the repository at this point in the history
DLP-1723: add ocr_enabled flag to DLP profiles
  • Loading branch information
jacobbednarz authored Apr 18, 2024
2 parents a1ec115 + 57d7da1 commit 7f9ff6a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/3224.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
resource/cloudflare_dlp_profile: Added support for `ocr_enabled` field to profiles
```
1 change: 1 addition & 0 deletions docs/resources/dlp_profile.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ resource "cloudflare_dlp_profile" "example_custom" {
- `entry` (Block Set, Min: 1) List of entries to apply to the profile. (see [below for nested schema](#nestedblock--entry))
- `name` (String) Name of the profile. **Modifying this attribute will force creation of a new resource.**
- `type` (String) The type of the profile. Available values: `custom`, `predefined`. **Modifying this attribute will force creation of a new resource.**
- `ocr_enabled` (Boolean) If true, scan images via OCR to determine if any text present matches filters.

### Optional

Expand Down
3 changes: 3 additions & 0 deletions internal/sdkv2provider/resource_cloudflare_dlp_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ func resourceCloudflareDLPProfileRead(ctx context.Context, d *schema.ResourceDat
d.Set("description", dlpProfile.Description)
}
d.Set("allowed_match_count", dlpProfile.AllowedMatchCount)
d.Set("ocr_enabled", dlpProfile.OCREnabled)
if dlpProfile.ContextAwareness != nil {
d.Set("context_awareness", []interface{}{dlpContextAwarenessToSchema(*dlpProfile.ContextAwareness)})
}
Expand All @@ -162,6 +163,7 @@ func resourceCloudflareDLPProfileCreate(ctx context.Context, d *schema.ResourceD
Type: d.Get("type").(string),
Description: d.Get("description").(string),
AllowedMatchCount: d.Get("allowed_match_count").(int),
OCREnabled: cloudflare.BoolPtr(d.Get("ocr_enabled").(bool)),
}

if contextAwarenessSchema, ok := d.GetOk("context_awareness.0"); ok {
Expand Down Expand Up @@ -202,6 +204,7 @@ func resourceCloudflareDLPProfileUpdate(ctx context.Context, d *schema.ResourceD
Name: d.Get("name").(string),
Type: d.Get("type").(string),
AllowedMatchCount: d.Get("allowed_match_count").(int),
OCREnabled: cloudflare.BoolPtr(d.Get("ocr_enabled").(bool)),
}
updatedDLPProfile.Description, _ = d.Get("description").(string)
if contextAwarenessSchema, ok := d.GetOk("context_awareness.0"); ok {
Expand Down
50 changes: 50 additions & 0 deletions internal/sdkv2provider/resource_cloudflare_dlp_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,35 @@ func TestAccCloudflareDLPProfile_CustomWithAllowedMatchCount(t *testing.T) {
})
}

func TestAccCloudflareDLPProfile_CustomWithOCREnabled(t *testing.T) {
rnd := generateRandomResourceName()
name := fmt.Sprintf("cloudflare_dlp_profile.%s", rnd)

resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheckAccount(t)
},
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
Config: testAccCloudflareDLPProfileConfigCustomWithOCREnabled(accountID, rnd, "custom profile", true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "account_id", accountID),
resource.TestCheckResourceAttr(name, "name", rnd),
resource.TestCheckResourceAttr(name, "description", "custom profile"),
resource.TestCheckResourceAttr(name, "allowed_match_count", "0"),
resource.TestCheckResourceAttr(name, "ocr_enabled", "true"),
resource.TestCheckResourceAttr(name, "type", "custom"),
resource.TestCheckResourceAttr(name, "entry.0.name", fmt.Sprintf("%s_entry1", rnd)),
resource.TestCheckResourceAttr(name, "entry.0.enabled", "true"),
resource.TestCheckResourceAttr(name, "entry.0.pattern.0.regex", "^4[0-9]"),
resource.TestCheckResourceAttr(name, "entry.0.pattern.0.validation", "luhn"),
),
},
},
})
}

func TestAccCloudflareDLPProfile_ContextAwareness(t *testing.T) {
rnd := generateRandomResourceName()
name := fmt.Sprintf("cloudflare_dlp_profile.%s", rnd)
Expand Down Expand Up @@ -213,6 +242,27 @@ resource "cloudflare_dlp_profile" "%[1]s" {
`, rnd, description, accountID, allowedMatchCount)
}

func testAccCloudflareDLPProfileConfigCustomWithOCREnabled(accountID, rnd, description string, ocrEnabled bool) string {
return fmt.Sprintf(`
resource "cloudflare_dlp_profile" "%[1]s" {
account_id = "%[3]s"
name = "%[1]s"
description = "%[2]s"
allowed_match_count = 0
ocr_enabled = "%[4]t"
type = "custom"
entry {
name = "%[1]s_entry1"
enabled = true
pattern {
regex = "^4[0-9]"
validation = "luhn"
}
}
}
`, rnd, description, accountID, ocrEnabled)
}

func testAccCloudflareDLPProfileConfigWithContextAwareness(accountID, rnd, description string, contextAwareness cloudflare.DLPContextAwareness) string {
return fmt.Sprintf(`
resource "cloudflare_dlp_profile" "%[2]s" {
Expand Down
5 changes: 5 additions & 0 deletions internal/sdkv2provider/schema_cloudflare_dlp_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,5 +142,10 @@ func resourceCloudflareDLPProfileSchema() map[string]*schema.Schema {
Schema: resourceCloudflareDLPContextAwarenessSchema(),
},
},
"ocr_enabled": {
Type: schema.TypeBool,
Optional: true,
Description: "If true, scan images via OCR to determine if any text present matches filters.",
},
}
}

0 comments on commit 7f9ff6a

Please sign in to comment.