diff --git a/hcloud/schema/server.go b/hcloud/schema/server.go index 068b3e81..b9c945a8 100644 --- a/hcloud/schema/server.go +++ b/hcloud/schema/server.go @@ -289,12 +289,6 @@ type ServerActionDetachISOResponse struct { Action Action `json:"action"` } -// ServerActionEnableBackupRequest defines the schema for the request to -// enable backup for a server. -type ServerActionEnableBackupRequest struct { - BackupWindow *string `json:"backup_window,omitempty"` -} - // ServerActionEnableBackupResponse defines the schema of the response when // creating a enable_backup server action. type ServerActionEnableBackupResponse struct { diff --git a/hcloud/server.go b/hcloud/server.go index a9f1cb95..11857e17 100644 --- a/hcloud/server.go +++ b/hcloud/server.go @@ -853,21 +853,13 @@ func (c *ServerClient) DetachISO(ctx context.Context, server *Server) (*Action, return ActionFromSchema(respBody.Action), resp, nil } -// EnableBackup enables backup for a server. Pass in an empty backup window to let the -// API pick a window for you. See the API documentation at docs.hetzner.cloud for a list -// of valid backup windows. +// EnableBackup enables backup for a server. +// The window parameter is deprecated and will be ignored. func (c *ServerClient) EnableBackup(ctx context.Context, server *Server, window string) (*Action, *Response, error) { - reqBody := schema.ServerActionEnableBackupRequest{} - if window != "" { - reqBody.BackupWindow = Ptr(window) - } - reqBodyData, err := json.Marshal(reqBody) - if err != nil { - return nil, nil, err - } + _ = window path := fmt.Sprintf("/servers/%d/actions/enable_backup", server.ID) - req, err := c.client.NewRequest(ctx, "POST", path, bytes.NewReader(reqBodyData)) + req, err := c.client.NewRequest(ctx, "POST", path, nil) if err != nil { return nil, nil, err } diff --git a/hcloud/server_test.go b/hcloud/server_test.go index 3551732b..0a015135 100644 --- a/hcloud/server_test.go +++ b/hcloud/server_test.go @@ -1696,61 +1696,24 @@ func TestServerClientEnableBackup(t *testing.T) { server = &Server{ID: 1} ) - t.Run("with a backup window", func(t *testing.T) { - env := newTestEnv() - defer env.Teardown() + env := newTestEnv() + defer env.Teardown() - env.Mux.HandleFunc("/servers/1/actions/enable_backup", func(w http.ResponseWriter, r *http.Request) { - var reqBody schema.ServerActionEnableBackupRequest - if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil { - t.Fatal(err) - } - if reqBody.BackupWindow == nil || *reqBody.BackupWindow != "9-17" { - t.Errorf("unexpected backup window: %v", reqBody.BackupWindow) - } - json.NewEncoder(w).Encode(schema.ServerActionEnableBackupResponse{ - Action: schema.Action{ - ID: 1, - }, - }) + env.Mux.HandleFunc("/servers/1/actions/enable_backup", func(w http.ResponseWriter, r *http.Request) { + json.NewEncoder(w).Encode(schema.ServerActionEnableBackupResponse{ + Action: schema.Action{ + ID: 1, + }, }) - - action, _, err := env.Client.Server.EnableBackup(ctx, server, "9-17") - if err != nil { - t.Fatal(err) - } - if action.ID != 1 { - t.Errorf("unexpected action ID: %d", action.ID) - } }) - t.Run("without a backup window", func(t *testing.T) { - env := newTestEnv() - defer env.Teardown() - - env.Mux.HandleFunc("/servers/1/actions/enable_backup", func(w http.ResponseWriter, r *http.Request) { - var reqBody schema.ServerActionEnableBackupRequest - if err := json.NewDecoder(r.Body).Decode(&reqBody); err != nil { - t.Fatal(err) - } - if reqBody.BackupWindow != nil { - t.Errorf("unexpected backup window: %v", reqBody.BackupWindow) - } - json.NewEncoder(w).Encode(schema.ServerActionEnableBackupResponse{ - Action: schema.Action{ - ID: 1, - }, - }) - }) - - action, _, err := env.Client.Server.EnableBackup(ctx, server, "") - if err != nil { - t.Fatal(err) - } - if action.ID != 1 { - t.Errorf("unexpected action ID: %d", action.ID) - } - }) + action, _, err := env.Client.Server.EnableBackup(ctx, server, "") + if err != nil { + t.Fatal(err) + } + if action.ID != 1 { + t.Errorf("unexpected action ID: %d", action.ID) + } } func TestServerClientDisableBackup(t *testing.T) { diff --git a/hcloud/zz_server_client_iface.go b/hcloud/zz_server_client_iface.go index 82038a30..f249f783 100644 --- a/hcloud/zz_server_client_iface.go +++ b/hcloud/zz_server_client_iface.go @@ -62,9 +62,8 @@ type IServerClient interface { AttachISO(ctx context.Context, server *Server, iso *ISO) (*Action, *Response, error) // DetachISO detaches the currently attached ISO from a server. DetachISO(ctx context.Context, server *Server) (*Action, *Response, error) - // EnableBackup enables backup for a server. Pass in an empty backup window to let the - // API pick a window for you. See the API documentation at docs.hetzner.cloud for a list - // of valid backup windows. + // EnableBackup enables backup for a server. + // The window parameter is deprecated and will be ignored. EnableBackup(ctx context.Context, server *Server, window string) (*Action, *Response, error) // DisableBackup disables backup for a server. DisableBackup(ctx context.Context, server *Server) (*Action, *Response, error)