Make sure we always log in as app or provisioner (#908)

This also adds previously-required parameters back into
@PSBoundParameters to pass down to pre- and post-scripts.

Co-authored-by: Heath Stewart <heaths@microsoft.com>
This commit is contained in:
Azure SDK Bot 2020-11-06 10:03:07 -08:00 committed by GitHub
parent 4b2e335d35
commit 088a4c85db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -141,6 +141,9 @@ $UserName = if ($env:USER) { $env:USER } else { "${env:USERNAME}" }
if (!$BaseName) {
$BaseName = "$UserName$ServiceDirectory"
# Make sure pre- and post-scripts are passed formerly required arguments.
$PSBoundParameters['BaseName'] = $BaseName
Log "BaseName was not set. Using default base name: '$BaseName'"
}
@ -167,8 +170,7 @@ if (!$Location) {
Write-Verbose "Location was not set. Using default location for environment: '$Location'"
}
# If no test application ID is specified during an interactive session, create a new service principal.
if (!$CI -and !$TestApplicationId) {
if (!$CI) {
# Make sure the user is logged in to create a service principal.
$context = Get-AzContext;
@ -177,13 +179,20 @@ if (!$CI -and !$TestApplicationId) {
$context = (Connect-AzAccount -Subscription $defaultSubscription).Context
}
Log "TestApplicationId was not specified; creating a new service principal"
$servicePrincipal = New-AzADServicePrincipal -Role Owner
# If no test application ID is specified during an interactive session, create a new service principal.
if (!$TestApplicationId) {
Log "TestApplicationId was not specified; creating a new service principal"
$servicePrincipal = New-AzADServicePrincipal -Role Owner
$TestApplicationId = $servicePrincipal.ApplicationId
$TestApplicationSecret = (ConvertFrom-SecureString $servicePrincipal.Secret -AsPlainText);
$TestApplicationId = $servicePrincipal.ApplicationId
$TestApplicationSecret = (ConvertFrom-SecureString $servicePrincipal.Secret -AsPlainText);
Log "Created service principal '$TestApplicationId'"
# Make sure pre- and post-scripts are passed formerly required arguments.
$PSBoundParameters['TestApplicationId'] = $TestApplicationId
$PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret
Log "Created service principal '$TestApplicationId'"
}
if (!$ProvisionerApplicationId) {
$ProvisionerApplicationId = $TestApplicationId