| | | 1 | | <# |
| | | 2 | | .SYNOPSIS |
| | | 3 | | Set the CORS credentials policy for a given CorsPolicyBuilder object. |
| | | 4 | | .DESCRIPTION |
| | | 5 | | This function sets the CORS credentials policy for a given CorsPolicyBuilder object. |
| | | 6 | | It can either allow or disallow credentials based on the provided parameters. |
| | | 7 | | The function uses the CorsPolicyBuilder object to configure the CORS policy. |
| | | 8 | | The function can be used in a pipeline to configure the CORS policy for a given CorsPolicy |
| | | 9 | | object. |
| | | 10 | | .PARAMETER Builder |
| | | 11 | | The CorsPolicyBuilder object to configure. |
| | | 12 | | .PARAMETER Allow |
| | | 13 | | Allows credentials in the CORS policy. |
| | | 14 | | .PARAMETER Disallow |
| | | 15 | | Disallows credentials in the CORS policy. |
| | | 16 | | .EXAMPLE |
| | | 17 | | $corsBuilder = New-KrCorsPolicyBuilder | Set-KrCorsCredential -Allow |
| | | 18 | | .EXAMPLE |
| | | 19 | | $corsBuilder = New-KrCorsPolicyBuilder | Set-KrCorsCredential -Disallow |
| | | 20 | | .OUTPUTS |
| | | 21 | | Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder |
| | | 22 | | #> |
| | | 23 | | function Set-KrCorsCredential { |
| | | 24 | | [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '')] |
| | | 25 | | [KestrunRuntimeApi('Definition')] |
| | | 26 | | [CmdletBinding(DefaultParameterSetName = 'Allow')] |
| | | 27 | | [OutputType([Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder])] |
| | | 28 | | param( |
| | | 29 | | [Parameter(Mandatory, ValueFromPipeline)] |
| | | 30 | | [Microsoft.AspNetCore.Cors.Infrastructure.CorsPolicyBuilder]$Builder, |
| | | 31 | | |
| | | 32 | | [Parameter(ParameterSetName = 'Allow')] |
| | | 33 | | [switch]$Allow, |
| | | 34 | | |
| | | 35 | | [Parameter(ParameterSetName = 'Disallow')] |
| | | 36 | | [switch]$Disallow |
| | | 37 | | ) |
| | | 38 | | process { |
| | 0 | 39 | | if ($Allow.IsPresent) { |
| | | 40 | | # This will throw later at runtime too, but it’s nicer to catch early: |
| | | 41 | | # AllowCredentials + AllowAnyOrigin is invalid. |
| | 0 | 42 | | $Builder.AllowCredentials() | Out-Null |
| | | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | if ($Disallow.IsPresent) { |
| | | 46 | | # This will throw later at runtime too, but it’s nicer to catch early: |
| | | 47 | | # DisallowCredentials + AllowAnyOrigin is invalid. |
| | 0 | 48 | | $Builder.DisallowCredentials() | Out-Null |
| | | 49 | | } |
| | | 50 | | |
| | 0 | 51 | | return $Builder |
| | | 52 | | } |
| | | 53 | | } |