Repository: cloudflare/cloudflare-go
Pull request #2974 (2024-08-29 18:56:13)

Add ai_bots_protection to bot management public API
## Description
<!-- 
Provide a general summary of your changes in the title above. You should
remove this overview, any sections and any section descriptions you
don't need below before submitting. There isn't a strict requirement to
use this template if you can structure your description and still cover
these points. 
-->

Added ability to configure ai_bots_protection using go bot_management api.

<!--
Describe your changes in detail through motivation and context. Why is
this change required? What problem does it solve? If it fixes an open
issue, link to the issue using GitHub's closing issues keywords[1].
-->
## Has your change been tested?

Yes, this change has been tested locally. 
<!--
Explain how the change has been tested and what you ran to confirm your
change affects other parts of the code. Automated tests are generally
expected and changes without tests should explain why they aren't
required.
-->

## Screenshots (if appropriate):

## Types of changes

What sort of change does your code introduce/modify?

- [ ] Bug fix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist:

- [x] My code follows the code style of this project.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [x] I have added tests to cover my changes.
- [x] All new and existing tests passed.
- [x] This change is using publicly documented in [cloudflare/api-schemas](https://github.com/cloudflare/api-schemas) 
      and relies on stable APIs.

[1]: https://help.github.com/articles/closing-issues-using-keywords/



Patch:
diff --git a/.changelog/2974.txt b/.changelog/2974.txt
new file mode 100644
index 000000000..ff0f072ef
--- /dev/null
+++ b/.changelog/2974.txt
@@ -0,0 +1,3 @@
+```release-note:enhancement
+bot_management: add ai_bots_protection to public API
+```
diff --git a/bot_management.go b/bot_management.go
index f77968f45..51205a6ae 100644
--- a/bot_management.go
+++ b/bot_management.go
@@ -20,6 +20,7 @@ type BotManagement struct {
 	SuppressSessionScore         *bool   `json:"suppress_session_score,omitempty"`
 	AutoUpdateModel              *bool   `json:"auto_update_model,omitempty"`
 	UsingLatestModel             *bool   `json:"using_latest_model,omitempty"`
+	AIBotsProtection             *string `json:"ai_bots_protection,omitempty"`
 }
 
 // BotManagementResponse represents the response from the bot_management endpoint.
@@ -38,6 +39,7 @@ type UpdateBotManagementParams struct {
 	OptimizeWordpress            *bool   `json:"optimize_wordpress,omitempty"`
 	SuppressSessionScore         *bool   `json:"suppress_session_score,omitempty"`
 	AutoUpdateModel              *bool   `json:"auto_update_model,omitempty"`
+	AIBotsProtection             *string `json:"ai_bots_protection,omitempty"`
 }
 
 // GetBotManagement gets a zone API shield configuration.


Test patch:
diff --git a/bot_management_test.go b/bot_management_test.go
index e0837804e..46ff1cff7 100644
--- a/bot_management_test.go
+++ b/bot_management_test.go
@@ -24,7 +24,8 @@ func TestGetBotManagement(t *testing.T) {
 	"result": {
 		"enable_js": false,
 		"fight_mode": true,
-		"using_latest_model": true
+		"using_latest_model": true,
+        "ai_bots_protection": "disabled"
 	}
 }
 		`)
@@ -36,6 +37,7 @@ func TestGetBotManagement(t *testing.T) {
 		EnableJS:         BoolPtr(false),
 		FightMode:        BoolPtr(true),
 		UsingLatestModel: BoolPtr(true),
+		AIBotsProtection: StringPtr("disabled"),
 	}
 
 	actual, err := client.GetBotManagement(context.Background(), ZoneIdentifier(testZoneID))
@@ -60,7 +62,8 @@ func TestUpdateBotManagement(t *testing.T) {
 	"result": {
 		"enable_js": false,
 		"fight_mode": true,
-		"using_latest_model": true
+		"using_latest_model": true,
+        "ai_bots_protection": "block"
 	}
 }
 		`)
@@ -69,14 +72,16 @@ func TestUpdateBotManagement(t *testing.T) {
 	mux.HandleFunc("/zones/"+testZoneID+"/bot_management", handler)
 
 	bmData := UpdateBotManagementParams{
-		EnableJS:  BoolPtr(false),
-		FightMode: BoolPtr(true),
+		EnableJS:         BoolPtr(false),
+		FightMode:        BoolPtr(true),
+		AIBotsProtection: StringPtr("block"),
 	}
 
 	want := BotManagement{
 		EnableJS:         BoolPtr(false),
 		FightMode:        BoolPtr(true),
 		UsingLatestModel: BoolPtr(true),
+		AIBotsProtection: StringPtr("block"),
 	}
 
 	actual, err := client.UpdateBotManagement(context.Background(), ZoneIdentifier(testZoneID), bmData)