Skip to content

Instantly share code, notes, and snippets.

@PlagueHO
Last active March 7, 2018 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PlagueHO/70ae184e1c8d22848ade6a7bc0f8255d to your computer and use it in GitHub Desktop.
Save PlagueHO/70ae184e1c8d22848ade6a7bc0f8255d to your computer and use it in GitHub Desktop.
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