Skip to content

Commit

Permalink
protect against panics on list for Droplets that do not have backups …
Browse files Browse the repository at this point in the history
…enabled
  • Loading branch information
loosla committed Nov 13, 2024
1 parent 10aabd3 commit b796bb5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 9 additions & 6 deletions commands/displayers/droplet_backup_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@ func (d *DropletBackupPolicy) ColMap() map[string]string {
func (d *DropletBackupPolicy) KV() []map[string]any {
out := make([]map[string]any, 0)
for _, policy := range d.DropletBackupPolicies {
m := map[string]any{
"DropletID": policy.DropletID, "BackupEnabled": policy.BackupEnabled, "BackupPolicyPlan": policy.BackupPolicy.Plan,
"BackupPolicyWeekday": policy.BackupPolicy.Weekday, "BackupPolicyHour": policy.BackupPolicy.Hour,
"BackupPolicyWindowLengthHours": policy.BackupPolicy.WindowLengthHours, "BackupPolicyRetentionPeriodDays": policy.BackupPolicy.RetentionPeriodDays,
"NextBackupWindowStart": policy.NextBackupWindow.Start, "NextBackupWindowEnd": policy.NextBackupWindow.End,
if policy.BackupPolicy != nil && policy.NextBackupWindow != nil {
m := map[string]any{
"DropletID": policy.DropletID, "BackupEnabled": policy.BackupEnabled,
"BackupPolicyPlan": policy.BackupPolicy.Plan,
"BackupPolicyWeekday": policy.BackupPolicy.Weekday, "BackupPolicyHour": policy.BackupPolicy.Hour,
"BackupPolicyWindowLengthHours": policy.BackupPolicy.WindowLengthHours, "BackupPolicyRetentionPeriodDays": policy.BackupPolicy.RetentionPeriodDays,
"NextBackupWindowStart": policy.NextBackupWindow.Start, "NextBackupWindowEnd": policy.NextBackupWindow.End,
}
out = append(out, m)
}
out = append(out, m)
}

return out
Expand Down
2 changes: 0 additions & 2 deletions do/droplets.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package do

import (
"context"
"fmt"

"github.com/digitalocean/godo"
"github.com/digitalocean/godo/util"
Expand Down Expand Up @@ -391,7 +390,6 @@ func (ds *dropletsService) ListBackupPolicies() (DropletBackupPolicies, error) {
}

list := make(DropletBackupPolicies, len(si))
fmt.Println("si: ", si)
for i := range si {
p := si[i].(*godo.DropletBackupPolicy)
list[i] = DropletBackupPolicy{DropletBackupPolicy: p}
Expand Down

0 comments on commit b796bb5

Please sign in to comment.