Last active
March 7, 2018 02:12
-
-
Save PlagueHO/70ae184e1c8d22848ade6a7bc0f8255d to your computer and use it in GitHub Desktop.
Get Azure API Management Git Credential Password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param | |
( | |
[Parameter(Mandatory = $True)] | |
[System.String] | |
$SubscriptionId, | |
[Parameter(Mandatory = $True)] | |
[System.String] | |
$ResourceGroup, | |
[Parameter(Mandatory = $True)] | |
[System.String] | |
$ServiceName, | |
[Parameter()] | |
[ValidateSet('primary','secondary')] | |
[System.String] | |
$KeyType = 'primary', | |
[Parameter()] | |
[timespan] | |
$ExpiryTimespan = (New-Timespan -Hours 2) | |
) | |
$context = New-AzureRmApiManagementContext -ResourceGroupName $ResourceGroup -ServiceName $ServiceName | |
// Correction thanks to @Shaun Titus | |
$expiry = (Get-Date).ToUniversalTime() + $ExpiryTimespan | |
$parameters = @{ | |
"keyType"= $KeyType | |
"expiry"= ('{0:yyyy-MM-ddTHH:mm:ss.000Z}' -f $expiry) | |
} | |
$resourceId = '/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.ApiManagement/service/{2}/users/git' -f $SubscriptionId,$ResourceGroup,$ServiceName | |
$gitUsername = 'apim' | |
$gitPassword = (Invoke-AzureRmResourceAction -Action 'token' -ResourceId $resourceId -Parameters $parameters -ApiVersion '2016-10-10' -Force).Value | |
return @{ | |
GitUsername = $gitUsername | |
GitPassword = $gitPassword | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment