Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions PSScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

@{
Rules = @{
PSAvoidUsingCmdletAliases = @{
Expand Down
7 changes: 6 additions & 1 deletion Polaris.psm1
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
$Script:Polaris = $null
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

$Script:Polaris = $null

# Handles the removal of the module
$ExecutionContext.SessionState.Module.OnRemove =
Expand Down
5 changes: 5 additions & 0 deletions Private/Create-NewPolarisIfNeeded.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

function CreateNewPolarisIfNeeded () {
if ( -not $Script:Polaris ) {
$Script:Polaris = [Polaris]::New(
Expand Down
13 changes: 9 additions & 4 deletions Public/Clear-Polaris.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Clears the internal instance of Polaris
Clears the internal instance of Polaris
.DESCRIPTION
Clears the internal Polaris .NET Standard object. The instance will be reinstantiated in other module calls.
Clears the internal Polaris .NET Standard object. The instance will be reinstantiated in other module calls.
.EXAMPLE
Clear-Polaris
Clear-Polaris
.NOTES
Should only be used for testing
Should only be used for testing
#>
function Clear-Polaris {
if ($Script:Polaris) {
Expand Down
14 changes: 9 additions & 5 deletions Public/Get-Polaris.ps1
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Returns the internal instance of Polaris
Returns the internal instance of Polaris
.DESCRIPTION
Returns the instance of the Polaris .NET Standard object
Returns the instance of the Polaris .NET Standard object
.EXAMPLE
Get-Polaris
Get-Polaris
.NOTES
Should only be used for testing
Should only be used for testing
#>
function Get-Polaris {
return $Script:Polaris
}

5 changes: 5 additions & 0 deletions Public/Get-PolarisRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Get web routes.
Expand Down
5 changes: 5 additions & 0 deletions Public/Get-PolarisRouteMiddleware.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Get route middleware.
Expand Down
37 changes: 22 additions & 15 deletions Public/New-DirectoryBrowser.ps1
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
function New-DirectoryBrowser {
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Renders a directory browser in HTML
.DESCRIPTION
Creates HTML that can be used as a directory browser
.PARAMETER RequestedItem
The directory you would like to generate HTML for
.PARAMETER HeaderName
The name you would like displayed at the top of the directory browser
.PARAMETER DirectoryBrowserPath
The current path in the directory browser relative to the root of the directory
browser (not the root of the site).
<#
.SYNOPSIS
Renders a directory browser in HTML
.DESCRIPTION
Creates HTML that can be used as a directory browser
.PARAMETER RequestedItem
The directory you would like to generate HTML for
.PARAMETER HeaderName
The name you would like displayed at the top of the directory browser
.PARAMETER DirectoryBrowserPath
The current path in the directory browser relative to the root of the directory
browser (not the root of the site).
.EXAMPLE
New-DirectoryBrowser -RequestedItem $directoryInfo
.EXAMPLE
New-DirectoryBrowser -RequestedItem $directoryInfo -DirectoryBrowserPath ./MyContent
#>

function New-DirectoryBrowser {
param (

[Parameter(
Expand Down Expand Up @@ -63,4 +70,4 @@ $(if ($RequestedItem.FullName.TrimEnd([System.IO.Path]::DirectorySeparatorChar)
</body>
</html>
"@
}
}
5 changes: 5 additions & 0 deletions Public/New-PolarisDeleteRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Add web route with method DELETE
Expand Down
6 changes: 5 additions & 1 deletion Public/New-PolarisGetRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Add web route with method GET
Expand Down Expand Up @@ -52,4 +57,3 @@ function New-PolarisGetRoute {
'ScriptPath' { New-PolarisRoute -Path $Path -Method "GET" -ScriptPath $ScriptPath -Force:$Force }
}
}

5 changes: 5 additions & 0 deletions Public/New-PolarisPostRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Add web route with method POST
Expand Down
5 changes: 5 additions & 0 deletions Public/New-PolarisPutRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Add web route with method PUT
Expand Down
5 changes: 5 additions & 0 deletions Public/New-PolarisRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Add web route.
Expand Down
19 changes: 13 additions & 6 deletions Public/New-PolarisRouteMiddleware.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Add new route middleware.
Expand All @@ -16,13 +21,15 @@
A Polaris object
Defaults to the script scoped Polaris
.EXAMPLE
$JsonBodyParserMiddleware =
{
if ($Request.BodyString -ne $null) {
$Request.Body = $Request.BodyString | ConvertFrom-Json
$JsonBodyParserMiddleware =
{
if ($Request.BodyString -ne $null) {
$Request.Body = $Request.BodyString | ConvertFrom-Json
}
}
}
New-PolarisRouteMiddleware -Name JsonBodyParser -Scriptblock $JsonBodyParserMiddleware
New-PolarisRouteMiddleware -Name JsonBodyParser -Scriptblock $JsonBodyParserMiddleware
.EXAMPLE
New-PolarisRouteMiddleware -Name JsonBodyParser -ScriptPath ./testMiddleware.ps1
#>
function New-PolarisRouteMiddleware {
[CmdletBinding()]
Expand Down
7 changes: 7 additions & 0 deletions Public/New-PolarisStaticRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Creates web routes to recursively serve folder contents
Expand All @@ -8,6 +13,8 @@
Defaults to "/".
.PARAMETER FolderPath
Full path and name of the folder to serve.
.PARAMETER EnableDirectoryBrowser
Enables the directory browser when the user requests a folder
.PARAMETER Force
Use -Force to overwrite existing web route(s) for the same paths.
.PARAMETER Polaris
Expand Down
56 changes: 29 additions & 27 deletions Public/New-ScriptblockCallback.ps1
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Allows running Scriptblocks via .NET async callbacks.
.DESCRIPTION
Allows running Scriptblocks via .NET async callbacks. Internally this is
managed by converting .NET async callbacks into .NET events. This enables
PowerShell 2.0 to run Scriptblocks indirectly through Register-ObjectEvent.
.PARAMETER Callback
Specify a Scriptblock to be executed in response to the callback.
Because the Scriptblock is executed by the eventing subsystem, it only has
access to global scope. Any additional arguments to this function will be
passed as event MessageData.
.EXAMPLE
You wish to run a scriptblock in reponse to a callback. Here is the .NET
method signature:

void Bar(AsyncCallback handler, int blah)

ps> [foo]::bar((New-ScriptblockCallback { ... }), 42)
.OUTPUTS
A System.AsyncCallback delegate.
#>
function New-ScriptblockCallback {
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[scriptblock]$Callback
)
<#
.SYNOPSIS
Allows running Scriptblocks via .NET async callbacks.

.DESCRIPTION
Allows running Scriptblocks via .NET async callbacks. Internally this is
managed by converting .NET async callbacks into .NET events. This enables
PowerShell 2.0 to run Scriptblocks indirectly through Register-ObjectEvent.

.PARAMETER Callback
Specify a Scriptblock to be executed in response to the callback.
Because the Scriptblock is executed by the eventing subsystem, it only has
access to global scope. Any additional arguments to this function will be
passed as event MessageData.

.EXAMPLE
You wish to run a scriptblock in reponse to a callback. Here is the .NET
method signature:

void Bar(AsyncCallback handler, int blah)

ps> [foo]::bar((New-ScriptblockCallback { ... }), 42)

.OUTPUTS
A System.AsyncCallback delegate.
#>

# is this type already defined?
if (-not ("CallbackEventBridge" -as [type])) {
Add-Type @"
Expand Down Expand Up @@ -61,4 +63,4 @@ function New-ScriptblockCallback {
$bridge = [callbackeventbridge]::create()
Register-ObjectEvent -input $bridge -EventName callbackcomplete -action $callback -messagedata $args > $null
$bridge.callback
}
}
5 changes: 5 additions & 0 deletions Public/Remove-PolarisRoute.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Removes the web route.
Expand Down
5 changes: 5 additions & 0 deletions Public/Remove-PolarisRouteMiddleware.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Remove route middleware.
Expand Down
7 changes: 7 additions & 0 deletions Public/Start-Polaris.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Start Polaris web server.
Expand All @@ -14,6 +19,8 @@
Defaults to 1.
.PARAMETER UseJsonBodyParserMiddleware
When present, JSONBodyParser middleware will be created, if needed.
.PARAMETER Https
Determines if you want to use https as the prefix.
.PARAMETER Polaris
A Polaris object
Defaults to the script scoped Polaris
Expand Down
8 changes: 5 additions & 3 deletions Public/Stop-Polaris.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Stop Polaris web server.
Expand All @@ -6,9 +11,6 @@
.PARAMETER ServerContext
Polaris instance to stop.
Defaults to the global instance.
.PARAMETER Polaris
A Polaris object
Defaults to the script scoped Polaris
.EXAMPLE
Stop-Polaris
.EXAMPLE
Expand Down
5 changes: 5 additions & 0 deletions Public/Use-PolarisJsonBodyParserMiddleware.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

<#
.SYNOPSIS
Helper function that turns on the Json Body parsing middleware.
Expand Down
7 changes: 6 additions & 1 deletion Tests/e2e/New-PolarisStaticRoute.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
Describe "New-PolarisStaticRoute (E2E)" {
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

Describe "New-PolarisStaticRoute (E2E)" {

BeforeAll {

Expand Down
5 changes: 5 additions & 0 deletions Tests/e2e/PolarisMiddleware.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#
# Copyright (c) Microsoft. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
#

Describe "Test middleware creation/usage (E2E)" {

BeforeAll {
Expand Down
Loading