| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Sets the methods for a CORS policy in a .NET Core application. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function sets the methods for a CORS policy in a .NET Core application. It takes a `CorsPolicyBuilder` object a |
| | | 6 | | .PARAMETER Builder |
| | | 7 | | The `CorsPolicyBuilder` object to configure. |
| | | 8 | | .PARAMETER Any |
| | | 9 | | If specified, allows any HTTP method in the CORS policy. |
| | | 10 | | .PARAMETER Methods |
| | | 11 | | A list of HTTP methods to allow in the CORS policy. |
| | | 12 | | .EXAMPLE |
| | | 13 | | New-KrCorsPolicyBuilder | Set-KrCorsMethod -Any |
| | | 14 | | .EXAMPLE |
| | | 15 | | New-KrCorsPolicyBuilder | Set-KrCorsMethod -Methods @('GET', 'POST', 'PUT', 'DELETE') |
| | | 16 | | .OUTPUTS |
| | | 17 | | Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder |
| | | 18 | | #> |
| | | 19 | | function Set-KrCorsMethod { |
| | | 20 | | [KestrunRuntimeApi('Definition')] |
| | | 21 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 22 | | [CmdletBinding(DefaultParameterSetName = 'With')] |
| | | 23 | | [OutputType([Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder])] |
| | | 24 | | param( |
| | | 25 | | [Parameter(Mandatory, ValueFromPipeline)] |
| | | 26 | | [Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder]$Builder, |
| | | 27 | | |
| | | 28 | | [Parameter(Mandatory, ParameterSetName = 'Any')] |
| | | 29 | | [switch]$Any, |
| | | 30 | | |
| | | 31 | | [Parameter(Mandatory, ParameterSetName = 'With')] |
| | | 32 | | [string[]]$Methods |
| | | 33 | | ) |
| | | 34 | | process { |
| | 0 | 35 | | if ($Any) { $Builder.AllowAnyMethod() | Out-Null } |
| | 0 | 36 | | else { $Builder.WithMethods($Methods) | Out-Null } |
| | 0 | 37 | | return $Builder |
| | | 38 | | } |
| | | 39 | | } |