Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Azure API Management Git Credential Password
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
You can’t perform that action at this time.