Repository: cloudflare/cloudflare-go
Pull request #2855 (2024-08-09 21:54:06)

Add automatic ssl mode setting support
<!-- 
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. 
-->

## Description
This PR adds support for reading and modifying the new automatic ssl mode setting. 

<!--
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, there are tests in placed to verify both reading and writing the setting value. 

<!--
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.
- [x] 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.
- [ ] 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/


github-actions[bot]: Oops! It looks like no changelog entry is attached to this PR. Please include a release note as described in https://github.com/cloudflare/cloudflare-go/blob/master/docs/changelog-process.md.

Example: 

~~~
```release-note:TYPE
Release note
```
~~~

If you do not require a release note to be included, please add the `workflow/skip-changelog-entry` label.

Patch:
diff --git a/.changelog/2855.txt b/.changelog/2855.txt
new file mode 100644
index 000000000..614807de5
--- /dev/null
+++ b/.changelog/2855.txt
@@ -0,0 +1,3 @@
+```release-notes:enhancement
+ssl: add support for ssl/tls automatic mode setting
+```
diff --git a/zone.go b/zone.go
index de92880a1..714c0edc8 100644
--- a/zone.go
+++ b/zone.go
@@ -146,11 +146,12 @@ type ZoneRatePlanResponse struct {
 
 // ZoneSetting contains settings for a zone.
 type ZoneSetting struct {
-	ID            string      `json:"id"`
-	Editable      bool        `json:"editable"`
-	ModifiedOn    string      `json:"modified_on,omitempty"`
-	Value         interface{} `json:"value"`
-	TimeRemaining int         `json:"time_remaining"`
+	ID                string      `json:"id"`
+	Editable          bool        `json:"editable"`
+	ModifiedOn        string      `json:"modified_on,omitempty"`
+	Value             interface{} `json:"value"`
+	TimeRemaining     int         `json:"time_remaining"`
+	NextScheduledScan string      `json:"next_scheduled_scan,omitempty"`
 }
 
 // ZoneSettingResponse represents the response from the Zone Setting endpoint.
@@ -175,7 +176,6 @@ type ZoneSSLSetting struct {
 }
 
 // ZoneSSLSettingResponse represents the response from the Zone SSL Setting
-// endpoint.
 type ZoneSSLSettingResponse struct {
 	Response
 	Result ZoneSSLSetting `json:"result"`


Test patch:
diff --git a/zone_test.go b/zone_test.go
index d8b94cd1c..d5a28fa4f 100644
--- a/zone_test.go
+++ b/zone_test.go
@@ -1511,6 +1511,65 @@ func TestUpdateZoneSSLSettings(t *testing.T) {
 	}
 }
 
+func TestUpdateZoneAutomaticSSLModeSetting(t *testing.T) {
+	setup()
+	defer teardown()
+	handler := func(w http.ResponseWriter, r *http.Request) {
+		assert.Equal(t, http.MethodPatch, r.Method, "Expected method 'PATCH', got %s", r.Method)
+		w.Header().Set("content-type", "application/json")
+		// JSON data from: https://api.cloudflare.com/#zone-settings-properties
+		_, _ = fmt.Fprintf(w, `{
+			"result": {
+				"id": "ssl_tls_configuration_mode",
+				"value": "auto",
+				"editable": true,
+				"modified_on": "2014-01-01T05:20:00.12345Z",
+				"next_scheduled_scan": "2014-01-01T05:20:00.12345Z"
+			}
+		}`)
+	}
+	mux.HandleFunc("/zones/foo/settings/ssl_automatic_mode", handler)
+	s, err := client.UpdateZoneSetting(context.Background(), ZoneIdentifier("foo"), UpdateZoneSettingParams{
+		Name:  "ssl_automatic_mode",
+		Value: "auto",
+	})
+
+	if assert.NoError(t, err) {
+		assert.Equal(t, s.ID, "ssl_tls_configuration_mode")
+		assert.Equal(t, s.Value, "auto")
+		assert.Equal(t, s.Editable, true)
+		assert.Equal(t, s.ModifiedOn, "2014-01-01T05:20:00.12345Z")
+		assert.Equal(t, s.NextScheduledScan, "2014-01-01T05:20:00.12345Z")
+	}
+}
+
+func TestGetZoneAutomaticSSLModeSetting(t *testing.T) {
+	setup()
+	defer teardown()
+	handler := func(w http.ResponseWriter, r *http.Request) {
+		assert.Equal(t, http.MethodGet, r.Method, "Expected method 'GET', got %s", r.Method)
+		w.Header().Set("content-type", "application/json")
+		_, _ = fmt.Fprintf(w, `{
+			"result": {
+				"id": "ssl_tls_configuration_mode",
+				"value": "custom",
+				"editable": true,
+				"modified_on": "2014-01-01T05:20:00.12345Z",
+				"next_scheduled_scan": "2024-01-01T05:20:00.12345Z"
+			}
+		}`)
+	}
+	mux.HandleFunc("/zones/foo/settings/ssl_automatic_mode", handler)
+	s, err := client.GetZoneSetting(context.Background(), ZoneIdentifier("foo"), GetZoneSettingParams{Name: "ssl_automatic_mode"})
+	if assert.NoError(t, err) {
+		assert.Equal(t, s.ID, "ssl_tls_configuration_mode")
+		assert.Equal(t, s.Value, "custom")
+		assert.Equal(t, s.Editable, true)
+		assert.Equal(t, s.ModifiedOn, "2014-01-01T05:20:00.12345Z")
+		assert.Equal(t, s.NextScheduledScan, "2024-01-01T05:20:00.12345Z")
+	}
+}
+
 func TestGetZoneSetting(t *testing.T) {
 	setup()
 	defer teardown()