1# Copyright (c) Microsoft Corporation. All rights reserved.
2# Licensed under the MIT License.
3
4# IMPORTANT: Do not invoke this file directly. Please instead run eng/common/TestResources/New-TestResources.ps1 from the repository root.
5
6[CmdletBinding(SupportsShouldProcess = $true, ConfirmImpact = 'Medium')]
7param (
8 [hashtable] $AdditionalParameters = @{},
9
10 # Captures any arguments from eng/New-TestResources.ps1 not declared here (no parameter errors).
11 [Parameter(ValueFromRemainingArguments = $true)]
12 $RemainingArguments
13)
14
15if (-not (Test-Path "$PSScriptRoot/sshkey.pub")) {
16 ssh-keygen -t rsa -b 4096 -f "$PSScriptRoot/sshkey" -N '' -C ''
17}
18$templateFileParameters['sshPubKey'] = Get-Content "$PSScriptRoot/sshkey.pub"
19
20if (!$CI) {
21 # TODO: Remove this once auto-cloud config downloads are supported locally
22 Write-Host "Skipping cert setup in local testing mode"
23 return
24}
25
26if ($null -eq $EnvironmentVariables -or $EnvironmentVariables.Count -eq 0) {
27 throw "EnvironmentVariables must be set in the calling script New-TestResources.ps1"
28}
29
30$tmp = $env:TEMP ? $env:TEMP : [System.IO.Path]::GetTempPath()
31$pfxPath = Join-Path $tmp "test.pfx"
32$pemPath = Join-Path $tmp "test.pem"
33
34Write-Host "Creating identity test files: $pfxPath $pemPath"
35
36[System.Convert]::FromBase64String($EnvironmentVariables['PFX_CONTENTS']) | Set-Content -Path $pfxPath -AsByteStream
37Set-Content -Path $pemPath -Value $EnvironmentVariables['PEM_CONTENTS']
38
39# Set for pipeline
40Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_PFX;]$pfxPath"
41Write-Host "##vso[task.setvariable variable=IDENTITY_SP_CERT_PEM;]$pemPath"
42# Set for local
43$env:IDENTITY_SP_CERT_PFX = $pfxPath
44$env:IDENTITY_SP_CERT_PEM = $pemPath