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 automatic ssl mode setting support #2855

Merged
merged 3 commits into from
Aug 29, 2024
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/2855.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-notes:enhancement
ssl: add support for ssl/tls automatic mode setting
```
12 changes: 6 additions & 6 deletions zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"`
Expand Down
59 changes: 59 additions & 0 deletions zone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading