Skip to content

Commit b4c4984

Browse files
jmckulkjkatz
authored andcommitted
Updates validation logic on pgBackRest backup options
Currently validation is run on backup options passed in with the --backup-opts flag to reject unknown or blacklisted flags. This commit updates the validation to only reject blacklisted flags and allow unknown flags to be passed into the operator. This will make new pgBackRest features and flags easier to support by relying on the builtin pgBackRest validation. Now new pgBackrest flags can be used without updating the list of known flags. The handleCustomParseErrors function now will take the unknown flag error and check if the flag is blacklisted. If not, the error is ignored and nil is returned. A second level check is added to validate the parsedBackupOpts. Now the return from handleCustomParseErrors is checked rather than immediately returned.
1 parent 185a9e2 commit b4c4984

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

apiserver/backupoptions/backupoptionsutil.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,10 @@ func convertBackupOptsToStruct(backupOpts string, request interface{}) (backupOp
9898

9999
err = commandLine.Parse(parsedBackupOpts)
100100
if err != nil {
101-
return nil, nil, handleCustomParseErrors(err, usage, optsStruct)
101+
err = handleCustomParseErrors(err, usage, optsStruct)
102+
if err != nil {
103+
return nil, nil, err
104+
}
102105
}
103106

104107
setFlagFieldNames := obtainSetFlagFieldNames(commandLine, structType)
@@ -183,6 +186,9 @@ func isValidValue(vals []string, val string) bool {
183186
return isValid
184187
}
185188

189+
// this function checks unknown options from the backup-opts flag to validate that they are not blacklisted
190+
// if the option is in the blacklist and error is returned, otherwise the flag is unkown to the operator
191+
// and can be passed to pgBackRest for validation.
186192
func handleCustomParseErrors(err error, usage *bytes.Buffer, optsStruct backupOptions) error {
187193
blacklistFlags, blacklistFlagsShort := optsStruct.getBlacklistFlags()
188194
if err.Error() == "pflag: help requested" {
@@ -205,7 +211,7 @@ func handleCustomParseErrors(err error, usage *bytes.Buffer, optsStruct backupOp
205211
}
206212
}
207213
}
208-
return err
214+
return nil
209215
}
210216

211217
func obtainSetFlagFieldNames(commandLine *pflag.FlagSet, structType reflect.Type) []string {

0 commit comments

Comments
 (0)