Skip to content

Commit

Permalink
Merge pull request #2855 from yj7o5/automatic-ssl-to-origin
Browse files Browse the repository at this point in the history
Add automatic ssl mode setting support
  • Loading branch information
jacobbednarz authored Aug 29, 2024
2 parents c8841b9 + 267d76e commit 1938337
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 6 deletions.
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

0 comments on commit 1938337

Please sign in to comment.