From 67130b86c527c70f8c390c43fc298a76ea017e6e Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 27 Mar 2018 15:34:22 +0200 Subject: [PATCH 01/16] Update PowerXaaS.ps1 --- PowerXaaS.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerXaaS.ps1 b/PowerXaaS.ps1 index 879d2cb..4b8ce89 100644 --- a/PowerXaaS.ps1 +++ b/PowerXaaS.ps1 @@ -10,7 +10,7 @@ .NOTES Author: Olivier TABUT - 1.5.0 release (08/04/2018) + 1.6.0 release (08/04/2018) .PARAMETER Version Display this script version and exit @@ -142,7 +142,7 @@ Param( ### GLOBAL SETTINGS ### # This script name, with various levels of details -$ScriptVersion = "1.5.0" +$ScriptVersion = "1.6.0" $argv0 = Get-Item $MyInvocation.MyCommand.Definition $Script = $argv0.basename # Ex: PowerXaaS $ScriptName = $argv0.name # Ex: PowerXaaS.ps1 From 55468198f5e920fa40ba3c278680e8278119dcf3 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 27 Mar 2018 15:34:54 +0200 Subject: [PATCH 02/16] Update PowerXaaS.psd1 --- module/PowerXaaS.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/PowerXaaS.psd1 b/module/PowerXaaS.psd1 index e47145c..2e721be 100644 --- a/module/PowerXaaS.psd1 +++ b/module/PowerXaaS.psd1 @@ -12,7 +12,7 @@ RootModule = 'PowerXaaS.psm1' # Version number of this module. -ModuleVersion = '1.5.0' +ModuleVersion = '1.6.0' # Supported PSEditions # CompatiblePSEditions = @() From f2ab27a56b3139141e5fd2f22c71ac94705ed033 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 27 Mar 2018 15:35:18 +0200 Subject: [PATCH 03/16] Update PowerXaaS.tests.ps1 --- pester/PowerXaaS.tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pester/PowerXaaS.tests.ps1 b/pester/PowerXaaS.tests.ps1 index 4440836..a27ada0 100644 --- a/pester/PowerXaaS.tests.ps1 +++ b/pester/PowerXaaS.tests.ps1 @@ -41,7 +41,7 @@ Describe "Validate PowerXaaS" { It "Version" { $result = & "$PSScriptRoot\..\PowerXaaS.ps1" -Version - $result | should be "1.5.0" + $result | should be "1.6.0" } It "Start" { From 53f98b9e2bbf24d4369e73968d26287af17dab31 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 27 Mar 2018 15:35:55 +0200 Subject: [PATCH 04/16] Create JSONvalidator-helper.ps1 --- functions/JSONvalidator-helper.ps1 | 1 + 1 file changed, 1 insertion(+) create mode 100644 functions/JSONvalidator-helper.ps1 diff --git a/functions/JSONvalidator-helper.ps1 b/functions/JSONvalidator-helper.ps1 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/functions/JSONvalidator-helper.ps1 @@ -0,0 +1 @@ + From 9b416ded13f261bec75cc1acc2fe7cfccda3c23d Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 27 Mar 2018 15:40:09 +0200 Subject: [PATCH 05/16] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f646e91..1241d26 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ PowerXaaS will allow you to : - add, disable (feature-flag) or remove features/endpoints dynamically with no downtime - manage authentication and rights - manage several versions of your API + - validate JSON body based on predefined JSON schema - handle HTTP standard errors - check how your APIs are used - and much more... From 503d875c4e88dd53263c79a1708d0c8cc9ebd7a2 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 27 Mar 2018 15:40:30 +0200 Subject: [PATCH 06/16] Update index.md --- docs/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/index.md b/docs/index.md index 550b6e2..7db8c4f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -12,6 +12,7 @@ PowerXaaS will allow you to : - add, disable (feature-flag) or remove features/endpoints dynamically with no downtime - manage authentication and rights - manage several versions of your API + - validate JSON body based on predefined JSON schema - handle HTTP standard errors - check how your APIs are used - and much more... From 90e997ec125a6ce86aac5b42bfed761eade55807 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Thu, 29 Mar 2018 09:35:22 +0200 Subject: [PATCH 07/16] Update JSONvalidator-helper.ps1 --- functions/JSONvalidator-helper.ps1 | 42 ++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/functions/JSONvalidator-helper.ps1 b/functions/JSONvalidator-helper.ps1 index 8b13789..7db6aaf 100644 --- a/functions/JSONvalidator-helper.ps1 +++ b/functions/JSONvalidator-helper.ps1 @@ -1 +1,43 @@ +Function Test-JSON +{ + param( + [Parameter(Mandatory=$true)][String]$Schema, + [Parameter(Mandatory=$true)][String]$JSON + ) + + $ErrorActionPreference = 'stop' + + $NewtonsoftJsonPath = Resolve-Path -Path "C:\Program Files\PowerXaaS\JsonSchema\Newtonsoft.Json.dll" + $NewtonsoftJsonSchemaPath = Resolve-Path -Path "C:\Program Files\PowerXaaS\JsonSchema\Newtonsoft.Json.Schema.dll" + + Add-Type -Path $NewtonsoftJsonPath + Add-Type -Path $NewtonsoftJsonSchemaPath + + $source = @' + public class Validator + { + public static System.Collections.Generic.IList Validate(Newtonsoft.Json.Linq.JToken token, Newtonsoft.Json.Schema.JSchema schema) + { + System.Collections.Generic.IList messages; + Newtonsoft.Json.Schema.SchemaExtensions.IsValid(token, schema, out messages); + return messages; + } + } +'@ + + Add-Type -TypeDefinition $source -ReferencedAssemblies $NewtonsoftJsonPath,$NewtonsoftJsonSchemaPath + + $Token = [Newtonsoft.Json.Linq.JToken]::Parse($JSON) + $Schema = [Newtonsoft.Json.Schema.JSchema]::Parse($Schema) + $ErrorMessages = [Validator]::Validate($Token,$Schema) + $IsValid = $ErrorMessages.Count -eq 0 + + $Result = [PSCustomObject]@{ + IsValid = $IsValid + ErrorCount = $ErrorMessages.Count + ErrorMessages = $ErrorMessages + } + + return $Result +} From 74cee9b8a83c4607738b1382169f4a138263ad5e Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Thu, 29 Mar 2018 09:37:18 +0200 Subject: [PATCH 08/16] Update JSONvalidator-helper.ps1 --- functions/JSONvalidator-helper.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/functions/JSONvalidator-helper.ps1 b/functions/JSONvalidator-helper.ps1 index 7db6aaf..8f6fe18 100644 --- a/functions/JSONvalidator-helper.ps1 +++ b/functions/JSONvalidator-helper.ps1 @@ -31,10 +31,9 @@ Function Test-JSON $Token = [Newtonsoft.Json.Linq.JToken]::Parse($JSON) $Schema = [Newtonsoft.Json.Schema.JSchema]::Parse($Schema) $ErrorMessages = [Validator]::Validate($Token,$Schema) - $IsValid = $ErrorMessages.Count -eq 0 $Result = [PSCustomObject]@{ - IsValid = $IsValid + IsValid = $ErrorMessages.Count -eq 0 ErrorCount = $ErrorMessages.Count ErrorMessages = $ErrorMessages } From 0ac7bb41bae243d1ac8cb192f678062e8dd4199d Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Thu, 31 May 2018 20:52:52 +0200 Subject: [PATCH 09/16] Formating --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 1241d26..bec1b54 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,3 @@ PowerXaaS will allow you to : ### [Features and Endpoints](https://github.com/otabut/PowerXaaS/blob/master/docs/features-and-endpoints.md) ### [Custom features scripts](https://github.com/otabut/PowerXaaS/blob/master/docs/custom-features-scripts.md) ### [Authentication with JSON web tokens](https://github.com/otabut/PowerXaaS/blob/master/docs/json-web-tokens.md) - From 7b7bd697b3dd95e0b022b13d2e057b30cbea538c Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 11 Dec 2018 15:23:05 +0100 Subject: [PATCH 10/16] setup with protocol setting --- pester/PowerXaaS.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pester/PowerXaaS.tests.ps1 b/pester/PowerXaaS.tests.ps1 index a27ada0..be91b07 100644 --- a/pester/PowerXaaS.tests.ps1 +++ b/pester/PowerXaaS.tests.ps1 @@ -33,7 +33,7 @@ Describe "Validate PowerXaaS" { It "Setup" { - & "$PSScriptRoot\..\PowerXaaS.ps1" -Setup -Ip $ip -Port $port | Out-Null + & "$PSScriptRoot\..\PowerXaaS.ps1" -Setup -Ip $ip -Port $port -Protocol $protocol | Out-Null $result = & "$PSScriptRoot\..\PowerXaaS.ps1" -Status $result | should be "Stopped" } @@ -64,7 +64,7 @@ Describe "Validate PowerXaaS" { & "$PSScriptRoot\..\PowerXaaS.ps1" -Remove | out-null $result = & "$PSScriptRoot\..\PowerXaaS.ps1" -Status $result | should be "Not installed" - & "$PSScriptRoot\..\PowerXaaS.ps1" -Setup -Ip $ip -Port $port -Start | Out-Null + & "$PSScriptRoot\..\PowerXaaS.ps1" -Setup -Ip $ip -Port $port -Protocol $protocol -Start | Out-Null start-sleep 2 Import-Module PowerXaaS } From e55d740e63279edfb1dadd7854aeee44b0af2ba0 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 11 Dec 2018 15:33:15 +0100 Subject: [PATCH 11/16] Update PowerXaaS.ps1 --- PowerXaaS.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PowerXaaS.ps1 b/PowerXaaS.ps1 index 4b8ce89..5447d25 100644 --- a/PowerXaaS.ps1 +++ b/PowerXaaS.ps1 @@ -205,7 +205,7 @@ if ($Setup) # Install the service { $pss = Get-Service $ServiceName -ErrorAction stop # Will error-out if not installed # Check if this script is newer than the installed copy. - if (((Get-Item $ScriptCopy -ErrorAction SilentlyContinue).LastWriteTime -lt (Get-Item $ScriptFullName -ErrorAction SilentlyContinue).LastWriteTime) -or ((Get-ItemProperty -Path HKLM:\Software\PowerXaaS -Name Bindings).Bindings) -notmatch $ip) + if (((Get-Item $ScriptCopy -ErrorAction SilentlyContinue).LastWriteTime -lt (Get-Item $ScriptFullName -ErrorAction SilentlyContinue).LastWriteTime) -or ((Get-ItemProperty -Path HKLM:\Software\PowerXaaS -Name Bindings -ErrorAction silentlyContinue).Bindings) -notmatch $ip) { Write-Output "Service $ServiceName is already Installed, but requires upgrade or reconfiguration" & $ScriptFullName -Remove From 0503411f5dd9201f2b5c7e26d1f0b117180ed6a4 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 11 Dec 2018 15:41:49 +0100 Subject: [PATCH 12/16] Update PowerXaaS.ps1 --- PowerXaaS.ps1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/PowerXaaS.ps1 b/PowerXaaS.ps1 index 5447d25..41df6f1 100644 --- a/PowerXaaS.ps1 +++ b/PowerXaaS.ps1 @@ -345,10 +345,13 @@ if ($Remove) # Uninstall the service # Unconfigure HTTP server Write-Output "Unconfiguring HTTP server" - $Bindings = (Get-ItemProperty -Path HKLM:\Software\PowerXaaS -Name Bindings).Bindings - $IpPort = $Bindings.split('/')[2] - Unregister-URLPrefix -Prefix $Bindings | Out-Null - Unregister-SSLCertificate -IpPort $IpPort | Out-Null + $Bindings = (Get-ItemProperty -Path HKLM:\Software\PowerXaaS -Name Bindings -ErrorAction SilentlyContinue).Bindings + if ($Bindings) + { + $IpPort = $Bindings.split('/')[2] + Unregister-URLPrefix -Prefix $Bindings | Out-Null + Unregister-SSLCertificate -IpPort $IpPort | Out-Null + } # Remove the installed files if (Test-Path $InstallDir) From 47de024f510c269b5ec7880e00614ac33434392c Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 11 Dec 2018 16:25:13 +0100 Subject: [PATCH 13/16] Update PowerXaaS.ps1 --- PowerXaaS.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/PowerXaaS.ps1 b/PowerXaaS.ps1 index 41df6f1..ef03931 100644 --- a/PowerXaaS.ps1 +++ b/PowerXaaS.ps1 @@ -337,6 +337,11 @@ if ($Remove) # Uninstall the service Write-Error "Failed to remove the service ${ServiceName}: $msg" exit 1 } + $processes = @(Get-WmiObject Win32_Process -filter "Name = 'powershell.exe'" | Where-Object { $_.CommandLine -match ".*$ScriptCopyCname.*-Service" }) + foreach ($process in $processes) + { + taskkill /PID $process.ProcessId /F + } } catch { From fb41ba7b2259f0bc8a29dcabb6920d86177a6227 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 11 Dec 2018 19:08:39 +0100 Subject: [PATCH 14/16] Update PowerXaaS.ps1 --- PowerXaaS.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/PowerXaaS.ps1 b/PowerXaaS.ps1 index ef03931..8ca64b8 100644 --- a/PowerXaaS.ps1 +++ b/PowerXaaS.ps1 @@ -452,13 +452,16 @@ if ($Status) # Get the current service status if (($pss.Status -eq "Running") -and (!$spid)) # This happened during the debugging phase { Write-Host "The Service Control Manager thinks $ServiceName is started, but $ServiceName.ps1 -Service is not running." -ForegroundColor Red - exit 1 + return "Inconsistent" } if (($pss.Status -eq "Stopped") -and ($spid)) # This happened during the debugging phase { Write-Host "The Service Control Manager thinks $ServiceName is stopped, but $ServiceName.ps1 -Service is running." -ForegroundColor Red - exit 1 - } + $processes = @(Get-WmiObject Win32_Process -filter "Name = 'powershell.exe'" | Where-Object { $_.CommandLine -match ".*$ScriptCopyCname.*-Service" }) + foreach ($process in $processes) + { + taskkill /PID $process.ProcessId /F + } return "$($pss.Status)$spid" } From 7dcdcd36e5f9829bf02415d0ea1f2d3877e34bf4 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 11 Dec 2018 19:14:52 +0100 Subject: [PATCH 15/16] Update PowerXaaS.ps1 --- PowerXaaS.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PowerXaaS.ps1 b/PowerXaaS.ps1 index 8ca64b8..6357196 100644 --- a/PowerXaaS.ps1 +++ b/PowerXaaS.ps1 @@ -340,7 +340,7 @@ if ($Remove) # Uninstall the service $processes = @(Get-WmiObject Win32_Process -filter "Name = 'powershell.exe'" | Where-Object { $_.CommandLine -match ".*$ScriptCopyCname.*-Service" }) foreach ($process in $processes) { - taskkill /PID $process.ProcessId /F + taskkill /PID $process.ProcessId /F | out-null } } catch @@ -460,7 +460,7 @@ if ($Status) # Get the current service status $processes = @(Get-WmiObject Win32_Process -filter "Name = 'powershell.exe'" | Where-Object { $_.CommandLine -match ".*$ScriptCopyCname.*-Service" }) foreach ($process in $processes) { - taskkill /PID $process.ProcessId /F + taskkill /PID $process.ProcessId /F | out-null } return "$($pss.Status)$spid" } From 342682dac330598c73ebfbcab82142b2216f6c71 Mon Sep 17 00:00:00 2001 From: otabut <33980031+otabut@users.noreply.github.com> Date: Tue, 11 Dec 2018 19:23:58 +0100 Subject: [PATCH 16/16] Update PowerXaaS.tests.ps1 --- pester/PowerXaaS.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pester/PowerXaaS.tests.ps1 b/pester/PowerXaaS.tests.ps1 index be91b07..a94541b 100644 --- a/pester/PowerXaaS.tests.ps1 +++ b/pester/PowerXaaS.tests.ps1 @@ -35,7 +35,7 @@ Describe "Validate PowerXaaS" { & "$PSScriptRoot\..\PowerXaaS.ps1" -Setup -Ip $ip -Port $port -Protocol $protocol | Out-Null $result = & "$PSScriptRoot\..\PowerXaaS.ps1" -Status - $result | should be "Stopped" + $result | should match "Stopped" } It "Version" { @@ -56,7 +56,7 @@ Describe "Validate PowerXaaS" { & "$PSScriptRoot\..\PowerXaaS.ps1" -Stop | Out-Null start-sleep 1 $result = & "$PSScriptRoot\..\PowerXaaS.ps1" -Status - $result | should be "Stopped" + $result | should match "Stopped" } It "Remove" {