Skip to content

Commit

Permalink
add droplet backup policy to droplet create request
Browse files Browse the repository at this point in the history
  • Loading branch information
loosla committed Oct 28, 2024
1 parent d1f708a commit 5419a19
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
63 changes: 36 additions & 27 deletions droplets.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,37 +219,46 @@ func (d DropletCreateSSHKey) MarshalJSON() ([]byte, error) {

// DropletCreateRequest represents a request to create a Droplet.
type DropletCreateRequest struct {
Name string `json:"name"`
Region string `json:"region"`
Size string `json:"size"`
Image DropletCreateImage `json:"image"`
SSHKeys []DropletCreateSSHKey `json:"ssh_keys"`
Backups bool `json:"backups"`
IPv6 bool `json:"ipv6"`
PrivateNetworking bool `json:"private_networking"`
Monitoring bool `json:"monitoring"`
UserData string `json:"user_data,omitempty"`
Volumes []DropletCreateVolume `json:"volumes,omitempty"`
Tags []string `json:"tags"`
VPCUUID string `json:"vpc_uuid,omitempty"`
WithDropletAgent *bool `json:"with_droplet_agent,omitempty"`
Name string `json:"name"`
Region string `json:"region"`
Size string `json:"size"`
Image DropletCreateImage `json:"image"`
SSHKeys []DropletCreateSSHKey `json:"ssh_keys"`
Backups bool `json:"backups"`
IPv6 bool `json:"ipv6"`
PrivateNetworking bool `json:"private_networking"`
Monitoring bool `json:"monitoring"`
UserData string `json:"user_data,omitempty"`
Volumes []DropletCreateVolume `json:"volumes,omitempty"`
Tags []string `json:"tags"`
VPCUUID string `json:"vpc_uuid,omitempty"`
WithDropletAgent *bool `json:"with_droplet_agent,omitempty"`
BackupPolicy *BackupPolicyCreateRequest `json:"backup_policy,omitempty"`
}

// DropletMultiCreateRequest is a request to create multiple Droplets.
type DropletMultiCreateRequest struct {
Names []string `json:"names"`
Region string `json:"region"`
Size string `json:"size"`
Image DropletCreateImage `json:"image"`
SSHKeys []DropletCreateSSHKey `json:"ssh_keys"`
Backups bool `json:"backups"`
IPv6 bool `json:"ipv6"`
PrivateNetworking bool `json:"private_networking"`
Monitoring bool `json:"monitoring"`
UserData string `json:"user_data,omitempty"`
Tags []string `json:"tags"`
VPCUUID string `json:"vpc_uuid,omitempty"`
WithDropletAgent *bool `json:"with_droplet_agent,omitempty"`
Names []string `json:"names"`
Region string `json:"region"`
Size string `json:"size"`
Image DropletCreateImage `json:"image"`
SSHKeys []DropletCreateSSHKey `json:"ssh_keys"`
Backups bool `json:"backups"`
IPv6 bool `json:"ipv6"`
PrivateNetworking bool `json:"private_networking"`
Monitoring bool `json:"monitoring"`
UserData string `json:"user_data,omitempty"`
Tags []string `json:"tags"`
VPCUUID string `json:"vpc_uuid,omitempty"`
WithDropletAgent *bool `json:"with_droplet_agent,omitempty"`
BackupPolicy *BackupPolicyCreateRequest `json:"backup_policy,omitempty"`
}

// BackupPolicyCreateRequest defines the backup policy when creating a Droplet.
type BackupPolicyCreateRequest struct {
Plan string `json:"plan,omitempty"`
Weekday string `json:"weekday,omitempty"`
Hour int `json:"hour,omitempty"`
}

func (d DropletCreateRequest) String() string {
Expand Down
9 changes: 7 additions & 2 deletions droplets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ func TestDroplets_Create(t *testing.T) {
},
Tags: []string{"one", "two"},
VPCUUID: "880b7f98-f062-404d-b33c-458d545696f6",
BackupPolicy: &BackupPolicyCreateRequest{
Plan: "weekly",
Weekday: "MON",
},
}

mux.HandleFunc("/v2/droplets", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -333,8 +337,9 @@ func TestDroplets_Create(t *testing.T) {
map[string]interface{}{"id": "hello-im-another-volume"},
map[string]interface{}{"id": "aaa-111-bbb-222-ccc"},
},
"tags": []interface{}{"one", "two"},
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6",
"tags": []interface{}{"one", "two"},
"vpc_uuid": "880b7f98-f062-404d-b33c-458d545696f6",
"backup_policy": map[string]interface{}{"plan": "weekly", "weekday": "MON"},
}
jsonBlob := `
{
Expand Down

0 comments on commit 5419a19

Please sign in to comment.