Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

version 1.6.0 #16

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
31 changes: 21 additions & 10 deletions PowerXaaS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 | out-null
}
}
catch
{
Expand All @@ -345,10 +350,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)
Expand Down Expand Up @@ -444,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 | out-null
}
return "$($pss.Status)$spid"
}

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -24,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)

1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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...
42 changes: 42 additions & 0 deletions functions/JSONvalidator-helper.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

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<string> Validate(Newtonsoft.Json.Linq.JToken token, Newtonsoft.Json.Schema.JSchema schema)
{
System.Collections.Generic.IList<string> 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)

$Result = [PSCustomObject]@{
IsValid = $ErrorMessages.Count -eq 0
ErrorCount = $ErrorMessages.Count
ErrorMessages = $ErrorMessages
}

return $Result
}
2 changes: 1 addition & 1 deletion module/PowerXaaS.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PowerXaaS.psm1'

# Version number of this module.
ModuleVersion = '1.5.0'
ModuleVersion = '1.6.0'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
10 changes: 5 additions & 5 deletions pester/PowerXaaS.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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"
$result | should match "Stopped"
}

It "Version" {

$result = & "$PSScriptRoot\..\PowerXaaS.ps1" -Version
$result | should be "1.5.0"
$result | should be "1.6.0"
}

It "Start" {
Expand All @@ -56,15 +56,15 @@ 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" {

& "$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
}
Expand Down