Skip to content

Commit

Permalink
Make sure we always log in as app or provisioner (#1480)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
azure-sdk and heaths authored Nov 6, 2020
1 parent 304e81d commit c29defd
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}

Expand All @@ -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;
Expand All @@ -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);
# Make sure pre- and post-scripts are passed formerly required arguments.
$PSBoundParameters['TestApplicationId'] = $TestApplicationId
$PSBoundParameters['TestApplicationSecret'] = $TestApplicationSecret

Log "Created service principal '$TestApplicationId'"
Log "Created service principal '$TestApplicationId'"
}

if (!$ProvisionerApplicationId) {
$ProvisionerApplicationId = $TestApplicationId
Expand Down

0 comments on commit c29defd

Please sign in to comment.