From cde1060e097e146962836e96009c862764e77063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Wed, 20 Mar 2024 08:49:01 +0100 Subject: [PATCH 01/17] onboard postgresflex backup commands --- go.mod | 1 + go.sum | 2 + .../postgresflex/instance/backups/backups.go | 29 +++ .../instance/backups/describe/describe.go | 140 +++++++++++ .../backups/describe/describe_test.go | 236 ++++++++++++++++++ .../instance/backups/list/list.go | 152 +++++++++++ .../instance/backups/list/list_test.go | 199 +++++++++++++++ .../update-schedule/update_schedule.go | 112 +++++++++ .../update-schedule/update_schedule_test.go | 216 ++++++++++++++++ .../cmd/postgresflex/instance/instance.go | 2 + 10 files changed, 1089 insertions(+) create mode 100644 internal/cmd/postgresflex/instance/backups/backups.go create mode 100644 internal/cmd/postgresflex/instance/backups/describe/describe.go create mode 100644 internal/cmd/postgresflex/instance/backups/describe/describe_test.go create mode 100644 internal/cmd/postgresflex/instance/backups/list/list.go create mode 100644 internal/cmd/postgresflex/instance/backups/list/list_test.go create mode 100644 internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule.go create mode 100644 internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule_test.go diff --git a/go.mod b/go.mod index 71faf172b..68732acdf 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/stackitcloud/stackit-cli go 1.21 require ( + github.com/depp/bytesize v1.1.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 diff --git a/go.sum b/go.sum index 8b29697ea..d4e1ad9ea 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/depp/bytesize v1.1.0 h1:HUJEFG8nW/vrfflMw0TB/5ZrwSuGAw3xrgyzKqzVLf4= +github.com/depp/bytesize v1.1.0/go.mod h1:W5nYZIYKjq8tqfzkVVwMblQwIRI4KcZGJz4DbNT9wwY= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= diff --git a/internal/cmd/postgresflex/instance/backups/backups.go b/internal/cmd/postgresflex/instance/backups/backups.go new file mode 100644 index 000000000..afa9b3194 --- /dev/null +++ b/internal/cmd/postgresflex/instance/backups/backups.go @@ -0,0 +1,29 @@ +package backups + +import ( + "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups/describe" + "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups/list" + updateschedule "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups/update-schedule" + "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + + "github.com/spf13/cobra" +) + +func NewCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "backups", + Short: "Provides functionality for PostgreSQL Flex instance backups", + Long: "Provides functionality for PostgreSQL Flex instance backups.", + Args: args.NoArgs, + Run: utils.CmdHelp, + } + addSubcommands(cmd) + return cmd +} + +func addSubcommands(cmd *cobra.Command) { + cmd.AddCommand(list.NewCmd()) + cmd.AddCommand(describe.NewCmd()) + cmd.AddCommand(updateschedule.NewCmd()) +} diff --git a/internal/cmd/postgresflex/instance/backups/describe/describe.go b/internal/cmd/postgresflex/instance/backups/describe/describe.go new file mode 100644 index 000000000..fc1ed64ee --- /dev/null +++ b/internal/cmd/postgresflex/instance/backups/describe/describe.go @@ -0,0 +1,140 @@ +package describe + +import ( + "context" + "encoding/json" + "fmt" + "time" + + "github.com/depp/bytesize" + "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/examples" + "github.com/stackitcloud/stackit-cli/internal/pkg/flags" + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" + "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" +) + +const ( + backupIdArg = "BACKUP_ID" + + instanceIdFlag = "instance-id" +) + +type inputModel struct { + *globalflags.GlobalFlagModel + + InstanceId string + BackupId string +} + +func NewCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: fmt.Sprintf("describe %s", backupIdArg), + Short: "Shows details of a backup for a specific PostgreSQL Flex instance", + Long: "Shows details of a backup for a specific PostgreSQL Flex instance.", + Example: examples.Build( + examples.NewExample( + `Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy"`, + "$ stackit postgresflex instance backups describe xxx --instance-id yyy"), + examples.NewExample( + `Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" in a table format`, + "$ stackit postgresflex instance backups describe xxx --instance-id yyy --output-format pretty"), + ), + Args: args.SingleArg(backupIdArg, nil), + RunE: func(cmd *cobra.Command, args []string) error { + ctx := context.Background() + model, err := parseInput(cmd, args) + if err != nil { + return err + } + + // Configure API client + apiClient, err := client.ConfigureClient(cmd) + if err != nil { + return err + } + + // Call API + req := buildRequest(ctx, model, apiClient) + resp, err := req.Execute() + + if err != nil { + return fmt.Errorf("describe backup for PostgreSQL Flex instance : %w", err) + } + + return outputResult(cmd, model.OutputFormat, *resp.Item) + }, + } + configureFlags(cmd) + return cmd +} + +func configureFlags(cmd *cobra.Command) { + cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") + + err := flags.MarkFlagsRequired(cmd, instanceIdFlag) + cobra.CheckErr(err) +} + +func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) { + backupId := inputArgs[0] + + globalFlags := globalflags.Parse(cmd) + if globalFlags.ProjectId == "" { + return nil, &errors.ProjectIdError{} + } + + return &inputModel{ + GlobalFlagModel: globalFlags, + InstanceId: flags.FlagToStringValue(cmd, instanceIdFlag), + BackupId: backupId, + }, nil +} + +func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiGetBackupRequest { + req := apiClient.GetBackup(ctx, model.ProjectId, model.InstanceId, model.BackupId) + return req +} + +func outputResult(cmd *cobra.Command, outputFormat string, backup postgresflex.Backup) error { + backupStartTime, err := time.Parse(time.RFC3339, *backup.StartTime) + if err != nil { + return fmt.Errorf("parse backup start time : %w", err) + } + backupExpireDate := backupStartTime.AddDate(0, 0, 30).Format(time.DateOnly) + + switch outputFormat { + case globalflags.PrettyOutputFormat: + table := tables.NewTable() + table.AddRow("ID", *backup.Id) + table.AddSeparator() + table.AddRow("NAME", *backup.Name) + table.AddSeparator() + table.AddRow("START TIME", *backup.StartTime) + table.AddSeparator() + table.AddRow("END TIME", *backup.EndTime) + table.AddSeparator() + table.AddRow("EXPIRES AT", backupExpireDate) + table.AddSeparator() + table.AddRow("BACKUP SIZE", bytesize.Format(uint64(*backup.Size))) + + err := table.Display(cmd) + if err != nil { + return fmt.Errorf("render table: %w", err) + } + + return nil + default: + details, err := json.MarshalIndent(backup, "", " ") + if err != nil { + return fmt.Errorf("marshal backup for PostgreSQL Flex instance : %w", err) + } + cmd.Println(string(details)) + + return nil + } +} diff --git a/internal/cmd/postgresflex/instance/backups/describe/describe_test.go b/internal/cmd/postgresflex/instance/backups/describe/describe_test.go new file mode 100644 index 000000000..f003f9b12 --- /dev/null +++ b/internal/cmd/postgresflex/instance/backups/describe/describe_test.go @@ -0,0 +1,236 @@ +package describe + +import ( + "context" + "testing" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/google/uuid" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" +) + +var projectIdFlag = globalflags.ProjectIdFlag + +type testCtxKey struct{} + +var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") +var testClient = &postgresflex.APIClient{} +var testProjectId = uuid.NewString() +var testInstanceId = uuid.NewString() +var testBackupId = "backupID" + +func fixtureArgValues(mods ...func(argValues []string)) []string { + argValues := []string{ + testBackupId, + } + for _, mod := range mods { + mod(argValues) + } + return argValues +} + +func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { + flagValues := map[string]string{ + projectIdFlag: testProjectId, + instanceIdFlag: testInstanceId, + } + for _, mod := range mods { + mod(flagValues) + } + return flagValues +} + +func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { + model := &inputModel{ + GlobalFlagModel: &globalflags.GlobalFlagModel{ + ProjectId: testProjectId, + }, + InstanceId: testInstanceId, + BackupId: testBackupId, + } + for _, mod := range mods { + mod(model) + } + return model +} + +func fixtureRequest(mods ...func(request *postgresflex.ApiGetBackupRequest)) postgresflex.ApiGetBackupRequest { + request := testClient.GetBackup(testCtx, testProjectId, testInstanceId, testBackupId) + for _, mod := range mods { + mod(&request) + } + return request +} + +func TestParseInput(t *testing.T) { + tests := []struct { + description string + argValues []string + flagValues map[string]string + isValid bool + expectedModel *inputModel + }{ + { + description: "base", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(), + isValid: true, + expectedModel: fixtureInputModel(), + }, + { + description: "no values", + argValues: []string{}, + flagValues: map[string]string{}, + isValid: false, + }, + { + description: "no arg values", + argValues: []string{}, + flagValues: fixtureFlagValues(), + isValid: false, + }, + { + description: "no flag values", + argValues: fixtureArgValues(), + flagValues: map[string]string{}, + isValid: false, + }, + { + description: "project id missing", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, projectIdFlag) + }), + isValid: false, + }, + { + description: "project id invalid 1", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "" + }), + isValid: false, + }, + { + description: "project id invalid 2", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "invalid-uuid" + }), + isValid: false, + }, + { + description: "instance id missing", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, instanceIdFlag) + }), + isValid: false, + }, + { + description: "instance id invalid 1", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "" + }), + isValid: false, + }, + { + description: "instance id invalid 2", + argValues: fixtureArgValues(), + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "invalid-uuid" + }), + isValid: false, + }, + { + description: "backup id invalid 1", + argValues: []string{""}, + flagValues: fixtureFlagValues(), + isValid: false, + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + cmd := NewCmd() + err := globalflags.Configure(cmd.Flags()) + if err != nil { + t.Fatalf("configure global flags: %v", err) + } + + for flag, value := range tt.flagValues { + err := cmd.Flags().Set(flag, value) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("setting flag --%s=%s: %v", flag, value, err) + } + } + + err = cmd.ValidateArgs(tt.argValues) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error validating args: %v", err) + } + + err = cmd.ValidateRequiredFlags() + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error validating flags: %v", err) + } + + model, err := parseInput(cmd, tt.argValues) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error parsing input: %v", err) + } + + if !tt.isValid { + t.Fatalf("did not fail on invalid input") + } + diff := cmp.Diff(model, tt.expectedModel) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} + +func TestBuildRequest(t *testing.T) { + tests := []struct { + description string + model *inputModel + expectedRequest postgresflex.ApiGetBackupRequest + }{ + { + description: "base", + model: fixtureInputModel(), + expectedRequest: fixtureRequest(), + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + request := buildRequest(testCtx, tt.model, testClient) + + diff := cmp.Diff(request, tt.expectedRequest, + cmp.AllowUnexported(tt.expectedRequest), + cmpopts.EquateComparable(testCtx), + ) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} diff --git a/internal/cmd/postgresflex/instance/backups/list/list.go b/internal/cmd/postgresflex/instance/backups/list/list.go new file mode 100644 index 000000000..b843ee618 --- /dev/null +++ b/internal/cmd/postgresflex/instance/backups/list/list.go @@ -0,0 +1,152 @@ +package list + +import ( + "context" + "encoding/json" + "fmt" + + "github.com/depp/bytesize" + "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/examples" + "github.com/stackitcloud/stackit-cli/internal/pkg/flags" + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" + postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" + "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + + "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" +) + +const ( + instanceIdFlag = "instance-id" + limitFlag = "limit" +) + +type inputModel struct { + *globalflags.GlobalFlagModel + + InstanceId *string + Limit *int64 +} + +func NewCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "list", + Short: "Lists all backups which are available for a specific PostgreSQL Flex instance", + Long: "Lists all backups which are available for a specific PostgreSQL Flex instance.", + Example: examples.Build( + examples.NewExample( + `List all backups of instance with ID "xxx"`, + "$ stackit postgresflex instance backups list --instance-id xxx"), + examples.NewExample( + `List all backups of instance with ID "xxx" in JSON format`, + "$ stackit postgresflex instance backups list --instance-id xxx --output-format json"), + examples.NewExample( + `List up to 10 backups of instance with ID "xxx"`, + "$ stackit postgresflex instance backups list --instance-id xxx --limit 10"), + ), + Args: args.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + ctx := context.Background() + model, err := parseInput(cmd) + if err != nil { + return err + } + + // Configure API client + apiClient, err := client.ConfigureClient(cmd) + if err != nil { + return err + } + + instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, *model.InstanceId) + if err != nil { + instanceLabel = *model.InstanceId + } + + // Call API + req := buildRequest(ctx, model, apiClient) + resp, err := req.Execute() + if err != nil { + return fmt.Errorf("get backups for PostgreSQL Flex instance %q: %w\n", instanceLabel, err) + } + if resp.Items == nil || len(*resp.Items) == 0 { + cmd.Printf("No backups found for instance %q\n", instanceLabel) + return nil + } + backups := *resp.Items + + // Truncate output + if model.Limit != nil && len(backups) > int(*model.Limit) { + backups = backups[:*model.Limit] + } + + return outputResult(cmd, model.OutputFormat, backups) + }, + } + + configureFlags(cmd) + return cmd +} + +func configureFlags(cmd *cobra.Command) { + cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") + cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list") + + err := flags.MarkFlagsRequired(cmd, instanceIdFlag) + cobra.CheckErr(err) +} + +func parseInput(cmd *cobra.Command) (*inputModel, error) { + globalFlags := globalflags.Parse(cmd) + if globalFlags.ProjectId == "" { + return nil, &errors.ProjectIdError{} + } + + limit := flags.FlagToInt64Pointer(cmd, limitFlag) + if limit != nil && *limit < 1 { + return nil, &errors.FlagValidationError{ + Flag: limitFlag, + Details: "must be greater than 0", + } + } + + return &inputModel{ + GlobalFlagModel: globalFlags, + InstanceId: flags.FlagToStringPointer(cmd, instanceIdFlag), + Limit: flags.FlagToInt64Pointer(cmd, limitFlag), + }, nil +} + +func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiListBackupsRequest { + req := apiClient.ListBackups(ctx, model.ProjectId, *model.InstanceId) + return req +} + +func outputResult(cmd *cobra.Command, outputFormat string, backups []postgresflex.Backup) error { + switch outputFormat { + case globalflags.JSONOutputFormat: + details, err := json.MarshalIndent(backups, "", " ") + if err != nil { + return fmt.Errorf("marshal PostgreSQL Flex instance list: %w", err) + } + cmd.Println(string(details)) + + return nil + default: + table := tables.NewTable() + table.SetHeader("ID", "NAME", "START TIME", "END TIME", "BACKUP SIZE") + for i := range backups { + backup := backups[i] + table.AddRow(*backup.Id, *backup.Name, *backup.StartTime, *backup.EndTime, bytesize.Format(uint64(*backup.Size))) + } + err := table.Display(cmd) + if err != nil { + return fmt.Errorf("render table: %w", err) + } + + return nil + } +} diff --git a/internal/cmd/postgresflex/instance/backups/list/list_test.go b/internal/cmd/postgresflex/instance/backups/list/list_test.go new file mode 100644 index 000000000..a8712b662 --- /dev/null +++ b/internal/cmd/postgresflex/instance/backups/list/list_test.go @@ -0,0 +1,199 @@ +package list + +import ( + "context" + "testing" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/google/uuid" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" +) + +var projectIdFlag = globalflags.ProjectIdFlag + +type testCtxKey struct{} + +var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") +var testClient = &postgresflex.APIClient{} +var testProjectId = uuid.NewString() +var testInstanceId = uuid.NewString() + +func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { + flagValues := map[string]string{ + projectIdFlag: testProjectId, + instanceIdFlag: testInstanceId, + limitFlag: "10", + } + for _, mod := range mods { + mod(flagValues) + } + return flagValues +} + +func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { + model := &inputModel{ + GlobalFlagModel: &globalflags.GlobalFlagModel{ + ProjectId: testProjectId, + }, + InstanceId: utils.Ptr(testInstanceId), + Limit: utils.Ptr(int64(10)), + } + for _, mod := range mods { + mod(model) + } + return model +} + +func fixtureRequest(mods ...func(request *postgresflex.ApiListBackupsRequest)) postgresflex.ApiListBackupsRequest { + request := testClient.ListBackups(testCtx, testProjectId, testInstanceId) + for _, mod := range mods { + mod(&request) + } + return request +} + +func TestParseInput(t *testing.T) { + tests := []struct { + description string + flagValues map[string]string + isValid bool + expectedModel *inputModel + }{ + { + description: "base", + flagValues: fixtureFlagValues(), + isValid: true, + expectedModel: fixtureInputModel(), + }, + { + description: "no values", + flagValues: map[string]string{}, + isValid: false, + }, + { + description: "project id missing", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, projectIdFlag) + }), + isValid: false, + }, + { + description: "project id invalid 1", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "" + }), + isValid: false, + }, + { + description: "project id invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "invalid-uuid" + }), + isValid: false, + }, + { + description: "instance id missing", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, instanceIdFlag) + }), + isValid: false, + }, + { + description: "instance id invalid 1", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "" + }), + isValid: false, + }, + { + description: "limit invalid", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "invalid" + }), + isValid: false, + }, + { + description: "limit invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[limitFlag] = "0" + }), + isValid: false, + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + cmd := NewCmd() + err := globalflags.Configure(cmd.Flags()) + if err != nil { + t.Fatalf("configure global flags: %v", err) + } + + for flag, value := range tt.flagValues { + err := cmd.Flags().Set(flag, value) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("setting flag --%s=%s: %v", flag, value, err) + } + } + + err = cmd.ValidateRequiredFlags() + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error validating flags: %v", err) + } + + model, err := parseInput(cmd) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error parsing input: %v", err) + } + + if !tt.isValid { + t.Fatalf("did not fail on invalid input") + } + diff := cmp.Diff(model, tt.expectedModel) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} + +func TestBuildRequest(t *testing.T) { + tests := []struct { + description string + model *inputModel + expectedRequest postgresflex.ApiListBackupsRequest + }{ + { + description: "base", + model: fixtureInputModel(), + expectedRequest: fixtureRequest(), + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + request := buildRequest(testCtx, tt.model, testClient) + + diff := cmp.Diff(request, tt.expectedRequest, + cmp.AllowUnexported(tt.expectedRequest), + cmpopts.EquateComparable(testCtx), + ) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} diff --git a/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule.go b/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule.go new file mode 100644 index 000000000..aa7ee4559 --- /dev/null +++ b/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule.go @@ -0,0 +1,112 @@ +package updateschedule + +import ( + "context" + "fmt" + + "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" + cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/examples" + "github.com/stackitcloud/stackit-cli/internal/pkg/flags" + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" + postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" +) + +const ( + instanceIdFlag = "instance-id" + backupScheduleFlag = "backup-schedule" +) + +type inputModel struct { + *globalflags.GlobalFlagModel + + InstanceId *string + BackupSchedule *string +} + +func NewCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: "update-schedule", + Short: "Updates backup schedule for a specific PostgreSQL Flex instance", + Long: "Updates backup schedule for a specific PostgreSQL Flex instance.", + Args: args.NoArgs, + Example: examples.Build( + examples.NewExample( + `Update the backup schedule of a PostgreSQL Flex instance with ID "xxx"`, + "$ stackit postgresflex instance backups update-schedule --instance-id xxx --backup-schedule '6 6 * * *'"), + ), + + RunE: func(cmd *cobra.Command, args []string) error { + ctx := context.Background() + + model, err := parseInput(cmd) + if err != nil { + return err + } + + // Configure API client + apiClient, err := client.ConfigureClient(cmd) + if err != nil { + return err + } + + instanceLabel, err := postgresflexUtils.GetInstanceName(ctx, apiClient, model.ProjectId, *model.InstanceId) + if err != nil { + instanceLabel = *model.InstanceId + } + + if !model.AssumeYes { + prompt := fmt.Sprintf("Are you sure you want to update backup schedule of instance %q?", instanceLabel) + err = confirm.PromptForConfirmation(cmd, prompt) + if err != nil { + return err + } + } + + // Call API + req := buildRequest(ctx, model, apiClient) + err = req.Execute() + if err != nil { + return fmt.Errorf("update backup schedule of PostgreSQL Flex instance: %w", err) + } + + cmd.Printf("Updated backup schedule of instance %q\n", instanceLabel) + return nil + }, + } + configureFlags(cmd) + return cmd +} + +func configureFlags(cmd *cobra.Command) { + cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") + cmd.Flags().String(backupScheduleFlag, "", "Backup schedule, in the cron scheduling system format e.g. '0 0 * * *'") + + err := flags.MarkFlagsRequired(cmd, instanceIdFlag, backupScheduleFlag) + cobra.CheckErr(err) +} + +func parseInput(cmd *cobra.Command) (*inputModel, error) { + globalFlags := globalflags.Parse(cmd) + if globalFlags.ProjectId == "" { + return nil, &cliErr.ProjectIdError{} + } + + return &inputModel{ + GlobalFlagModel: globalFlags, + InstanceId: flags.FlagToStringPointer(cmd, instanceIdFlag), + BackupSchedule: flags.FlagToStringPointer(cmd, backupScheduleFlag), + }, nil +} + +func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresflex.APIClient) postgresflex.ApiUpdateBackupScheduleRequest { + req := apiClient.UpdateBackupSchedule(ctx, model.ProjectId, *model.InstanceId) + req = req.UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{ + BackupSchedule: model.BackupSchedule, + }) + return req +} diff --git a/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule_test.go b/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule_test.go new file mode 100644 index 000000000..299ec11aa --- /dev/null +++ b/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule_test.go @@ -0,0 +1,216 @@ +package updateschedule + +import ( + "context" + "testing" + + "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/utils" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/google/uuid" + "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" +) + +var projectIdFlag = globalflags.ProjectIdFlag + +type testCtxKey struct{} + +var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") +var testClient = &postgresflex.APIClient{} +var testProjectId = uuid.NewString() +var testInstanceId = uuid.NewString() +var testBackupSchedule = "0 0 * * *" + +func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { + flagValues := map[string]string{ + projectIdFlag: testProjectId, + backupScheduleFlag: testBackupSchedule, + instanceIdFlag: testInstanceId, + } + for _, mod := range mods { + mod(flagValues) + } + return flagValues +} + +func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { + model := &inputModel{ + GlobalFlagModel: &globalflags.GlobalFlagModel{ + ProjectId: testProjectId, + }, + InstanceId: utils.Ptr(testInstanceId), + BackupSchedule: &testBackupSchedule, + } + for _, mod := range mods { + mod(model) + } + return model +} + +func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePayload)) postgresflex.UpdateBackupSchedulePayload { + payload := postgresflex.UpdateBackupSchedulePayload{ + BackupSchedule: utils.Ptr(testBackupSchedule), + } + for _, mod := range mods { + mod(&payload) + } + return payload +} + +func fixtureRequest(mods ...func(request *postgresflex.ApiUpdateBackupScheduleRequest)) postgresflex.ApiUpdateBackupScheduleRequest { + request := testClient.UpdateBackupSchedule(testCtx, testProjectId, testInstanceId) + request = request.UpdateBackupSchedulePayload(fixturePayload()) + for _, mod := range mods { + mod(&request) + } + return request +} + +func TestParseInput(t *testing.T) { + tests := []struct { + description string + flagValues map[string]string + aclValues []string + isValid bool + expectedModel *inputModel + }{ + { + description: "base", + flagValues: fixtureFlagValues(), + isValid: true, + expectedModel: fixtureInputModel(), + }, + { + description: "no values", + flagValues: map[string]string{}, + isValid: false, + }, + { + description: "project id missing", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, projectIdFlag) + }), + isValid: false, + }, + { + description: "project id invalid 1", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "" + }), + isValid: false, + }, + { + description: "project id invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[projectIdFlag] = "invalid-uuid" + }), + isValid: false, + }, + { + description: "instance id missing", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, instanceIdFlag) + }), + isValid: false, + }, + { + description: "instance id invalid 1", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "" + }), + isValid: false, + }, + { + description: "backup schedule missing", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + delete(flagValues, backupScheduleFlag) + }), + isValid: false, + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + cmd := NewCmd() + err := globalflags.Configure(cmd.Flags()) + if err != nil { + t.Fatalf("configure global flags: %v", err) + } + + for flag, value := range tt.flagValues { + err := cmd.Flags().Set(flag, value) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("setting flag --%s=%s: %v", flag, value, err) + } + } + + err = cmd.ValidateRequiredFlags() + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error validating flags: %v", err) + } + + model, err := parseInput(cmd) + if err != nil { + if !tt.isValid { + return + } + t.Fatalf("error parsing flags: %v", err) + } + + if !tt.isValid { + t.Fatalf("did not fail on invalid input") + } + diff := cmp.Diff(model, tt.expectedModel) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} + +func TestBuildRequest(t *testing.T) { + tests := []struct { + description string + model *inputModel + expectedRequest postgresflex.ApiUpdateBackupScheduleRequest + }{ + { + description: "base", + model: fixtureInputModel(), + expectedRequest: fixtureRequest(), + }, + { + description: "required fields only", + model: &inputModel{ + GlobalFlagModel: &globalflags.GlobalFlagModel{ + ProjectId: testProjectId, + }, + InstanceId: utils.Ptr(testInstanceId), + }, + expectedRequest: testClient.UpdateBackupSchedule(testCtx, testProjectId, testInstanceId). + UpdateBackupSchedulePayload(postgresflex.UpdateBackupSchedulePayload{}), + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + request := buildRequest(testCtx, tt.model, testClient) + + diff := cmp.Diff(request, tt.expectedRequest, + cmp.AllowUnexported(tt.expectedRequest), + cmpopts.EquateComparable(testCtx), + ) + if diff != "" { + t.Fatalf("Data does not match: %s", diff) + } + }) + } +} diff --git a/internal/cmd/postgresflex/instance/instance.go b/internal/cmd/postgresflex/instance/instance.go index 0d16db1f8..3c7f0850c 100644 --- a/internal/cmd/postgresflex/instance/instance.go +++ b/internal/cmd/postgresflex/instance/instance.go @@ -1,6 +1,7 @@ package instance import ( + "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/clone" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/create" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/delete" @@ -32,4 +33,5 @@ func addSubcommands(cmd *cobra.Command) { cmd.AddCommand(update.NewCmd()) cmd.AddCommand(delete.NewCmd()) cmd.AddCommand(clone.NewCmd()) + cmd.AddCommand(backups.NewCmd()) } From a65ea70a031c360a51befd348693b8c4466aebe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Wed, 20 Mar 2024 09:34:45 +0100 Subject: [PATCH 02/17] add docs --- docs/stackit_postgresflex_instance.md | 1 + docs/stackit_postgresflex_instance_backups.md | 34 ++++++++++++++ ..._postgresflex_instance_backups_describe.md | 42 +++++++++++++++++ ...ckit_postgresflex_instance_backups_list.md | 46 +++++++++++++++++++ ...esflex_instance_backups_update-schedule.md | 40 ++++++++++++++++ docs/stackit_postgresflex_instance_clone.md | 2 +- 6 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 docs/stackit_postgresflex_instance_backups.md create mode 100644 docs/stackit_postgresflex_instance_backups_describe.md create mode 100644 docs/stackit_postgresflex_instance_backups_list.md create mode 100644 docs/stackit_postgresflex_instance_backups_update-schedule.md diff --git a/docs/stackit_postgresflex_instance.md b/docs/stackit_postgresflex_instance.md index 0d6fa26ea..950b78f7b 100644 --- a/docs/stackit_postgresflex_instance.md +++ b/docs/stackit_postgresflex_instance.md @@ -28,6 +28,7 @@ stackit postgresflex instance [flags] ### SEE ALSO * [stackit postgresflex](./stackit_postgresflex.md) - Provides functionality for PostgreSQL Flex +* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups * [stackit postgresflex instance clone](./stackit_postgresflex_instance_clone.md) - Clones a PostgreSQL Flex instance * [stackit postgresflex instance create](./stackit_postgresflex_instance_create.md) - Creates a PostgreSQL Flex instance * [stackit postgresflex instance delete](./stackit_postgresflex_instance_delete.md) - Deletes a PostgreSQL Flex instance diff --git a/docs/stackit_postgresflex_instance_backups.md b/docs/stackit_postgresflex_instance_backups.md new file mode 100644 index 000000000..b93d56c54 --- /dev/null +++ b/docs/stackit_postgresflex_instance_backups.md @@ -0,0 +1,34 @@ +## stackit postgresflex instance backups + +Provides functionality for PostgreSQL Flex instance backups + +### Synopsis + +Provides functionality for PostgreSQL Flex instance backups. + +``` +stackit postgresflex instance backups [flags] +``` + +### Options + +``` + -h, --help Help for "stackit postgresflex instance backups" +``` + +### Options inherited from parent commands + +``` + -y, --assume-yes If set, skips all confirmation prompts + --async If set, runs the command asynchronously + -o, --output-format string Output format, one of ["json" "pretty"] + -p, --project-id string Project ID +``` + +### SEE ALSO + +* [stackit postgresflex instance](./stackit_postgresflex_instance.md) - Provides functionality for PostgreSQL Flex instances +* [stackit postgresflex instance backups describe](./stackit_postgresflex_instance_backups_describe.md) - Shows details of a backup for a specific PostgreSQL Flex instance +* [stackit postgresflex instance backups list](./stackit_postgresflex_instance_backups_list.md) - Lists all backups which are available for a specific PostgreSQL Flex instance +* [stackit postgresflex instance backups update-schedule](./stackit_postgresflex_instance_backups_update-schedule.md) - Updates backup schedule for a specific PostgreSQL Flex instance + diff --git a/docs/stackit_postgresflex_instance_backups_describe.md b/docs/stackit_postgresflex_instance_backups_describe.md new file mode 100644 index 000000000..3cccf6d6f --- /dev/null +++ b/docs/stackit_postgresflex_instance_backups_describe.md @@ -0,0 +1,42 @@ +## stackit postgresflex instance backups describe + +Shows details of a backup for a specific PostgreSQL Flex instance + +### Synopsis + +Shows details of a backup for a specific PostgreSQL Flex instance. + +``` +stackit postgresflex instance backups describe BACKUP_ID [flags] +``` + +### Examples + +``` + Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" + $ stackit postgresflex instance backups describe xxx --instance-id yyy + + Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" in a table format + $ stackit postgresflex instance backups describe xxx --instance-id yyy --output-format pretty +``` + +### Options + +``` + -h, --help Help for "stackit postgresflex instance backups describe" + --instance-id string Instance ID +``` + +### Options inherited from parent commands + +``` + -y, --assume-yes If set, skips all confirmation prompts + --async If set, runs the command asynchronously + -o, --output-format string Output format, one of ["json" "pretty"] + -p, --project-id string Project ID +``` + +### SEE ALSO + +* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups + diff --git a/docs/stackit_postgresflex_instance_backups_list.md b/docs/stackit_postgresflex_instance_backups_list.md new file mode 100644 index 000000000..6a47cac12 --- /dev/null +++ b/docs/stackit_postgresflex_instance_backups_list.md @@ -0,0 +1,46 @@ +## stackit postgresflex instance backups list + +Lists all backups which are available for a specific PostgreSQL Flex instance + +### Synopsis + +Lists all backups which are available for a specific PostgreSQL Flex instance. + +``` +stackit postgresflex instance backups list [flags] +``` + +### Examples + +``` + List all backups of instance with ID "xxx" + $ stackit postgresflex instance backups list --instance-id xxx + + List all backups of instance with ID "xxx" in JSON format + $ stackit postgresflex instance backups list --instance-id xxx --output-format json + + List up to 10 backups of instance with ID "xxx" + $ stackit postgresflex instance backups list --instance-id xxx --limit 10 +``` + +### Options + +``` + -h, --help Help for "stackit postgresflex instance backups list" + --instance-id string Instance ID + --limit int Maximum number of entries to list +``` + +### Options inherited from parent commands + +``` + -y, --assume-yes If set, skips all confirmation prompts + --async If set, runs the command asynchronously + -o, --output-format string Output format, one of ["json" "pretty"] + -p, --project-id string Project ID +``` + +### SEE ALSO + +* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups + diff --git a/docs/stackit_postgresflex_instance_backups_update-schedule.md b/docs/stackit_postgresflex_instance_backups_update-schedule.md new file mode 100644 index 000000000..418acd54c --- /dev/null +++ b/docs/stackit_postgresflex_instance_backups_update-schedule.md @@ -0,0 +1,40 @@ +## stackit postgresflex instance backups update-schedule + +Updates backup schedule for a specific PostgreSQL Flex instance + +### Synopsis + +Updates backup schedule for a specific PostgreSQL Flex instance. + +``` +stackit postgresflex instance backups update-schedule [flags] +``` + +### Examples + +``` + Update the backup schedule of a PostgreSQL Flex instance with ID "xxx" + $ stackit postgresflex instance backups update-schedule --instance-id xxx --backup-schedule '6 6 * * *' +``` + +### Options + +``` + --backup-schedule string Backup schedule, in the cron scheduling system format e.g. '0 0 * * *' + -h, --help Help for "stackit postgresflex instance backups update-schedule" + --instance-id string Instance ID +``` + +### Options inherited from parent commands + +``` + -y, --assume-yes If set, skips all confirmation prompts + --async If set, runs the command asynchronously + -o, --output-format string Output format, one of ["json" "pretty"] + -p, --project-id string Project ID +``` + +### SEE ALSO + +* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups + diff --git a/docs/stackit_postgresflex_instance_clone.md b/docs/stackit_postgresflex_instance_clone.md index 64acbc209..cbc9f1e9b 100644 --- a/docs/stackit_postgresflex_instance_clone.md +++ b/docs/stackit_postgresflex_instance_clone.md @@ -27,7 +27,7 @@ stackit postgresflex instance clone INSTANCE_ID [flags] ``` -h, --help Help for "stackit postgresflex instance clone" - --recovery-timestamp string Recovery timestamp for the instance, specified in UTC time following the format, e.g. 2024-03-12T09:28:00+00:00 + --recovery-timestamp string Recovery timestamp for the instance, in a date-time with the RFC3339 layout format, e.g. 2024-01-01T00:00:00Z --storage-class string Storage class. If not specified, storage class from the existing instance will be used. --storage-size int Storage size (in GB). If not specified, storage size from the existing instance will be used. ``` From 072d191a39a87557f3f76aa3c573da696567250f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 09:11:32 +0100 Subject: [PATCH 03/17] move backups directly under postgresflex --- .../{instance/backups => backup}/backups.go | 10 +++++----- .../{instance/backups => backup}/describe/describe.go | 4 ++-- .../backups => backup}/describe/describe_test.go | 0 .../{instance/backups => backup}/list/list.go | 6 +++--- .../{instance/backups => backup}/list/list_test.go | 0 .../update-schedule/update_schedule.go | 2 +- .../update-schedule/update_schedule_test.go | 0 internal/cmd/postgresflex/instance/instance.go | 2 -- internal/cmd/postgresflex/postgresflex.go | 2 ++ 9 files changed, 13 insertions(+), 13 deletions(-) rename internal/cmd/postgresflex/{instance/backups => backup}/backups.go (85%) rename internal/cmd/postgresflex/{instance/backups => backup}/describe/describe.go (95%) rename internal/cmd/postgresflex/{instance/backups => backup}/describe/describe_test.go (100%) rename internal/cmd/postgresflex/{instance/backups => backup}/list/list.go (94%) rename internal/cmd/postgresflex/{instance/backups => backup}/list/list_test.go (100%) rename internal/cmd/postgresflex/{instance/backups => backup}/update-schedule/update_schedule.go (96%) rename internal/cmd/postgresflex/{instance/backups => backup}/update-schedule/update_schedule_test.go (100%) diff --git a/internal/cmd/postgresflex/instance/backups/backups.go b/internal/cmd/postgresflex/backup/backups.go similarity index 85% rename from internal/cmd/postgresflex/instance/backups/backups.go rename to internal/cmd/postgresflex/backup/backups.go index afa9b3194..4ccab21fe 100644 --- a/internal/cmd/postgresflex/instance/backups/backups.go +++ b/internal/cmd/postgresflex/backup/backups.go @@ -1,9 +1,9 @@ -package backups +package backup import ( - "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups/describe" - "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups/list" - updateschedule "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups/update-schedule" + "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/describe" + "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/list" + updateschedule "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup/update-schedule" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -12,7 +12,7 @@ import ( func NewCmd() *cobra.Command { cmd := &cobra.Command{ - Use: "backups", + Use: "backup", Short: "Provides functionality for PostgreSQL Flex instance backups", Long: "Provides functionality for PostgreSQL Flex instance backups.", Args: args.NoArgs, diff --git a/internal/cmd/postgresflex/instance/backups/describe/describe.go b/internal/cmd/postgresflex/backup/describe/describe.go similarity index 95% rename from internal/cmd/postgresflex/instance/backups/describe/describe.go rename to internal/cmd/postgresflex/backup/describe/describe.go index fc1ed64ee..1cdcac5dc 100644 --- a/internal/cmd/postgresflex/instance/backups/describe/describe.go +++ b/internal/cmd/postgresflex/backup/describe/describe.go @@ -39,10 +39,10 @@ func NewCmd() *cobra.Command { Example: examples.Build( examples.NewExample( `Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy"`, - "$ stackit postgresflex instance backups describe xxx --instance-id yyy"), + "$ stackit postgresflex backup describe xxx --instance-id yyy"), examples.NewExample( `Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" in a table format`, - "$ stackit postgresflex instance backups describe xxx --instance-id yyy --output-format pretty"), + "$ stackit postgresflex backup describe xxx --instance-id yyy --output-format pretty"), ), Args: args.SingleArg(backupIdArg, nil), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/cmd/postgresflex/instance/backups/describe/describe_test.go b/internal/cmd/postgresflex/backup/describe/describe_test.go similarity index 100% rename from internal/cmd/postgresflex/instance/backups/describe/describe_test.go rename to internal/cmd/postgresflex/backup/describe/describe_test.go diff --git a/internal/cmd/postgresflex/instance/backups/list/list.go b/internal/cmd/postgresflex/backup/list/list.go similarity index 94% rename from internal/cmd/postgresflex/instance/backups/list/list.go rename to internal/cmd/postgresflex/backup/list/list.go index b843ee618..40a2a5284 100644 --- a/internal/cmd/postgresflex/instance/backups/list/list.go +++ b/internal/cmd/postgresflex/backup/list/list.go @@ -39,13 +39,13 @@ func NewCmd() *cobra.Command { Example: examples.Build( examples.NewExample( `List all backups of instance with ID "xxx"`, - "$ stackit postgresflex instance backups list --instance-id xxx"), + "$ stackit postgresflex backup list --instance-id xxx"), examples.NewExample( `List all backups of instance with ID "xxx" in JSON format`, - "$ stackit postgresflex instance backups list --instance-id xxx --output-format json"), + "$ stackit postgresflex backup list --instance-id xxx --output-format json"), examples.NewExample( `List up to 10 backups of instance with ID "xxx"`, - "$ stackit postgresflex instance backups list --instance-id xxx --limit 10"), + "$ stackit postgresflex backup list --instance-id xxx --limit 10"), ), Args: args.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/cmd/postgresflex/instance/backups/list/list_test.go b/internal/cmd/postgresflex/backup/list/list_test.go similarity index 100% rename from internal/cmd/postgresflex/instance/backups/list/list_test.go rename to internal/cmd/postgresflex/backup/list/list_test.go diff --git a/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule.go b/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go similarity index 96% rename from internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule.go rename to internal/cmd/postgresflex/backup/update-schedule/update_schedule.go index aa7ee4559..add1af926 100644 --- a/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule.go +++ b/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go @@ -37,7 +37,7 @@ func NewCmd() *cobra.Command { Example: examples.Build( examples.NewExample( `Update the backup schedule of a PostgreSQL Flex instance with ID "xxx"`, - "$ stackit postgresflex instance backups update-schedule --instance-id xxx --backup-schedule '6 6 * * *'"), + "$ stackit postgresflex backup update-schedule --instance-id xxx --backup-schedule '6 6 * * *'"), ), RunE: func(cmd *cobra.Command, args []string) error { diff --git a/internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule_test.go b/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go similarity index 100% rename from internal/cmd/postgresflex/instance/backups/update-schedule/update_schedule_test.go rename to internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go diff --git a/internal/cmd/postgresflex/instance/instance.go b/internal/cmd/postgresflex/instance/instance.go index 3c7f0850c..0d16db1f8 100644 --- a/internal/cmd/postgresflex/instance/instance.go +++ b/internal/cmd/postgresflex/instance/instance.go @@ -1,7 +1,6 @@ package instance import ( - "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/backups" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/clone" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/create" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/delete" @@ -33,5 +32,4 @@ func addSubcommands(cmd *cobra.Command) { cmd.AddCommand(update.NewCmd()) cmd.AddCommand(delete.NewCmd()) cmd.AddCommand(clone.NewCmd()) - cmd.AddCommand(backups.NewCmd()) } diff --git a/internal/cmd/postgresflex/postgresflex.go b/internal/cmd/postgresflex/postgresflex.go index 3f74e35c8..a69149cad 100644 --- a/internal/cmd/postgresflex/postgresflex.go +++ b/internal/cmd/postgresflex/postgresflex.go @@ -1,6 +1,7 @@ package postgresflex import ( + "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/backup" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/options" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user" @@ -27,4 +28,5 @@ func addSubcommands(cmd *cobra.Command) { cmd.AddCommand(instance.NewCmd()) cmd.AddCommand(user.NewCmd()) cmd.AddCommand(options.NewCmd()) + cmd.AddCommand(backup.NewCmd()) } From 10963e281015325f5893b03206f8261b5b8da468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 09:39:17 +0100 Subject: [PATCH 04/17] change used bytesize library --- go.mod | 2 +- go.sum | 4 ++-- internal/cmd/postgresflex/backup/describe/describe.go | 4 ++-- internal/cmd/postgresflex/backup/list/list.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 68732acdf..2f64d4015 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,10 @@ module github.com/stackitcloud/stackit-cli go 1.21 require ( - github.com/depp/bytesize v1.1.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/go-cmp v0.6.0 github.com/google/uuid v1.6.0 + github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf github.com/jedib0t/go-pretty/v6 v6.5.5 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 diff --git a/go.sum b/go.sum index d4e1ad9ea..f05bb2efa 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/depp/bytesize v1.1.0 h1:HUJEFG8nW/vrfflMw0TB/5ZrwSuGAw3xrgyzKqzVLf4= -github.com/depp/bytesize v1.1.0/go.mod h1:W5nYZIYKjq8tqfzkVVwMblQwIRI4KcZGJz4DbNT9wwY= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= @@ -31,6 +29,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf h1:FtEj8sfIcaaBfAKrE1Cwb61YDtYq9JxChK1c7AKce7s= +github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf/go.mod h1:yrqSXGoD/4EKfF26AOGzscPOgTTJcyAwM2rpixWT+t4= github.com/jedib0t/go-pretty/v6 v6.5.5 h1:PpIU8lOjxvVYGGKule0QxxJfNysUSbC9lggQU2cpZJc= github.com/jedib0t/go-pretty/v6 v6.5.5/go.mod h1:5LQIxa52oJ/DlDSLv0HEkWOFMDGoWkJb9ss5KqPpJBg= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= diff --git a/internal/cmd/postgresflex/backup/describe/describe.go b/internal/cmd/postgresflex/backup/describe/describe.go index 1cdcac5dc..4d2b85566 100644 --- a/internal/cmd/postgresflex/backup/describe/describe.go +++ b/internal/cmd/postgresflex/backup/describe/describe.go @@ -6,7 +6,7 @@ import ( "fmt" "time" - "github.com/depp/bytesize" + "github.com/inhies/go-bytesize" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" @@ -120,7 +120,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, backup postgresflex.B table.AddSeparator() table.AddRow("EXPIRES AT", backupExpireDate) table.AddSeparator() - table.AddRow("BACKUP SIZE", bytesize.Format(uint64(*backup.Size))) + table.AddRow("BACKUP SIZE", bytesize.New(float64(*backup.Size))) err := table.Display(cmd) if err != nil { diff --git a/internal/cmd/postgresflex/backup/list/list.go b/internal/cmd/postgresflex/backup/list/list.go index 40a2a5284..64d13ee29 100644 --- a/internal/cmd/postgresflex/backup/list/list.go +++ b/internal/cmd/postgresflex/backup/list/list.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/depp/bytesize" + "github.com/inhies/go-bytesize" "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" @@ -140,7 +140,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, backups []postgresfle table.SetHeader("ID", "NAME", "START TIME", "END TIME", "BACKUP SIZE") for i := range backups { backup := backups[i] - table.AddRow(*backup.Id, *backup.Name, *backup.StartTime, *backup.EndTime, bytesize.Format(uint64(*backup.Size))) + table.AddRow(*backup.Id, *backup.Name, *backup.StartTime, *backup.EndTime, bytesize.New(float64(*backup.Size))) } err := table.Display(cmd) if err != nil { From 13206dc824f02ebc386311d268818d7a3c02c491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 09:41:01 +0100 Subject: [PATCH 05/17] remove empty spaces --- internal/cmd/postgresflex/backup/describe/describe.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/cmd/postgresflex/backup/describe/describe.go b/internal/cmd/postgresflex/backup/describe/describe.go index 4d2b85566..76f55c290 100644 --- a/internal/cmd/postgresflex/backup/describe/describe.go +++ b/internal/cmd/postgresflex/backup/describe/describe.go @@ -63,7 +63,7 @@ func NewCmd() *cobra.Command { resp, err := req.Execute() if err != nil { - return fmt.Errorf("describe backup for PostgreSQL Flex instance : %w", err) + return fmt.Errorf("describe backup for PostgreSQL Flex instance: %w", err) } return outputResult(cmd, model.OutputFormat, *resp.Item) @@ -103,7 +103,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresfle func outputResult(cmd *cobra.Command, outputFormat string, backup postgresflex.Backup) error { backupStartTime, err := time.Parse(time.RFC3339, *backup.StartTime) if err != nil { - return fmt.Errorf("parse backup start time : %w", err) + return fmt.Errorf("parse backup start time: %w", err) } backupExpireDate := backupStartTime.AddDate(0, 0, 30).Format(time.DateOnly) @@ -131,7 +131,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, backup postgresflex.B default: details, err := json.MarshalIndent(backup, "", " ") if err != nil { - return fmt.Errorf("marshal backup for PostgreSQL Flex instance : %w", err) + return fmt.Errorf("marshal backup for PostgreSQL Flex instance: %w", err) } cmd.Println(string(details)) From a7f30c80769341fd396761fcb27edfb299e7ae53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 09:58:14 +0100 Subject: [PATCH 06/17] use constants for backup expiration offset --- internal/cmd/postgresflex/backup/describe/describe.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/cmd/postgresflex/backup/describe/describe.go b/internal/cmd/postgresflex/backup/describe/describe.go index 76f55c290..7d858aaec 100644 --- a/internal/cmd/postgresflex/backup/describe/describe.go +++ b/internal/cmd/postgresflex/backup/describe/describe.go @@ -22,6 +22,10 @@ const ( backupIdArg = "BACKUP_ID" instanceIdFlag = "instance-id" + + backupExpireYearOffset = 0 + backupExpireMonthOffset = 0 + backupExpireDayOffset = 30 ) type inputModel struct { @@ -105,7 +109,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, backup postgresflex.B if err != nil { return fmt.Errorf("parse backup start time: %w", err) } - backupExpireDate := backupStartTime.AddDate(0, 0, 30).Format(time.DateOnly) + backupExpireDate := backupStartTime.AddDate(backupExpireYearOffset, backupExpireMonthOffset, backupExpireDayOffset).Format(time.DateOnly) switch outputFormat { case globalflags.PrettyOutputFormat: From ca538a0f625cc05173b0fbe871ca0b37ffa50796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 09:58:46 +0100 Subject: [PATCH 07/17] add expire date in list output --- internal/cmd/postgresflex/backup/list/list.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/internal/cmd/postgresflex/backup/list/list.go b/internal/cmd/postgresflex/backup/list/list.go index 64d13ee29..72e058494 100644 --- a/internal/cmd/postgresflex/backup/list/list.go +++ b/internal/cmd/postgresflex/backup/list/list.go @@ -14,14 +14,18 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "time" "github.com/spf13/cobra" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) const ( - instanceIdFlag = "instance-id" - limitFlag = "limit" + instanceIdFlag = "instance-id" + limitFlag = "limit" + backupExpireYearOffset = 0 + backupExpireMonthOffset = 0 + backupExpireDayOffset = 30 ) type inputModel struct { @@ -137,10 +141,17 @@ func outputResult(cmd *cobra.Command, outputFormat string, backups []postgresfle return nil default: table := tables.NewTable() - table.SetHeader("ID", "NAME", "START TIME", "END TIME", "BACKUP SIZE") + table.SetHeader("ID", "NAME", "START TIME", "END TIME", "EXPIRES AT", "BACKUP SIZE") for i := range backups { backup := backups[i] - table.AddRow(*backup.Id, *backup.Name, *backup.StartTime, *backup.EndTime, bytesize.New(float64(*backup.Size))) + + backupStartTime, err := time.Parse(time.RFC3339, *backup.StartTime) + if err != nil { + return fmt.Errorf("parse backup start time: %w", err) + } + backupExpireDate := backupStartTime.AddDate(backupExpireYearOffset, backupExpireMonthOffset, backupExpireDayOffset).Format(time.DateOnly) + + table.AddRow(*backup.Id, *backup.Name, *backup.StartTime, *backup.EndTime, backupExpireDate, bytesize.New(float64(*backup.Size))) } err := table.Display(cmd) if err != nil { From 899ca0ccea0a1b80876b4fb83e5d0fb0638b7fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 10:12:59 +0100 Subject: [PATCH 08/17] remove redundant backup --- .../backup/update-schedule/update_schedule.go | 12 ++++++------ .../backup/update-schedule/update_schedule_test.go | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go b/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go index add1af926..f3a7c16f2 100644 --- a/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go +++ b/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go @@ -17,8 +17,8 @@ import ( ) const ( - instanceIdFlag = "instance-id" - backupScheduleFlag = "backup-schedule" + instanceIdFlag = "instance-id" + scheduleFlag = "schedule" ) type inputModel struct { @@ -37,7 +37,7 @@ func NewCmd() *cobra.Command { Example: examples.Build( examples.NewExample( `Update the backup schedule of a PostgreSQL Flex instance with ID "xxx"`, - "$ stackit postgresflex backup update-schedule --instance-id xxx --backup-schedule '6 6 * * *'"), + "$ stackit postgresflex backup update-schedule --instance-id xxx --schedule '6 6 * * *'"), ), RunE: func(cmd *cobra.Command, args []string) error { @@ -84,9 +84,9 @@ func NewCmd() *cobra.Command { func configureFlags(cmd *cobra.Command) { cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID") - cmd.Flags().String(backupScheduleFlag, "", "Backup schedule, in the cron scheduling system format e.g. '0 0 * * *'") + cmd.Flags().String(scheduleFlag, "", "Backup schedule, in the cron scheduling system format e.g. '0 0 * * *'") - err := flags.MarkFlagsRequired(cmd, instanceIdFlag, backupScheduleFlag) + err := flags.MarkFlagsRequired(cmd, instanceIdFlag, scheduleFlag) cobra.CheckErr(err) } @@ -99,7 +99,7 @@ func parseInput(cmd *cobra.Command) (*inputModel, error) { return &inputModel{ GlobalFlagModel: globalFlags, InstanceId: flags.FlagToStringPointer(cmd, instanceIdFlag), - BackupSchedule: flags.FlagToStringPointer(cmd, backupScheduleFlag), + BackupSchedule: flags.FlagToStringPointer(cmd, scheduleFlag), }, nil } diff --git a/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go b/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go index 299ec11aa..2390bf444 100644 --- a/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go +++ b/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go @@ -21,13 +21,13 @@ var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo") var testClient = &postgresflex.APIClient{} var testProjectId = uuid.NewString() var testInstanceId = uuid.NewString() -var testBackupSchedule = "0 0 * * *" +var testSchedule = "0 0 * * *" func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string { flagValues := map[string]string{ - projectIdFlag: testProjectId, - backupScheduleFlag: testBackupSchedule, - instanceIdFlag: testInstanceId, + projectIdFlag: testProjectId, + scheduleFlag: testSchedule, + instanceIdFlag: testInstanceId, } for _, mod := range mods { mod(flagValues) @@ -41,7 +41,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { ProjectId: testProjectId, }, InstanceId: utils.Ptr(testInstanceId), - BackupSchedule: &testBackupSchedule, + BackupSchedule: &testSchedule, } for _, mod := range mods { mod(model) @@ -51,7 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { func fixturePayload(mods ...func(payload *postgresflex.UpdateBackupSchedulePayload)) postgresflex.UpdateBackupSchedulePayload { payload := postgresflex.UpdateBackupSchedulePayload{ - BackupSchedule: utils.Ptr(testBackupSchedule), + BackupSchedule: utils.Ptr(testSchedule), } for _, mod := range mods { mod(&payload) @@ -125,7 +125,7 @@ func TestParseInput(t *testing.T) { { description: "backup schedule missing", flagValues: fixtureFlagValues(func(flagValues map[string]string) { - delete(flagValues, backupScheduleFlag) + delete(flagValues, scheduleFlag) }), isValid: false, }, From fa190ae3cba71d9513a0daebd93957b837f390c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 11:15:45 +0100 Subject: [PATCH 09/17] adapt table columns for list and describe output --- internal/cmd/postgresflex/backup/describe/describe.go | 5 +---- internal/cmd/postgresflex/backup/list/list.go | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/internal/cmd/postgresflex/backup/describe/describe.go b/internal/cmd/postgresflex/backup/describe/describe.go index 7d858aaec..00f84db15 100644 --- a/internal/cmd/postgresflex/backup/describe/describe.go +++ b/internal/cmd/postgresflex/backup/describe/describe.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "time" "github.com/inhies/go-bytesize" @@ -116,12 +117,8 @@ func outputResult(cmd *cobra.Command, outputFormat string, backup postgresflex.B table := tables.NewTable() table.AddRow("ID", *backup.Id) table.AddSeparator() - table.AddRow("NAME", *backup.Name) - table.AddSeparator() table.AddRow("START TIME", *backup.StartTime) table.AddSeparator() - table.AddRow("END TIME", *backup.EndTime) - table.AddSeparator() table.AddRow("EXPIRES AT", backupExpireDate) table.AddSeparator() table.AddRow("BACKUP SIZE", bytesize.New(float64(*backup.Size))) diff --git a/internal/cmd/postgresflex/backup/list/list.go b/internal/cmd/postgresflex/backup/list/list.go index 72e058494..2eeeb9756 100644 --- a/internal/cmd/postgresflex/backup/list/list.go +++ b/internal/cmd/postgresflex/backup/list/list.go @@ -14,6 +14,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" + "time" "github.com/spf13/cobra" @@ -141,7 +142,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, backups []postgresfle return nil default: table := tables.NewTable() - table.SetHeader("ID", "NAME", "START TIME", "END TIME", "EXPIRES AT", "BACKUP SIZE") + table.SetHeader("ID", "CREATED AT", "EXPIRES AT", "BACKUP SIZE") for i := range backups { backup := backups[i] @@ -151,7 +152,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, backups []postgresfle } backupExpireDate := backupStartTime.AddDate(backupExpireYearOffset, backupExpireMonthOffset, backupExpireDayOffset).Format(time.DateOnly) - table.AddRow(*backup.Id, *backup.Name, *backup.StartTime, *backup.EndTime, backupExpireDate, bytesize.New(float64(*backup.Size))) + table.AddRow(*backup.Id, *backup.StartTime, backupExpireDate, bytesize.New(float64(*backup.Size))) } err := table.Display(cmd) if err != nil { From 104febd9706a10e2254b77324cb5c00afe6b0146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Mon, 25 Mar 2024 11:19:01 +0100 Subject: [PATCH 10/17] generate docs --- docs/stackit_postgresflex.md | 1 + docs/stackit_postgresflex_backup.md | 34 ++++++++++++++++ ...> stackit_postgresflex_backup_describe.md} | 12 +++--- ...md => stackit_postgresflex_backup_list.md} | 14 +++---- ...kit_postgresflex_backup_update-schedule.md | 40 +++++++++++++++++++ docs/stackit_postgresflex_instance.md | 1 - docs/stackit_postgresflex_instance_backups.md | 34 ---------------- ...esflex_instance_backups_update-schedule.md | 40 ------------------- 8 files changed, 88 insertions(+), 88 deletions(-) create mode 100644 docs/stackit_postgresflex_backup.md rename docs/{stackit_postgresflex_instance_backups_describe.md => stackit_postgresflex_backup_describe.md} (59%) rename docs/{stackit_postgresflex_instance_backups_list.md => stackit_postgresflex_backup_list.md} (59%) create mode 100644 docs/stackit_postgresflex_backup_update-schedule.md delete mode 100644 docs/stackit_postgresflex_instance_backups.md delete mode 100644 docs/stackit_postgresflex_instance_backups_update-schedule.md diff --git a/docs/stackit_postgresflex.md b/docs/stackit_postgresflex.md index f97789144..592dc051d 100644 --- a/docs/stackit_postgresflex.md +++ b/docs/stackit_postgresflex.md @@ -28,6 +28,7 @@ stackit postgresflex [flags] ### SEE ALSO * [stackit](./stackit.md) - Manage STACKIT resources using the command line +* [stackit postgresflex backup](./stackit_postgresflex_backup.md) - Provides functionality for PostgreSQL Flex instance backups * [stackit postgresflex instance](./stackit_postgresflex_instance.md) - Provides functionality for PostgreSQL Flex instances * [stackit postgresflex options](./stackit_postgresflex_options.md) - Lists PostgreSQL Flex options * [stackit postgresflex user](./stackit_postgresflex_user.md) - Provides functionality for PostgreSQL Flex users diff --git a/docs/stackit_postgresflex_backup.md b/docs/stackit_postgresflex_backup.md new file mode 100644 index 000000000..34147faed --- /dev/null +++ b/docs/stackit_postgresflex_backup.md @@ -0,0 +1,34 @@ +## stackit postgresflex backup + +Provides functionality for PostgreSQL Flex instance backups + +### Synopsis + +Provides functionality for PostgreSQL Flex instance backups. + +``` +stackit postgresflex backup [flags] +``` + +### Options + +``` + -h, --help Help for "stackit postgresflex backup" +``` + +### Options inherited from parent commands + +``` + -y, --assume-yes If set, skips all confirmation prompts + --async If set, runs the command asynchronously + -o, --output-format string Output format, one of ["json" "pretty"] + -p, --project-id string Project ID +``` + +### SEE ALSO + +* [stackit postgresflex](./stackit_postgresflex.md) - Provides functionality for PostgreSQL Flex +* [stackit postgresflex backup describe](./stackit_postgresflex_backup_describe.md) - Shows details of a backup for a specific PostgreSQL Flex instance +* [stackit postgresflex backup list](./stackit_postgresflex_backup_list.md) - Lists all backups which are available for a specific PostgreSQL Flex instance +* [stackit postgresflex backup update-schedule](./stackit_postgresflex_backup_update-schedule.md) - Updates backup schedule for a specific PostgreSQL Flex instance + diff --git a/docs/stackit_postgresflex_instance_backups_describe.md b/docs/stackit_postgresflex_backup_describe.md similarity index 59% rename from docs/stackit_postgresflex_instance_backups_describe.md rename to docs/stackit_postgresflex_backup_describe.md index 3cccf6d6f..c9f827f75 100644 --- a/docs/stackit_postgresflex_instance_backups_describe.md +++ b/docs/stackit_postgresflex_backup_describe.md @@ -1,4 +1,4 @@ -## stackit postgresflex instance backups describe +## stackit postgresflex backup describe Shows details of a backup for a specific PostgreSQL Flex instance @@ -7,23 +7,23 @@ Shows details of a backup for a specific PostgreSQL Flex instance Shows details of a backup for a specific PostgreSQL Flex instance. ``` -stackit postgresflex instance backups describe BACKUP_ID [flags] +stackit postgresflex backup describe BACKUP_ID [flags] ``` ### Examples ``` Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" - $ stackit postgresflex instance backups describe xxx --instance-id yyy + $ stackit postgresflex backup describe xxx --instance-id yyy Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" in a table format - $ stackit postgresflex instance backups describe xxx --instance-id yyy --output-format pretty + $ stackit postgresflex backup describe xxx --instance-id yyy --output-format pretty ``` ### Options ``` - -h, --help Help for "stackit postgresflex instance backups describe" + -h, --help Help for "stackit postgresflex backup describe" --instance-id string Instance ID ``` @@ -38,5 +38,5 @@ stackit postgresflex instance backups describe BACKUP_ID [flags] ### SEE ALSO -* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups +* [stackit postgresflex backup](./stackit_postgresflex_backup.md) - Provides functionality for PostgreSQL Flex instance backups diff --git a/docs/stackit_postgresflex_instance_backups_list.md b/docs/stackit_postgresflex_backup_list.md similarity index 59% rename from docs/stackit_postgresflex_instance_backups_list.md rename to docs/stackit_postgresflex_backup_list.md index 6a47cac12..6a3094dd0 100644 --- a/docs/stackit_postgresflex_instance_backups_list.md +++ b/docs/stackit_postgresflex_backup_list.md @@ -1,4 +1,4 @@ -## stackit postgresflex instance backups list +## stackit postgresflex backup list Lists all backups which are available for a specific PostgreSQL Flex instance @@ -7,26 +7,26 @@ Lists all backups which are available for a specific PostgreSQL Flex instance Lists all backups which are available for a specific PostgreSQL Flex instance. ``` -stackit postgresflex instance backups list [flags] +stackit postgresflex backup list [flags] ``` ### Examples ``` List all backups of instance with ID "xxx" - $ stackit postgresflex instance backups list --instance-id xxx + $ stackit postgresflex backup list --instance-id xxx List all backups of instance with ID "xxx" in JSON format - $ stackit postgresflex instance backups list --instance-id xxx --output-format json + $ stackit postgresflex backup list --instance-id xxx --output-format json List up to 10 backups of instance with ID "xxx" - $ stackit postgresflex instance backups list --instance-id xxx --limit 10 + $ stackit postgresflex backup list --instance-id xxx --limit 10 ``` ### Options ``` - -h, --help Help for "stackit postgresflex instance backups list" + -h, --help Help for "stackit postgresflex backup list" --instance-id string Instance ID --limit int Maximum number of entries to list ``` @@ -42,5 +42,5 @@ stackit postgresflex instance backups list [flags] ### SEE ALSO -* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups +* [stackit postgresflex backup](./stackit_postgresflex_backup.md) - Provides functionality for PostgreSQL Flex instance backups diff --git a/docs/stackit_postgresflex_backup_update-schedule.md b/docs/stackit_postgresflex_backup_update-schedule.md new file mode 100644 index 000000000..5658469a3 --- /dev/null +++ b/docs/stackit_postgresflex_backup_update-schedule.md @@ -0,0 +1,40 @@ +## stackit postgresflex backup update-schedule + +Updates backup schedule for a specific PostgreSQL Flex instance + +### Synopsis + +Updates backup schedule for a specific PostgreSQL Flex instance. + +``` +stackit postgresflex backup update-schedule [flags] +``` + +### Examples + +``` + Update the backup schedule of a PostgreSQL Flex instance with ID "xxx" + $ stackit postgresflex backup update-schedule --instance-id xxx --schedule '6 6 * * *' +``` + +### Options + +``` + -h, --help Help for "stackit postgresflex backup update-schedule" + --instance-id string Instance ID + --schedule string Backup schedule, in the cron scheduling system format e.g. '0 0 * * *' +``` + +### Options inherited from parent commands + +``` + -y, --assume-yes If set, skips all confirmation prompts + --async If set, runs the command asynchronously + -o, --output-format string Output format, one of ["json" "pretty"] + -p, --project-id string Project ID +``` + +### SEE ALSO + +* [stackit postgresflex backup](./stackit_postgresflex_backup.md) - Provides functionality for PostgreSQL Flex instance backups + diff --git a/docs/stackit_postgresflex_instance.md b/docs/stackit_postgresflex_instance.md index 950b78f7b..0d6fa26ea 100644 --- a/docs/stackit_postgresflex_instance.md +++ b/docs/stackit_postgresflex_instance.md @@ -28,7 +28,6 @@ stackit postgresflex instance [flags] ### SEE ALSO * [stackit postgresflex](./stackit_postgresflex.md) - Provides functionality for PostgreSQL Flex -* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups * [stackit postgresflex instance clone](./stackit_postgresflex_instance_clone.md) - Clones a PostgreSQL Flex instance * [stackit postgresflex instance create](./stackit_postgresflex_instance_create.md) - Creates a PostgreSQL Flex instance * [stackit postgresflex instance delete](./stackit_postgresflex_instance_delete.md) - Deletes a PostgreSQL Flex instance diff --git a/docs/stackit_postgresflex_instance_backups.md b/docs/stackit_postgresflex_instance_backups.md deleted file mode 100644 index b93d56c54..000000000 --- a/docs/stackit_postgresflex_instance_backups.md +++ /dev/null @@ -1,34 +0,0 @@ -## stackit postgresflex instance backups - -Provides functionality for PostgreSQL Flex instance backups - -### Synopsis - -Provides functionality for PostgreSQL Flex instance backups. - -``` -stackit postgresflex instance backups [flags] -``` - -### Options - -``` - -h, --help Help for "stackit postgresflex instance backups" -``` - -### Options inherited from parent commands - -``` - -y, --assume-yes If set, skips all confirmation prompts - --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty"] - -p, --project-id string Project ID -``` - -### SEE ALSO - -* [stackit postgresflex instance](./stackit_postgresflex_instance.md) - Provides functionality for PostgreSQL Flex instances -* [stackit postgresflex instance backups describe](./stackit_postgresflex_instance_backups_describe.md) - Shows details of a backup for a specific PostgreSQL Flex instance -* [stackit postgresflex instance backups list](./stackit_postgresflex_instance_backups_list.md) - Lists all backups which are available for a specific PostgreSQL Flex instance -* [stackit postgresflex instance backups update-schedule](./stackit_postgresflex_instance_backups_update-schedule.md) - Updates backup schedule for a specific PostgreSQL Flex instance - diff --git a/docs/stackit_postgresflex_instance_backups_update-schedule.md b/docs/stackit_postgresflex_instance_backups_update-schedule.md deleted file mode 100644 index 418acd54c..000000000 --- a/docs/stackit_postgresflex_instance_backups_update-schedule.md +++ /dev/null @@ -1,40 +0,0 @@ -## stackit postgresflex instance backups update-schedule - -Updates backup schedule for a specific PostgreSQL Flex instance - -### Synopsis - -Updates backup schedule for a specific PostgreSQL Flex instance. - -``` -stackit postgresflex instance backups update-schedule [flags] -``` - -### Examples - -``` - Update the backup schedule of a PostgreSQL Flex instance with ID "xxx" - $ stackit postgresflex instance backups update-schedule --instance-id xxx --backup-schedule '6 6 * * *' -``` - -### Options - -``` - --backup-schedule string Backup schedule, in the cron scheduling system format e.g. '0 0 * * *' - -h, --help Help for "stackit postgresflex instance backups update-schedule" - --instance-id string Instance ID -``` - -### Options inherited from parent commands - -``` - -y, --assume-yes If set, skips all confirmation prompts - --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty"] - -p, --project-id string Project ID -``` - -### SEE ALSO - -* [stackit postgresflex instance backups](./stackit_postgresflex_instance_backups.md) - Provides functionality for PostgreSQL Flex instance backups - From ca7bdc69b8155a9e3f82cae5f3c0f9a14bb30da8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Thu, 25 Apr 2024 09:49:29 +0200 Subject: [PATCH 11/17] generate docs --- docs/stackit_postgresflex_backup.md | 3 ++- docs/stackit_postgresflex_backup_describe.md | 3 ++- docs/stackit_postgresflex_backup_list.md | 3 ++- docs/stackit_postgresflex_backup_update-schedule.md | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/stackit_postgresflex_backup.md b/docs/stackit_postgresflex_backup.md index 34147faed..d191d03f5 100644 --- a/docs/stackit_postgresflex_backup.md +++ b/docs/stackit_postgresflex_backup.md @@ -21,8 +21,9 @@ stackit postgresflex backup [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty"] + -o, --output-format string Output format, one of ["json" "pretty" "none"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_backup_describe.md b/docs/stackit_postgresflex_backup_describe.md index c9f827f75..5de87ccb6 100644 --- a/docs/stackit_postgresflex_backup_describe.md +++ b/docs/stackit_postgresflex_backup_describe.md @@ -32,8 +32,9 @@ stackit postgresflex backup describe BACKUP_ID [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty"] + -o, --output-format string Output format, one of ["json" "pretty" "none"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_backup_list.md b/docs/stackit_postgresflex_backup_list.md index 6a3094dd0..36b0584d6 100644 --- a/docs/stackit_postgresflex_backup_list.md +++ b/docs/stackit_postgresflex_backup_list.md @@ -36,8 +36,9 @@ stackit postgresflex backup list [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty"] + -o, --output-format string Output format, one of ["json" "pretty" "none"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_backup_update-schedule.md b/docs/stackit_postgresflex_backup_update-schedule.md index 5658469a3..6c33afb57 100644 --- a/docs/stackit_postgresflex_backup_update-schedule.md +++ b/docs/stackit_postgresflex_backup_update-schedule.md @@ -30,8 +30,9 @@ stackit postgresflex backup update-schedule [flags] ``` -y, --assume-yes If set, skips all confirmation prompts --async If set, runs the command asynchronously - -o, --output-format string Output format, one of ["json" "pretty"] + -o, --output-format string Output format, one of ["json" "pretty" "none"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO From 5fbaa6931b52964573f7a708bf97b50c4cf1ae2f Mon Sep 17 00:00:00 2001 From: GokceGK <161626272+GokceGK@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:04:53 +0200 Subject: [PATCH 12/17] Edit descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Diogo Ferrão --- internal/cmd/postgresflex/backup/describe/describe.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/postgresflex/backup/describe/describe.go b/internal/cmd/postgresflex/backup/describe/describe.go index f12e3d171..e184f9dde 100644 --- a/internal/cmd/postgresflex/backup/describe/describe.go +++ b/internal/cmd/postgresflex/backup/describe/describe.go @@ -40,8 +40,8 @@ type inputModel struct { func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", backupIdArg), - Short: "Shows details of a backup for a specific PostgreSQL Flex instance", - Long: "Shows details of a backup for a specific PostgreSQL Flex instance.", + Short: "Shows details of a backup for a PostgreSQL Flex instance", + Long: "Shows details of a backup for a PostgreSQL Flex instance.", Example: examples.Build( examples.NewExample( `Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy"`, From 465fbd38aefb71cf28a140b32b97d0aa4ceebe81 Mon Sep 17 00:00:00 2001 From: GokceGK <161626272+GokceGK@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:05:16 +0200 Subject: [PATCH 13/17] Edit descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Diogo Ferrão --- internal/cmd/postgresflex/backup/list/list.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/postgresflex/backup/list/list.go b/internal/cmd/postgresflex/backup/list/list.go index 87266535f..b6ff4641b 100644 --- a/internal/cmd/postgresflex/backup/list/list.go +++ b/internal/cmd/postgresflex/backup/list/list.go @@ -40,8 +40,8 @@ type inputModel struct { func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", - Short: "Lists all backups which are available for a specific PostgreSQL Flex instance", - Long: "Lists all backups which are available for a specific PostgreSQL Flex instance.", + Short: "Lists all backups which are available for a PostgreSQL Flex instance", + Long: "Lists all backups which are available for a PostgreSQL Flex instance.", Example: examples.Build( examples.NewExample( `List all backups of instance with ID "xxx"`, From eb2ff8977aa18fdf3d995bc01af69db1db90c6b4 Mon Sep 17 00:00:00 2001 From: GokceGK <161626272+GokceGK@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:05:40 +0200 Subject: [PATCH 14/17] Edit descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Diogo Ferrão --- .../postgresflex/backup/update-schedule/update_schedule.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go b/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go index 0617ca710..94ec2c20c 100644 --- a/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go +++ b/internal/cmd/postgresflex/backup/update-schedule/update_schedule.go @@ -31,8 +31,8 @@ type inputModel struct { func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "update-schedule", - Short: "Updates backup schedule for a specific PostgreSQL Flex instance", - Long: "Updates backup schedule for a specific PostgreSQL Flex instance.", + Short: "Updates backup schedule for a PostgreSQL Flex instance", + Long: "Updates backup schedule for a PostgreSQL Flex instance.", Args: args.NoArgs, Example: examples.Build( examples.NewExample( From 0c75131250c76d9e948fd106a7e13a5578906291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Fri, 26 Apr 2024 11:10:57 +0200 Subject: [PATCH 15/17] rename backup file --- internal/cmd/postgresflex/backup/{backups.go => backup.go} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename internal/cmd/postgresflex/backup/{backups.go => backup.go} (100%) diff --git a/internal/cmd/postgresflex/backup/backups.go b/internal/cmd/postgresflex/backup/backup.go similarity index 100% rename from internal/cmd/postgresflex/backup/backups.go rename to internal/cmd/postgresflex/backup/backup.go From 9cc8138dbab1a23cf591113d32dffa934c6e16c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Fri, 26 Apr 2024 11:22:34 +0200 Subject: [PATCH 16/17] add missing test cases --- internal/cmd/postgresflex/backup/list/list_test.go | 7 +++++++ .../backup/update-schedule/update_schedule_test.go | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/internal/cmd/postgresflex/backup/list/list_test.go b/internal/cmd/postgresflex/backup/list/list_test.go index db4091ce5..242bc9563 100644 --- a/internal/cmd/postgresflex/backup/list/list_test.go +++ b/internal/cmd/postgresflex/backup/list/list_test.go @@ -110,6 +110,13 @@ func TestParseInput(t *testing.T) { }), isValid: false, }, + { + description: "instance id invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "invalid-uuid" + }), + isValid: false, + }, { description: "limit invalid", flagValues: fixtureFlagValues(func(flagValues map[string]string) { diff --git a/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go b/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go index 5cf64e753..0f28528cb 100644 --- a/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go +++ b/internal/cmd/postgresflex/backup/update-schedule/update_schedule_test.go @@ -123,6 +123,13 @@ func TestParseInput(t *testing.T) { }), isValid: false, }, + { + description: "instance id invalid 2", + flagValues: fixtureFlagValues(func(flagValues map[string]string) { + flagValues[instanceIdFlag] = "invalid-uuid" + }), + isValid: false, + }, { description: "backup schedule missing", flagValues: fixtureFlagValues(func(flagValues map[string]string) { From ada6656236273d88bc1b25b9042882c216088be7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Go=CC=88kc=CC=A7e=20Go=CC=88k=20Klingel?= Date: Fri, 26 Apr 2024 14:43:07 +0200 Subject: [PATCH 17/17] generate docs --- docs/stackit_postgresflex_backup.md | 6 +++--- docs/stackit_postgresflex_backup_describe.md | 4 ++-- docs/stackit_postgresflex_backup_list.md | 4 ++-- docs/stackit_postgresflex_backup_update-schedule.md | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/stackit_postgresflex_backup.md b/docs/stackit_postgresflex_backup.md index d191d03f5..2a3d9a7e3 100644 --- a/docs/stackit_postgresflex_backup.md +++ b/docs/stackit_postgresflex_backup.md @@ -29,7 +29,7 @@ stackit postgresflex backup [flags] ### SEE ALSO * [stackit postgresflex](./stackit_postgresflex.md) - Provides functionality for PostgreSQL Flex -* [stackit postgresflex backup describe](./stackit_postgresflex_backup_describe.md) - Shows details of a backup for a specific PostgreSQL Flex instance -* [stackit postgresflex backup list](./stackit_postgresflex_backup_list.md) - Lists all backups which are available for a specific PostgreSQL Flex instance -* [stackit postgresflex backup update-schedule](./stackit_postgresflex_backup_update-schedule.md) - Updates backup schedule for a specific PostgreSQL Flex instance +* [stackit postgresflex backup describe](./stackit_postgresflex_backup_describe.md) - Shows details of a backup for a PostgreSQL Flex instance +* [stackit postgresflex backup list](./stackit_postgresflex_backup_list.md) - Lists all backups which are available for a PostgreSQL Flex instance +* [stackit postgresflex backup update-schedule](./stackit_postgresflex_backup_update-schedule.md) - Updates backup schedule for a PostgreSQL Flex instance diff --git a/docs/stackit_postgresflex_backup_describe.md b/docs/stackit_postgresflex_backup_describe.md index 5de87ccb6..84f786c55 100644 --- a/docs/stackit_postgresflex_backup_describe.md +++ b/docs/stackit_postgresflex_backup_describe.md @@ -1,10 +1,10 @@ ## stackit postgresflex backup describe -Shows details of a backup for a specific PostgreSQL Flex instance +Shows details of a backup for a PostgreSQL Flex instance ### Synopsis -Shows details of a backup for a specific PostgreSQL Flex instance. +Shows details of a backup for a PostgreSQL Flex instance. ``` stackit postgresflex backup describe BACKUP_ID [flags] diff --git a/docs/stackit_postgresflex_backup_list.md b/docs/stackit_postgresflex_backup_list.md index 36b0584d6..e655afdcf 100644 --- a/docs/stackit_postgresflex_backup_list.md +++ b/docs/stackit_postgresflex_backup_list.md @@ -1,10 +1,10 @@ ## stackit postgresflex backup list -Lists all backups which are available for a specific PostgreSQL Flex instance +Lists all backups which are available for a PostgreSQL Flex instance ### Synopsis -Lists all backups which are available for a specific PostgreSQL Flex instance. +Lists all backups which are available for a PostgreSQL Flex instance. ``` stackit postgresflex backup list [flags] diff --git a/docs/stackit_postgresflex_backup_update-schedule.md b/docs/stackit_postgresflex_backup_update-schedule.md index 6c33afb57..331980d75 100644 --- a/docs/stackit_postgresflex_backup_update-schedule.md +++ b/docs/stackit_postgresflex_backup_update-schedule.md @@ -1,10 +1,10 @@ ## stackit postgresflex backup update-schedule -Updates backup schedule for a specific PostgreSQL Flex instance +Updates backup schedule for a PostgreSQL Flex instance ### Synopsis -Updates backup schedule for a specific PostgreSQL Flex instance. +Updates backup schedule for a PostgreSQL Flex instance. ``` stackit postgresflex backup update-schedule [flags]