@@ -3,12 +3,12 @@ package describe
33import (
44 "context"
55 "fmt"
6- "time "
6+ "strconv "
77
88 "github.com/stackitcloud/stackit-cli/internal/pkg/types"
99
1010 "github.com/spf13/cobra"
11- postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v2api "
11+ postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3api "
1212
1313 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
1414 "github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -18,24 +18,19 @@ import (
1818 "github.com/stackitcloud/stackit-cli/internal/pkg/print"
1919 "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client"
2020 "github.com/stackitcloud/stackit-cli/internal/pkg/tables"
21- "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
2221)
2322
2423const (
2524 backupIdArg = "BACKUP_ID"
2625
2726 instanceIdFlag = "instance-id"
28-
29- backupExpireYearOffset = 0
30- backupExpireMonthOffset = 0
31- backupExpireDayOffset = 30
3227)
3328
3429type inputModel struct {
3530 * globalflags.GlobalFlagModel
3631
3732 InstanceId string
38- BackupId string
33+ BackupId int64
3934}
4035
4136func NewCmd (params * types.CmdParams ) * cobra.Command {
@@ -73,7 +68,7 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7368 return fmt .Errorf ("describe backup for PostgreSQL Flex instance: %w" , err )
7469 }
7570
76- return outputResult (params .Printer , model .OutputFormat , resp . Item )
71+ return outputResult (params .Printer , model .OutputFormat , resp )
7772 },
7873 }
7974 configureFlags (cmd )
@@ -88,13 +83,18 @@ func configureFlags(cmd *cobra.Command) {
8883}
8984
9085func parseInput (p * print.Printer , cmd * cobra.Command , inputArgs []string ) (* inputModel , error ) {
91- backupId := inputArgs [0 ]
86+ backupIdStr := inputArgs [0 ]
9287
9388 globalFlags := globalflags .Parse (p , cmd )
9489 if globalFlags .ProjectId == "" {
9590 return nil , & errors.ProjectIdError {}
9691 }
9792
93+ backupId , err := strconv .ParseInt (backupIdStr , 10 , 64 )
94+ if err != nil {
95+ return nil , fmt .Errorf ("invalid backup id format, must be an integer: %w" , err )
96+ }
97+
9898 return & inputModel {
9999 GlobalFlagModel : globalFlags ,
100100 InstanceId : flags .FlagToStringValue (p , cmd , instanceIdFlag ),
@@ -107,30 +107,20 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresfle
107107 return req
108108}
109109
110- func outputResult (p * print.Printer , outputFormat string , backup * postgresflex.Backup ) error {
111- if backup == nil {
112- return fmt .Errorf ("backup is nil" )
113- }
114- if backup .StartTime == nil || * backup .StartTime == "" {
115- return fmt .Errorf ("start time not defined" )
116- }
117- backupStartTime , err := time .Parse (time .RFC3339 , utils .PtrString (backup .StartTime ))
118- if err != nil {
119- return fmt .Errorf ("parse backup start time: %w" , err )
120- }
121- backupExpireDate := backupStartTime .AddDate (backupExpireYearOffset , backupExpireMonthOffset , backupExpireDayOffset ).Format (time .DateOnly )
122-
110+ func outputResult (p * print.Printer , outputFormat string , backup * postgresflex.BackupData ) error {
123111 return p .OutputResult (outputFormat , backup , func () error {
112+ if backup == nil {
113+ return fmt .Errorf ("backup is nil" )
114+ }
115+
124116 table := tables .NewTable ()
125- table .AddRow ("ID" , utils . PtrString ( backup .Id ) )
117+ table .AddRow ("ID" , backup .Id )
126118 table .AddSeparator ()
127- table .AddRow ("CREATED AT" , utils . PtrString ( backup .StartTime ) )
119+ table .AddRow ("COMPLETED AT" , backup .CompletionTime )
128120 table .AddSeparator ()
129- table .AddRow ("EXPIRES AT " , backupExpireDate )
121+ table .AddRow ("RETAINED UNTIL " , backup . RetainedUntil )
130122 table .AddSeparator ()
131-
132- backupSize := utils .PtrByteSizeDefault (backup .Size , "n/a" )
133- table .AddRow ("BACKUP SIZE" , backupSize )
123+ table .AddRow ("BACKUP SIZE" , backup .Size )
134124
135125 err := table .Display (p )
136126 if err != nil {
0 commit comments