Skip to content

Commit 929f248

Browse files
hi-leiclaude
andcommitted
feat(volume): upgrade SDK to v1.4.1, use proper trash API
Upgrade verdacloud-sdk-go to v1.4.1 which adds: - VolumeInTrash type with DeletedAt and IsPermanentlyDeleted fields - GetVolumesInTrash() method using /volumes/trash endpoint The trash command now shows: - Deletion time and recovery expiry countdown (96h window) - "permanently deleted" warning in red - Volume type (OS/Block), contract, and monthly price Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c07e06d commit 929f248

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/spf13/cobra v1.10.2
88
github.com/spf13/pflag v1.0.10
99
github.com/spf13/viper v1.21.0
10-
github.com/verda-cloud/verdacloud-sdk-go v1.4.0
10+
github.com/verda-cloud/verdacloud-sdk-go v1.4.1
1111
github.com/verda-cloud/verdagostack v1.0.0
1212
go.yaml.in/yaml/v3 v3.0.4
1313
gopkg.in/ini.v1 v1.67.1

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
104104
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
105105
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
106106
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
107-
github.com/verda-cloud/verdacloud-sdk-go v1.4.0 h1:HdbYsOpYhlK7R+IhBZlDBLWQ5RP0rTh2uEsJRy9FRRU=
108-
github.com/verda-cloud/verdacloud-sdk-go v1.4.0/go.mod h1:pmlpiCL9fTSikZ3qWLJPpHOG0E8PKkQVUX5s4Z+SktY=
107+
github.com/verda-cloud/verdacloud-sdk-go v1.4.1 h1:5lr8s+wsT/W4N4/lsVDEh35q7zSsA1mkj4D6oT1SWK0=
108+
github.com/verda-cloud/verdacloud-sdk-go v1.4.1/go.mod h1:pmlpiCL9fTSikZ3qWLJPpHOG0E8PKkQVUX5s4Z+SktY=
109109
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
110110
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
111111
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=

internal/verda-cli/cmd/volume/trash.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package volume
33
import (
44
"context"
55
"fmt"
6+
"time"
67

78
"github.com/charmbracelet/lipgloss"
89
"github.com/spf13/cobra"
@@ -42,7 +43,7 @@ func runTrash(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStreams
4243
if status := f.Status(); status != nil {
4344
sp, _ = status.Spinner(ctx, "Loading trash...")
4445
}
45-
volumes, err := client.Volumes.ListVolumesByStatus(ctx, "deleted")
46+
volumes, err := client.Volumes.GetVolumesInTrash(ctx)
4647
if sp != nil {
4748
sp.Stop("")
4849
}
@@ -57,6 +58,7 @@ func runTrash(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStreams
5758

5859
dim := lipgloss.NewStyle().Foreground(lipgloss.Color("8"))
5960
bold := lipgloss.NewStyle().Bold(true)
61+
warnStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("1"))
6062

6163
_, _ = fmt.Fprintf(ioStreams.Out, " %d volume(s) in trash\n\n", len(volumes))
6264

@@ -65,16 +67,39 @@ func runTrash(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStreams
6567
if v.IsOSVolume {
6668
volType = "OS"
6769
}
68-
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", bold.Render(v.Name), dim.Render(volType))
70+
71+
permStatus := ""
72+
if v.IsPermanentlyDeleted {
73+
permStatus = warnStyle.Render(" (permanently deleted)")
74+
}
75+
76+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s%s\n", bold.Render(v.Name), dim.Render(volType), permStatus)
6977
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("ID: "), v.ID)
7078
_, _ = fmt.Fprintf(ioStreams.Out, " %s %dGB %s\n", dim.Render("Size: "), v.Size, v.Type)
7179
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("Location:"), v.Location)
7280
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("Contract:"), v.Contract)
7381
if v.MonthlyPrice > 0 {
7482
_, _ = fmt.Fprintf(ioStreams.Out, " %s $%.2f/mo (%s)\n", dim.Render("Price: "), v.MonthlyPrice, v.Currency)
7583
}
76-
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n\n", dim.Render("Created: "), v.CreatedAt.Format("2 Jan 2006, 15:04"))
84+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("Deleted: "), v.DeletedAt.Format("2 Jan 2006, 15:04"))
85+
86+
if !v.IsPermanentlyDeleted && !v.DeletedAt.IsZero() {
87+
expiresAt := v.DeletedAt.Add(96 * time.Hour)
88+
remaining := time.Until(expiresAt)
89+
if remaining > 0 {
90+
_, _ = fmt.Fprintf(ioStreams.Out, " %s %s\n", dim.Render("Expires: "), fmt.Sprintf("%s (%s remaining)", expiresAt.Format("2 Jan 2006, 15:04"), formatDuration(remaining)))
91+
}
92+
}
93+
_, _ = fmt.Fprintln(ioStreams.Out)
7794
}
7895

7996
return nil
8097
}
98+
99+
func formatDuration(d time.Duration) string {
100+
h := int(d.Hours())
101+
if h >= 24 {
102+
return fmt.Sprintf("%dd %dh", h/24, h%24)
103+
}
104+
return fmt.Sprintf("%dh", h)
105+
}

0 commit comments

Comments
 (0)