mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Improves wizard argument escaping, duplicates and arg conversion
Fix #61
This commit is contained in:
parent
d205989007
commit
efdca87b7e
2 changed files with 197 additions and 81 deletions
|
|
@ -112,6 +112,10 @@ function Start-IcingaAgentDirectorWizard()
|
|||
$DirectorOverrideArgs.Add(
|
||||
'Ticket', $IcingaTicket
|
||||
);
|
||||
$DirectorOverrideArgs.Add(
|
||||
'OverrideDirectorVars', 0
|
||||
);
|
||||
|
||||
if ([string]::IsNullOrEmpty($TemplateKey) -eq $FALSE) {
|
||||
$DirectorOverrideArgs.Add(
|
||||
'SelfServiceAPIKey', $TemplateKey
|
||||
|
|
@ -136,13 +140,16 @@ function Start-IcingaDirectorAPIArgumentOverride()
|
|||
|
||||
foreach ($entry in $Arguments.Keys) {
|
||||
$value = (Get-IcingaAgentInstallerAnswerInput -Prompt ([string]::Format('Please enter the new value for the argument "{0}"', $entry)) -Default 'v' -DefaultInput $Arguments[$entry]).answer;
|
||||
if ($Arguments[$entry] -is [array]) {
|
||||
if ($Arguments[$entry] -is [array] -Or ($value -is [string] -And $value.Contains(','))) {
|
||||
if ([string]::IsNullOrEmpty($value) -eq $FALSE) {
|
||||
while ($value.Contains(', ')) {
|
||||
$value = $value.Replace(', ', ',');
|
||||
}
|
||||
[array]$tmpArray = $value.Split(',');
|
||||
if ($null -ne (Compare-Object -ReferenceObject $Arguments[$entry] -DifferenceObject $tmpArray)) {
|
||||
$NewArguments.Add(
|
||||
$entry,
|
||||
([string]::Join(',', $tmpArray))
|
||||
$tmpArray
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,9 +102,6 @@ function Start-IcingaAgentInstallWizard()
|
|||
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AcceptConnections' -Value $AcceptConnections -InstallerArguments $InstallerArguments;
|
||||
$AcceptConnections = $Result.Value;
|
||||
$InstallerArguments = $Result.Args;
|
||||
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'AddFirewallRule' -Value $AddFirewallRule -InstallerArguments $InstallerArguments;
|
||||
$AddFirewallRule = $Result.Value;
|
||||
$InstallerArguments = $Result.Args;
|
||||
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'ServiceUser' -Value $ServiceUser -InstallerArguments $InstallerArguments;
|
||||
$ServiceUser = $Result.Value;
|
||||
$InstallerArguments = $Result.Args;
|
||||
|
|
@ -132,6 +129,9 @@ function Start-IcingaAgentInstallWizard()
|
|||
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'EndpointConnections' -Value $EndpointConnections -InstallerArguments $InstallerArguments;
|
||||
$EndpointConnections = $Result.Value;
|
||||
$InstallerArguments = $Result.Args;
|
||||
$Result = Set-IcingaWizardArgument -DirectorArgs $DirectorArgs -WizardArg 'OverrideDirectorVars' -Value $OverrideDirectorVars -InstallerArguments $InstallerArguments;
|
||||
$OverrideDirectorVars = $Result.Value;
|
||||
$InstallerArguments = $Result.Args;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +265,9 @@ function Start-IcingaAgentInstallWizard()
|
|||
}
|
||||
} elseif ($AcceptConnections) {
|
||||
$CanConnectToParent = $TRUE;
|
||||
$InstallerArguments += ("-AcceptConnections $AcceptConnections");
|
||||
if ((Test-IcingaWizardArgument -Argument 'AcceptConnections') -eq $FALSE) {
|
||||
$InstallerArguments += ([string]::Format('-AcceptConnections {0}', [int]$AcceptConnections));
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -eq $AddFirewallRule) {
|
||||
|
|
@ -428,6 +430,10 @@ function Start-IcingaAgentInstallWizard()
|
|||
$result = Install-IcingaFrameworkPlugins -PluginsUrl $PluginsUrl;
|
||||
$InstallerArguments += "-InstallFrameworkPlugins 1";
|
||||
$InstallerArguments += "-PluginsUrl '$PluginsUrl'";
|
||||
} else {
|
||||
if ((Test-IcingaWizardArgument -Argument 'InstallFrameworkPlugins') -eq $FALSE) {
|
||||
$InstallerArguments += "-InstallFrameworkPlugins 0";
|
||||
}
|
||||
}
|
||||
|
||||
if ($null -eq $InstallFrameworkService) {
|
||||
|
|
@ -495,6 +501,106 @@ function Start-IcingaAgentInstallWizard()
|
|||
}
|
||||
}
|
||||
|
||||
function Add-InstallerArgument()
|
||||
{
|
||||
param(
|
||||
$InstallerArguments,
|
||||
[string]$Key,
|
||||
$Value,
|
||||
[switch]$ReturnValue
|
||||
);
|
||||
|
||||
[bool]$IsArray = $Value -is [array];
|
||||
|
||||
# Check for arrays
|
||||
if ($IsArray) {
|
||||
[array]$NewArray = @();
|
||||
foreach ($entry in $Value) {
|
||||
$NewArray += Add-InstallerArgument -Value $entry -ReturnValue;
|
||||
}
|
||||
|
||||
if ($ReturnValue) {
|
||||
return ([string]::Join(',', $NewArray));
|
||||
}
|
||||
|
||||
$InstallerArguments += [string]::Format(
|
||||
'-{0} {1}',
|
||||
$Key,
|
||||
[string]::Join(',', $NewArray)
|
||||
);
|
||||
|
||||
return $InstallerArguments;
|
||||
}
|
||||
|
||||
# Check for integers
|
||||
if (Test-Numeric $Value) {
|
||||
if ($ReturnValue) {
|
||||
return $Value;
|
||||
}
|
||||
|
||||
$InstallerArguments += [string]::Format(
|
||||
'-{0} {1}',
|
||||
$Key,
|
||||
$Value
|
||||
);
|
||||
|
||||
return $InstallerArguments;
|
||||
}
|
||||
|
||||
# Check for integer conversion
|
||||
$IntValue = ConvertTo-Integer -Value $Value;
|
||||
if ([string]$Value -ne [string]$IntValue) {
|
||||
if ($ReturnValue) {
|
||||
return $IntValue;
|
||||
}
|
||||
|
||||
$InstallerArguments += [string]::Format(
|
||||
'-{0} {1}',
|
||||
$Key,
|
||||
$IntValue
|
||||
);
|
||||
|
||||
return $InstallerArguments;
|
||||
}
|
||||
|
||||
$Type = $Value.GetType().Name;
|
||||
$NewValue = $null;
|
||||
|
||||
if ($Type -eq 'String') {
|
||||
$NewValue = [string]::Format(
|
||||
"'{0}'",
|
||||
$Value
|
||||
);
|
||||
|
||||
if ($ReturnValue) {
|
||||
return $NewValue;
|
||||
}
|
||||
|
||||
$InstallerArguments += [string]::Format(
|
||||
'-{0} {1}',
|
||||
$Key,
|
||||
$NewValue
|
||||
);
|
||||
|
||||
return $InstallerArguments;
|
||||
}
|
||||
}
|
||||
|
||||
function Test-IcingaWizardArgument()
|
||||
{
|
||||
param(
|
||||
[string]$Argument
|
||||
);
|
||||
|
||||
foreach ($entry in $InstallerArguments) {
|
||||
if ($entry -like [string]::Format('-{0} *', $Argument)) {
|
||||
return $TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return $FALSE;
|
||||
}
|
||||
|
||||
function Set-IcingaWizardArgument()
|
||||
{
|
||||
param(
|
||||
|
|
@ -506,11 +612,12 @@ function Set-IcingaWizardArgument()
|
|||
);
|
||||
|
||||
if ($DirectorArgs.Overrides.ContainsKey($WizardArg)) {
|
||||
$Override = $DirectorArgs.Overrides[$WizardArg];
|
||||
if ($Value -is [array]) {
|
||||
$Override = [string]::Join(',', $Override);
|
||||
}
|
||||
$InstallerArguments += "-$WizardArg $Override";
|
||||
|
||||
$InstallerArguments = Add-InstallerArgument `
|
||||
-InstallerArguments $InstallerArguments `
|
||||
-Key $WizardArg `
|
||||
-Value $DirectorArgs.Overrides[$WizardArg];
|
||||
|
||||
return @{
|
||||
'Value' = $DirectorArgs.Overrides[$WizardArg];
|
||||
'Args' = $InstallerArguments;
|
||||
|
|
@ -523,11 +630,12 @@ function Set-IcingaWizardArgument()
|
|||
$RetValue = $DirectorArgs.Arguments[$WizardArg];
|
||||
} else {
|
||||
if ($null -ne $Value -Or [string]::IsNullOrEmpty($Value) -eq $FALSE) {
|
||||
$TmpValue = $Value;
|
||||
if ($Value -is [array]) {
|
||||
$TmpValue = [string]::Join(',', $TmpValue);
|
||||
}
|
||||
$InstallerArguments += "-$WizardArg $TmpValue";
|
||||
|
||||
$InstallerArguments = Add-InstallerArgument `
|
||||
-InstallerArguments $InstallerArguments `
|
||||
-Key $WizardArg `
|
||||
-Value $Value;
|
||||
|
||||
return @{
|
||||
'Value' = $Value;
|
||||
'Args' = $InstallerArguments;
|
||||
|
|
@ -541,11 +649,12 @@ function Set-IcingaWizardArgument()
|
|||
}
|
||||
|
||||
if ([string]::IsNullOrEmpty($Value) -eq $FALSE) {
|
||||
$TmpValue = $Value;
|
||||
if ($Value -is [array]) {
|
||||
$TmpValue = [string]::Join(',', $Value);
|
||||
}
|
||||
$InstallerArguments += "-$WizardArg $TmpValue";
|
||||
|
||||
$InstallerArguments = Add-InstallerArgument `
|
||||
-InstallerArguments $InstallerArguments `
|
||||
-Key $WizardArg `
|
||||
-Value $Value;
|
||||
|
||||
return @{
|
||||
'Value' = $Value;
|
||||
'Args' = $InstallerArguments;
|
||||
|
|
|
|||
Loading…
Reference in a new issue