| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Sets the preflight max age for CORS policies in ASP.NET Core. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function sets the preflight max age for CORS policies in ASP.NET Core. |
| | | 6 | | It takes a CorsPolicyBuilder object and a TimeSpan object as input parameters. |
| | | 7 | | The SetPreflightMaxAge method of the CorsPolicyBuilder object is called with the provided TimeSpan object to set the |
| | | 8 | | The modified CorsPolicyBuilder object is then returned. |
| | | 9 | | .PARAMETER Builder |
| | | 10 | | The CorsPolicyBuilder object to set the preflight max age for. |
| | | 11 | | .PARAMETER MaxAge |
| | | 12 | | The TimeSpan object representing the preflight max age to set. |
| | | 13 | | .PARAMETER Seconds |
| | | 14 | | The number of seconds representing the preflight max age to set. |
| | | 15 | | .EXAMPLE |
| | | 16 | | New-KrCorsPolicyBuilder | Set-KrCorsPreflightMaxAge -MaxAge (New-TimeSpan -Hours 24) | Add-KrCorsPolicy -Server $ser |
| | | 17 | | .EXAMPLE |
| | | 18 | | New-KrCorsPolicyBuilder | Set-KrCorsPreflightMaxAge -Seconds 86400 | Add-KrCorsPolicy -Name 'MyCORSPolicy' |
| | | 19 | | .OUTPUTS |
| | | 20 | | Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder |
| | | 21 | | #> |
| | | 22 | | function Set-KrCorsPreflightMaxAge { |
| | | 23 | | [KestrunRuntimeApi('Definition')] |
| | | 24 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 25 | | [CmdletBinding(DefaultParameterSetName = 'TimeSpan')] |
| | | 26 | | [OutputType([Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder])] |
| | | 27 | | param( |
| | | 28 | | [Parameter(Mandatory, ValueFromPipeline)] |
| | | 29 | | [Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder]$Builder, |
| | | 30 | | |
| | | 31 | | [Parameter(Mandatory = $true, ParameterSetName = 'TimeSpan')] |
| | | 32 | | [TimeSpan]$MaxAge, |
| | | 33 | | |
| | | 34 | | [Parameter(Mandatory = $true, ParameterSetName = 'Seconds')] |
| | | 35 | | [int]$Seconds |
| | | 36 | | ) |
| | | 37 | | process { |
| | 0 | 38 | | if ($PSCmdlet.ParameterSetName -eq 'Seconds') { |
| | 0 | 39 | | $MaxAge = New-TimeSpan -Seconds $Seconds |
| | | 40 | | } |
| | 0 | 41 | | $Builder.SetPreflightMaxAge($MaxAge) | Out-Null |
| | 0 | 42 | | $Builder |
| | | 43 | | } |
| | | 44 | | } |