Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions pkg/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,33 @@ type DataBackupConfiguration struct {
// behavior during execution.
// +optional
AdditionalCommandArgs []string `json:"additionalCommandArgs,omitempty"`

// ShowAdditionalCommandArgs represents additional arguments that can be appended
// to the 'barman-cloud-backup-show' command-line invocation. This command is
// used after a successful upload to verify and record metadata about the
// freshly-written backup, so flags relevant to the underlying S3 client
// (e.g. `--addressing-style=virtual` for strictly virtual-hosted S3-compatible
// endpoints) generally belong here as well.
//
// Note:
// It's essential to ensure that the provided arguments are valid and supported
// by the 'barman-cloud-backup-show' command, to avoid potential errors or
// unintended behavior during execution.
// +optional
ShowAdditionalCommandArgs []string `json:"showAdditionalCommandArgs,omitempty"`

// ListAdditionalCommandArgs represents additional arguments that can be appended
// to the 'barman-cloud-backup-list' command-line invocation. This command is
// used internally for retention-policy enforcement; flags relevant to the
// underlying S3 client (e.g. `--addressing-style=virtual` for strictly
// virtual-hosted S3-compatible endpoints) generally belong here as well.
//
// Note:
// It's essential to ensure that the provided arguments are valid and supported
// by the 'barman-cloud-backup-list' command, to avoid potential errors or
// unintended behavior during execution.
// +optional
ListAdditionalCommandArgs []string `json:"listAdditionalCommandArgs,omitempty"`
}

// ArePopulated checks if the passed set of credentials contains
Expand Down Expand Up @@ -466,6 +493,24 @@ func (cfg *DataBackupConfiguration) AppendAdditionalCommandArgs(options []string
return appendAdditionalCommandArgs(cfg.AdditionalCommandArgs, options)
}

// AppendShowAdditionalCommandArgs adds custom arguments as barman-cloud-backup-show
// command-line options
func (cfg *DataBackupConfiguration) AppendShowAdditionalCommandArgs(options []string) []string {
if cfg == nil || len(cfg.ShowAdditionalCommandArgs) == 0 {
return options
}
return appendAdditionalCommandArgs(cfg.ShowAdditionalCommandArgs, options)
}

// AppendListAdditionalCommandArgs adds custom arguments as barman-cloud-backup-list
// command-line options
func (cfg *DataBackupConfiguration) AppendListAdditionalCommandArgs(options []string) []string {
if cfg == nil || len(cfg.ListAdditionalCommandArgs) == 0 {
return options
}
return appendAdditionalCommandArgs(cfg.ListAdditionalCommandArgs, options)
}

// AppendArchiveAdditionalCommandArgs adds custom arguments as barman-cloud-wal-archive command-line options
func (cfg *WalBackupConfiguration) AppendArchiveAdditionalCommandArgs(options []string) []string {
if cfg == nil || len(cfg.ArchiveAdditionalCommandArgs) == 0 {
Expand Down
44 changes: 44 additions & 0 deletions pkg/api/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,50 @@ var _ = Describe("DataBackupConfiguration.AppendAdditionalCommandArgs", func() {
})
})

var _ = Describe("DataBackupConfiguration.AppendShowAdditionalCommandArgs", func() {
var options []string
var config DataBackupConfiguration
BeforeEach(func() {
options = []string{"--option1", "--option2"}
config = DataBackupConfiguration{
ShowAdditionalCommandArgs: []string{"--option3", "--option4"},
}
})

It("should append additional command args to the options", func() {
updatedOptions := config.AppendShowAdditionalCommandArgs(options)
Expect(updatedOptions).To(Equal([]string{"--option1", "--option2", "--option3", "--option4"}))
})

It("should return the original options if there are no additional command args", func() {
config.ShowAdditionalCommandArgs = nil
updatedOptions := config.AppendShowAdditionalCommandArgs(options)
Expect(updatedOptions).To(Equal(options))
})
})

var _ = Describe("DataBackupConfiguration.AppendListAdditionalCommandArgs", func() {
var options []string
var config DataBackupConfiguration
BeforeEach(func() {
options = []string{"--option1", "--option2"}
config = DataBackupConfiguration{
ListAdditionalCommandArgs: []string{"--option3", "--option4"},
}
})

It("should append additional command args to the options", func() {
updatedOptions := config.AppendListAdditionalCommandArgs(options)
Expect(updatedOptions).To(Equal([]string{"--option1", "--option2", "--option3", "--option4"}))
})

It("should return the original options if there are no additional command args", func() {
config.ListAdditionalCommandArgs = nil
updatedOptions := config.AppendListAdditionalCommandArgs(options)
Expect(updatedOptions).To(Equal(options))
})
})

var _ = Describe("WalBackupConfiguration.AppendArchiveAdditionalCommandArgs", func() {
var options []string
var config WalBackupConfiguration
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions pkg/command/backuplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func executeQueryCommand(
barmanCommand string,
barmanConfiguration *barmanApi.BarmanObjectStoreConfiguration,
serverName string,
additionalOptions []string,
additionalFlagArgs []string,
trailingArgs []string,
env []string,
) (string, error) {
contextLogger := log.FromContext(ctx).WithName("barman")
Expand All @@ -77,8 +78,14 @@ func executeQueryCommand(
return "", err
}

// User-provided per-subcommand flags are appended after the standard
// options (cloud provider, endpoint, etc.) but before the positional
// arguments, matching the shape of the other Append*AdditionalCommandArgs
// helpers in the rest of this library.
options = append(options, additionalFlagArgs...)

options = append(options, barmanConfiguration.DestinationPath, serverName)
options = append(options, additionalOptions...)
options = append(options, trailingArgs...)

var stdoutBuffer bytes.Buffer
var stderrBuffer bytes.Buffer
Expand Down Expand Up @@ -114,6 +121,7 @@ func GetBackupList(
utils.BarmanCloudBackupList,
barmanConfiguration,
serverName,
barmanConfiguration.Data.AppendListAdditionalCommandArgs(nil),
[]string{},
env,
)
Expand Down Expand Up @@ -146,6 +154,7 @@ func GetBackupByName(
utils.BarmanCloudBackupShow,
barmanConfiguration,
serverName,
barmanConfiguration.Data.AppendShowAdditionalCommandArgs(nil),
[]string{backupName},
env,
)
Expand Down