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

fix: deprecate unused window parameter in the EnableBackup call #531

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Changes from 1 commit
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
Next Next commit
fix: remove handling of deprecated backup window parameter and update…
… docs
phm07 committed Sep 6, 2024
commit 47bdef54158cb95d263bc1166853444a6608cfe5
6 changes: 0 additions & 6 deletions hcloud/schema/server.go
Original file line number Diff line number Diff line change
@@ -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"`
}

jooola marked this conversation as resolved.
Show resolved Hide resolved
// ServerActionEnableBackupResponse defines the schema of the response when
// creating a enable_backup server action.
type ServerActionEnableBackupResponse struct {
16 changes: 4 additions & 12 deletions hcloud/server.go
Original file line number Diff line number Diff line change
@@ -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
}
65 changes: 14 additions & 51 deletions hcloud/server_test.go
Original file line number Diff line number Diff line change
@@ -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) {