mirror of
https://github.com/ovh/the-bastion.git
synced 2025-02-28 17:44:16 +08:00
chore: check for spurious args in all helpers
This commit is contained in:
parent
90dbe04dde
commit
7cc350b40d
29 changed files with 66 additions and 3 deletions
|
@ -39,6 +39,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $action or not $ip or not $account or not $group) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'action' or 'ip' or 'account' or 'group'");
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ eval {
|
|||
};
|
||||
if ($@) { die $@ }
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$result) {
|
||||
local $" = ", ";
|
||||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
|
|
|
@ -35,6 +35,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account || !$type) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'type'");
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $size or not $account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'size' or 'account'");
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account && !$all) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'all'");
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account || !@modify) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'modify'");
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $account or not $command or not $action) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account', 'command' or 'action'");
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ eval {
|
|||
};
|
||||
if ($@) { die $@ }
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$result) {
|
||||
local $" = ", ";
|
||||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
|
|
|
@ -37,6 +37,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account || !$policy || !$step) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'modify' or 'step'");
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $action) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'action'");
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $ip or not $group or not $action) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'ip' or 'group' or 'action'");
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $account or not $group or not $action) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account', 'group' or 'action'");
|
||||
}
|
||||
|
|
|
@ -39,6 +39,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$group || !$owner) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group' or 'owner'");
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$group || !$id) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group' or 'id'");
|
||||
}
|
||||
|
|
|
@ -32,6 +32,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$group) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group'");
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$size || !$algo || !$group) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'size', 'algo' or 'group'");
|
||||
}
|
||||
|
|
|
@ -33,6 +33,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $size or not $group) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'size' or 'group'");
|
||||
}
|
||||
|
|
|
@ -34,6 +34,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$group) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'group'");
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
osh_debug("groupSetRole: checking preconditions");
|
||||
$fnret = OVH::Bastion::Plugin::groupSetRole::preconditions(self => $self, account => $account, group => $group, action => $action, type => $type, sudo => 1, silentoverride => 1);
|
||||
osh_debug("groupSetRole: checking preconditions result: $fnret");
|
||||
|
|
|
@ -31,6 +31,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (!$account || !defined $step) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account' or 'step'");
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@ if (!$result) {
|
|||
HEXIT('ERR_BAD_OPTIONS', msg => "Error parsing options: @optwarns");
|
||||
}
|
||||
|
||||
OVH::Bastion::Helper::check_spurious_args();
|
||||
|
||||
if (not $account) {
|
||||
HEXIT('ERR_MISSING_PARAMETER', msg => "Missing argument 'account'");
|
||||
}
|
||||
|
|
|
@ -134,9 +134,9 @@ push @command, "--type", "normal";
|
|||
push @command, "--account", $account;
|
||||
push @command, "--pubKey", $pubKey if !$noKey;
|
||||
push @command, "--always-active" if $alwaysActive;
|
||||
push @command, "--comment", $comment if $comment;
|
||||
push @command, "--uid", $uid if defined $uid;
|
||||
push @command, "--osh-only", $oshOnly if $oshOnly;
|
||||
push @command, "--comment", $comment if $comment;
|
||||
push @command, "--uid", $uid if defined $uid;
|
||||
push @command, "--osh-only", if $oshOnly;
|
||||
push @command, "--max-inactive-days", $maxInactiveDays if defined $maxInactiveDays;
|
||||
push @command, "--uid-auto" if $uidAuto;
|
||||
push @command, "--immutable-key" if $immutableKey;
|
||||
|
|
|
@ -37,6 +37,15 @@ sub HEXIT { ## no critic (ArgUnpacking)
|
|||
exit 0;
|
||||
}
|
||||
|
||||
# Used after Getopt::Long::GetOptions() in each helper, to ensure there are no unparsed/spurious args
|
||||
sub check_spurious_args {
|
||||
if (@ARGV) {
|
||||
local $" = ", ";
|
||||
warn_syslog("Spurious arguments on command line: @ARGV");
|
||||
HEXIT('ERR_BAD_OPTIONS', msg => "Spurious arguments on command line: @ARGV");
|
||||
}
|
||||
}
|
||||
|
||||
#
|
||||
# This code has to be ran for all helpers before they attempt to do anything useful,
|
||||
# and as we're only use'd by helpers, we include it here directly on top-level.
|
||||
|
|
Loading…
Reference in a new issue