1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Limit option validity by command role.

Building on 23f5712, limit option validity by role. This is mostly for options that weren't needed for certain roles but were harmless. However, the upcoming multi repository functionality requires the granularity implemented here.

The remote role benefits since host options can automatically excluded when building the options. Also, many options that are only required for the default role (e.g. repo-retention-full) no longer need to be passed in tests for other roles.
This commit is contained in:
David Steele 2020-12-29 15:49:37 -05:00 committed by GitHub
parent 26e81785d9
commit abb8ebe58b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 394 additions and 805 deletions

View File

@ -367,7 +367,7 @@ sub buildConfigParse
{
if (defined($rhOption->{&CFGDEF_COMMAND}{$strCommand}))
{
if (defined($rhCommandDefine->{$strCommand}{&CFGDEF_COMMAND_ROLE}{$strCommandRole}))
if (defined($rhOption->{&CFGDEF_COMMAND}{$strCommand}{&CFGDEF_COMMAND_ROLE}{$strCommandRole}))
{
$strBuildSourceSub .=
" PARSE_RULE_OPTION_COMMAND(" . buildConfigCommandEnum($strCommand) . ")\n";

View File

@ -16,9 +16,20 @@
# (B), else it will still error on the option (A).
#
# CFGDEF_COMMAND_ROLE:
# 1) Define the command roles for a command. CFGCMD_ROLE_DEFAULT is valid for all commands and is therefore added
# programmatically.
#
# Define the command roles that a command is valid for. CFGCMD_ROLE_DEFAULT is valid for all commands and is therefore added
# programmatically.
# 2) Define the command roles for an option. If not defined, the option will be valid for all roles of all commands for which it
# is valid. If command roles are defined for the option, then they override the roles for all commands for which the option
# is valid. CFGCMD_ROLE_DEFAULT must be defined explicitly in this case. For example, if an option is only valid for the
# default role and the async role for each command then CFGDEF_COMMAND_ROLE must list the CFGCMD_ROLE_DEFAULT and
# CFGCMD_ROLE_ASYNC, meaning each command has a default role so the option is valid for that role and for commands that have
# the async role, it is also valid for the async role of those commands.
#
# 3) Define the command roles for an option command override. If not defined, the option will be valid for all roles of the
# command or the roles specified by rule 2) above. CFGCMD_ROLE_DEFAULT must be defined explicitly in this case. If command
# roles are defined for the option command override, then they override command roles defined for the option (rule 2) above)
# and all roles defined for the command (rule 1) above).
#
# CFGDEF_REQUIRED:
# In global section:
@ -105,14 +116,23 @@ use constant CFGCMD_VERIFY => 'verify';
use constant CFGCMD_VERSION => 'version';
####################################################################################################################################
# Command role constants - roles allowed for each command
# Command role constants - roles allowed for each command. Commands may have multiple processes that work together to implement
# their functionality. These roles allow each process to know what it is supposed to do.
####################################################################################################################################
# Called directly by the user. This is the main part of the command that may or may not spawn other command roles.
use constant CFGCMD_ROLE_DEFAULT => 'default';
push @EXPORT, qw(CFGCMD_ROLE_DEFAULT);
# Async worker that is spawned so the main process can return a result while work continues. An async worker may spawn local or
# remote workers.
use constant CFGCMD_ROLE_ASYNC => 'async';
push @EXPORT, qw(CFGCMD_ROLE_ASYNC);
# Local worker for parallelizing jobs. A local work may spawn a remote worker.
use constant CFGCMD_ROLE_LOCAL => 'local';
push @EXPORT, qw(CFGCMD_ROLE_LOCAL);
# Remote worker for accessing resources on another host
use constant CFGCMD_ROLE_REMOTE => 'remote';
push @EXPORT, qw(CFGCMD_ROLE_REMOTE);
@ -796,6 +816,10 @@ my %hConfigDefine =
{
&CFGCMD_EXPIRE => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_FORCE =>
@ -833,7 +857,11 @@ my %hConfigDefine =
{
&CFGDEF_DEFAULT => false
}
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_ONLINE =>
@ -846,7 +874,11 @@ my %hConfigDefine =
&CFGCMD_BACKUP => {},
&CFGCMD_STANZA_CREATE => {},
&CFGCMD_STANZA_UPGRADE => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_SET =>
@ -875,7 +907,11 @@ my %hConfigDefine =
&CFGDEF_REQUIRED => false,
&CFGDEF_INTERNAL => true,
},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_STANZA =>
@ -947,6 +983,10 @@ my %hConfigDefine =
},
},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_TARGET_EXCLUSIVE =>
@ -968,6 +1008,10 @@ my %hConfigDefine =
},
},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_TARGET_ACTION =>
@ -999,6 +1043,10 @@ my %hConfigDefine =
},
},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_TARGET_TIMELINE =>
@ -1023,6 +1071,10 @@ my %hConfigDefine =
},
},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_TYPE =>
@ -1056,7 +1108,11 @@ my %hConfigDefine =
&CFGOPTVAL_RESTORE_TYPE_STANDBY,
]
}
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_OUTPUT =>
@ -1083,7 +1139,11 @@ my %hConfigDefine =
&CFGOPTVAL_OUTPUT_JSON,
]
}
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
# Command-line only local/remote options
@ -1119,6 +1179,11 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_VERIFY => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_LOCAL => {},
&CFGCMD_ROLE_REMOTE => {},
},
},
&CFGOPT_REMOTE_TYPE =>
@ -1149,6 +1214,11 @@ my %hConfigDefine =
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_VERIFY => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_LOCAL => {},
&CFGCMD_ROLE_REMOTE => {},
},
},
# Command-line only storage options
@ -1162,7 +1232,11 @@ my %hConfigDefine =
{
&CFGCMD_REPO_GET => {},
&CFGCMD_REPO_PUT => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_FILTER =>
@ -1172,7 +1246,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_REPO_LS => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_IGNORE_MISSING =>
@ -1182,7 +1260,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_REPO_GET => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_RAW =>
@ -1193,7 +1275,11 @@ my %hConfigDefine =
{
&CFGCMD_REPO_GET => {},
&CFGCMD_REPO_PUT => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_RECURSE =>
@ -1204,7 +1290,11 @@ my %hConfigDefine =
{
&CFGCMD_REPO_LS => {},
&CFGCMD_REPO_RM => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_SORT =>
@ -1220,7 +1310,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_REPO_LS => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
# General options
@ -1238,6 +1332,10 @@ my %hConfigDefine =
&CFGCMD_BACKUP => {},
&CFGCMD_CHECK => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_BUFFER_SIZE =>
@ -1364,6 +1462,10 @@ my %hConfigDefine =
&CFGCMD_BACKUP => {},
&CFGCMD_RESTORE => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
# Option is deprecated and should not be referenced outside of cfgLoadUpdateOption().
@ -1376,7 +1478,11 @@ my %hConfigDefine =
{
&CFGCMD_ARCHIVE_PUSH => {},
&CFGCMD_BACKUP => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_COMPRESS_TYPE =>
@ -1393,6 +1499,11 @@ my %hConfigDefine =
'zst',
],
&CFGDEF_COMMAND => CFGOPT_COMPRESS,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
},
},
&CFGOPT_COMPRESS_LEVEL =>
@ -1402,6 +1513,11 @@ my %hConfigDefine =
&CFGDEF_REQUIRED => false,
&CFGDEF_ALLOW_RANGE => [CFGDEF_DEFAULT_COMPRESS_LEVEL_MIN, CFGDEF_DEFAULT_COMPRESS_LEVEL_MAX],
&CFGDEF_COMMAND => CFGOPT_COMPRESS,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
},
},
&CFGOPT_COMPRESS_LEVEL_NETWORK =>
@ -1425,7 +1541,13 @@ my %hConfigDefine =
&CFGCMD_STANZA_DELETE => {},
&CFGCMD_STANZA_UPGRADE => {},
&CFGCMD_VERIFY => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
},
&CFGOPT_NEUTRAL_UMASK =>
@ -1481,6 +1603,12 @@ my %hConfigDefine =
&CFGCMD_STOP => {},
&CFGCMD_VERIFY => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
},
&CFGOPT_IO_TIMEOUT =>
@ -1632,6 +1760,10 @@ my %hConfigDefine =
{
&CFGCMD_BACKUP => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_REPO_LOCAL =>
@ -1695,6 +1827,12 @@ my %hConfigDefine =
&CFGDEF_DEPEND_OPTION => CFGOPT_REPO_LOCAL,
&CFGDEF_DEPEND_LIST => [false],
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
},
&CFGOPT_REPO_HOST_CMD =>
@ -1723,6 +1861,12 @@ my %hConfigDefine =
&CFGCMD_STOP => {},
&CFGCMD_VERIFY => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
&CFGDEF_DEPEND =>
{
&CFGDEF_DEPEND_OPTION => CFGOPT_REPO_HOST
@ -1740,6 +1884,12 @@ my %hConfigDefine =
'backup-config' => {&CFGDEF_INDEX => 1, &CFGDEF_RESET => false},
},
&CFGDEF_COMMAND => CFGOPT_REPO_HOST_CMD,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
&CFGDEF_DEPEND =>
{
&CFGDEF_DEPEND_OPTION => CFGOPT_REPO_HOST
@ -1772,6 +1922,12 @@ my %hConfigDefine =
'backup-ssh-port' => {&CFGDEF_INDEX => 1, &CFGDEF_RESET => false},
},
&CFGDEF_COMMAND => CFGOPT_REPO_HOST_CMD,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
&CFGDEF_DEPEND =>
{
&CFGDEF_DEPEND_OPTION => CFGOPT_REPO_HOST
@ -1789,6 +1945,12 @@ my %hConfigDefine =
'backup-user' => {&CFGDEF_INDEX => 1, &CFGDEF_RESET => false},
},
&CFGDEF_COMMAND => CFGOPT_REPO_HOST_CMD,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
&CFGDEF_REQUIRED => false,
&CFGDEF_DEPEND =>
{
@ -1824,7 +1986,11 @@ my %hConfigDefine =
{
&CFGCMD_BACKUP => {},
&CFGCMD_EXPIRE => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_REPO_RETENTION_ARCHIVE_TYPE =>
@ -1838,6 +2004,10 @@ my %hConfigDefine =
&CFGCMD_BACKUP => {},
&CFGCMD_EXPIRE => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
&CFGDEF_NAME_ALT =>
{
'retention-archive-type' => {&CFGDEF_INDEX => 1, &CFGDEF_RESET => false},
@ -1865,7 +2035,11 @@ my %hConfigDefine =
{
&CFGCMD_BACKUP => {},
&CFGCMD_EXPIRE => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_REPO_RETENTION_FULL =>
@ -1880,6 +2054,10 @@ my %hConfigDefine =
'retention-full' => {&CFGDEF_INDEX => 1, &CFGDEF_RESET => false},
},
&CFGDEF_COMMAND => CFGOPT_REPO_RETENTION_FULL_TYPE,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_REPO_RETENTION_FULL_TYPE =>
@ -1897,7 +2075,11 @@ my %hConfigDefine =
{
&CFGCMD_BACKUP => {},
&CFGCMD_EXPIRE => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_REPO_AZURE_ACCOUNT =>
@ -2238,6 +2420,12 @@ my %hConfigDefine =
},
},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
},
&CFGOPT_PROCESS_MAX =>
@ -2253,7 +2441,12 @@ my %hConfigDefine =
&CFGCMD_BACKUP => {},
&CFGCMD_RESTORE => {},
&CFGCMD_VERIFY => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
},
},
# Logging options
@ -2418,6 +2611,11 @@ my %hConfigDefine =
{
&CFGCMD_ARCHIVE_PUSH => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
},
},
&CFGOPT_ARCHIVE_GET_QUEUE_MAX =>
@ -2430,6 +2628,11 @@ my %hConfigDefine =
{
&CFGCMD_ARCHIVE_GET => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
},
},
# Backup options
@ -2451,6 +2654,10 @@ my %hConfigDefine =
},
&CFGCMD_CHECK => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_ARCHIVE_COPY =>
@ -2468,7 +2675,11 @@ my %hConfigDefine =
&CFGDEF_DEPEND_LIST => [true],
}
}
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_BACKUP_STANDBY =>
@ -2483,6 +2694,10 @@ my %hConfigDefine =
&CFGCMD_STANZA_CREATE => {},
&CFGCMD_STANZA_UPGRADE => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_CHECKSUM_PAGE =>
@ -2493,7 +2708,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_BACKUP => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_EXCLUDE =>
@ -2505,6 +2724,10 @@ my %hConfigDefine =
{
&CFGCMD_BACKUP => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_EXPIRE_AUTO =>
@ -2515,7 +2738,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_BACKUP => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_MANIFEST_SAVE_THRESHOLD =>
@ -2527,7 +2754,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_BACKUP => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_RESUME =>
@ -2538,7 +2769,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_BACKUP => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_START_FAST =>
@ -2549,7 +2784,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_BACKUP => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_STOP_AUTO =>
@ -2560,7 +2799,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_BACKUP => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
# Restore options
@ -2579,6 +2822,10 @@ my %hConfigDefine =
'off',
'preserve',
],
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_DB_INCLUDE =>
@ -2590,6 +2837,10 @@ my %hConfigDefine =
{
&CFGCMD_RESTORE => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_LINK_ALL =>
@ -2600,7 +2851,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_RESTORE => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_LINK_MAP =>
@ -2612,6 +2867,10 @@ my %hConfigDefine =
{
&CFGCMD_RESTORE => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_TABLESPACE_MAP_ALL =>
@ -2622,7 +2881,11 @@ my %hConfigDefine =
&CFGDEF_COMMAND =>
{
&CFGCMD_RESTORE => {},
}
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_TABLESPACE_MAP =>
@ -2634,6 +2897,10 @@ my %hConfigDefine =
{
&CFGCMD_RESTORE => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
&CFGOPT_RECOVERY_OPTION =>
@ -2658,6 +2925,10 @@ my %hConfigDefine =
&CFGOPTVAL_RESTORE_TYPE_XID,
],
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
},
},
# Stanza options
@ -2675,20 +2946,33 @@ my %hConfigDefine =
&CFGCMD_ARCHIVE_PUSH => {},
&CFGCMD_BACKUP =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_LOCAL => {},
&CFGCMD_ROLE_REMOTE => {},
},
},
&CFGCMD_CHECK =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_REMOTE => {},
},
},
&CFGCMD_RESTORE => {},
&CFGCMD_STANZA_CREATE =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_REMOTE => {},
},
},
&CFGCMD_STANZA_UPGRADE =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_REMOTE => {},
},
},
},
},
@ -2737,6 +3021,12 @@ my %hConfigDefine =
'db?-host' => {&CFGDEF_RESET => false},
},
&CFGDEF_COMMAND => CFGOPT_PG_LOCAL,
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
&CFGDEF_DEPEND =>
{
&CFGDEF_DEPEND_OPTION => CFGOPT_PG_LOCAL,
@ -2766,6 +3056,12 @@ my %hConfigDefine =
&CFGCMD_START => {},
&CFGCMD_STOP => {},
},
&CFGDEF_COMMAND_ROLE =>
{
&CFGCMD_ROLE_DEFAULT => {},
&CFGCMD_ROLE_ASYNC => {},
&CFGCMD_ROLE_LOCAL => {},
},
&CFGDEF_DEPEND =>
{
&CFGDEF_DEPEND_OPTION => CFGOPT_PG_HOST
@ -3056,7 +3352,6 @@ foreach my $strKey (sort(keys(%hConfigDefine)))
$rhOption->{&CFGDEF_PREFIX} = $rhGroup->{&CFGDEF_PREFIX};
}
# If command is not specified then the option is valid for all commands except version and help
if (!defined($rhOption->{&CFGDEF_COMMAND}))
{
@ -3165,6 +3460,51 @@ foreach my $strKey (sort(keys(%hConfigDefine)))
}
}
# Generate valid command roles for each option
foreach my $strOption (sort(keys(%hConfigDefine)))
{
my $rhOption = $hConfigDefine{$strOption};
# Generate valid command roles for each command in the option
foreach my $strCommand (sort(keys(%{$rhOption->{&CFGDEF_COMMAND}})))
{
# If command roles are defined in the option command override then check that they are valid
if (defined($rhOption->{&CFGDEF_COMMAND}{$strCommand}{&CFGDEF_COMMAND_ROLE}))
{
foreach my $strCommandRole (sort(keys(%{$rhOption->{&CFGDEF_COMMAND}{$strCommand}{&CFGDEF_COMMAND_ROLE}})))
{
if (!defined($rhCommandDefine->{$strCommand}{&CFGDEF_COMMAND_ROLE}{$strCommandRole}))
{
confess &log(
ASSERT, "option '${strOption}', command '${strCommand}' has invalid command role '${strCommandRole}'");
}
}
}
# Else if the option has command roles defined then use the intersection of command roles with the command
elsif (defined($rhOption->{&CFGDEF_COMMAND_ROLE}))
{
foreach my $strCommandRole (sort(keys(%{$rhOption->{&CFGDEF_COMMAND_ROLE}})))
{
if (defined($rhCommandDefine->{$strCommand}{&CFGDEF_COMMAND_ROLE}{$strCommandRole}))
{
$rhOption->{&CFGDEF_COMMAND}{$strCommand}{&CFGDEF_COMMAND_ROLE}{$strCommandRole} = {};
}
}
}
# Else copy the command roles from the command
else
{
foreach my $strCommandRole (sort(keys(%{$rhCommandDefine->{$strCommand}{&CFGDEF_COMMAND_ROLE}})))
{
$rhOption->{&CFGDEF_COMMAND}{$strCommand}{&CFGDEF_COMMAND_ROLE}{$strCommandRole} = {};
}
}
}
# Remove option command roles so they don't accidentally get used in processing (since they were copied to option commands)
delete($rhOption->{&CFGDEF_COMMAND_ROLE});
}
####################################################################################################################################
# Get option definition
####################################################################################################################################

View File

@ -23,6 +23,18 @@
<p>Add <id>pack</id> type.</p>
</release-item>
<release-item>
<commit subject="Allow option validity to be determined by command role."/>
<commit subject="Update unit tests for stricter option validity."/>
<commit subject="Limit option validity by command role."/>
<release-item-contributor-list>
<release-item-reviewer id="cynthia.shang"/>
</release-item-contributor-list>
<p>Allow option validity to be determined by command role.</p>
</release-item>
<release-item>
<release-item-contributor-list>
<release-item-reviewer id="cynthia.shang"/>

View File

@ -134,7 +134,7 @@ cfgLoadUpdateOption(void)
}
// Warn when repo-retention-full is not set on a configured repo
if (!cfgCommandHelp() && cfgOptionValid(cfgOptRepoRetentionFullType) && cfgCommandRole() == cfgCmdRoleDefault)
if (!cfgCommandHelp() && cfgOptionValid(cfgOptRepoRetentionFullType))
{
for (unsigned int optionIdx = 0; optionIdx < cfgOptionGroupIdxTotal(cfgOptGrpRepo); optionIdx++)
{

File diff suppressed because it is too large Load Diff

View File

@ -341,43 +341,30 @@ protocolRemoteParam(ProtocolStorageType protocolStorageType, unsigned int hostId
cfgOptionIdxSource(optConfigPath, hostIdx) != cfgSourceDefault ? VARSTR(cfgOptionIdxStr(optConfigPath, hostIdx)) : NULL);
// Update/remove repo/pg options that are sent to the remote
const String *repoHostPrefix = STR(cfgParseOptionName(cfgOptRepoHost));
const String *pgHostPrefix = STR(cfgParseOptionName(cfgOptPgHost));
for (ConfigOption optionId = 0; optionId < CFG_OPTION_TOTAL; optionId++)
{
// Skip options that are not part of a group
if (!cfgOptionGroup(optionId))
continue;
const String *optionDefName = STR(cfgParseOptionName(optionId));
unsigned int groupId = cfgOptionGroupId(optionId);
bool remove = false;
bool skipHostZero = false;
// Remove repo host options that are not needed on the remote. The remote is not expecting to see host settings so it could
// get confused about the locality of the repo, i.e. local or remote. Also remove repo options when the remote type is pg
// since they won't be used.
if (groupId == cfgOptGrpRepo)
// Remove repo options when the remote type is pg since they won't be used
if (cfgOptionGroupId(optionId) == cfgOptGrpRepo)
{
remove = protocolStorageType == protocolStorageTypePg || strBeginsWith(optionDefName, repoHostPrefix);
remove = protocolStorageType == protocolStorageTypePg;
}
// Remove pg host options that are not needed on the remote
else
{
ASSERT(groupId == cfgOptGrpPg);
ASSERT(cfgOptionGroupId(optionId) == cfgOptGrpPg);
// Remove unrequired/defaulted pg options when the remote type is repo since they won't be used
if (protocolStorageType == protocolStorageTypeRepo)
{
remove = !cfgParseOptionRequired(cfgCommand(), optionId) || cfgParseOptionDefault(cfgCommand(), optionId) != NULL;
}
// The remote is not expecting to see host settings so it could get confused about the locality of pg, i.e. local or
// remote.
else if (strBeginsWith(optionDefName, pgHostPrefix))
{
remove = true;
}
// Move pg options to host index 0 (key 1) so they will be in the default index on the remote host
else
{

View File

@ -36,7 +36,7 @@ testRun(void)
TEST_RESULT_STR(
strLstJoin(cfgExecParam(cfgCmdArchiveGet, cfgCmdRoleAsync, NULL, false, true), "|"),
strNewFmt(
"--archive-async|--archive-timeout=5|--no-config|--exec-id=1-test|--log-subprocess|--reset-neutral-umask"
"--archive-async|--no-config|--exec-id=1-test|--log-subprocess|--reset-neutral-umask"
"|--pg1-path=\"%s/db path\"|--pg2-path=/db2|--repo1-path=%s/repo|--stanza=test1|archive-get:async",
testPath(), testPath()),
"exec archive-get -> archive-get:async");

View File

@ -188,7 +188,6 @@ testRun(void)
hrnCfgArgRawZ(argList, cfgOptPg, "7");
strLstAddZ(argList, "--" CFGOPT_REMOTE_TYPE "=" PROTOCOL_REMOTE_TYPE_PG);
strLstAddZ(argList, "--process=0");
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, CFGCMD_BACKUP ":" CONFIG_COMMAND_ROLE_LOCAL);
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
@ -245,7 +244,7 @@ testRun(void)
TEST_RESULT_STR_Z(
strLstJoin(protocolLocalParam(protocolStorageTypePg, 0, 1), "|"),
"--exec-id=1-test|--log-level-console=off|--log-level-file=info|--log-level-stderr=error|--log-subprocess|--pg=1"
"|--pg1-path=/pg|--process=1|--remote-type=pg|--repo1-retention-full=1|--stanza=test1|backup:local",
"|--pg1-path=/pg|--process=1|--remote-type=pg|--stanza=test1|backup:local",
"local pg protocol params");
}
@ -346,7 +345,6 @@ testRun(void)
strLstAddZ(argList, "--pg2-path=/path/to/2");
strLstAddZ(argList, "--pg2-host=pg2-host");
strLstAddZ(argList, "--" CFGOPT_REMOTE_TYPE "=" PROTOCOL_REMOTE_TYPE_PG);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, CFGCMD_BACKUP ":" CONFIG_COMMAND_ROLE_LOCAL);
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));
@ -369,7 +367,6 @@ testRun(void)
strLstAddZ(argList, "--pg3-socket-path=/socket3");
strLstAddZ(argList, "--pg3-port=3333");
strLstAddZ(argList, "--" CFGOPT_REMOTE_TYPE "=" PROTOCOL_REMOTE_TYPE_PG);
hrnCfgArgRawZ(argList, cfgOptRepoRetentionFull, "1");
strLstAddZ(argList, CFGCMD_BACKUP ":" CONFIG_COMMAND_ROLE_LOCAL);
harnessCfgLoadRaw(strLstSize(argList), strLstPtr(argList));