-
Notifications
You must be signed in to change notification settings - Fork 39
Onboard postgresflex backup commands #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
cde1060
onboard postgresflex backup commands
GokceGK a65ea70
add docs
GokceGK 072d191
move backups directly under postgresflex
GokceGK 10963e2
change used bytesize library
GokceGK 13206dc
remove empty spaces
GokceGK a7f30c8
use constants for backup expiration offset
GokceGK ca538a0
add expire date in list output
GokceGK 899ca0c
remove redundant backup
GokceGK fa190ae
adapt table columns for list and describe output
GokceGK 104febd
generate docs
GokceGK fbce5cd
Merge branch 'main' into gg/onboard-postgresflex-backup-commands
GokceGK b107165
merge main // solve merge conflicts
GokceGK ca7bdc6
generate docs
GokceGK 5fbaa69
Edit descriptions
GokceGK 465fbd3
Edit descriptions
GokceGK eb2ff89
Edit descriptions
GokceGK 0c75131
rename backup file
GokceGK 9cc8138
add missing test cases
GokceGK ada6656
generate docs
GokceGK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| ## 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" "none"] | ||
| -p, --project-id string Project ID | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### 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 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| ## stackit postgresflex backup describe | ||
|
|
||
| Shows details of a backup for a PostgreSQL Flex instance | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Shows details of a backup for a PostgreSQL Flex instance. | ||
|
|
||
| ``` | ||
| 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 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 backup describe xxx --instance-id yyy --output-format pretty | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit postgresflex backup 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" "none"] | ||
| -p, --project-id string Project ID | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit postgresflex backup](./stackit_postgresflex_backup.md) - Provides functionality for PostgreSQL Flex instance backups | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| ## stackit postgresflex backup list | ||
|
|
||
| Lists all backups which are available for a PostgreSQL Flex instance | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Lists all backups which are available for a PostgreSQL Flex instance. | ||
|
|
||
| ``` | ||
| stackit postgresflex backup list [flags] | ||
| ``` | ||
|
|
||
| ### Examples | ||
|
|
||
| ``` | ||
| List all backups of instance with ID "xxx" | ||
| $ stackit postgresflex backup list --instance-id xxx | ||
|
|
||
| List all backups of instance with ID "xxx" in JSON format | ||
| $ stackit postgresflex backup list --instance-id xxx --output-format json | ||
|
|
||
| List up to 10 backups of instance with ID "xxx" | ||
| $ stackit postgresflex backup list --instance-id xxx --limit 10 | ||
| ``` | ||
|
|
||
| ### Options | ||
|
|
||
| ``` | ||
| -h, --help Help for "stackit postgresflex backup 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" "none"] | ||
| -p, --project-id string Project ID | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit postgresflex backup](./stackit_postgresflex_backup.md) - Provides functionality for PostgreSQL Flex instance backups | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| ## stackit postgresflex backup update-schedule | ||
|
|
||
| Updates backup schedule for a PostgreSQL Flex instance | ||
|
|
||
| ### Synopsis | ||
|
|
||
| Updates backup schedule for a 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" "none"] | ||
| -p, --project-id string Project ID | ||
| --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") | ||
| ``` | ||
|
|
||
| ### SEE ALSO | ||
|
|
||
| * [stackit postgresflex backup](./stackit_postgresflex_backup.md) - Provides functionality for PostgreSQL Flex instance backups | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package backup | ||
|
|
||
| import ( | ||
| "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/print" | ||
| "github.com/stackitcloud/stackit-cli/internal/pkg/utils" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func NewCmd(p *print.Printer) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "backup", | ||
| Short: "Provides functionality for PostgreSQL Flex instance backups", | ||
| Long: "Provides functionality for PostgreSQL Flex instance backups.", | ||
| Args: args.NoArgs, | ||
| Run: utils.CmdHelp, | ||
| } | ||
| addSubcommands(cmd, p) | ||
| return cmd | ||
| } | ||
|
|
||
| func addSubcommands(cmd *cobra.Command, p *print.Printer) { | ||
| cmd.AddCommand(list.NewCmd(p)) | ||
| cmd.AddCommand(describe.NewCmd(p)) | ||
| cmd.AddCommand(updateschedule.NewCmd(p)) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| package describe | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
|
|
||
| "time" | ||
|
|
||
| "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" | ||
| "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/print" | ||
| "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" | ||
|
|
||
| backupExpireYearOffset = 0 | ||
| backupExpireMonthOffset = 0 | ||
| backupExpireDayOffset = 30 | ||
| ) | ||
|
|
||
| type inputModel struct { | ||
| *globalflags.GlobalFlagModel | ||
|
|
||
| InstanceId string | ||
| BackupId string | ||
| } | ||
|
|
||
| func NewCmd(p *print.Printer) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: fmt.Sprintf("describe %s", backupIdArg), | ||
| 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"`, | ||
| "$ 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 backup 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(p, cmd, args) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| // Configure API client | ||
| apiClient, err := client.ConfigureClient(p) | ||
| 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(p, 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(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) { | ||
| backupId := inputArgs[0] | ||
|
|
||
| globalFlags := globalflags.Parse(p, cmd) | ||
| if globalFlags.ProjectId == "" { | ||
| return nil, &errors.ProjectIdError{} | ||
| } | ||
|
|
||
| return &inputModel{ | ||
| GlobalFlagModel: globalFlags, | ||
| InstanceId: flags.FlagToStringValue(p, 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(p *print.Printer, 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(backupExpireYearOffset, backupExpireMonthOffset, backupExpireDayOffset).Format(time.DateOnly) | ||
|
|
||
| switch outputFormat { | ||
| case print.PrettyOutputFormat: | ||
| table := tables.NewTable() | ||
| table.AddRow("ID", *backup.Id) | ||
| table.AddSeparator() | ||
| table.AddRow("START TIME", *backup.StartTime) | ||
| table.AddSeparator() | ||
| table.AddRow("EXPIRES AT", backupExpireDate) | ||
| table.AddSeparator() | ||
| table.AddRow("BACKUP SIZE", bytesize.New(float64(*backup.Size))) | ||
|
|
||
| err := table.Display(p) | ||
| 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 | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.