diff --git a/Private/Write-JBossClientCmd.ps1 b/Private/Write-JBossClientCmd.ps1 index f8cca14..875b920 100644 --- a/Private/Write-JBossClientCmd.ps1 +++ b/Private/Write-JBossClientCmd.ps1 @@ -25,8 +25,9 @@ function Write-JBossClientCmd { File name: Write-JBossClientCmd.ps1 Author: Florian Carrier Creation date: 21/10/2019 - Last modified: 15/01/2020 + Last modified: 28/01/2020 TODO: - Handle path with spaces with batch script + - Prevent pause with batch script #> [CmdletBinding ( SupportsShouldProcess = $true @@ -34,7 +35,7 @@ function Write-JBossClientCmd { Param ( [Parameter ( Position = 1, - Mandatory = $false, + Mandatory = $true, HelpMessage = "Path to JBoss client" )] [ValidateNotNUllOrEmpty ()] @@ -74,13 +75,6 @@ function Write-JBossClientCmd { Begin { # Get global preference variables Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState - # JBoss client path - if ($PSBoundParameters.ContainsKey('Path')) { - $JBossCliPath = $Path - } else { - # Use PATH environment variable - $JBossCliPath = 'jboss-cli.bat' - } # Batch command error stream redirection if ($Redirect) { $Redirection = "2>&1" @@ -113,10 +107,6 @@ function Write-JBossClientCmd { $JBossCliCmd = "& ""$Path"" $CommandLine".Trim() } default { - # If path exists - if ($JBossClient) { - Write-Log -Type "ERROR" -Object "Unsupported JBoss client type ($Extension)" - } Write-Log -Type "WARN" -Object "Defaulting to Windows Command line." $JBossCliCmd = "cmd /c '""$Path"" $CommandLine $Redirection'".Trim() } diff --git a/Public/Invoke-JBossClient.ps1 b/Public/Invoke-JBossClient.ps1 index 7a96496..416d407 100644 --- a/Public/Invoke-JBossClient.ps1 +++ b/Public/Invoke-JBossClient.ps1 @@ -25,7 +25,7 @@ function Invoke-JBossClient { File name: Invoke-JBossClient.ps1 Author: Florian Carrier Creation date: 21/10/2019 - Last modified: 22/01/2020 + Last modified: 28/01/2020 #> [CmdletBinding ( SupportsShouldProcess = $true @@ -33,7 +33,7 @@ function Invoke-JBossClient { Param ( [Parameter ( Position = 1, - Mandatory = $true, + Mandatory = $false, HelpMessage = "Path to the JBoss client" )] [ValidateNotNUllOrEmpty ()] @@ -75,6 +75,18 @@ function Invoke-JBossClient { Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState } Process { + # JBoss client path + if ($PSBoundParameters.ContainsKey('Path')) { + # Check path + if (-Not (Test-Path -Path $Path)) { + return "Path not found $Path" + exit 1 + } + } else { + # Use PATH environment variable + Write-Log -Type "WARN" -Object "No path was provided, using PATH environment variable" + $Path = 'jboss-cli.ps1' + } # Check controller if ($PSBoundParameters.ContainsKey("Controller")) { # Remote controller @@ -96,8 +108,13 @@ function Invoke-JBossClient { } } # Execute command - $JBossCliLog = Invoke-Expression -Command $JBossCliCmd | Out-String - Write-Log -Type "DEBUG" -Object $JBossCliLog + try { + $JBossCliLog = Invoke-Expression -Command $JBossCliCmd | Out-String + Write-Log -Type "DEBUG" -Object $JBossCliLog + } catch { + return $Error[0].Exception + exit 1 + } # Return log return $JBossCliLog } diff --git a/Public/Invoke-ReloadServer.ps1 b/Public/Invoke-ReloadServer.ps1 index 2f212e2..cc91d0f 100644 --- a/Public/Invoke-ReloadServer.ps1 +++ b/Public/Invoke-ReloadServer.ps1 @@ -10,7 +10,7 @@ function Invoke-ReloadServer { The path parameter corresponds to the path to the JBoss client. .PARAMETER Controller - The controller parameter corresponds to the hostname and port of the JBoss host. + The optional controller parameter corresponds to the hostname and port of the JBoss host. .PARAMETER Credentials The optional credentials parameter correspond to the credentials of the account to use to connect to JBoss. @@ -30,7 +30,7 @@ function Invoke-ReloadServer { File name: Invoke-ReloadServer.ps1 Author: Florian Carrier Creation date: 02/12/2019 - Last modified: 10/01/2020 + Last modified: 28/01/2020 .LINK Invoke-JBossClient @@ -41,7 +41,7 @@ function Invoke-ReloadServer { Param ( [Parameter ( Position = 1, - Mandatory = $true, + Mandatory = $false, HelpMessage = "Path to the JBoss client" )] [ValidateNotNUllOrEmpty ()] @@ -49,7 +49,7 @@ function Invoke-ReloadServer { $Path, [Parameter ( Position = 2, - Mandatory = $true, + Mandatory = $false, HelpMessage = "Controller" )] # TODO validate format @@ -72,11 +72,35 @@ function Invoke-ReloadServer { Process { # Define command $Command = ':reload()' - # Execute command - if ($PSBoundParameters.ContainsKey('Credentials')) { - Invoke-JBossClient -Path $Path -Controller $Controller -Command $Command -Credentials $Credentials -Redirect + # Run command + if ($PSBoundParameters.ContainsKey("Path")) { + if ($PSBoundParameters.ContainsKey("Controller")) { + if ($PSBoundParameters.ContainsKey("Credentials")) { + Invoke-JBossClient -Path $Path -Controller $Controller -Command $Command -Credentials $Credentials + } else { + Invoke-JBossClient -Path $Path -Controller $Controller -Command $Command + } + } else { + if ($PSBoundParameters.ContainsKey("Credentials")) { + Invoke-JBossClient -Path $Path -Command $Command -Credentials $Credentials + } else { + Invoke-JBossClient -Path $Path -Command $Command + } + } } else { - Invoke-JBossClient -Path $Path -Controller $Controller -Command $Command -Redirect + if ($PSBoundParameters.ContainsKey("Controller")) { + if ($PSBoundParameters.ContainsKey("Credentials")) { + Invoke-JBossClient -Controller $Controller -Command $Command -Credentials $Credentials + } else { + Invoke-JBossClient -Controller $Controller -Command $Command + } + } else { + if ($PSBoundParameters.ContainsKey("Credentials")) { + Invoke-JBossClient -Command $Command -Credentials $Credentials + } else { + Invoke-JBossClient -Command $Command + } + } } } } diff --git a/Public/Test-JBossClientOutcome.ps1 b/Public/Test-JBossClientOutcome.ps1 index 6cdba49..d5c2dfa 100644 --- a/Public/Test-JBossClientOutcome.ps1 +++ b/Public/Test-JBossClientOutcome.ps1 @@ -13,7 +13,7 @@ function Test-JBossClientOutcome { File name: Test-JBossClientOutcome.ps1 Author: Florian Carrier Creation date: 10/01/2020 - Last modified: 10/01/2020 + Last modified: 26/02/2020 #> [CmdletBinding()] Param ( @@ -24,8 +24,8 @@ function Test-JBossClientOutcome { ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true )] - [ValidateNotNullOrEmpty()] - [Object] + # [ValidateNotNullOrEmpty()] + [System.Object] $Log ) Begin { @@ -33,13 +33,18 @@ function Test-JBossClientOutcome { Get-CallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState } Process { - # Check JBoss client operation outcome - if (Select-String -InputObject $Log -Pattern '"outcome" => "success"' -SimpleMatch -Quiet) { - # If outcome is successfull - return $true - } else { - # If outcome is failed or an error occured + # Check if log contains information + if (($Log -eq $null) -Or ($Log -eq "")) { return $false + } else { + # Check JBoss client operation outcome + if (Select-String -InputObject $Log -Pattern '"outcome" => "success"' -SimpleMatch -Quiet) { + # If outcome is successfull + return $true + } else { + # If outcome is failed or an error occured + return $false + } } } } diff --git a/Public/Test-Resource.ps1 b/Public/Test-Resource.ps1 index 3374aee..a1698be 100644 --- a/Public/Test-Resource.ps1 +++ b/Public/Test-Resource.ps1 @@ -28,7 +28,8 @@ function Test-Resource { File name: Test-Resource.ps1 Author: Florian Carrier Creation date: 14/01/2020 - Last modified: 14/01/2020 + Last modified: 26/02/2020 + TODO Wait for return from JBoss client to prevnt issue "Cannot validate argument on parameter 'Log'. The argument is null or empty." .LINK Invoke-JBossClient diff --git a/README.md b/README.md index 87e42f1..58ba482 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,8 @@ WildFly PowerShell Module (PSWF) is a framework to manage WildFly using PowerShe ### Installation There are two ways of setting up the WildFly PowerShell Module on your system: -1. Download the PSWF module from the [Github repository](https://github.com/Akaizoku/PSWF); -1. Install the PSWF module from the [PowerShell Gallery](https://www.powershellgallery.com/packages/PSWF). +1. Download the PSWF module from the [Github repository](https://github.com/Akaizoku/PSWF); +2. Install the PSWF module from the [PowerShell Gallery](https://www.powershellgallery.com/packages/PSWF). ```powershell Install-Module -Name "PSWF" -Repository "PSGallery" @@ -37,42 +37,55 @@ Import-Module -Name "PSWF" Get-Command -Module "PSWF" ``` -| CommandType | Name | Version | Source | -| ----------- | ---- | ------- | ------ | -| Function | Add-DataSource | 1.0.0 | PSWF | -| Function | Add-JDBCDriver | 1.0.0 | PSWF | -| Function | Add-Module | 1.0.0 | PSWF | -| Function | Add-SecurityRole | 1.0.0 | PSWF | -| Function | Add-User | 1.0.0 | PSWF | -| Function | Add-UserGroupRole | 1.0.0 | PSWF | -| Function | Disable-RBAC | 1.0.0 | PSWF | -| Function | Enable-RBAC | 1.0.0 | PSWF | -| Function | Grant-SecurityRole | 1.0.0 | PSWF | -| Function | Invoke-DeployWAR | 1.0.0 | PSWF | -| Function | Invoke-JBossClient | 1.0.0 | PSWF | -| Function | Invoke-ReloadServer | 1.0.0 | PSWF | -| Function | Invoke-UndeployWAR | 1.0.0 | PSWF | -| Function | Read-DeploymentStatus | 1.0.0 | PSWF | -| Function | Read-Resource | 1.0.0 | PSWF | -| Function | Read-ServerState | 1.0.0 | PSWF | -| Function | Remove-DataSource | 1.0.0 | PSWF | -| Function | Remove-JDBCDriver | 1.0.0 | PSWF | -| Function | Remove-Module | 1.0.0 | PSWF | -| Function | Remove-Resource | 1.0.0 | PSWF | -| Function | Remove-SecurityRole | 1.0.0 | PSWF | -| Function | Remove-User | 1.0.0 | PSWF | -| Function | Remove-UserGroupRole | 1.0.0 | PSWF | -| Function | Resolve-ServerState | 1.0.0 | PSWF | -| Function | Set-Interface | 1.0.0 | PSWF | -| Function | Set-JavaOptions | 1.0.0 | PSWF | -| Function | Set-PortNumber | 1.0.0 | PSWF | -| Function | Set-PortOffset | 1.0.0 | PSWF | -| Function | Test-JBossClientOutcome | 1.0.0 | PSWF | -| Function | Test-Module | 1.0.0 | PSWF | -| Function | Test-SecurityRole | 1.0.0 | PSWF | -| Function | Test-ServerState | 1.0.0 | PSWF | -| Function | Test-User | 1.0.0 | PSWF | -| Function | Test-UserGroupRole | 1.0.0 | PSWF | +| CommandType | Name | Version | Source | +| ----------- | -------------------------- | ------- | ------ | +| Function | Add-DataSource | 1.0.1 | PSWF | +| Function | Add-JDBCDriver | 1.0.1 | PSWF | +| Function | Add-Module | 1.0.1 | PSWF | +| Function | Add-Resource | 1.0.1 | PSWF | +| Function | Add-SecurityDomain | 1.0.1 | PSWF | +| Function | Add-SecurityRole | 1.0.1 | PSWF | +| Function | Add-User | 1.0.1 | PSWF | +| Function | Add-UserGroupRole | 1.0.1 | PSWF | +| Function | Disable-DataSource | 1.0.1 | PSWF | +| Function | Disable-Deployment | 1.0.1 | PSWF | +| Function | Disable-RBAC | 1.0.1 | PSWF | +| Function | Enable-DataSource | 1.0.1 | PSWF | +| Function | Enable-Deployment | 1.0.1 | PSWF | +| Function | Enable-RBAC | 1.0.1 | PSWF | +| Function | Get-DeploymentStatus | 1.0.1 | PSWF | +| Function | Grant-SecurityRole | 1.0.1 | PSWF | +| Function | Invoke-DeployApplication | 1.0.1 | PSWF | +| Function | Invoke-JBossClient | 1.0.1 | PSWF | +| Function | Invoke-ReloadServer | 1.0.1 | PSWF | +| Function | Invoke-UndeployApplication | 1.0.1 | PSWF | +| Function | Read-Attribute | 1.0.1 | PSWF | +| Function | Read-DeploymentStatus | 1.0.1 | PSWF | +| Function | Read-Resource | 1.0.1 | PSWF | +| Function | Read-SecurityDomain | 1.0.1 | PSWF | +| Function | Read-ServerState | 1.0.1 | PSWF | +| Function | Remove-Attribute | 1.0.1 | PSWF | +| Function | Remove-DataSource | 1.0.1 | PSWF | +| Function | Remove-JDBCDriver | 1.0.1 | PSWF | +| Function | Remove-Module | 1.0.1 | PSWF | +| Function | Remove-Resource | 1.0.1 | PSWF | +| Function | Remove-SecurityDomain | 1.0.1 | PSWF | +| Function | Remove-SecurityRole | 1.0.1 | PSWF | +| Function | Remove-User | 1.0.1 | PSWF | +| Function | Remove-UserGroupRole | 1.0.1 | PSWF | +| Function | Test-DataSource | 1.0.1 | PSWF | +| Function | Test-DataSourceConnection | 1.0.1 | PSWF | +| Function | Test-Deployment | 1.0.1 | PSWF | +| Function | Test-JBossClientOutcome | 1.0.1 | PSWF | +| Function | Test-JDBCDriver | 1.0.1 | PSWF | +| Function | Test-Module | 1.0.1 | PSWF | +| Function | Test-Resource | 1.0.1 | PSWF | +| Function | Test-SecurityDomain | 1.0.1 | PSWF | +| Function | Test-SecurityRole | 1.0.1 | PSWF | +| Function | Test-ServerState | 1.0.1 | PSWF | +| Function | Test-User | 1.0.1 | PSWF | +| Function | Test-UserGroupRole | 1.0.1 | PSWF | +| Function | Write-Attribute | 1.0.1 | PSWF | ## Dependencies