-
Notifications
You must be signed in to change notification settings - Fork 8.1k
WebCmdlet unix-sockets #19343
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
Merged
daxian-dbw
merged 29 commits into
PowerShell:master
from
CarloToso:WebCmdlets-UnixSockets2
Jul 24, 2023
Merged
WebCmdlet unix-sockets #19343
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
e2fbf1e
Unix sockets
CarloToso 550707e
rework _custommethod
CarloToso ec2fcf1
use SetClassVar
CarloToso 84968e7
Pass UnixSocket to WebSession even if it's null
CarloToso 95d2b33
Merge branch 'PowerShell:master' into WebCmdlets-UnixSockets2
CarloToso 30132a8
UnixDomainSocketEndPoint nullable
CarloToso 43f2772
remove useless line
CarloToso d9ec5c4
Add Socket.OSSupportsUnixDomainSockets validation
CarloToso bd5c4d6
move error to ValidateParameters()
CarloToso f7ec7e8
Update src/Microsoft.PowerShell.Commands.Utility/resources/WebCmdletS…
CarloToso 2b9a2b9
update error
CarloToso e7090f3
remove error
CarloToso 87ed139
fix UseDefaultCredentials
CarloToso 3712927
Add Tests
CarloToso f173a78
Merge branch 'master' into WebCmdlets-UnixSockets2
CarloToso f82c20f
fix codefactor
CarloToso 5ba37ac
change author
CarloToso 47595c5
follow suggestions
CarloToso 35f1e0c
follow suggestions @xtqqczze
CarloToso 0e17d60
fix
CarloToso ac69e97
fix Get-UnixSocketName
CarloToso b719bd2
fix
CarloToso 22ae762
Add $using:
CarloToso aa5e0ed
Update test/tools/Modules/UnixSocket/UnixSocket.psm1
CarloToso 8eda977
remove After-All
CarloToso 62b1b88
change extension to sock
CarloToso 3627347
Merge branch 'master' into WebCmdlets-UnixSockets2
CarloToso 48df0f8
Merge branch 'PowerShell:master' into WebCmdlets-UnixSockets2
CarloToso 352b050
fix MD025 - Multiple top-level headings in the same document
CarloToso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # UnixSocket Module | ||
|
|
||
| A PowerShell module for managing the UnixSocket App. | ||
|
|
||
| ## Running UnixSocket | ||
|
|
||
| ```powershell | ||
| Import-Module .\build.psm1 | ||
| Publish-PSTestTools | ||
| $Listener = Start-UnixSocket | ||
| ``` | ||
|
|
||
| ## Stopping UnixSocket | ||
|
|
||
| ```powershell | ||
| Stop-UnixSocket | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| @{ | ||
| ModuleVersion = '1.0.0' | ||
| GUID = '86471f04-5b94-4136-a299-caf98464a06b' | ||
| Author = 'PowerShell' | ||
| Description = 'An UnixSocket Server for testing purposes' | ||
| RootModule = 'UnixSocket.psm1' | ||
| RequiredModules = @() | ||
| FunctionsToExport = @( | ||
| 'Get-UnixSocket' | ||
| 'Get-UnixSocketName' | ||
| 'Get-UnixSocketUri' | ||
| 'Start-UnixSocket' | ||
| 'Stop-UnixSocket' | ||
| ) | ||
| AliasesToExport = @() | ||
| CmdletsToExport = @() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Class UnixSocket | ||
| { | ||
| [System.Management.Automation.Job]$Job | ||
|
|
||
| UnixSocket () { } | ||
|
|
||
| [String] GetStatus() | ||
| { | ||
| return $this.Job.JobStateInfo.State | ||
| } | ||
| } | ||
|
|
||
| [UnixSocket]$UnixSocket | ||
|
|
||
| function Get-UnixSocket | ||
| { | ||
| [CmdletBinding(ConfirmImpact = 'Low')] | ||
| [OutputType([UnixSocket])] | ||
| param() | ||
|
|
||
| process | ||
| { | ||
| return [UnixSocket]$Script:UnixSocket | ||
| } | ||
| } | ||
|
|
||
| function Start-UnixSocket | ||
| { | ||
| [CmdletBinding(ConfirmImpact = 'Low')] | ||
| [OutputType([UnixSocket])] | ||
| param([string] $socketPath) | ||
|
|
||
| process | ||
| { | ||
| $runningListener = Get-UnixSocket | ||
| if ($null -ne $runningListener -and $runningListener.GetStatus() -eq 'Running') | ||
| { | ||
| return $runningListener | ||
| } | ||
|
|
||
| $initTimeoutSeconds = 25 | ||
| $appExe = (Get-Command UnixSocket).Path | ||
| $initCompleteMessage = 'Now listening on' | ||
| $sleepMilliseconds = 100 | ||
|
|
||
| $Job = Start-Job { | ||
| $path = Split-Path -Parent (Get-Command UnixSocket).Path -Verbose | ||
| Push-Location $path -Verbose | ||
| 'appEXE: {0}' -f $using:appExe | ||
| $env:ASPNETCORE_ENVIRONMENT = 'Development' | ||
| & $using:appExe $using:socketPath | ||
| } | ||
|
|
||
| $Script:UnixSocket = [UnixSocket]@{ | ||
| Job = $Job | ||
| } | ||
|
|
||
| # Count iterations of $sleepMilliseconds instead of using system time to work around possible CI VM sleep/delays | ||
| $sleepCountRemaining = $initTimeoutSeconds * 1000 / $sleepMilliseconds | ||
| do | ||
| { | ||
| Start-Sleep -Milliseconds $sleepMilliseconds | ||
| $initStatus = $Job.ChildJobs[0].Output | Out-String | ||
| $isRunning = $initStatus -match $initCompleteMessage | ||
| $sleepCountRemaining-- | ||
| } | ||
| while (-not $isRunning -and $sleepCountRemaining -gt 0) | ||
|
|
||
| if (-not $isRunning) | ||
| { | ||
| $jobErrors = $Job.ChildJobs[0].Error | Out-String | ||
| $jobOutput = $Job.ChildJobs[0].Output | Out-String | ||
| $jobVerbose = $Job.ChildJobs[0].Verbose | Out-String | ||
| $Job | Stop-Job | ||
| $Job | Remove-Job -Force | ||
| $message = 'UnixSocket did not start before the timeout was reached.{0}Errors:{0}{1}{0}Output:{0}{2}{0}Verbose:{0}{3}' -f ([System.Environment]::NewLine), $jobErrors, $jobOutput, $jobVerbose | ||
| throw $message | ||
| } | ||
| return $Script:UnixSocket | ||
| } | ||
| } | ||
|
|
||
| function Stop-UnixSocket | ||
| { | ||
| [CmdletBinding(ConfirmImpact = 'Low')] | ||
| [OutputType([Void])] | ||
| param() | ||
|
|
||
| process | ||
| { | ||
| $Script:UnixSocket.Job | Stop-Job -PassThru | Remove-Job | ||
| $Script:UnixSocket = $null | ||
| } | ||
| } | ||
|
|
||
| function Get-UnixSocketName { | ||
| [CmdletBinding()] | ||
| [OutputType([string])] | ||
| param () | ||
|
|
||
| process { | ||
| return [System.IO.Path]::Join([System.IO.Path]::GetTempPath(), [System.IO.Path]::ChangeExtension([System.IO.Path]::GetRandomFileName(), "sock")) | ||
| } | ||
| } | ||
|
|
||
| function Get-UnixSocketUri { | ||
| [CmdletBinding()] | ||
| [OutputType([Uri])] | ||
| param () | ||
|
|
||
| process { | ||
| $runningListener = Get-UnixSocket | ||
| if ($null -eq $runningListener -or $runningListener.GetStatus() -ne 'Running') | ||
| { | ||
| return $null | ||
| } | ||
| $Uri = [System.UriBuilder]::new() | ||
| $Uri.Host = '127.0.0.0' | ||
|
|
||
| return [Uri]$Uri.ToString() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.IO; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using static Microsoft.AspNetCore.Hosting.WebHostBuilderKestrelExtensions; | ||
|
|
||
| namespace UnixSocket | ||
| { | ||
| public static class Program | ||
| { | ||
| public static void Main(string[] args) | ||
| { | ||
| WebApplicationBuilder builder = WebApplication.CreateBuilder(); | ||
| builder.WebHost.ConfigureKestrel(options => | ||
| { | ||
| options.ListenUnixSocket(args[0]); | ||
| }); | ||
|
|
||
| var app = builder.Build(); | ||
| app.MapGet("/", () => "Hello World Unix Socket."); | ||
|
|
||
| app.Run(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <Import Project="..\..\Test.Common.props" /> | ||
|
|
||
| <PropertyGroup> | ||
| <Description>A very simple ASP.NET Core app to provide an UnixSocket server for testing.</Description> | ||
| <AssemblyName>UnixSocket</AssemblyName> | ||
| <OutputType>Exe</OutputType> | ||
| <TieredCompilation>true</TieredCompilation> | ||
| <TieredCompilationQuickJit>true</TieredCompilationQuickJit> | ||
| <RuntimeIdentifiers>win7-x86;win7-x64;osx-x64;linux-x64</RuntimeIdentifiers> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.