-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
msi for native support #6655
msi for native support #6655
Changes from 10 commits
9ec0e7e
79199a7
b1555f2
a28efdb
b8b3e66
220491b
89aaae1
563c8dd
856c041
08aa73a
93d616b
62756df
d059c7d
7cca967
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -161,7 +161,32 @@ function Initialize-AzureSubscription { | |
|
||
Set-CurrentAzureRMSubscription -SubscriptionId $Endpoint.Data.SubscriptionId -TenantId $Endpoint.Auth.Parameters.TenantId | ||
} | ||
} else { | ||
} elseif ($Endpoint.Auth.Scheme -eq 'ManagedServiceIdentity') { | ||
$accountId = $env:BUILD_BUILDID | ||
if($env:RELEASE_RELEASEID){ | ||
$accountId = $env:RELEASE_RELEASEID | ||
} | ||
$date = Get-Date -Format o | ||
$accountId = -join($accountId, "-", $date) | ||
$port = 50342 | ||
if($Endpoint.Data.MsiPort){ | ||
$port = $Endpoint.Data.MsiPort | ||
} | ||
$msiUri = "http://localhost:$port/oauth2/token" | ||
$response = Invoke-WebRequest -Uri $msiUri -Method GET -Body @{resource= $Endpoint.Url} -Headers @{Metadata="true"} -UseBasicParsing | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these logic has to change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
$content =$response.Content | ConvertFrom-Json | ||
$access_token = $content.access_token | ||
try { | ||
Write-Host "##[command]Add-AzureRmAccount -AccessToken ****** -AccountId $accountId " | ||
$null = Add-AzureRmAccount -AccessToken $access_token -AccountId $accountId | ||
} catch { | ||
# Provide an additional, custom, credentials-related error message. | ||
Write-VstsTaskError -Message $_.Exception.Message | ||
throw (New-Object System.Exception((Get-VstsLocString -Key AZ_ManagedServiceIdentityError), $_.Exception)) | ||
} | ||
|
||
Set-CurrentAzureRMSubscription -SubscriptionId $Endpoint.Data.SubscriptionId -TenantId $Endpoint.Auth.Parameters.TenantId | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you merge with latest changes for TLS done by Rajat. |
||
}else { | ||
throw (Get-VstsLocString -Key AZ_UnsupportedAuthScheme0 -ArgumentList $Endpoint.Auth.Scheme) | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
[CmdletBinding()] | ||
param() | ||
|
||
# Arrange. | ||
. $PSScriptRoot\..\..\..\..\Tests\lib\Initialize-Test.ps1 | ||
Microsoft.PowerShell.Core\Import-Module Microsoft.PowerShell.Security | ||
Unregister-Mock Import-Module | ||
Register-Mock Write-VstsTaskError | ||
$module = Microsoft.PowerShell.Core\Import-Module $PSScriptRoot\.. -PassThru | ||
|
||
$endpoint = @{ | ||
Auth = @{ | ||
Parameters = @{ | ||
ServicePrincipalId = 'Some service principal ID' | ||
ServicePrincipalKey = 'Some service principal key' | ||
TenantId = 'Some tenant ID' | ||
} | ||
Scheme = 'ManagedServiceIdentity' | ||
} | ||
Data = @{ | ||
SubscriptionId = 'Some subscription ID' | ||
SubscriptionName = 'Some subscription name' | ||
} | ||
} | ||
|
||
$content = @" | ||
{"access_token" : "Dummy Token" } | ||
"@ | ||
|
||
$variableSets = @( | ||
@{ StorageAccount = 'Some storage account' } | ||
) | ||
foreach ($variableSet in $variableSets) { | ||
Write-Verbose ('-' * 80) | ||
Unregister-Mock Add-AzureRMAccount | ||
Unregister-Mock Set-CurrentAzureRMSubscription | ||
Unregister-Mock Invoke-WebRequest | ||
Unregister-Mock Set-UserAgent | ||
Register-Mock Add-AzureRMAccount { 'some output' } | ||
Register-Mock Set-CurrentAzureRMSubscription | ||
Register-Mock Set-UserAgent | ||
Register-Mock Invoke-WebRequest { @{Content = $content} } | ||
|
||
# Act. | ||
$result = & $module Initialize-AzureSubscription -Endpoint $endpoint -StorageAccount $variableSet.StorageAccount | ||
|
||
Assert-AreEqual $null $result | ||
Assert-WasCalled Set-CurrentAzureRMSubscription -- -SubscriptionId $endpoint.Data.SubscriptionId -TenantId $endpoint.Auth.Parameters.TenantId | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be good to move the empty check to the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.