Skip to content

Commit c9759b8

Browse files
jmckulkjkatz
authored andcommitted
Updates the list if disbled pgBackRest commands
1 parent b4c4984 commit c9759b8

File tree

3 files changed

+83
-35
lines changed

3 files changed

+83
-35
lines changed

apiserver/backupoptions/backupoptionsutil.go

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
type backupOptions interface {
3131
validate([]string) error
32-
getBlacklistFlags() ([]string, []string)
32+
getDenyListFlags() ([]string, []string)
3333
}
3434

3535
// ValidateBackupOpts validates the backup/restore options that can be provided to the various backup
@@ -98,9 +98,8 @@ func convertBackupOptsToStruct(backupOpts string, request interface{}) (backupOp
9898

9999
err = commandLine.Parse(parsedBackupOpts)
100100
if err != nil {
101-
err = handleCustomParseErrors(err, usage, optsStruct)
102-
if err != nil {
103-
return nil, nil, err
101+
if customErr := handleCustomParseErrors(err, usage, optsStruct); customErr != nil {
102+
return nil, nil, customErr
104103
}
105104
}
106105

@@ -186,28 +185,28 @@ func isValidValue(vals []string, val string) bool {
186185
return isValid
187186
}
188187

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
188+
// this function checks unknown options from the backup-opts flag to validate that they are not denied
189+
// if the option is in the deny list and error is returned, otherwise the flag is unkown to the operator
191190
// and can be passed to pgBackRest for validation.
192191
func handleCustomParseErrors(err error, usage *bytes.Buffer, optsStruct backupOptions) error {
193-
blacklistFlags, blacklistFlagsShort := optsStruct.getBlacklistFlags()
192+
denyListFlags, denyListFlagsShort := optsStruct.getDenyListFlags()
194193
if err.Error() == "pflag: help requested" {
195194
pflag.Usage()
196195
return errors.New(usage.String())
197196
} else if strings.Contains(err.Error(), "unknown flag") {
198-
for _, blacklistFlag := range blacklistFlags {
199-
flagMatch, err := regexp.MatchString("\\B"+blacklistFlag+"$", err.Error())
197+
for _, denyListFlag := range denyListFlags {
198+
flagMatch, err := regexp.MatchString("\\B"+denyListFlag+"$", err.Error())
200199
if err != nil {
201200
return err
202201
} else if flagMatch {
203-
return fmt.Errorf("Flag %s is not supported for use with PGO", blacklistFlag)
202+
return fmt.Errorf("Flag %s is not supported for use with PGO", denyListFlag)
204203
}
205204
}
206205
} else if strings.Contains(err.Error(), "unknown shorthand flag") {
207-
for _, blacklistFlagShort := range blacklistFlagsShort {
208-
blacklistFlagQuotes := "'" + strings.TrimPrefix(blacklistFlagShort, "-") + "'"
209-
if strings.Contains(err.Error(), blacklistFlagQuotes) {
210-
return fmt.Errorf("Shorthand flag %s is not supported for use with PGO", blacklistFlagShort)
206+
for _, denyListFlagShort := range denyListFlagsShort {
207+
denyListFlagQuotes := "'" + strings.TrimPrefix(denyListFlagShort, "-") + "'"
208+
if strings.Contains(err.Error(), denyListFlagQuotes) {
209+
return fmt.Errorf("Shorthand flag %s is not supported for use with PGO", denyListFlagShort)
211210
}
212211
}
213212
}

apiserver/backupoptions/pgbackrestoptions.go

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,45 @@ import (
2020
"strings"
2121
)
2222

23-
var pgBackRestOptsBlacklist = []string{"--archive-check", "--no-archive-check", "--online", "--no-online", "--link-all",
24-
"--link-map", "--tablespace-map", "--tablespace-map-all", "--cmd-ssh", "--config", "--config-include-path",
25-
"--config-path", "--lock-path", "--neutral-umask", "--no-neutral-umask", "--stanza", "--log-timestamp",
26-
"--repo-cipher-type", "--repo-host", "--repo-host-cmd", "--repo-host-config", "--repo-host-config-include-path",
27-
"--repo-host-config-path", "--repo-host-port", "--repo-host-user", "--repo-path", "--repo-s3-bucket",
28-
"--repo-s3-ca-file", "--repo-s3-ca-path", "--repo-s3-endpoint", "--repo-s3-host", "--repo-s3-region",
29-
"--repo-s3-verify-ssl", "--repo-type", "--pg-host", "--pg-host-cmd", "--pg-host-config",
30-
"--pg-host-config-include-path", "--pg-host-config-path", "--pg-host-port", "--pg-host-user", "--pg-path", "--pg-port"}
23+
var pgBackRestOptsDenyList = []string{
24+
"--cmd-ssh",
25+
"--config",
26+
"--config-include-path",
27+
"--config-path",
28+
"--link-all",
29+
"--link-map",
30+
"--lock-path",
31+
"--log-timestamp",
32+
"--neutral-umask",
33+
"--no-neutral-umask",
34+
"--no-online",
35+
"--online",
36+
"--pg-host",
37+
"--pg-host-cmd",
38+
"--pg-host-config",
39+
"--pg-host-config-include-path",
40+
"--pg-host-config-path",
41+
"--pg-host-port",
42+
"--pg-host-user",
43+
"--pg-path",
44+
"--pg-port",
45+
"--repo-host",
46+
"--repo-host-cmd",
47+
"--repo-host-config",
48+
"--repo-host-config-include-path",
49+
"--repo-host-config-path",
50+
"--repo-host-port",
51+
"--repo-host-user",
52+
"--repo-path",
53+
"--repo-s3-bucket",
54+
"--repo-s3-endpoint",
55+
"--repo-s3-host",
56+
"--repo-s3-region",
57+
"--repo-type",
58+
"--stanza",
59+
"--tablespace-map",
60+
"--tablespace-map-all",
61+
}
3162

3263
type pgBackRestBackupOptions struct {
3364
ArchiveCopy bool `flag:"archive-copy"`
@@ -225,10 +256,10 @@ func isValidBackrestLogLevel(logLevel string) bool {
225256
return isValidValue(logLevels, logLevel)
226257
}
227258

228-
func (backRestBackupOpts pgBackRestBackupOptions) getBlacklistFlags() ([]string, []string) {
229-
return pgBackRestOptsBlacklist, nil
259+
func (backRestBackupOpts pgBackRestBackupOptions) getDenyListFlags() ([]string, []string) {
260+
return pgBackRestOptsDenyList, nil
230261
}
231262

232-
func (backRestRestoreOpts pgBackRestRestoreOptions) getBlacklistFlags() ([]string, []string) {
233-
return pgBackRestOptsBlacklist, nil
263+
func (backRestRestoreOpts pgBackRestRestoreOptions) getDenyListFlags() ([]string, []string) {
264+
return pgBackRestOptsDenyList, nil
234265
}

apiserver/backupoptions/pgdumpoptions.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,28 @@ import (
2020
"strings"
2121
)
2222

23-
var pgDumpRestoreOptsBlacklist = []string{"--binary-upgrade", "--no-reconnect", "--dbname", "--host", "--port",
24-
"--username", "--no-password", "--password", "--version"}
23+
var pgDumpRestoreOptsDenyList = []string{
24+
"--binary-upgrade",
25+
"--dbname",
26+
"--host",
27+
"--no-password",
28+
"--no-reconnect",
29+
"--password",
30+
"--port",
31+
"--username",
32+
"--version",
33+
}
2534

26-
var pgDumpRestoreOptsBlacklistShort = []string{"-R", "-d", "-h", "-p", "-U", "-w", "-W", "-V"}
35+
var pgDumpRestoreOptsDenyListShort = []string{
36+
"-R",
37+
"-d",
38+
"-h",
39+
"-p",
40+
"-U",
41+
"-w",
42+
"-W",
43+
"-V",
44+
}
2745

2846
type pgDumpOptions struct {
2947
DataOnly bool `flag:"data-only" flag-short:"a"`
@@ -265,14 +283,14 @@ func (restoreOpts pgRestoreOptions) validate(setFlagFieldNames []string) error {
265283
return nil
266284
}
267285

268-
func (dumpOpts pgDumpOptions) getBlacklistFlags() ([]string, []string) {
269-
return pgDumpRestoreOptsBlacklist, pgDumpRestoreOptsBlacklistShort
286+
func (dumpOpts pgDumpOptions) getDenyListFlags() ([]string, []string) {
287+
return pgDumpRestoreOptsDenyList, pgDumpRestoreOptsDenyListShort
270288
}
271289

272-
func (dumpAllOpts pgDumpAllOptions) getBlacklistFlags() ([]string, []string) {
273-
return pgDumpRestoreOptsBlacklist, pgDumpRestoreOptsBlacklistShort
290+
func (dumpAllOpts pgDumpAllOptions) getDenyListFlags() ([]string, []string) {
291+
return pgDumpRestoreOptsDenyList, pgDumpRestoreOptsDenyListShort
274292
}
275293

276-
func (restoreOpts pgRestoreOptions) getBlacklistFlags() ([]string, []string) {
277-
return pgDumpRestoreOptsBlacklist, pgDumpRestoreOptsBlacklistShort
294+
func (restoreOpts pgRestoreOptions) getDenyListFlags() ([]string, []string) {
295+
return pgDumpRestoreOptsDenyList, pgDumpRestoreOptsDenyListShort
278296
}

0 commit comments

Comments
 (0)