|
| 1 | +[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')] |
| 2 | +param ( |
| 3 | + # Captures any arguments from eng/New-TestResources.ps1 not declared here (no parameter errors). |
| 4 | + [Parameter(ValueFromRemainingArguments = $true)] |
| 5 | + $RemainingArguments |
| 6 | +) |
| 7 | + |
| 8 | +if (!$CI) { |
| 9 | + # TODO: Remove this once auto-cloud config downloads are supported locally |
| 10 | + Write-Host "Skipping cert setup in local testing mode" |
| 11 | + return |
| 12 | +} |
| 13 | + |
| 14 | +if ($EnvironmentVariables -eq $null -or $EnvironmentVariables.Count -eq 0) { |
| 15 | + throw "EnvironmentVariables must be set in the calling script New-TestResources.ps1" |
| 16 | +} |
| 17 | + |
| 18 | +$tmp = $env:TEMP ? $env:TEMP : [System.IO.Path]::GetTempPath() |
| 19 | +$pfxPath = Join-Path $tmp "test.pfx" |
| 20 | +$pemPath = Join-Path $tmp "test.pem" |
| 21 | +$sniPath = Join-Path $tmp "testsni.pfx" |
| 22 | +$sniPemPath = Join-Path $tmp "testsni.pem" |
| 23 | + |
| 24 | +Write-Host "Creating identity test files: $pfxPath $pemPath $sniPath $sniPemPath" |
| 25 | + |
| 26 | +# javascript wants to read \n escaped as \\n which does not match the certificate pattern regex in the identity sdk |
| 27 | +# Convert to real newlines before writing to the file |
| 28 | +$pemContents = $EnvironmentVariables['PEM_CONTENTS'] -replace "\n","`n" |
| 29 | +$sniPemContents = $EnvironmentVariables['SNI_PEM_CONTENTS'] -replace "\n","`n" |
| 30 | +Set-Content -Path $pemPath -Value $pemContents |
| 31 | +Set-Content -Path $sniPemPath -Value $sniPemContents |
| 32 | +[System.Convert]::FromBase64String($EnvironmentVariables['PFX_CONTENTS']) | Set-Content -Path $pfxPath -AsByteStream |
| 33 | +[System.Convert]::FromBase64String($EnvironmentVariables['SNI_CONTENTS']) | Set-Content -Path $sniPath -AsByteStream |
| 34 | + |
| 35 | +# Set for pipeline |
| 36 | +Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_PFX;]$pfxPath" |
| 37 | +Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_PEM;]$pemPath" |
| 38 | +Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_SNI;]$sniPath" |
| 39 | +Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_SNI_PEM;]$sniPemPath" |
| 40 | +# Set for local |
| 41 | +$env:IDENTITY_SP_CERT_PFX = $pfxPath |
| 42 | +$env:IDENTITY_SP_CERT_PEM = $pemPath |
| 43 | +$env:IDENTITY_SP_CERT_SNI = $sniPath |
| 44 | +$env:IDENTITY_SP_CERT_SNI_PEM = $sniPemPath |
0 commit comments