Skip to content

Commit

Permalink
Make e2e var loading faster (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
David R. Williamson authored Feb 8, 2023
1 parent b4fecf0 commit 784e866
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Function Connect-AzureSubscription()

if (-not $azureContext)
{
Write-Host "`nPlease login to Azure..."
Write-Host "`nPlease login to Azure."
az login
$azureContext = az account show
}
Expand All @@ -28,7 +28,7 @@ Function Connect-AzureSubscription()
$sub = az account show --output tsv --query id
if ($sub -ne $SubscriptionId)
{
Write-Host "`nSelecting subscription $SubscriptionId`n"
Write-Host "`nSelecting subscription $SubscriptionId.`n"
az account set --subscription $SubscriptionId
}

Expand All @@ -37,16 +37,17 @@ Function Connect-AzureSubscription()

Connect-AzureSubscription | Out-Null

# Load all secrets from KeyVault and set the appropriate Environment Variable
# Load all secrets from KeyVault and set the appropriate environment variable
$ids = az keyvault secret list --subscription $SubscriptionId --vault-name $KeyVaultName --query '[*].id' --output tsv
ForEach ($id in $ids)
{
Write-Host "`nSetting environment variables:"
$ids | ForEach-Object -Parallel {
# az keyvault secret show does not return a name in its properties so we need to extract it from the id
# The ids have parts seperated by / and extracting the 5th part gets us the name of the Key
$value = az keyvault secret show --subscription $using:SubscriptionId --id $_ --query 'value' --output tsv

# The ids have parts separated by a '/' and extracting the 5th part gets us the name of the Key
# After we extract the name of the Key, we also want to replace dashes with underscores so that we convert it to the correct Environment Vairable name to be set
# Ex: https://test-kv.vault.azure.net/secrets/IOTHUB-NAME/f7953b248a3e46cfa6fc59651794db2e - Extract IOTHUB-NAME and convert to IOTHUB_NAME
$name = $id.split('/')[4].Replace('-', '_')
Write-Host("Setting Environment Variable $name")
$value = az keyvault secret show --subscription $SubscriptionId --id $id --query 'value' --output tsv
Set-Item -Path Env:$name -Value "$value"
$envVarName = $_.split('/')[4].Replace('-', '_')
Write-Host "`t$envVarName"
Set-Item -Path Env:$envVarName -Value "$value"
}

0 comments on commit 784e866

Please sign in to comment.